quickdraw/compilation_equivalence_cases/forwarded_method_block.rb
Lines
0%0 of 42 covered
Branches
0%0 of 2 covered
Methods
0%0 of 8 covered
- Not run
- 3-46-711-15172022-24283040-4244-4547-4954-5659-707275-76
- Never called
EquivalenceCases::ForwardedMethodBlock::OnceState#should_render?EquivalenceCases::ForwardedMethodBlock::FiberAttribute#view_templateEquivalenceCases::ForwardedMethodBlock::FiberAttribute#wrapEquivalenceCases::ForwardedMethodBlock::FiberAttribute#to_h#<Class:EquivalenceCases::ForwardedMethodBlock::ForwardedMethodBlock>#equivalence_scenariosEquivalenceCases::ForwardedMethodBlock::ForwardedMethodBlock#initializeEquivalenceCases::ForwardedMethodBlock::ForwardedMethodBlock#view_templateEquivalenceCases::ForwardedMethodBlock::ForwardedMethodBlock#wrapper
| 1 | # frozen_string_literal: true | |
| 2 | ||
| 3 | 0 | module EquivalenceCases |
| 4 | 0 | module ForwardedMethodBlock |
| 5 | # Renders only the first time it's asked. | |
| 6 | 0 | class OnceState < Phlex::SGML::State |
| 7 | 0 | def should_render? = (@reads = @reads.to_i + 1) == 1 |
| 8 | end | |
| 9 | ||
| 10 | # Suspends while its attributes are serialised, then raises. | |
| 11 | 0 | class FiberAttribute < Phlex::HTML |
| 12 | 0 | def view_template |
| 13 | 0 | fiber = Fiber.new { wrap } |
| 14 | 0 | fiber.resume |
| 15 | 0 | capture { fiber.resume } |
| 16 | rescue RuntimeError | |
| 17 | 0 | plain "rescued" |
| 18 | end | |
| 19 | ||
| 20 | 0 | def wrap(&) = div(data: self, &) |
| 21 | ||
| 22 | 0 | def to_h |
| 23 | 0 | Fiber.yield |
| 24 | 0 | raise "bad" |
| 25 | end | |
| 26 | end | |
| 27 | ||
| 28 | 0 | class ForwardedMethodBlock < Phlex::HTML |
| 29 | VALUES = [ | |
| 30 | 0 | "text <b>", |
| 31 | :a_symbol, | |
| 32 | 1, | |
| 33 | 1.5, | |
| 34 | nil, | |
| 35 | Object.new, | |
| 36 | Phlex::SGML::SafeValue.new("<i>"), | |
| 37 | "safe".dup.extend(Phlex::SGML::SafeObject), | |
| 38 | ].freeze | |
| 39 | ||
| 40 | 0 | def self.equivalence_scenarios |
| 41 | 0 | VALUES.each_with_index.to_h do |value, index| |
| 42 | 0 | ["value #{index}", -> (klass) { klass.new(value).call }] |
| 43 | end.merge( | |
| 44 | 0 | "fragment" => -> (klass) { klass.new("x").call(fragments: [:f]) }, |
| 45 | 0 | "bad attribute" => -> (klass) { klass.new("x", id: Object.new).call }, |
| 46 | "rendering checked once" => -> (klass) { | |
| 47 | 0 | state = OnceState.new(output_buffer: +"", fragments: nil) |
| 48 | 0 | klass.new("x").internal_call(state:) |
| 49 | 0 | state.buffer |
| 50 | }, | |
| 51 | ) | |
| 52 | end | |
| 53 | ||
| 54 | 0 | def initialize(value, id: "w") |
| 55 | 0 | @value = value |
| 56 | 0 | @id = id |
| 57 | end | |
| 58 | ||
| 59 | 0 | def view_template |
| 60 | 0 | value = @value |
| 61 | 0 | wrapper { value } |
| 62 | 0 | wrapper { span { "written" }; "ignored" } |
| 63 | 0 | wrapper |
| 64 | 0 | catch(:out) { wrapper { throw :out } } |
| 65 | 0 | [1, 2].each { |i| wrapper { break if i == 1 } } |
| 66 | 0 | fiber = Fiber.new { wrapper { Fiber.yield; "resumed" } } |
| 67 | 0 | fiber.resume |
| 68 | 0 | plain capture { fiber.resume } |
| 69 | 0 | fragment(:f) { wrapper { "in fragment" } } |
| 70 | 0 | wrapper { raise ArgumentError } |
| 71 | rescue => error | |
| 72 | 0 | plain "rescued #{error.class}" |
| 73 | end | |
| 74 | ||
| 75 | 0 | def wrapper(&) |
| 76 | 0 | article(id: @id, class: "w", &) |
| 77 | end | |
| 78 | end | |
| 79 | end | |
| 80 | end |