canon 0.1.6 → 0.1.7

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.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +163 -67
  3. data/README.adoc +400 -7
  4. data/docs/Gemfile +9 -0
  5. data/docs/INDEX.adoc +99 -182
  6. data/docs/_config.yml +100 -0
  7. data/docs/advanced/diff-classification.adoc +547 -0
  8. data/docs/advanced/diff-pipeline.adoc +358 -0
  9. data/docs/advanced/index.adoc +214 -0
  10. data/docs/advanced/semantic-diff-report.adoc +390 -0
  11. data/docs/{VERBOSE.adoc → advanced/verbose-mode-architecture.adoc} +51 -53
  12. data/docs/features/diff-formatting/algorithm-specific-output.adoc +533 -0
  13. data/docs/{CHARACTER_VISUALIZATION.adoc → features/diff-formatting/character-visualization.adoc} +23 -62
  14. data/docs/features/diff-formatting/colors-and-symbols.adoc +606 -0
  15. data/docs/features/diff-formatting/context-and-grouping.adoc +490 -0
  16. data/docs/features/diff-formatting/display-filtering.adoc +472 -0
  17. data/docs/features/diff-formatting/index.adoc +140 -0
  18. data/docs/features/environment-configuration/index.adoc +327 -0
  19. data/docs/features/environment-configuration/override-system.adoc +436 -0
  20. data/docs/features/environment-configuration/size-limits.adoc +273 -0
  21. data/docs/features/index.adoc +173 -0
  22. data/docs/features/input-validation/index.adoc +521 -0
  23. data/docs/features/match-options/algorithm-specific-behavior.adoc +365 -0
  24. data/docs/features/match-options/html-policies.adoc +312 -0
  25. data/docs/features/match-options/index.adoc +621 -0
  26. data/docs/getting-started/index.adoc +83 -0
  27. data/docs/getting-started/quick-start.adoc +76 -0
  28. data/docs/guides/choosing-configuration.adoc +689 -0
  29. data/docs/guides/index.adoc +181 -0
  30. data/docs/{CLI.adoc → interfaces/cli/index.adoc} +18 -13
  31. data/docs/interfaces/index.adoc +101 -0
  32. data/docs/{RSPEC.adoc → interfaces/rspec/index.adoc} +242 -31
  33. data/docs/{RUBY_API.adoc → interfaces/ruby-api/index.adoc} +118 -16
  34. data/docs/lychee.toml +65 -0
  35. data/docs/reference/cli-options.adoc +418 -0
  36. data/docs/reference/environment-variables.adoc +375 -0
  37. data/docs/reference/index.adoc +204 -0
  38. data/docs/reference/options-across-interfaces.adoc +417 -0
  39. data/docs/understanding/algorithms/dom-diff.adoc +389 -0
  40. data/docs/understanding/algorithms/index.adoc +314 -0
  41. data/docs/understanding/algorithms/semantic-tree-diff.adoc +533 -0
  42. data/docs/understanding/architecture.adoc +447 -0
  43. data/docs/understanding/comparison-pipeline.adoc +317 -0
  44. data/docs/understanding/formats/html.adoc +380 -0
  45. data/docs/understanding/formats/index.adoc +261 -0
  46. data/docs/understanding/formats/json.adoc +390 -0
  47. data/docs/understanding/formats/xml.adoc +366 -0
  48. data/docs/understanding/formats/yaml.adoc +504 -0
  49. data/docs/understanding/index.adoc +130 -0
  50. data/lib/canon/cli.rb +42 -1
  51. data/lib/canon/commands/diff_command.rb +108 -23
  52. data/lib/canon/comparison/compare_profile.rb +101 -0
  53. data/lib/canon/comparison/comparison_result.rb +41 -2
  54. data/lib/canon/comparison/html_comparator.rb +292 -71
  55. data/lib/canon/comparison/html_compare_profile.rb +117 -0
  56. data/lib/canon/comparison/match_options.rb +42 -4
  57. data/lib/canon/comparison/strategies/base_match_strategy.rb +99 -0
  58. data/lib/canon/comparison/strategies/match_strategy_factory.rb +74 -0
  59. data/lib/canon/comparison/strategies/semantic_tree_match_strategy.rb +220 -0
  60. data/lib/canon/comparison/xml_comparator.rb +695 -91
  61. data/lib/canon/comparison.rb +207 -2
  62. data/lib/canon/config/env_provider.rb +71 -0
  63. data/lib/canon/config/env_schema.rb +58 -0
  64. data/lib/canon/config/override_resolver.rb +55 -0
  65. data/lib/canon/config/type_converter.rb +59 -0
  66. data/lib/canon/config.rb +158 -29
  67. data/lib/canon/data_model.rb +29 -0
  68. data/lib/canon/diff/diff_classifier.rb +74 -14
  69. data/lib/canon/diff/diff_context_builder.rb +41 -0
  70. data/lib/canon/diff/diff_line.rb +18 -2
  71. data/lib/canon/diff/diff_node.rb +18 -3
  72. data/lib/canon/diff/diff_node_mapper.rb +71 -12
  73. data/lib/canon/diff/formatting_detector.rb +53 -0
  74. data/lib/canon/diff_formatter/by_line/base_formatter.rb +60 -5
  75. data/lib/canon/diff_formatter/by_line/html_formatter.rb +68 -16
  76. data/lib/canon/diff_formatter/by_line/json_formatter.rb +0 -37
  77. data/lib/canon/diff_formatter/by_line/simple_formatter.rb +0 -42
  78. data/lib/canon/diff_formatter/by_line/xml_formatter.rb +116 -31
  79. data/lib/canon/diff_formatter/by_line/yaml_formatter.rb +0 -37
  80. data/lib/canon/diff_formatter/by_object/base_formatter.rb +126 -19
  81. data/lib/canon/diff_formatter/by_object/xml_formatter.rb +30 -1
  82. data/lib/canon/diff_formatter/debug_output.rb +7 -1
  83. data/lib/canon/diff_formatter/diff_detail_formatter.rb +674 -57
  84. data/lib/canon/diff_formatter/legend.rb +42 -0
  85. data/lib/canon/diff_formatter.rb +78 -9
  86. data/lib/canon/errors.rb +56 -0
  87. data/lib/canon/formatters/html_formatter_base.rb +35 -1
  88. data/lib/canon/formatters/json_formatter.rb +3 -0
  89. data/lib/canon/formatters/yaml_formatter.rb +3 -0
  90. data/lib/canon/html/data_model.rb +229 -0
  91. data/lib/canon/html.rb +9 -0
  92. data/lib/canon/options/cli_generator.rb +70 -0
  93. data/lib/canon/options/registry.rb +234 -0
  94. data/lib/canon/rspec_matchers.rb +34 -13
  95. data/lib/canon/tree_diff/adapters/html_adapter.rb +316 -0
  96. data/lib/canon/tree_diff/adapters/json_adapter.rb +204 -0
  97. data/lib/canon/tree_diff/adapters/xml_adapter.rb +285 -0
  98. data/lib/canon/tree_diff/adapters/yaml_adapter.rb +213 -0
  99. data/lib/canon/tree_diff/core/attribute_comparator.rb +84 -0
  100. data/lib/canon/tree_diff/core/matching.rb +241 -0
  101. data/lib/canon/tree_diff/core/node_signature.rb +164 -0
  102. data/lib/canon/tree_diff/core/node_weight.rb +135 -0
  103. data/lib/canon/tree_diff/core/tree_node.rb +450 -0
  104. data/lib/canon/tree_diff/matchers/hash_matcher.rb +258 -0
  105. data/lib/canon/tree_diff/matchers/similarity_matcher.rb +168 -0
  106. data/lib/canon/tree_diff/matchers/structural_propagator.rb +242 -0
  107. data/lib/canon/tree_diff/matchers/universal_matcher.rb +220 -0
  108. data/lib/canon/tree_diff/operation_converter.rb +631 -0
  109. data/lib/canon/tree_diff/operations/operation.rb +92 -0
  110. data/lib/canon/tree_diff/operations/operation_detector.rb +626 -0
  111. data/lib/canon/tree_diff/tree_diff_integrator.rb +140 -0
  112. data/lib/canon/tree_diff.rb +33 -0
  113. data/lib/canon/validators/json_validator.rb +3 -1
  114. data/lib/canon/validators/yaml_validator.rb +3 -1
  115. data/lib/canon/version.rb +1 -1
  116. data/lib/canon/xml/data_model.rb +22 -23
  117. data/lib/canon/xml/element_matcher.rb +128 -20
  118. data/lib/canon/xml/namespace_helper.rb +110 -0
  119. data/lib/canon.rb +3 -0
  120. metadata +81 -23
  121. data/_config.yml +0 -116
  122. data/docs/ADVANCED_TOPICS.adoc +0 -20
  123. data/docs/BASIC_USAGE.adoc +0 -16
  124. data/docs/CUSTOMIZING_BEHAVIOR.adoc +0 -19
  125. data/docs/DIFF_ARCHITECTURE.adoc +0 -435
  126. data/docs/DIFF_FORMATTING.adoc +0 -540
  127. data/docs/FORMATS.adoc +0 -447
  128. data/docs/INPUT_VALIDATION.adoc +0 -477
  129. data/docs/MATCH_ARCHITECTURE.adoc +0 -463
  130. data/docs/MATCH_OPTIONS.adoc +0 -719
  131. data/docs/MODES.adoc +0 -432
  132. data/docs/NORMATIVE_INFORMATIVE_DIFFS.adoc +0 -219
  133. data/docs/OPTIONS.adoc +0 -1387
  134. data/docs/PREPROCESSING.adoc +0 -491
  135. data/docs/SEMANTIC_DIFF_REPORT.adoc +0 -528
  136. data/docs/UNDERSTANDING_CANON.adoc +0 -17
