quickdraw/compilation_equivalence_cases/conditional_tokens.rb

Lines

0%

0 of 36 covered

Branches

0%

0 of 46 covered

Methods

0%

0 of 6 covered

Not run
3-68-1014-1720-29313337-4245-474952-54
Never called
1# frozen_string_literal: true
2
30module EquivalenceCases
40 module ConditionalTokens
50 class ConditionalTokens < Phlex::HTML
60 def self.equivalence_scenarios
7 {
80 "off" => -> (klass) { klass.new(on: false).call },
90 "fragment" => -> (klass) { klass.new.call(fragments: [:log]) },
100 "raising" => -> (klass) { klass.new(raising: true).call },
11 }
12 end
13
140 def initialize(on: true, raising: false)
150 @on = on
160 @raising = raising
170 @log = []
18 end
19
200 def view_template
210 div(class: ["field", ("field-error" if @on)]) { "a" }
220 span(class: ["badge", (@on ? :is_on : :is_off), ("big" unless @on), 1, ["x", nil]])
230 span(class: [(nil if @on), (false unless @on)])
240 span(class: ['say "hi"', ("on" if @on)], style: ["color: red", ("margin: 0" if @on)])
250 span(class: [("a" if check(:a)), ("b" if check(:b))], title: check(:title))
260 span(class: ["c", ("d" if @on)], title: toggle)
270 span(class: [("a" if @on), ("b" if @on), ("c" if @on), ("d" if @on)])
280 span(class: [("ok" if @on), ({ a: 1 } if @on)])
290 conditions
30 rescue Phlex::ArgumentError, RuntimeError => error
310 plain "rescued #{error.class}"
32 ensure
330 fragment(:log) { plain @log.join(",") }
34 end
35
36 # Expressions that mean something else in condition position.
370 private def conditions
380 div(class: [("in" if 1 in String), ("or" if (false or itself))])
390 2.times { div(class: [("flip" if (@on..!@on))]) } # rubocop:disable Lint/FlipFlop
400 div(class: [("é" if @on)], id: "x")
410 a(href: [(@log ? "/ok" : "\xFF&")])
420 div(class: [(Set["set"] if @on)])
43 end
44
450 private def check(name)
460 @log << name
470 raise "check" if @raising && name == :b
48
490 @on
50 end
51
520 private def toggle
530 @on = !@on
540 "toggled"
55 end
56 end
57 end
58end