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
1# frozen_string_literal: true
2
30module EquivalenceCases
40 module PerKeyAttributes
50 class Values < Phlex::HTML
60 ToHash = Struct.new(:x, :y) do
70 def to_h = { x:, y: }
8 end
9
100 def initialize
110 @string = 'a"b'
120 @symbol = :snake_case
130 @integer = 1
140 @float = 1.5
150 @true = true
160 @false = false
170 @nil = nil
180 @array = ["a", :b, 1, nil, ["c", :d]]
190 @set = Set["a", :b]
200 @hash = { x: 1, "y" => "z", _: "root", nested: { deep: true } }
210 @styles = { color: "red", "font-size" => "1px", top: nil }
220 @style_list = ["color: red", "top: 0;", { left: 1 }]
230 @sparse_style_list = ["color: red", {}, "", { top: nil }, "x: y"]
240 @empty_styles = { color: nil }
250 @to_hash = ToHash.new(1, "two")
260 @date = Date.new(2020, 1, 2)
270 @time = Time.at(0).utc
28 end
29
300 def view_template
310 div(class: @string, id: "static", data: @hash) { "mixed" }
320 span("data-x" => @integer, class: @symbol, title: @float)
330 span(class: "static", title: @float, id: @string)
340 input(type: "checkbox", checked: @true, disabled: @false, hidden: @nil, name: @string)
350 div(class: @array, data_set: @set)
360 div(style: @styles)
370 div(style: @style_list)
380 div(style: @sparse_style_list)
390 div(style: @empty_styles, id: "empty-styles")
400 div(style: { color: nil }, id: "static-empty-styles")
410 div(style: ["color: red", {}, "x: y"], id: "static-sparse-styles")
420 div(style: @string)
430 div(class: safe("<b>"), onclick: safe("alert(1)"))
440 div(data: @to_hash, title: @date)
450 div(data: { on: @date, at: @time, point: @to_hash }, datetime: @time)
460 div(class: @string, "class" => "string key") # rubocop:disable Style/HashSyntax
470 img(src: "/a.png", alt: @string)
480 input(type: "text", name: @string, value: @string)
490 div(class: "btn #{@symbol}", id: "id-#{@string}", title: "#{@integer}") { "interpolated" } # rubocop:disable Style/RedundantInterpolation
500 a(href: "/users/#{@integer}", class: "link #{@string}") { "reference" }
510 div(class: "btn #{@string}", id: dom_id)
52 end
53
540 def dom_id = "generated"
55 end
56
570 class References < Phlex::HTML
580 def self.equivalence_scenarios
59 {
600 "safe" => -> (klass) { klass.new("/ok?a=1&b=2").call },
610 "javascript" => -> (klass) { klass.new("javascript:alert(1)").call },
620 "obscured" => -> (klass) { klass.new("JAVA\tscript:alert(1)").call },
630 "encoded" => -> (klass) { klass.new("&#106;avascript:alert(1)").call },
640 "named entity" => -> (klass) { klass.new("java&Tab;script:alert(1)").call },
650 "quoted" => -> (klass) { klass.new('/ok"').call },
660 "true" => -> (klass) { klass.new(true).call },
670 "nil" => -> (klass) { klass.new(nil).call },
680 "integer" => -> (klass) { klass.new(1).call },
690 "hash" => -> (klass) { klass.new({ a: 1 }).call },
70 }
71 end
72
730 def initialize(href)
740 @href = href
75 end
76
770 def view_template
780 a(href: @href, class: "link") { "link" }
790 a(href: safe(@href.to_s)) { "safe" }
800 img(src: @href, alt: "image")
810 form(action: @href, method: "post")
82 end
83 end
84
850 class Errors < Phlex::HTML
860 def initialize
870 @bad = Object.new
880 @raising = Object.new.tap { |object| def object.to_h = raise("bad to_h") }
89 end
90
910 def view_template
92 begin
930 div(id: "static", class: @bad)
94 rescue Phlex::ArgumentError
950 plain "rescued after static"
96 end
97
98 begin
990 div(class: @bad, id: "static") { "content" }
100 rescue Phlex::ArgumentError
1010 plain "rescued before static"
102 end
103
104 begin
1050 div(class: "ok", data: @raising, id: @bad)
106 rescue RuntimeError => e
1070 plain e.message
108 end
109
110 begin
1110 div("data-bad name" => @bad)
112 rescue Phlex::ArgumentError
1130 plain "rescued name"
114 end
115
116 begin
1170 div("id" => "string") # rubocop:disable Style/HashSyntax
118 rescue Phlex::ArgumentError
1190 plain "rescued string id"
120 end
121 end
122 end
123
1240 class EvaluationOrder < Phlex::HTML
1250 def initialize
1260 @flag = true
1270 @log = []
128 end
129
1300 def view_template
1310 div(class: @flag, id: flip, title: @flag, "data-a" => flip, lang: @flag)
1320 div(class: @flag ? "on" : "off", id: flip)
1330 div(class: log("a"), id: log("b")) { "order" }
1340 plain @log.join(",")
135 end
136
1370 def flip
1380 @flag = !@flag
1390 @flag.to_s
140 end
141
1420 def log(name)
1430 @log << name
1440 name
145 end
146 end
147 end
148end