@@ -0,0 +1,181 @@
1
+ ---
2
+ layout: default
3
+ title: Guides
4
+ nav_order: 8
5
+ has_children: true
6
+ ---
7
+ = Guides
8
+
9
+ Task-oriented tutorials for common Canon use cases.
10
+
11
+ == Overview
12
+
13
+ This section provides step-by-step guides for accomplishing specific tasks with Canon. Each guide walks you through a complete workflow from start to finish.
14
+
15
+ Unlike reference documentation that explains individual features, these guides show you how to combine features to solve real problems.
16
+
17
+ == Available Guides
18
+
19
+ link:testing-xml-generation[**Testing XML Generation**]::
20
+ How to use Canon in RSpec tests to validate generated XML output.
21
+ +
22
+ Covers: RSpec matchers, match profiles, handling whitespace, debugging failures.
23
+
24
+ link:debugging-test-failures[**Debugging Test Failures**]::
25
+ Strategies for diagnosing and fixing test failures when comparing documents.
26
+ +
27
+ Covers: Verbose mode, character visualization, match dimension tuning, common pitfalls.
28
+
29
+ link:migrating-from-xmldiff[**Migrating from XMLDiff**]::
30
+ Guide for users switching from other XML comparison tools.
31
+ +
32
+ Covers: Feature mapping, option translation, behavior differences, migration checklist.
33
+
34
+ link:performance-optimization[**Performance Optimization**]::
35
+ Techniques for improving comparison performance on large documents.
36
+ +
37
+ Covers: Algorithm selection, size limits, preprocessing strategies, batch processing.
38
+
39
+ link:custom-comparators[**Building Custom Comparators**]::
40
+ How to extend Canon with custom comparison logic for specialized formats.
41
+ +
42
+ Covers: Comparator interface, adapter pattern, integration, testing.
43
+
44
+ == By Use Case
45
+
46
+ === Testing and QA
47
+
48
+ **Writing reliable XML tests**::
49
+ link:testing-xml-generation[Testing XML Generation] shows how to use Canon's RSpec matchers for robust testing.
50
+
51
+ **Debugging test failures**::
52
+ link:debugging-test-failures[Debugging Test Failures] provides systematic troubleshooting strategies.
53
+
54
+ **Comparing configuration files**::
55
+ Use link:../features/match-options/profiles[Match Profiles] with the `spec_friendly` profile.
56
+
57
+ === Migration and Integration
58
+
59
+ **Switching from another tool**::
60
+ link:migrating-from-xmldiff[Migrating from XMLDiff] helps you transition smoothly.
61
+
62
+ **Integrating into CI/CD**::
63
+ See link:../interfaces/cli/[CLI Reference] for command-line usage in pipelines.
64
+
65
+ **Adding to existing test suite**::
66
+ link:testing-xml-generation[Testing XML Generation] covers integration patterns.
67
+
68
+ === Performance and Scale
69
+
70
+ **Handling large files**::
71
+ link:performance-optimization[Performance Optimization] shows strategies for large documents.
72
+
73
+ **Batch processing**::
74
+ See link:performance-optimization#batch-processing[Batch Processing] section.
75
+
76
+ **Optimizing comparison speed**::
77
+ link:performance-optimization#algorithm-selection[Algorithm Selection] explains trade-offs.
78
+
79
+ === Customization and Extension
80
+
81
+ **Custom comparison logic**::
82
+ link:custom-comparators[Building Custom Comparators] walks through the process.
83
+
84
+ **Format-specific handling**::
85
+ See link:../advanced/extending-canon[Extending Canon] for adapter development.
86
+
87
+ == Guide Structure
88
+
89
+ Each guide follows this structure:
90
+
91
+ **Overview**::
92
+ What you'll learn and prerequisites.
93
+
94
+ **Problem**::
95
+ The real-world problem this guide solves.
96
+
97
+ **Solution**::
98
+ Step-by-step walkthrough with code examples.
99
+
100
+ **Explanation**::
101
+ Why the solution works and alternatives to consider.
102
+
103
+ **Summary**::
104
+ Key takeaways and next steps.
105
+
106
+ == Prerequisites
107
+
108
+ Most guides assume:
109
+
110
+ * Ruby 2.7 or higher installed
111
+ * Basic familiarity with Canon concepts
112
+ * Understanding of the format you're working with
113
+
114
+ If you're new to Canon, start with link:../getting-started/[Getting Started] first.
115
+
116
+ == Common Patterns
117
+
118
+ === Test-Friendly Comparison
119
+
120
+ [source,ruby]
121
+ ----
122
+ # Ignore formatting differences in tests
123
+ expect(actual_xml).to be_xml_equivalent_to(expected_xml,
124
+ match_profile: :spec_friendly
125
+ )
126
+ ----
127
+
128
+ See link:testing-xml-generation#test-friendly-matching[Test-Friendly Matching].
129
+
130
+ === Detailed Debugging
131
+
132
+ [source,ruby]
133
+ ----
134
+ # Get detailed diff output
135
+ result = Canon::Comparison.compare(expected, actual,
136
+ verbose: true,
137
+ visualize_whitespace: true,
138
+ context_lines: 10
139
+ )
140
+ puts result.diff
141
+ ----
142
+
143
+ See link:debugging-test-failures#verbose-output[Verbose Output].
144
+
145
+ === Performance Tuning
146
+
147
+ [source,ruby]
148
+ ----
149
+ # Optimize for large files
150
+ Canon::Comparison.equivalent?(doc1, doc2,
151
+ preprocessing: :none, # Skip preprocessing
152
+ diff_algorithm: :dom, # Use faster algorithm
153
+ max_nodes: 50000 # Increase limit if needed
154
+ )
155
+ ----
156
+
157
+ See link:performance-optimization#tuning-options[Tuning Options].
158
+
159
+ == Getting Help
160
+
161
+ **Can't find what you need?**::
162
+ Check link:../reference/[Reference] for complete option listings.
163
+
164
+ **Need conceptual understanding?**::
165
+ See link:../understanding/[Understanding Canon] for architectural details.
166
+
167
+ **Want to contribute a guide?**::
168
+ See link:../contributing[Contributing Guidelines].
169
+
170
+ == Next Steps
171
+
172
+ * Choose a guide that matches your current task
173
+ * Follow along with the code examples
174
+ * Experiment with variations
175
+ * Share your learnings with the community
176
+
177
+ == See Also
178
+
179
+ * link:../getting-started/[Getting Started] - Basic Canon usage
180
+ * link:../features/[Features] - Configuration options
181
+ * link:../reference/[Reference] - Complete option listings
@@ -1,8 +1,9 @@
1
1
  ---
