quickdraw/compilation_equivalence_cases/fused_enclosures.rb
Lines
95%22 of 23 covered
Branches
100%4 of 4 covered
Methods
75%3 of 4 covered
- Not run
- 6
- Never called
| 1 | # frozen_string_literal: true | |
| 2 | ||
| 3 | 1 | module EquivalenceCases |
| 4 | 1 | module FusedEnclosures |
| 5 | 1 | class Loud < String |
| 6 | 0 | def to_str = raise("loud") |
| 7 | end | |
| 8 | ||
| 9 | 1 | class FusedEnclosures < Phlex::HTML |
| 10 | 1 | register_element :snow, tag: "雪" |
| 11 | ||
| 12 | VALUES = [ | |
| 13 | 1 | "plain <b>", |
| 14 | :a_symbol, | |
| 15 | 1, | |
| 16 | nil, | |
| 17 | Object.new, | |
| 18 | Loud.new("loud"), | |
| 19 | "safe".dup.extend(Phlex::SGML::SafeObject), | |
| 20 | Phlex::SGML::SafeValue.new("<i>"), | |
| 21 | "é".encode(Encoding::ISO_8859_1), | |
| 22 | "x".encode(Encoding::UTF_16LE), | |
| 23 | ].freeze | |
| 24 | ||
| 25 | 1 | def self.equivalence_scenarios |
| 26 | 2 | VALUES.each_with_index.to_h do |value, index| |
| 27 | 40 | ["value #{index}", -> (klass) { klass.new(value).call }] |
| 28 | end.merge( | |
| 29 | 2 | "after binary" => -> (klass) { klass.new("é", binary: true).call }, |
| 30 | 2 | "fragment" => -> (klass) { klass.new("x").call(fragments: [:f]) }, |
| 31 | ) | |
| 32 | end | |
| 33 | ||
| 34 | 1 | def initialize(value, binary: false) |
| 35 | 24 | @value = value |
| 36 | 24 | @binary = binary |
| 37 | end | |
| 38 | ||
| 39 | 1 | def view_template |
| 40 | 12 | raw safe("\xFF".b) if @binary |
| 41 | 58 | div(class: "card") { div(class: "header") { h3 { @value } }; p { "after" } } |
| 42 | 38 | section { snow { span { @value } } } |
| 43 | 36 | catch(:out) { div { article { throw :out } } } |
| 44 | 72 | ul { [1, 2].each { |i| li { em { break if i == 2 } } } } |
| 45 | 36 | fragment(:f) { aside { nav { @value } } } |
| 46 | rescue => error | |
| 47 | 3 | plain "rescued #{error.class}" |
| 48 | end | |
| 49 | end | |
| 50 | end | |
| 51 | end |