quickdraw/compilation_equivalence_cases/direct_attribute_appends.rb

Lines

0%

0 of 28 covered

Branches

0%

0 of 2 covered

Methods

0%

0 of 6 covered

Not run
3-46-79-1115-171923-2426-2933-3437-4446
Never called
1# frozen_string_literal: true
2
30module EquivalenceCases
40 module DirectAttributeAppends
5 # Changes the string it was given when it's serialised.
60 class Mutator
70 def initialize(string) = @string = string
8
90 def to_h
100 @string << " changed"
110 { key: "value" }
12 end
13 end
14
150 class Loud < String
160 def include?(other)
170 raise "loud" if start_with?("raise")
18
190 super
20 end
21 end
22
230 class DirectAttributeAppends < Phlex::HTML
240 def self.equivalence_scenarios
25 {
260 "quoted" => -> (klass) { klass.new(%(say "hi")).call },
270 "loud" => -> (klass) { klass.new(Loud.new("raise")).call },
280 "true" => -> (klass) { klass.new(true).call },
290 "fragment" => -> (klass) { klass.new("x").call(fragments: [:f]) },
30 }
31 end
32
330 def initialize(value = "plain")
340 @value = value
35 end
36
370 def view_template
380 name = +"name"
390 div(title: name, data: Mutator.new(name)) { "a" }
400 other = +"other"
410 div(data: { a: other, b: Mutator.new(other) })
420 input(value: @value, title: @value, class: "c")
430 a(href: "/posts/#{@value}", title: @value)
440 fragment(:f) { span(title: @value) }
45 rescue RuntimeError => error
460 plain "rescued #{error.message}"
47 end
48 end
49 end
50end