2
2
  layout: default
3
- title: Command-Line Interface
4
- nav_order: 11
5
- parent: Basic Usage
3
+ title: CLI Reference
4
+ parent: Interfaces
5
+ nav_order: 2
6
+ has_children: true
6
7
  ---
7
8
  = Canon command-line interface
8
9
  :toc:
@@ -13,9 +14,9 @@ parent: Basic Usage
13
14
  This document describes Canon's command-line interface (CLI). The `canon`
14
15
  command provides file formatting and comparison capabilities.
15
16
 
16
- For Ruby API usage, see link:RUBY_API[Ruby API documentation].
17
+ For Ruby API usage, see link:../ruby-api/[Ruby API documentation].
17
18
 
18
- For RSpec testing, see link:RSPEC[RSpec documentation].
19
+ For RSpec testing, see link:../rspec/[RSpec documentation].
19
20
 
20
21
  == General
21
22
 
@@ -197,7 +198,7 @@ structural changes
197
198
  `by-line`:: (default for HTML, optional for XML) Line-by-line diff after
198
199
  canonicalization
199
200
 
200
- See link:MODES[Diff modes] for details.
201
+ See link:../../understanding/diff-modes/[Diff modes] for details.
201
202
 
202
203
  === Format options
203
204
 
@@ -213,6 +214,10 @@ See link:MODES[Diff modes] for details.
213
214
  `-v, --verbose`:: Show detailed differences (default: just show if files
214
215
  differ)
