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 | ||
| 3 | 0 | module EquivalenceCases |
| 4 | 0 | module TypedAttributeValues |
| 5 | 0 | class Loud < String |
| 6 | 0 | def include?(other) |
| 7 | 0 | raise "loud" if start_with?("raise") |
| 8 | ||
| 9 | 0 | super |
| 10 | end | |
| 11 | end | |
| 12 | ||
| 13 | 0 | class TypedAttributeValues < Phlex::HTML |
| 14 | VALUES = [ | |
| 15 | 0 | 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 | ||
| 37 | 0 | def self.equivalence_scenarios |
| 38 | 0 | VALUES.each_with_index.to_h do |value, index| |
| 39 | 0 | ["value #{index}", -> (klass) { klass.new(value).call }] |
| 40 | 0 | end.merge("fragment" => -> (klass) { klass.new("x").call(fragments: [:f]) }) |
| 41 | end | |
| 42 | ||
| 43 | 0 | def initialize(value) |
| 44 | 0 | @value = value |
| 45 | end | |
| 46 | ||
| 47 | 0 | def view_template |
| 48 | 0 | div(title: @value) { "a" } |
| 49 | 0 | input(value: @value, disabled: @value == "x", class: "c") |
| 50 | 0 | fragment(:f) { span(title: @value) } |
| 51 | 0 | reassigned = +"old" |
| 52 | 0 | reassigned.define_singleton_method(:include?) { |_| reassigned = "new"; false } |
| 53 | 0 | div(title: reassigned) |
| 54 | rescue => error | |
| 55 | 0 | plain "rescued #{error.class}" |
| 56 | end | |
| 57 | end | |
| 58 | end | |
| 59 | end |