canon 0.1.10 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +13 -61
- data/README.adoc +220 -26
- data/lib/canon/cli.rb +30 -0
- data/lib/canon/commands/diff_command.rb +3 -0
- data/lib/canon/config/env_schema.rb +5 -1
- data/lib/canon/config.rb +30 -0
- data/lib/canon/diff_formatter.rb +102 -12
- data/lib/canon/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e123b3a909e4ca7309ed6815282fd03c86e4514fa325d82f1e8973f1428ce83a
|
|
4
|
+
data.tar.gz: '09e45b9a9f5e8721f4df5b41465b199d0a34824640745321f35cd7edd6d65a91'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c027b7abd237f7b0f3dc679c3b919c11dea6d02f8636aaca9ac95ba56c2d9e321ed3dc23691c33274fa1403f7147b0547011adebb4cb70f1073875cac557a394
|
|
7
|
+
data.tar.gz: 75aea03c181390b0f927c5d7ba979a8ed6a5ab807e9ab40fa281257e3d165fa001e62fa7ad9bfff3c1d007e1d8157aa49c7218cb2a99bb07919efb1b7da6b120
|
data/.rubocop_todo.yml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# This configuration was generated by
|
|
2
2
|
# `rubocop --auto-gen-config`
|
|
3
|
-
# on 2026-01-21
|
|
3
|
+
# on 2026-01-21 06:10:55 UTC using RuboCop version 1.81.7.
|
|
4
4
|
# The point is for the user to remove these configuration records
|
|
5
5
|
# one by one as the offenses are removed from the code base.
|
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
|
@@ -12,51 +12,29 @@ Gemspec/RequiredRubyVersion:
|
|
|
12
12
|
Exclude:
|
|
13
13
|
- 'canon.gemspec'
|
|
14
14
|
|
|
15
|
-
# Offense count:
|
|
15
|
+
# Offense count: 4
|
|
16
16
|
# This cop supports safe autocorrection (--autocorrect).
|
|
17
17
|
# Configuration parameters: EnforcedStyle, IndentationWidth.
|
|
18
18
|
# SupportedStyles: with_first_argument, with_fixed_indentation
|
|
19
19
|
Layout/ArgumentAlignment:
|
|
20
20
|
Exclude:
|
|
21
|
-
- 'lib/canon/
|
|
22
|
-
- '
|
|
23
|
-
- 'spec/canon/diff/xml_serialization_formatter_spec.rb'
|
|
24
|
-
|
|
25
|
-
# Offense count: 1
|
|
26
|
-
# This cop supports safe autocorrection (--autocorrect).
|
|
27
|
-
# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.
|
|
28
|
-
# SupportedHashRocketStyles: key, separator, table
|
|
29
|
-
# SupportedColonStyles: key, separator, table
|
|
30
|
-
# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
|
|
31
|
-
Layout/HashAlignment:
|
|
32
|
-
Exclude:
|
|
33
|
-
- 'test_verify_equivalent.rb'
|
|
21
|
+
- 'lib/canon/diff_formatter.rb'
|
|
22
|
+
- 'spec/canon/diff_formatter_spec.rb'
|
|
34
23
|
|
|
35
|
-
# Offense count:
|
|
24
|
+
# Offense count: 705
|
|
36
25
|
# This cop supports safe autocorrection (--autocorrect).
|
|
37
26
|
# Configuration parameters: Max, AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
|
|
38
27
|
# URISchemes: http, https
|
|
39
28
|
Layout/LineLength:
|
|
40
29
|
Enabled: false
|
|
41
30
|
|
|
42
|
-
# Offense count:
|
|
43
|
-
# This cop supports safe autocorrection (--autocorrect).
|
|
44
|
-
# Configuration parameters: EnforcedStyle, IndentationWidth.
|
|
45
|
-
# SupportedStyles: aligned, indented
|
|
46
|
-
Layout/MultilineOperationIndentation:
|
|
47
|
-
Exclude:
|
|
48
|
-
- 'lib/canon/diff/diff_classifier.rb'
|
|
49
|
-
- 'lib/canon/diff/xml_serialization_formatter.rb'
|
|
50
|
-
|
|
51
|
-
# Offense count: 17
|
|
31
|
+
# Offense count: 5
|
|
52
32
|
# This cop supports safe autocorrection (--autocorrect).
|
|
53
33
|
# Configuration parameters: AllowInHeredoc.
|
|
54
34
|
Layout/TrailingWhitespace:
|
|
55
35
|
Exclude:
|
|
56
|
-
- 'lib/canon/
|
|
57
|
-
- '
|
|
58
|
-
- 'spec/canon/diff/xml_serialization_formatter_spec.rb'
|
|
59
|
-
- 'test_verify_equivalent.rb'
|
|
36
|
+
- 'lib/canon/diff_formatter.rb'
|
|
37
|
+
- 'spec/canon/diff_formatter_spec.rb'
|
|
60
38
|
|
|
61
39
|
# Offense count: 48
|
|
62
40
|
# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches, IgnoreDuplicateElseBranch.
|
|
@@ -98,7 +76,7 @@ Lint/UnusedMethodArgument:
|
|
|
98
76
|
- 'lib/canon/diff_formatter/by_line/xml_formatter.rb'
|
|
99
77
|
- 'lib/canon/diff_formatter/by_object/base_formatter.rb'
|
|
100
78
|
|
|
101
|
-
# Offense count:
|
|
79
|
+
# Offense count: 209
|
|
102
80
|
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max.
|
|
103
81
|
Metrics/AbcSize:
|
|
104
82
|
Enabled: false
|
|
@@ -114,12 +92,12 @@ Metrics/BlockLength:
|
|
|
114
92
|
Metrics/CyclomaticComplexity:
|
|
115
93
|
Enabled: false
|
|
116
94
|
|
|
117
|
-
# Offense count:
|
|
95
|
+
# Offense count: 362
|
|
118
96
|
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
|
119
97
|
Metrics/MethodLength:
|
|
120
98
|
Max: 110
|
|
121
99
|
|
|
122
|
-
# Offense count:
|
|
100
|
+
# Offense count: 44
|
|
123
101
|
# Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
|
|
124
102
|
Metrics/ParameterLists:
|
|
125
103
|
Max: 9
|
|
@@ -182,7 +160,7 @@ RSpec/DescribeMethod:
|
|
|
182
160
|
- 'spec/canon/comparison/multiple_differences_spec.rb'
|
|
183
161
|
- 'spec/canon/diff_formatter/character_map_customization_spec.rb'
|
|
184
162
|
|
|
185
|
-
# Offense count:
|
|
163
|
+
# Offense count: 679
|
|
186
164
|
# Configuration parameters: CountAsOne.
|
|
187
165
|
RSpec/ExampleLength:
|
|
188
166
|
Max: 67
|
|
@@ -233,7 +211,7 @@ RSpec/MultipleDescribes:
|
|
|
233
211
|
Exclude:
|
|
234
212
|
- 'spec/canon/comparison/match_options_spec.rb'
|
|
235
213
|
|
|
236
|
-
# Offense count:
|
|
214
|
+
# Offense count: 522
|
|
237
215
|
RSpec/MultipleExpectations:
|
|
238
216
|
Max: 15
|
|
239
217
|
|
|
@@ -311,35 +289,9 @@ Style/IdenticalConditionalBranches:
|
|
|
311
289
|
- 'lib/canon/diff_formatter/by_object/base_formatter.rb'
|
|
312
290
|
- 'lib/canon/diff_formatter/legend.rb'
|
|
313
291
|
|
|
314
|
-
# Offense count: 2
|
|
315
|
-
# This cop supports unsafe autocorrection (--autocorrect-all).
|
|
316
|
-
# Configuration parameters: InverseMethods, InverseBlocks.
|
|
317
|
-
Style/InverseMethods:
|
|
318
|
-
Exclude:
|
|
319
|
-
- 'lib/canon/comparison/markup_comparator.rb'
|
|
320
|
-
- 'lib/canon/comparison/xml_comparator/diff_node_builder.rb'
|
|
321
|
-
|
|
322
292
|
# Offense count: 1
|
|
323
293
|
# Configuration parameters: AllowedMethods.
|
|
324
294
|
# AllowedMethods: respond_to_missing?
|
|
325
295
|
Style/OptionalBooleanParameter:
|
|
326
296
|
Exclude:
|
|
327
297
|
- 'lib/canon/diff_formatter/debug_output.rb'
|
|
328
|
-
|
|
329
|
-
# Offense count: 3
|
|
330
|
-
# This cop supports safe autocorrection (--autocorrect).
|
|
331
|
-
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
|
|
332
|
-
# SupportedStyles: single_quotes, double_quotes
|
|
333
|
-
Style/StringLiterals:
|
|
334
|
-
Exclude:
|
|
335
|
-
- 'lib/canon/comparison/markup_comparator.rb'
|
|
336
|
-
- 'lib/canon/comparison/xml_comparator/diff_node_builder.rb'
|
|
337
|
-
- 'test_verify_equivalent.rb'
|
|
338
|
-
|
|
339
|
-
# Offense count: 12
|
|
340
|
-
# This cop supports safe autocorrection (--autocorrect).
|
|
341
|
-
# Configuration parameters: EnforcedStyleForMultiline.
|
|
342
|
-
# SupportedStylesForMultiline: comma, consistent_comma, diff_comma, no_comma
|
|
343
|
-
Style/TrailingCommaInArguments:
|
|
344
|
-
Exclude:
|
|
345
|
-
- 'spec/canon/diff/xml_serialization_formatter_spec.rb'
|
data/README.adoc
CHANGED
|
@@ -224,68 +224,262 @@ expect(actual).to be_xml_equivalent_to(expected)
|
|
|
224
224
|
.show_diffs(:normative)
|
|
225
225
|
----
|
|
226
226
|
|
|
227
|
-
===
|
|
227
|
+
=== Input display options
|
|
228
228
|
|
|
229
|
-
When debugging test failures, it's often helpful to see the exact
|
|
230
|
-
|
|
231
|
-
`verbose_diff` option displays the original input strings in an RSpec-style
|
|
232
|
-
format with line numbers.
|
|
229
|
+
When debugging test failures, it's often helpful to see the exact inputs that were
|
|
230
|
+
passed to the comparison. Canon provides four input display options:
|
|
233
231
|
|
|
232
|
+
`show_raw_inputs`:: Show raw/original file contents (before preprocessing)
|
|
233
|
+
|
|
234
|
+
`show_preprocessed_inputs`:: Show what was actually compared (after preprocessing)
|
|
235
|
+
|
|
236
|
+
`show_line_numbered_inputs`:: Show raw inputs with line numbers (for reference)
|
|
237
|
+
|
|
238
|
+
`verbose_diff`:: Convenience flag that enables all three options above
|
|
239
|
+
|
|
240
|
+
You can enable any combination of them independently.
|
|
241
|
+
|
|
242
|
+
==== Show raw inputs
|
|
243
|
+
|
|
244
|
+
Display the raw file contents before any preprocessing. This shows exactly what's
|
|
245
|
+
in your files, useful for copying to specs.
|
|
246
|
+
|
|
247
|
+
**Ruby API:**
|
|
234
248
|
[source,ruby]
|
|
235
249
|
----
|
|
236
|
-
# Enable
|
|
250
|
+
# Enable raw input display in configuration
|
|
237
251
|
Canon::Config.configure do |config|
|
|
238
|
-
config.xml.diff.
|
|
252
|
+
config.xml.diff.show_raw_inputs = true
|
|
239
253
|
end
|
|
240
254
|
|
|
241
255
|
# Or programmatically for a specific comparison
|
|
242
256
|
result = Canon::Comparison.equivalent?(xml1, xml2,
|
|
243
257
|
verbose: true,
|
|
244
|
-
|
|
258
|
+
show_raw_inputs: true
|
|
245
259
|
)
|
|
246
260
|
----
|
|
247
261
|
|
|
262
|
+
**CLI usage:**
|
|
263
|
+
[source,bash]
|
|
264
|
+
----
|
|
265
|
+
# Show raw file contents (for copying to specs)
|
|
266
|
+
$ canon diff file1.xml file2.xml --show-raw-inputs
|
|
267
|
+
|
|
268
|
+
# Show both raw and preprocessed (full trace)
|
|
269
|
+
$ canon diff file1.xml file2.xml --show-raw-inputs --show-preprocessed-inputs
|
|
270
|
+
----
|
|
271
|
+
|
|
272
|
+
**Environment variables:**
|
|
273
|
+
[source,bash]
|
|
274
|
+
----
|
|
275
|
+
# Global (all formats)
|
|
276
|
+
export CANON_SHOW_RAW_INPUTS=true
|
|
277
|
+
|
|
278
|
+
# Format-specific
|
|
279
|
+
export CANON_XML_SHOW_RAW_INPUTS=true
|
|
280
|
+
export CANON_HTML_SHOW_RAW_INPUTS=true
|
|
281
|
+
export CANON_JSON_SHOW_RAW_INPUTS=true
|
|
282
|
+
export CANON_YAML_SHOW_RAW_INPUTS=true
|
|
283
|
+
----
|
|
284
|
+
|
|
248
285
|
**Output format:**
|
|
249
286
|
----
|
|
250
|
-
|
|
251
|
-
ORIGINAL INPUT STRINGS
|
|
252
|
-
==================================================================
|
|
287
|
+
=== ORIGINAL INPUTS (Raw) ===
|
|
253
288
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
289
|
+
EXPECTED:
|
|
290
|
+
----------------------------------------------------------------------
|
|
291
|
+
<root> hello
|
|
292
|
+
world</root>
|
|
293
|
+
|
|
294
|
+
RECEIVED:
|
|
295
|
+
----------------------------------------------------------------------
|
|
296
|
+
<root>hello world</root>
|
|
297
|
+
|
|
298
|
+
----
|
|
299
|
+
|
|
300
|
+
==== Show preprocessed inputs
|
|
301
|
+
|
|
302
|
+
Display the content after preprocessing (c14n, normalize, format, etc.).
|
|
303
|
+
This shows what the comparison actually compared, useful for understanding
|
|
304
|
+
how preprocessing affects your content.
|
|
305
|
+
|
|
306
|
+
**Ruby API:**
|
|
307
|
+
[source,ruby]
|
|
308
|
+
----
|
|
309
|
+
# Enable preprocessed input display in configuration
|
|
310
|
+
Canon::Config.configure do |config|
|
|
311
|
+
config.xml.diff.show_preprocessed_inputs = true
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
# Or programmatically for a specific comparison
|
|
315
|
+
result = Canon::Comparison.equivalent?(xml1, xml2,
|
|
316
|
+
verbose: true,
|
|
317
|
+
show_preprocessed_inputs: true
|
|
318
|
+
)
|
|
319
|
+
----
|
|
320
|
+
|
|
321
|
+
**CLI usage:**
|
|
322
|
+
[source,bash]
|
|
323
|
+
----
|
|
324
|
+
# Show what was actually compared
|
|
325
|
+
$ canon diff file1.xml file2.xml --show-preprocessed-inputs
|
|
326
|
+
|
|
327
|
+
# Preprocess with normalization and show what was compared
|
|
328
|
+
$ canon diff file1.xml file2.xml --preprocessing normalize --show-preprocessed-inputs
|
|
329
|
+
----
|
|
330
|
+
|
|
331
|
+
**Environment variables:**
|
|
332
|
+
[source,bash]
|
|
333
|
+
----
|
|
334
|
+
# Global (all formats)
|
|
335
|
+
export CANON_SHOW_PROCESSED_INPUTS=true
|
|
336
|
+
|
|
337
|
+
# Format-specific
|
|
338
|
+
export CANON_XML_SHOW_PROCESSED_INPUTS=true
|
|
339
|
+
export CANON_HTML_SHOW_PROCESSED_INPUTS=true
|
|
340
|
+
export CANON_JSON_SHOW_PROCESSED_INPUTS=true
|
|
341
|
+
export CANON_YAML_SHOW_PROCESSED_INPUTS=true
|
|
342
|
+
----
|
|
343
|
+
|
|
344
|
+
**Output format:**
|
|
345
|
+
----
|
|
346
|
+
=== PREPROCESSED INPUTS (Compared) ===
|
|
347
|
+
Preprocessing: normalize
|
|
348
|
+
|
|
349
|
+
EXPECTED:
|
|
350
|
+
----------------------------------------------------------------------
|
|
351
|
+
<root> hello world </root>
|
|
352
|
+
|
|
353
|
+
RECEIVED:
|
|
354
|
+
----------------------------------------------------------------------
|
|
355
|
+
<root>hello world</root>
|
|
258
356
|
|
|
259
|
-
|
|
357
|
+
----
|
|
358
|
+
|
|
359
|
+
==== Show line-numbered inputs
|
|
360
|
+
|
|
361
|
+
Display raw inputs with line numbers (RSpec-style format). Useful for
|
|
362
|
+
pinpointing specific lines when debugging.
|
|
363
|
+
|
|
364
|
+
**Ruby API:**
|
|
365
|
+
[source,ruby]
|
|
366
|
+
----
|
|
367
|
+
# Enable line-numbered input display in configuration
|
|
368
|
+
Canon::Config.configure do |config|
|
|
369
|
+
config.xml.diff.show_line_numbered_inputs = true
|
|
370
|
+
end
|
|
371
|
+
|
|
372
|
+
# Or programmatically for a specific comparison
|
|
373
|
+
result = Canon::Comparison.equivalent?(xml1, xml2,
|
|
374
|
+
verbose: true,
|
|
375
|
+
show_line_numbered_inputs: true
|
|
376
|
+
)
|
|
377
|
+
----
|
|
378
|
+
|
|
379
|
+
**CLI usage:**
|
|
380
|
+
[source,bash]
|
|
381
|
+
----
|
|
382
|
+
# Show raw inputs with line numbers (RSpec-style)
|
|
383
|
+
$ canon diff file1.xml file2.xml --show-line-numbered-inputs
|
|
384
|
+
----
|
|
385
|
+
|
|
386
|
+
**Environment variables:**
|
|
387
|
+
[source,bash]
|
|
388
|
+
----
|
|
389
|
+
# Global (all formats)
|
|
390
|
+
export CANON_SHOW_LINE_NUMBERED_INPUTS=true
|
|
391
|
+
|
|
392
|
+
# Format-specific
|
|
393
|
+
export CANON_XML_SHOW_LINE_NUMBERED_INPUTS=true
|
|
394
|
+
export CANON_HTML_SHOW_LINE_NUMBERED_INPUTS=true
|
|
395
|
+
export CANON_JSON_SHOW_LINE_NUMBERED_INPUTS=true
|
|
396
|
+
export CANON_YAML_SHOW_LINE_NUMBERED_INPUTS=true
|
|
397
|
+
----
|
|
398
|
+
|
|
399
|
+
**Output format:**
|
|
400
|
+
----
|
|
401
|
+
======================================================================
|
|
402
|
+
ORIGINAL INPUTS (with line numbers)
|
|
403
|
+
======================================================================
|
|
404
|
+
|
|
405
|
+
Expected:
|
|
260
406
|
1 | <root>
|
|
261
|
-
2 |
|
|
407
|
+
2 | hello
|
|
262
408
|
3 | </root>
|
|
263
409
|
|
|
264
|
-
|
|
410
|
+
Received:
|
|
411
|
+
1 | <root>hello world</root>
|
|
412
|
+
|
|
413
|
+
======================================================================
|
|
265
414
|
----
|
|
266
415
|
|
|
267
|
-
|
|
416
|
+
==== Verbose diff (all input displays)
|
|
268
417
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
418
|
+
The `verbose_diff` option is a convenience flag that enables all three input
|
|
419
|
+
display options at once. This is useful for maximum debugging output.
|
|
420
|
+
|
|
421
|
+
**Ruby API:**
|
|
422
|
+
[source,ruby]
|
|
423
|
+
----
|
|
424
|
+
# Enable all input displays in configuration
|
|
425
|
+
Canon::Config.configure do |config|
|
|
426
|
+
config.xml.diff.verbose_diff = true
|
|
427
|
+
end
|
|
273
428
|
|
|
274
|
-
|
|
429
|
+
# Or programmatically for a specific comparison
|
|
430
|
+
result = Canon::Comparison.equivalent?(xml1, xml2,
|
|
431
|
+
verbose: true,
|
|
432
|
+
verbose_diff: true
|
|
433
|
+
)
|
|
434
|
+
----
|
|
435
|
+
|
|
436
|
+
**CLI usage:**
|
|
437
|
+
[source,bash]
|
|
438
|
+
----
|
|
439
|
+
# Show all three input displays
|
|
440
|
+
$ canon diff file1.xml file2.xml --verbose
|
|
441
|
+
----
|
|
442
|
+
|
|
443
|
+
**Environment variables:**
|
|
275
444
|
[source,bash]
|
|
276
445
|
----
|
|
446
|
+
# Format-specific
|
|
277
447
|
export CANON_XML_DIFF_VERBOSE_DIFF=true
|
|
278
448
|
export CANON_HTML_DIFF_VERBOSE_DIFF=true
|
|
279
449
|
export CANON_JSON_DIFF_VERBOSE_DIFF=true
|
|
280
450
|
export CANON_YAML_DIFF_VERBOSE_DIFF=true
|
|
281
451
|
----
|
|
282
452
|
|
|
453
|
+
==== When to use each option
|
|
454
|
+
|
|
455
|
+
`show_raw_inputs`::
|
|
456
|
+
** You want to copy the expected output to paste into your test specs
|
|
457
|
+
** You need to see the exact formatting/structure of your input files
|
|
458
|
+
** You're debugging file reading/parsing issues
|
|
459
|
+
|
|
460
|
+
`show_preprocessed_inputs`::
|
|
461
|
+
** You want to understand what the comparison actually compared
|
|
462
|
+
** You're debugging why two documents are considered equivalent (or not)
|
|
463
|
+
** You need to trace the effect of preprocessing (c14n, normalize, format)
|
|
464
|
+
|
|
465
|
+
`show_line_numbered_inputs`::
|
|
466
|
+
** You need line numbers for pinpointing specific lines
|
|
467
|
+
** You prefer the RSpec-style format
|
|
468
|
+
** You're collaborating on debugging with others
|
|
469
|
+
|
|
470
|
+
`verbose_diff`::
|
|
471
|
+
** You want maximum debugging output (all three displays at once)
|
|
472
|
+
** You're doing initial investigation of a complex comparison issue
|
|
473
|
+
|
|
283
474
|
=== Algorithm choice
|
|
284
475
|
|
|
285
476
|
Canon provides two diff algorithms:
|
|
286
477
|
|
|
287
|
-
|
|
288
|
-
|
|
478
|
+
DOM diff (default):: Stable, position-based comparison for traditional
|
|
479
|
+
line-by-line output
|
|
480
|
+
|
|
481
|
+
Semantic tree diff (experimental):: Advanced operation detection (INSERT,
|
|
482
|
+
DELETE, UPDATE, MOVE, MERGE, SPLIT, UPGRADE, DOWNGRADE)
|
|
289
483
|
|
|
290
484
|
[source,ruby]
|
|
291
485
|
----
|
data/lib/canon/cli.rb
CHANGED
|
@@ -126,6 +126,24 @@ module Canon
|
|
|
126
126
|
|
|
127
127
|
# Disable color output
|
|
128
128
|
$ canon diff file1.xml file2.xml --no-color
|
|
129
|
+
|
|
130
|
+
# Show raw file contents (for copying to specs)
|
|
131
|
+
$ canon diff file1.xml file2.xml --show-raw-inputs
|
|
132
|
+
|
|
133
|
+
# Show preprocessed contents (what was actually compared)
|
|
134
|
+
$ canon diff file1.xml file2.xml --show-preprocessed-inputs
|
|
135
|
+
|
|
136
|
+
# Show both raw and preprocessed (full trace)
|
|
137
|
+
$ canon diff file1.xml file2.xml --show-raw-inputs --show-preprocessed-inputs
|
|
138
|
+
|
|
139
|
+
# Preprocess with normalization and show what was compared
|
|
140
|
+
$ canon diff file1.xml file2.xml --preprocessing normalize --show-preprocessed-inputs
|
|
141
|
+
|
|
142
|
+
# Show raw inputs with line numbers (RSpec-style)
|
|
143
|
+
$ canon diff file1.xml file2.xml --show-line-numbered-inputs
|
|
144
|
+
|
|
145
|
+
# Verbose mode (shows all three input displays)
|
|
146
|
+
$ canon diff file1.xml file2.xml --verbose
|
|
129
147
|
DESC
|
|
130
148
|
method_option :format,
|
|
131
149
|
aliases: "-f",
|
|
@@ -213,6 +231,18 @@ module Canon
|
|
|
213
231
|
method_option :diff_grouping_lines,
|
|
214
232
|
type: :numeric,
|
|
215
233
|
desc: "Group diffs within N lines into context blocks (default: no grouping)"
|
|
234
|
+
method_option :show_raw_inputs,
|
|
235
|
+
type: :boolean,
|
|
236
|
+
default: false,
|
|
237
|
+
desc: "Show raw/original file contents before diff"
|
|
238
|
+
method_option :show_preprocessed_inputs,
|
|
239
|
+
type: :boolean,
|
|
240
|
+
default: false,
|
|
241
|
+
desc: "Show preprocessed contents (what was actually compared)"
|
|
242
|
+
method_option :show_line_numbered_inputs,
|
|
243
|
+
type: :boolean,
|
|
244
|
+
default: false,
|
|
245
|
+
desc: "Show raw inputs with line numbers (RSpec-style)"
|
|
216
246
|
def diff(file1, file2)
|
|
217
247
|
Commands::DiffCommand.new(options).run(file1, file2)
|
|
218
248
|
end
|
|
@@ -53,6 +53,9 @@ module Canon
|
|
|
53
53
|
context_lines: @options.fetch(:context_lines, 3),
|
|
54
54
|
diff_grouping_lines: @options[:diff_grouping_lines],
|
|
55
55
|
show_diffs: @options[:show_diffs]&.to_sym || :all,
|
|
56
|
+
show_raw_inputs: @options[:show_raw_inputs] || false,
|
|
57
|
+
show_preprocessed_inputs: @options[:show_preprocessed_inputs] || false,
|
|
58
|
+
show_line_numbered_inputs: @options[:show_line_numbered_inputs] || false,
|
|
56
59
|
)
|
|
57
60
|
|
|
58
61
|
# Show configuration in verbose mode using shared DebugOutput
|
|
@@ -14,6 +14,9 @@ module Canon
|
|
|
14
14
|
show_diffs: :symbol,
|
|
15
15
|
verbose_diff: :boolean,
|
|
16
16
|
algorithm: :symbol,
|
|
17
|
+
show_raw_inputs: :boolean,
|
|
18
|
+
show_preprocessed_inputs: :boolean,
|
|
19
|
+
show_line_numbered_inputs: :boolean,
|
|
17
20
|
|
|
18
21
|
# MatchConfig attributes
|
|
19
22
|
profile: :symbol,
|
|
@@ -42,7 +45,8 @@ module Canon
|
|
|
42
45
|
|
|
43
46
|
def all_diff_attributes
|
|
44
47
|
%i[mode use_color context_lines grouping_lines show_diffs
|
|
45
|
-
verbose_diff algorithm
|
|
48
|
+
verbose_diff algorithm show_raw_inputs show_preprocessed_inputs
|
|
49
|
+
show_line_numbered_inputs max_file_size max_node_count max_diff_lines]
|
|
46
50
|
end
|
|
47
51
|
|
|
48
52
|
def all_match_attributes
|
data/lib/canon/config.rb
CHANGED
|
@@ -221,6 +221,30 @@ module Canon
|
|
|
221
221
|
@resolver.set_programmatic(:verbose_diff, value)
|
|
222
222
|
end
|
|
223
223
|
|
|
224
|
+
def show_raw_inputs
|
|
225
|
+
@resolver.resolve(:show_raw_inputs)
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
def show_raw_inputs=(value)
|
|
229
|
+
@resolver.set_programmatic(:show_raw_inputs, value)
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
def show_preprocessed_inputs
|
|
233
|
+
@resolver.resolve(:show_preprocessed_inputs)
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
def show_preprocessed_inputs=(value)
|
|
237
|
+
@resolver.set_programmatic(:show_preprocessed_inputs, value)
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
def show_line_numbered_inputs
|
|
241
|
+
@resolver.resolve(:show_line_numbered_inputs)
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
def show_line_numbered_inputs=(value)
|
|
245
|
+
@resolver.set_programmatic(:show_line_numbered_inputs, value)
|
|
246
|
+
end
|
|
247
|
+
|
|
224
248
|
def algorithm
|
|
225
249
|
@resolver.resolve(:algorithm)
|
|
226
250
|
end
|
|
@@ -266,6 +290,9 @@ module Canon
|
|
|
266
290
|
show_diffs: show_diffs,
|
|
267
291
|
verbose_diff: verbose_diff,
|
|
268
292
|
diff_algorithm: algorithm,
|
|
293
|
+
show_raw_inputs: show_raw_inputs,
|
|
294
|
+
show_preprocessed_inputs: show_preprocessed_inputs,
|
|
295
|
+
show_line_numbered_inputs: show_line_numbered_inputs,
|
|
269
296
|
max_file_size: max_file_size,
|
|
270
297
|
max_node_count: max_node_count,
|
|
271
298
|
max_diff_lines: max_diff_lines,
|
|
@@ -283,6 +310,9 @@ module Canon
|
|
|
283
310
|
show_diffs: :all,
|
|
284
311
|
verbose_diff: false,
|
|
285
312
|
algorithm: :dom,
|
|
313
|
+
show_raw_inputs: false,
|
|
314
|
+
show_preprocessed_inputs: false,
|
|
315
|
+
show_line_numbered_inputs: false,
|
|
286
316
|
max_file_size: 5_242_880, # 5MB in bytes
|
|
287
317
|
max_node_count: 10_000, # Maximum nodes in tree
|
|
288
318
|
max_diff_lines: 10_000, # Maximum diff output lines
|
data/lib/canon/diff_formatter.rb
CHANGED
|
@@ -162,16 +162,23 @@ module Canon
|
|
|
162
162
|
Comparison::UNEQUAL_PRIMITIVES => "Unequal primitive values",
|
|
163
163
|
}.freeze
|
|
164
164
|
|
|
165
|
+
# rubocop:disable Metrics/ParameterLists
|
|
165
166
|
def initialize(use_color: true, mode: :by_object, context_lines: 3,
|
|
166
167
|
diff_grouping_lines: nil, visualization_map: nil,
|
|
167
168
|
character_map_file: nil, character_definitions: nil,
|
|
168
|
-
show_diffs: :all, verbose_diff: false
|
|
169
|
+
show_diffs: :all, verbose_diff: false,
|
|
170
|
+
show_raw_inputs: false, show_preprocessed_inputs: false,
|
|
171
|
+
show_line_numbered_inputs: false)
|
|
172
|
+
# rubocop:enable Metrics/ParameterLists
|
|
169
173
|
@use_color = use_color
|
|
170
174
|
@mode = mode
|
|
171
175
|
@context_lines = context_lines
|
|
172
176
|
@diff_grouping_lines = diff_grouping_lines
|
|
173
177
|
@show_diffs = show_diffs
|
|
174
178
|
@verbose_diff = verbose_diff
|
|
179
|
+
@show_raw_inputs = show_raw_inputs
|
|
180
|
+
@show_preprocessed_inputs = show_preprocessed_inputs
|
|
181
|
+
@show_line_numbered_inputs = show_line_numbered_inputs
|
|
175
182
|
@visualization_map = build_visualization_map(
|
|
176
183
|
visualization_map: visualization_map,
|
|
177
184
|
character_map_file: character_map_file,
|
|
@@ -329,15 +336,39 @@ module Canon
|
|
|
329
336
|
)
|
|
330
337
|
end
|
|
331
338
|
|
|
332
|
-
#
|
|
333
|
-
|
|
339
|
+
# verbose_diff enables all three input displays as a convenience
|
|
340
|
+
verbose = @verbose_diff || @show_raw_inputs
|
|
341
|
+
show_prep = @verbose_diff || @show_preprocessed_inputs
|
|
342
|
+
show_line = @verbose_diff || @show_line_numbered_inputs
|
|
343
|
+
|
|
344
|
+
# 3. Raw/Original Input Display (when show_raw_inputs is enabled)
|
|
345
|
+
if verbose && comparison_result.is_a?(Canon::Comparison::ComparisonResult)
|
|
346
|
+
original1, original2 = comparison_result.original_strings
|
|
347
|
+
if original1 && original2
|
|
348
|
+
output << format_raw_inputs(original1, original2)
|
|
349
|
+
end
|
|
350
|
+
end
|
|
351
|
+
|
|
352
|
+
# 4. Preprocessed Input Display (when show_preprocessed_inputs is enabled)
|
|
353
|
+
if show_prep && comparison_result.is_a?(Canon::Comparison::ComparisonResult)
|
|
354
|
+
preprocessed1, preprocessed2 = comparison_result.preprocessed_strings
|
|
355
|
+
if preprocessed1 && preprocessed2
|
|
356
|
+
preprocessing_info = comparison_result.match_options&.dig(:match,
|
|
357
|
+
:preprocessing)
|
|
358
|
+
output << format_preprocessed_inputs(preprocessed1, preprocessed2,
|
|
359
|
+
preprocessing_info)
|
|
360
|
+
end
|
|
361
|
+
end
|
|
362
|
+
|
|
363
|
+
# 5. Line-Numbered Input Display (when show_line_numbered_inputs is enabled)
|
|
364
|
+
if show_line && comparison_result.is_a?(Canon::Comparison::ComparisonResult)
|
|
334
365
|
original1, original2 = comparison_result.original_strings
|
|
335
366
|
if original1 && original2
|
|
336
|
-
output <<
|
|
367
|
+
output << format_line_numbered_inputs(original1, original2)
|
|
337
368
|
end
|
|
338
369
|
end
|
|
339
370
|
|
|
340
|
-
#
|
|
371
|
+
# 6. Main diff output (by-line or by-object) - ALWAYS
|
|
341
372
|
|
|
342
373
|
# Check if comparison result is a ComparisonResult object
|
|
343
374
|
if comparison_result.is_a?(Canon::Comparison::ComparisonResult)
|
|
@@ -428,24 +459,24 @@ module Canon
|
|
|
428
459
|
html.to_s
|
|
429
460
|
end
|
|
430
461
|
|
|
431
|
-
# Format original input strings
|
|
432
|
-
# Shows the actual strings that were passed in
|
|
462
|
+
# Format original input strings with line numbers (RSpec-style)
|
|
463
|
+
# Shows the actual strings that were passed in with line numbers for reference
|
|
433
464
|
#
|
|
434
465
|
# @param original1 [String] First original input string
|
|
435
466
|
# @param original2 [String] Second original input string
|
|
436
|
-
# @return [String] Formatted display
|
|
437
|
-
def
|
|
467
|
+
# @return [String] Formatted display with line numbers
|
|
468
|
+
def format_line_numbered_inputs(original1, original2)
|
|
438
469
|
return "" if original1.nil? || original2.nil?
|
|
439
470
|
|
|
440
471
|
output = []
|
|
441
472
|
output << ""
|
|
442
473
|
output << colorize("=" * 70, :cyan, :bold)
|
|
443
|
-
output << colorize(" ORIGINAL
|
|
474
|
+
output << colorize(" ORIGINAL INPUTS (with line numbers)", :cyan, :bold)
|
|
444
475
|
output << colorize("=" * 70, :cyan, :bold)
|
|
445
476
|
output << ""
|
|
446
477
|
|
|
447
478
|
# Format expected
|
|
448
|
-
output << colorize("Expected
|
|
479
|
+
output << colorize("Expected:", :yellow, :bold)
|
|
449
480
|
original1.each_line.with_index do |line, idx|
|
|
450
481
|
output << " #{colorize(sprintf('%4d', idx + 1),
|
|
451
482
|
:blue)} | #{line.chomp}"
|
|
@@ -453,7 +484,7 @@ module Canon
|
|
|
453
484
|
output << ""
|
|
454
485
|
|
|
455
486
|
# Format actual
|
|
456
|
-
output << colorize("
|
|
487
|
+
output << colorize("Received:", :yellow, :bold)
|
|
457
488
|
original2.each_line.with_index do |line, idx|
|
|
458
489
|
output << " #{colorize(sprintf('%4d', idx + 1),
|
|
459
490
|
:blue)} | #{line.chomp}"
|
|
@@ -465,6 +496,65 @@ module Canon
|
|
|
465
496
|
output.join("\n")
|
|
466
497
|
end
|
|
467
498
|
|
|
499
|
+
# Format raw/original inputs for display (user-friendly copyable format)
|
|
500
|
+
# Shows the raw file contents before any preprocessing
|
|
501
|
+
#
|
|
502
|
+
# @param raw1 [String] First raw input string
|
|
503
|
+
# @param raw2 [String] Second raw input string
|
|
504
|
+
# @return [String] Formatted display of raw inputs
|
|
505
|
+
def format_raw_inputs(raw1, raw2)
|
|
506
|
+
return "" if raw1.nil? || raw2.nil?
|
|
507
|
+
|
|
508
|
+
output = []
|
|
509
|
+
output << ""
|
|
510
|
+
output << colorize("=== ORIGINAL INPUTS (Raw) ===", :cyan, :bold)
|
|
511
|
+
output << ""
|
|
512
|
+
output << colorize("EXPECTED:", :yellow, :bold)
|
|
513
|
+
output << "-" * 70
|
|
514
|
+
output << raw1
|
|
515
|
+
output << ""
|
|
516
|
+
output << colorize("RECEIVED:", :yellow, :bold)
|
|
517
|
+
output << "-" * 70
|
|
518
|
+
output << raw2
|
|
519
|
+
output << ""
|
|
520
|
+
output << ""
|
|
521
|
+
|
|
522
|
+
output.join("\n")
|
|
523
|
+
end
|
|
524
|
+
|
|
525
|
+
# Format preprocessed inputs for display (what was actually compared)
|
|
526
|
+
# Shows the content after preprocessing (c14n, normalize, format, etc.)
|
|
527
|
+
#
|
|
528
|
+
# @param preprocessed1 [String] First preprocessed string
|
|
529
|
+
# @param preprocessed2 [String] Second preprocessed string
|
|
530
|
+
# @param preprocessing_info [Symbol, nil] Preprocessing mode (:c14n, :normalize, :format, etc.)
|
|
531
|
+
# @return [String] Formatted display of preprocessed inputs
|
|
532
|
+
def format_preprocessed_inputs(preprocessed1, preprocessed2,
|
|
533
|
+
preprocessing_info = nil)
|
|
534
|
+
return "" if preprocessed1.nil? || preprocessed2.nil?
|
|
535
|
+
|
|
536
|
+
output = []
|
|
537
|
+
output << ""
|
|
538
|
+
output << colorize("=== PREPROCESSED INPUTS (Compared) ===", :cyan, :bold)
|
|
539
|
+
|
|
540
|
+
# Show preprocessing mode if available
|
|
541
|
+
if preprocessing_info
|
|
542
|
+
output << "Preprocessing: #{preprocessing_info}"
|
|
543
|
+
end
|
|
544
|
+
output << ""
|
|
545
|
+
output << colorize("EXPECTED:", :yellow, :bold)
|
|
546
|
+
output << "-" * 70
|
|
547
|
+
output << preprocessed1
|
|
548
|
+
output << ""
|
|
549
|
+
output << colorize("RECEIVED:", :yellow, :bold)
|
|
550
|
+
output << "-" * 70
|
|
551
|
+
output << preprocessed2
|
|
552
|
+
output << ""
|
|
553
|
+
output << ""
|
|
554
|
+
|
|
555
|
+
output.join("\n")
|
|
556
|
+
end
|
|
557
|
+
|
|
468
558
|
# Build the final visualization map from various customization options
|
|
469
559
|
#
|
|
470
560
|
# @param visualization_map [Hash, nil] Complete custom visualization map
|
data/lib/canon/version.rb
CHANGED