215
216
 
217
+ `--diff-algorithm ALGORITHM`:: Diff algorithm to use: `dom` (default) or
218
+ `semantic`. DOM uses positional matching, semantic uses tree-based matching
219
+ with operation detection.
220
+
216
221
  `--by-line`:: Use line-by-line diff for XML (default: by-object mode)
217
222
 
218
223
  `--text-content BEHAVIOR`:: How to compare text content: `strict`,
@@ -239,7 +244,7 @@ values: `strict`, `normalize`, or `ignore` (XML/HTML only)
239
244
  `--match-profile PROFILE`:: Use predefined match profile: `strict`,
240
245
  `rendered`, `spec_friendly`, or `content_only`
241
246
 
242
- See link:MATCH_OPTIONS[Match options] for detailed dimension reference.
247
+ See link:../../features/match-options/[Match options] for detailed dimension reference.
243
248
 
244
249
  === Output options
245
250
 
@@ -249,7 +254,7 @@ See link:MATCH_OPTIONS[Match options] for detailed dimension reference.
249
254
 
250
255
  `--diff-grouping-lines N`:: Group changes within N lines into blocks
251
256
 
252
- See link:DIFF_FORMATTING[Diff formatting] for details.
257
+ See link:../../features/diff-formatting/[Diff formatting] for details.
253
258
 
