quickdraw/compilation_equivalence_cases/typed_attribute_values.rb

Lines

0%

0 of 22 covered

Branches

0%

0 of 2 covered

Methods

0%

0 of 4 covered

Not run
3-79131537-4043-4447-5355
Never called
1# frozen_string_literal: true
2
30module EquivalenceCases
40 module TypedAttributeValues
50 class Loud < String
60 def include?(other)
70 raise "loud" if start_with?("raise")
8
90 super
10 end
11 end
12
130 class TypedAttributeValues < Phlex::HTML
14 VALUES = [
150 true,
16 false,
17 nil,
18 "plain",
19 %(say "hi"),
20 :a_symbol,
21 :"say \"hi_there\"",
22 -2,
23 2 ** 70,
24 1,
25 1.5,
26 [:a, "b"],
27 "x".encode(Encoding::UTF_16LE),
28 "".encode(Encoding::UTF_16LE),
29 "é".dup.force_encoding(Encoding::US_ASCII),
30 Loud.new(%(loud "quote")),
31 Loud.new("raise"),
32 "safe".dup.extend(Phlex::SGML::SafeObject),
33 Phlex::SGML::SafeValue.new(%(a"b)),
34 Object.new,
35 ].freeze
36
370 def self.equivalence_scenarios
380 VALUES.each_with_index.to_h do |value, index|
390 ["value #{index}", -> (klass) { klass.new(value).call }]
400 end.merge("fragment" => -> (klass) { klass.new("x").call(fragments: [:f]) })
41 end
42
430 def initialize(value)
440 @value = value
45 end
46
470 def view_template
480 div(title: @value) { "a" }
490 input(value: @value, disabled: @value == "x", class: "c")
500 fragment(:f) { span(title: @value) }
510 reassigned = +"old"
520 reassigned.define_singleton_method(:include?) { |_| reassigned = "new"; false }
530 div(title: reassigned)
54 rescue => error
550 plain "rescued #{error.class}"
56 end
57 end
58 end
59end