Module: Oselvar::Var::Core::ParamDiff
- Defined in:
- lib/oselvar/var/core/param_diff.rb
Overview
Compare a sensor's returned inline actuals against captured document values. Port of param-diff.ts.
Class Method Summary collapse
-
.compare_params(returned, expected, param_spans, source_texts, formats = nil) ⇒ Object
Compare returned actuals against expected document values.
-
.render_param_value(value, format) ⇒ Object
Render one side of a parameter diff as [text, via_format].
Class Method Details
.compare_params(returned, expected, param_spans, source_texts, formats = nil) ⇒ Object
Compare returned actuals against expected document values. Arrays align 1:1; structural equality (==) compares by value across references.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/oselvar/var/core/param_diff.rb', line 29 def compare_params(returned, expected, param_spans, source_texts, formats = nil) expected.each_index.map do |i| ok = returned[i] == expected[i] format = formats && i < formats.length ? formats[i] : nil actual_text, via_format = render_param_value(returned[i], format) expected_text = if i < source_texts.length source_texts[i] else render_param_value(expected[i], format)[0] end CellDiff.new( column: "arg #{i + 1}", span: param_spans[i], expected: expected_text, actual: actual_text, ok: ok, expected_value: expected[i], actual_value: returned[i], formatted: via_format ) end end |
.render_param_value(value, format) ⇒ Object
Render one side of a parameter diff as [text, via_format]. The parameter type's format wins (document notation), else the shared string/primitive/inspect chain; a raising formatter falls through.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/oselvar/var/core/param_diff.rb', line 16 def render_param_value(value, format) if format begin return [format.call(value), true] rescue StandardError # fall through to the native rendering end end [CellDiffs.render_cell_value(value), false] end |