254
259
  === Exit codes
255
260
 
@@ -486,8 +491,8 @@ $ canon --version
486
491
 
487
492
  == See also
488
493
 
489
- * link:RUBY_API[Ruby API documentation]
490
- * link:RSPEC[RSpec matchers]
491
- * link:MATCH_OPTIONS[Match options reference]
492
- * link:MODES[Diff modes]
493
- * link:DIFF_FORMATTING[Diff formatting options]
494
+ * link:../ruby-api/[Ruby API documentation]
495
+ * link:../rspec/[RSpec matchers]
496
+ * link:../../features/match-options/[Match options reference]
497
+ * link:../../understanding/diff-modes/[Diff modes]
498
+ * link:../../features/diff-formatting/[Diff formatting options]
@@ -0,0 +1,101 @@
1
+ ---
2
+ layout: default
3
+ title: Interfaces
4
+ nav_order: 3
5
+ has_children: true
6
+ ---
7
+ = Interfaces
8
+
9
+ Learn how to use Canon through different interfaces.
10
+
11
+ == Overview
12
+
13
+ Canon provides three main interfaces for different use cases:
14
+
15
+ link:ruby-api/[**Ruby API**]::
16
+ Integrate Canon into Ruby applications for programmatic formatting and comparison.
17
+
18
+ link:cli/[**Command-Line Interface**]::
19
+ Use Canon from the terminal for one-off tasks and shell scripting.
20
+
21
+ link:rspec/[**RSpec Matchers**]::
22
+ Test XML, JSON, and YAML generation with semantic matchers.
23
+
24
+ == Choosing an Interface
25
+
26
+ **Use Ruby API when**::
27
+ * Integrating into a Ruby application
28
+ * Need programmatic control
29
+ * Building custom tooling
30
+ * Processing multiple files
31
+
32
+ **Use CLI when**::
33
+ * Running one-off comparisons
34
+ * Shell scripting
35
+ * CI/CD pipelines
36
+ * Quick formatting tasks
37
+
38
+ **Use RSpec when**::
39
+ * Writing tests
40
+ * Validating generated output
41
+ * TDD/BDD workflows
42
+ * Continuous integration
43
+
44
+ == Common Patterns Across Interfaces
45
+
46
+ All interfaces share the same core concepts:
47
+
48
+ * **Formats**: XML, HTML, JSON, YAML
49
+ * **Operations**: Format (canonicalize/pretty-print) and Compare
50
+ * **Options**: Match dimensions, profiles, preprocessing
51
+ * **Output**: Color-coded diffs, character visualization
52
+
53
+ The interface you choose determines **how** you invoke these features, but the underlying behavior is consistent.
54
+
55
+ == Quick Examples
56
+
57
+ === Format a File
58
+
59
+ **Ruby**:
60
+ [source,ruby]
61
+ ----
62
+ Canon.format(xml_string, :xml, mode: :pretty)
63
+ ----
64
+
65
+ **CLI**:
66
+ [source,bash]
67
+ ----
68
+ canon format file.xml --mode pretty
69
+ ----
70
+
71
+ === Compare Files
72
+
73
+ **Ruby**:
74
+ [source,ruby]
75
+ ----
76
+ Canon::Comparison.equivalent?(doc1, doc2)
77
+ ----
78
+
79
+ **CLI**:
80
+ [source,bash]
81
+ ----
82
+ canon diff file1.xml file2.xml
83
+ ----
84
+
85
+ **RSpec**:
86
+ [source,ruby]
87
+ ----
88
+ expect(actual_xml).to be_xml_equivalent_to(expected_xml)
89
+ ----
90
+
91
+ == Next Steps
92
+
93
+ * Choose your primary interface and dive into its documentation
94
+ * Review link:../features/match-options/[Match Options] to understand configuration
95
+ * Check link:../guides/[Guides] for task-oriented tutorials
96
+
97
+ == See Also
98
+
99
+ * link:../getting-started/quick-start[Quick Start] - Basic usage examples
100
+ * link:../features/match-options/[Match Options] - Customizing comparison behavior
101
+ * link:../understanding/architecture[Architecture] - How Canon works internally