quickdraw/compilation_equivalence_cases/per_key_attributes.rb
Lines
0%0 of 95 covered
Branches
0%0 of 2 covered
Methods
0%0 of 14 covered
- Not run
- 3-710-2730-515457-5860-6973-7477-8185-8891939599101105107111113117119124-127130-134137-139142-144
- Never called
EquivalenceCases::PerKeyAttributes::Values::ToHash#to_hEquivalenceCases::PerKeyAttributes::Values#initializeEquivalenceCases::PerKeyAttributes::Values#view_templateEquivalenceCases::PerKeyAttributes::Values#dom_id#<Class:EquivalenceCases::PerKeyAttributes::References>#equivalence_scenariosEquivalenceCases::PerKeyAttributes::References#initializeEquivalenceCases::PerKeyAttributes::References#view_templateEquivalenceCases::PerKeyAttributes::Errors#initialize#<Class:#<Object>>#to_hEquivalenceCases::PerKeyAttributes::Errors#view_templateEquivalenceCases::PerKeyAttributes::EvaluationOrder#initializeEquivalenceCases::PerKeyAttributes::EvaluationOrder#view_templateEquivalenceCases::PerKeyAttributes::EvaluationOrder#flipEquivalenceCases::PerKeyAttributes::EvaluationOrder#log
| 1 | # frozen_string_literal: true | |
| 2 | ||
| 3 | 0 | module EquivalenceCases |
| 4 | 0 | module PerKeyAttributes |
| 5 | 0 | class Values < Phlex::HTML |
| 6 | 0 | ToHash = Struct.new(:x, :y) do |
| 7 | 0 | def to_h = { x:, y: } |
| 8 | end | |
| 9 | ||
| 10 | 0 | def initialize |
| 11 | 0 | @string = 'a"b' |
| 12 | 0 | @symbol = :snake_case |
| 13 | 0 | @integer = 1 |
| 14 | 0 | @float = 1.5 |
| 15 | 0 | @true = true |
| 16 | 0 | @false = false |
| 17 | 0 | @nil = nil |
| 18 | 0 | @array = ["a", :b, 1, nil, ["c", :d]] |
| 19 | 0 | @set = Set["a", :b] |
| 20 | 0 | @hash = { x: 1, "y" => "z", _: "root", nested: { deep: true } } |
| 21 | 0 | @styles = { color: "red", "font-size" => "1px", top: nil } |
| 22 | 0 | @style_list = ["color: red", "top: 0;", { left: 1 }] |
| 23 | 0 | @sparse_style_list = ["color: red", {}, "", { top: nil }, "x: y"] |
| 24 | 0 | @empty_styles = { color: nil } |
| 25 | 0 | @to_hash = ToHash.new(1, "two") |
| 26 | 0 | @date = Date.new(2020, 1, 2) |
| 27 | 0 | @time = Time.at(0).utc |
| 28 | end | |
| 29 | ||
| 30 | 0 | def view_template |
| 31 | 0 | div(class: @string, id: "static", data: @hash) { "mixed" } |
| 32 | 0 | span("data-x" => @integer, class: @symbol, title: @float) |
| 33 | 0 | span(class: "static", title: @float, id: @string) |
| 34 | 0 | input(type: "checkbox", checked: @true, disabled: @false, hidden: @nil, name: @string) |
| 35 | 0 | div(class: @array, data_set: @set) |
| 36 | 0 | div(style: @styles) |
| 37 | 0 | div(style: @style_list) |
| 38 | 0 | div(style: @sparse_style_list) |
| 39 | 0 | div(style: @empty_styles, id: "empty-styles") |
| 40 | 0 | div(style: { color: nil }, id: "static-empty-styles") |
| 41 | 0 | div(style: ["color: red", {}, "x: y"], id: "static-sparse-styles") |
| 42 | 0 | div(style: @string) |
| 43 | 0 | div(class: safe("<b>"), onclick: safe("alert(1)")) |
| 44 | 0 | div(data: @to_hash, title: @date) |
| 45 | 0 | div(data: { on: @date, at: @time, point: @to_hash }, datetime: @time) |
| 46 | 0 | div(class: @string, "class" => "string key") # rubocop:disable Style/HashSyntax |
| 47 | 0 | img(src: "/a.png", alt: @string) |
| 48 | 0 | input(type: "text", name: @string, value: @string) |
| 49 | 0 | div(class: "btn #{@symbol}", id: "id-#{@string}", title: "#{@integer}") { "interpolated" } # rubocop:disable Style/RedundantInterpolation |
| 50 | 0 | a(href: "/users/#{@integer}", class: "link #{@string}") { "reference" } |
| 51 | 0 | div(class: "btn #{@string}", id: dom_id) |
| 52 | end | |
| 53 | ||
| 54 | 0 | def dom_id = "generated" |
| 55 | end | |
| 56 | ||
| 57 | 0 | class References < Phlex::HTML |
| 58 | 0 | def self.equivalence_scenarios |
| 59 | { | |
| 60 | 0 | "safe" => -> (klass) { klass.new("/ok?a=1&b=2").call }, |
| 61 | 0 | "javascript" => -> (klass) { klass.new("javascript:alert(1)").call }, |
| 62 | 0 | "obscured" => -> (klass) { klass.new("JAVA\tscript:alert(1)").call }, |
| 63 | 0 | "encoded" => -> (klass) { klass.new("javascript:alert(1)").call }, |
| 64 | 0 | "named entity" => -> (klass) { klass.new("java	script:alert(1)").call }, |
| 65 | 0 | "quoted" => -> (klass) { klass.new('/ok"').call }, |
| 66 | 0 | "true" => -> (klass) { klass.new(true).call }, |
| 67 | 0 | "nil" => -> (klass) { klass.new(nil).call }, |
| 68 | 0 | "integer" => -> (klass) { klass.new(1).call }, |
| 69 | 0 | "hash" => -> (klass) { klass.new({ a: 1 }).call }, |
| 70 | } | |
| 71 | end | |
| 72 | ||
| 73 | 0 | def initialize(href) |
| 74 | 0 | @href = href |
| 75 | end | |
| 76 | ||
| 77 | 0 | def view_template |
| 78 | 0 | a(href: @href, class: "link") { "link" } |
| 79 | 0 | a(href: safe(@href.to_s)) { "safe" } |
| 80 | 0 | img(src: @href, alt: "image") |
| 81 | 0 | form(action: @href, method: "post") |
| 82 | end | |
| 83 | end | |
| 84 | ||
| 85 | 0 | class Errors < Phlex::HTML |
| 86 | 0 | def initialize |
| 87 | 0 | @bad = Object.new |
| 88 | 0 | @raising = Object.new.tap { |object| def object.to_h = raise("bad to_h") } |
| 89 | end | |
| 90 | ||
| 91 | 0 | def view_template |
| 92 | begin | |
| 93 | 0 | div(id: "static", class: @bad) |
| 94 | rescue Phlex::ArgumentError | |
| 95 | 0 | plain "rescued after static" |
| 96 | end | |
| 97 | ||
| 98 | begin | |
| 99 | 0 | div(class: @bad, id: "static") { "content" } |
| 100 | rescue Phlex::ArgumentError | |
| 101 | 0 | plain "rescued before static" |
| 102 | end | |
| 103 | ||
| 104 | begin | |
| 105 | 0 | div(class: "ok", data: @raising, id: @bad) |
| 106 | rescue RuntimeError => e | |
| 107 | 0 | plain e.message |
| 108 | end | |
| 109 | ||
| 110 | begin | |
| 111 | 0 | div("data-bad name" => @bad) |
| 112 | rescue Phlex::ArgumentError | |
| 113 | 0 | plain "rescued name" |
| 114 | end | |
| 115 | ||
| 116 | begin | |
| 117 | 0 | div("id" => "string") # rubocop:disable Style/HashSyntax |
| 118 | rescue Phlex::ArgumentError | |
| 119 | 0 | plain "rescued string id" |
| 120 | end | |
| 121 | end | |
| 122 | end | |
| 123 | ||
| 124 | 0 | class EvaluationOrder < Phlex::HTML |
| 125 | 0 | def initialize |
| 126 | 0 | @flag = true |
| 127 | 0 | @log = [] |
| 128 | end | |
| 129 | ||
| 130 | 0 | def view_template |
| 131 | 0 | div(class: @flag, id: flip, title: @flag, "data-a" => flip, lang: @flag) |
| 132 | 0 | div(class: @flag ? "on" : "off", id: flip) |
| 133 | 0 | div(class: log("a"), id: log("b")) { "order" } |
| 134 | 0 | plain @log.join(",") |
| 135 | end | |
| 136 | ||
| 137 | 0 | def flip |
| 138 | 0 | @flag = !@flag |
| 139 | 0 | @flag.to_s |
| 140 | end | |
| 141 | ||
| 142 | 0 | def log(name) |
| 143 | 0 | @log << name |
| 144 | 0 | name |
| 145 | end | |
| 146 | end | |
| 147 | end | |
| 148 | end |