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.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +163 -67
- data/README.adoc +400 -7
- data/docs/Gemfile +9 -0
- data/docs/INDEX.adoc +99 -182
- data/docs/_config.yml +100 -0
- data/docs/advanced/diff-classification.adoc +547 -0
- data/docs/advanced/diff-pipeline.adoc +358 -0
- data/docs/advanced/index.adoc +214 -0
- data/docs/advanced/semantic-diff-report.adoc +390 -0
- data/docs/{VERBOSE.adoc → advanced/verbose-mode-architecture.adoc} +51 -53
- data/docs/features/diff-formatting/algorithm-specific-output.adoc +533 -0
- data/docs/{CHARACTER_VISUALIZATION.adoc → features/diff-formatting/character-visualization.adoc} +23 -62
- data/docs/features/diff-formatting/colors-and-symbols.adoc +606 -0
- data/docs/features/diff-formatting/context-and-grouping.adoc +490 -0
- data/docs/features/diff-formatting/display-filtering.adoc +472 -0
- data/docs/features/diff-formatting/index.adoc +140 -0
- data/docs/features/environment-configuration/index.adoc +327 -0
- data/docs/features/environment-configuration/override-system.adoc +436 -0
- data/docs/features/environment-configuration/size-limits.adoc +273 -0
- data/docs/features/index.adoc +173 -0
- data/docs/features/input-validation/index.adoc +521 -0
- data/docs/features/match-options/algorithm-specific-behavior.adoc +365 -0
- data/docs/features/match-options/html-policies.adoc +312 -0
- data/docs/features/match-options/index.adoc +621 -0
- data/docs/getting-started/index.adoc +83 -0
- data/docs/getting-started/quick-start.adoc +76 -0
- data/docs/guides/choosing-configuration.adoc +689 -0
- data/docs/guides/index.adoc +181 -0
- data/docs/{CLI.adoc → interfaces/cli/index.adoc} +18 -13
- data/docs/interfaces/index.adoc +101 -0
- data/docs/{RSPEC.adoc → interfaces/rspec/index.adoc} +242 -31
- data/docs/{RUBY_API.adoc → interfaces/ruby-api/index.adoc} +118 -16
- data/docs/lychee.toml +65 -0
- data/docs/reference/cli-options.adoc +418 -0
- data/docs/reference/environment-variables.adoc +375 -0
- data/docs/reference/index.adoc +204 -0
- data/docs/reference/options-across-interfaces.adoc +417 -0
- data/docs/understanding/algorithms/dom-diff.adoc +389 -0
- data/docs/understanding/algorithms/index.adoc +314 -0
- data/docs/understanding/algorithms/semantic-tree-diff.adoc +533 -0
- data/docs/understanding/architecture.adoc +447 -0
- data/docs/understanding/comparison-pipeline.adoc +317 -0
- data/docs/understanding/formats/html.adoc +380 -0
- data/docs/understanding/formats/index.adoc +261 -0
- data/docs/understanding/formats/json.adoc +390 -0
- data/docs/understanding/formats/xml.adoc +366 -0
- data/docs/understanding/formats/yaml.adoc +504 -0
- data/docs/understanding/index.adoc +130 -0
- data/lib/canon/cli.rb +42 -1
- data/lib/canon/commands/diff_command.rb +108 -23
- data/lib/canon/comparison/compare_profile.rb +101 -0
- data/lib/canon/comparison/comparison_result.rb +41 -2
- data/lib/canon/comparison/html_comparator.rb +292 -71
- data/lib/canon/comparison/html_compare_profile.rb +117 -0
- data/lib/canon/comparison/match_options.rb +42 -4
- data/lib/canon/comparison/strategies/base_match_strategy.rb +99 -0
- data/lib/canon/comparison/strategies/match_strategy_factory.rb +74 -0
- data/lib/canon/comparison/strategies/semantic_tree_match_strategy.rb +220 -0
- data/lib/canon/comparison/xml_comparator.rb +695 -91
- data/lib/canon/comparison.rb +207 -2
- data/lib/canon/config/env_provider.rb +71 -0
- data/lib/canon/config/env_schema.rb +58 -0
- data/lib/canon/config/override_resolver.rb +55 -0
- data/lib/canon/config/type_converter.rb +59 -0
- data/lib/canon/config.rb +158 -29
- data/lib/canon/data_model.rb +29 -0
- data/lib/canon/diff/diff_classifier.rb +74 -14
- data/lib/canon/diff/diff_context_builder.rb +41 -0
- data/lib/canon/diff/diff_line.rb +18 -2
- data/lib/canon/diff/diff_node.rb +18 -3
- data/lib/canon/diff/diff_node_mapper.rb +71 -12
- data/lib/canon/diff/formatting_detector.rb +53 -0
- data/lib/canon/diff_formatter/by_line/base_formatter.rb +60 -5
- data/lib/canon/diff_formatter/by_line/html_formatter.rb +68 -16
- data/lib/canon/diff_formatter/by_line/json_formatter.rb +0 -37
- data/lib/canon/diff_formatter/by_line/simple_formatter.rb +0 -42
- data/lib/canon/diff_formatter/by_line/xml_formatter.rb +116 -31
- data/lib/canon/diff_formatter/by_line/yaml_formatter.rb +0 -37
- data/lib/canon/diff_formatter/by_object/base_formatter.rb +126 -19
- data/lib/canon/diff_formatter/by_object/xml_formatter.rb +30 -1
- data/lib/canon/diff_formatter/debug_output.rb +7 -1
- data/lib/canon/diff_formatter/diff_detail_formatter.rb +674 -57
- data/lib/canon/diff_formatter/legend.rb +42 -0
- data/lib/canon/diff_formatter.rb +78 -9
- data/lib/canon/errors.rb +56 -0
- data/lib/canon/formatters/html_formatter_base.rb +35 -1
- data/lib/canon/formatters/json_formatter.rb +3 -0
- data/lib/canon/formatters/yaml_formatter.rb +3 -0
- data/lib/canon/html/data_model.rb +229 -0
- data/lib/canon/html.rb +9 -0
- data/lib/canon/options/cli_generator.rb +70 -0
- data/lib/canon/options/registry.rb +234 -0
- data/lib/canon/rspec_matchers.rb +34 -13
- data/lib/canon/tree_diff/adapters/html_adapter.rb +316 -0
- data/lib/canon/tree_diff/adapters/json_adapter.rb +204 -0
- data/lib/canon/tree_diff/adapters/xml_adapter.rb +285 -0
- data/lib/canon/tree_diff/adapters/yaml_adapter.rb +213 -0
- data/lib/canon/tree_diff/core/attribute_comparator.rb +84 -0
- data/lib/canon/tree_diff/core/matching.rb +241 -0
- data/lib/canon/tree_diff/core/node_signature.rb +164 -0
- data/lib/canon/tree_diff/core/node_weight.rb +135 -0
- data/lib/canon/tree_diff/core/tree_node.rb +450 -0
- data/lib/canon/tree_diff/matchers/hash_matcher.rb +258 -0
- data/lib/canon/tree_diff/matchers/similarity_matcher.rb +168 -0
- data/lib/canon/tree_diff/matchers/structural_propagator.rb +242 -0
- data/lib/canon/tree_diff/matchers/universal_matcher.rb +220 -0
- data/lib/canon/tree_diff/operation_converter.rb +631 -0
- data/lib/canon/tree_diff/operations/operation.rb +92 -0
- data/lib/canon/tree_diff/operations/operation_detector.rb +626 -0
- data/lib/canon/tree_diff/tree_diff_integrator.rb +140 -0
- data/lib/canon/tree_diff.rb +33 -0
- data/lib/canon/validators/json_validator.rb +3 -1
- data/lib/canon/validators/yaml_validator.rb +3 -1
- data/lib/canon/version.rb +1 -1
- data/lib/canon/xml/data_model.rb +22 -23
- data/lib/canon/xml/element_matcher.rb +128 -20
- data/lib/canon/xml/namespace_helper.rb +110 -0
- data/lib/canon.rb +3 -0
- metadata +81 -23
- data/_config.yml +0 -116
- data/docs/ADVANCED_TOPICS.adoc +0 -20
- data/docs/BASIC_USAGE.adoc +0 -16
- data/docs/CUSTOMIZING_BEHAVIOR.adoc +0 -19
- data/docs/DIFF_ARCHITECTURE.adoc +0 -435
- data/docs/DIFF_FORMATTING.adoc +0 -540
- data/docs/FORMATS.adoc +0 -447
- data/docs/INPUT_VALIDATION.adoc +0 -477
- data/docs/MATCH_ARCHITECTURE.adoc +0 -463
- data/docs/MATCH_OPTIONS.adoc +0 -719
- data/docs/MODES.adoc +0 -432
- data/docs/NORMATIVE_INFORMATIVE_DIFFS.adoc +0 -219
- data/docs/OPTIONS.adoc +0 -1387
- data/docs/PREPROCESSING.adoc +0 -491
- data/docs/SEMANTIC_DIFF_REPORT.adoc +0 -528
- data/docs/UNDERSTANDING_CANON.adoc +0 -17
data/docs/FORMATS.adoc
DELETED
|
@@ -1,447 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
layout: default
|
|
3
|
-
title: Format Support
|
|
4
|
-
nav_order: 20
|
|
5
|
-
parent: Understanding Canon
|
|
6
|
-
---
|
|
7
|
-
= Format support
|
|
8
|
-
:toc:
|
|
9
|
-
:toclevels: 3
|
|
10
|
-
|
|
11
|
-
== Scope
|
|
12
|
-
|
|
13
|
-
This document describes Canon's support for XML, HTML, JSON, and YAML formats,
|
|
14
|
-
including canonicalization rules, format detection, and format-specific
|
|
15
|
-
features.
|
|
16
|
-
|
|
17
|
-
For usage examples, see link:RUBY_API[Ruby API], link:CLI[CLI], or
|
|
18
|
-
link:RSPEC[RSpec documentation].
|
|
19
|
-
|
|
20
|
-
== General
|
|
21
|
-
|
|
22
|
-
Canon provides unified canonicalization and comparison for four serialization
|
|
23
|
-
formats. Each format has specific rules and defaults optimized for its typical
|
|
24
|
-
usage.
|
|
25
|
-
|
|
26
|
-
== XML format
|
|
27
|
-
|
|
28
|
-
=== Canonicalization
|
|
29
|
-
|
|
30
|
-
Canon implements the https://www.w3.org/TR/xml-c14n11/[W3C Canonical XML
|
|
31
|
-
Version 1.1] specification.
|
|
32
|
-
|
|
33
|
-
**Key features:**
|
|
34
|
-
|
|
35
|
-
* Namespace declaration ordering (lexicographic by prefix)
|
|
36
|
-
* Attribute ordering (lexicographic by namespace URI, then local name)
|
|
37
|
-
* Character encoding normalization to UTF-8
|
|
38
|
-
* Special character encoding in text and attributes
|
|
39
|
-
* Removal of superfluous namespace declarations
|
|
40
|
-
* Support for xml:base, xml:lang, xml:space, and xml:id attributes
|
|
41
|
-
* Processing instruction and comment handling
|
|
42
|
-
* Document subset support with attribute inheritance
|
|
43
|
-
|
|
44
|
-
.XML canonicalization example
|
|
45
|
-
[example]
|
|
46
|
-
====
|
|
47
|
-
[source,ruby]
|
|
48
|
-
----
|
|
49
|
-
xml = <<~XML
|
|
50
|
-
<root xmlns:b="http://b.com" xmlns:a="http://a.com">
|
|
51
|
-
<item b:attr="2" a:attr="1">
|
|
52
|
-
Text content
|
|
53
|
-
</item>
|
|
54
|
-
</root>
|
|
55
|
-
XML
|
|
56
|
-
|
|
57
|
-
Canon.format(xml, :xml)
|
|
58
|
-
# => Namespace prefixes sorted, attributes sorted, whitespace normalized
|
|
59
|
-
----
|
|
60
|
-
====
|
|
61
|
-
|
|
62
|
-
=== Format defaults
|
|
63
|
-
|
|
64
|
-
[cols="1,1"]
|
|
65
|
-
|===
|
|
66
|
-
|Dimension |Default Behavior
|
|
67
|
-
|
|
68
|
-
|`text_content`
|
|
69
|
-
|`:strict`
|
|
70
|
-
|
|
71
|
-
|`structural_whitespace`
|
|
72
|
-
|`:strict`
|
|
73
|
-
|
|
74
|
-
|`attribute_whitespace`
|
|
75
|
-
|`:strict`
|
|
76
|
-
|
|
77
|
-
|`attribute_order`
|
|
78
|
-
|`:strict`
|
|
79
|
-
|
|
80
|
-
|`attribute_values`
|
|
81
|
-
|`:strict`
|
|
82
|
-
|
|
83
|
-
|`comments`
|
|
84
|
-
|`:strict`
|
|
85
|
-
|===
|
|
86
|
-
|
|
87
|
-
Default diff mode: `:by_object` (tree-based semantic diff)
|
|
88
|
-
|
|
89
|
-
=== XML-specific features
|
|
90
|
-
|
|
91
|
-
**Comment handling**: XML comments are preserved in canonical form unless
|
|
92
|
-
`--with-comments` is explicitly set.
|
|
93
|
-
|
|
94
|
-
**Namespace normalization**: Namespace declarations are sorted and duplicate
|
|
95
|
-
declarations are removed.
|
|
96
|
-
|
|
97
|
-
**xml: attributes**: Special attributes like `xml:lang`, `xml:space`, `xml:id`,
|
|
98
|
-
and `xml:base` are properly handled per specification.
|
|
99
|
-
|
|
100
|
-
== HTML format
|
|
101
|
-
|
|
102
|
-
=== Canonicalization
|
|
103
|
-
|
|
104
|
-
Canon supports HTML 4, HTML5, and XHTML with automatic format detection.
|
|
105
|
-
|
|
106
|
-
**Key features:**
|
|
107
|
-
|
|
108
|
-
* Automatic HTML vs XHTML detection
|
|
109
|
-
* HTML5 parser for modern HTML
|
|
110
|
-
* XML parser for XHTML
|
|
111
|
-
* Consistent attribute ordering
|
|
112
|
-
* Whitespace normalization
|
|
113
|
-
* Comment handling in `<style>` and `<script>` tags
|
|
114
|
-
|
|
115
|
-
.HTML canonicalization example
|
|
116
|
-
[example]
|
|
117
|
-
====
|
|
118
|
-
[source,ruby]
|
|
119
|
-
----
|
|
120
|
-
html = <<~HTML
|
|
121
|
-
<!DOCTYPE html>
|
|
122
|
-
<html>
|
|
123
|
-
<body>
|
|
124
|
-
<div class="foo" id="bar">
|
|
125
|
-
Content
|
|
126
|
-
</div>
|
|
127
|
-
</body>
|
|
128
|
-
</html>
|
|
129
|
-
HTML
|
|
130
|
-
|
|
131
|
-
Canon.format(html, :html)
|
|
132
|
-
# => Normalized structure with consistent formatting
|
|
133
|
-
----
|
|
134
|
-
====
|
|
135
|
-
|
|
136
|
-
=== Format defaults
|
|
137
|
-
|
|
138
|
-
[cols="1,1"]
|
|
139
|
-
|===
|
|
140
|
-
|Dimension |Default Behavior
|
|
141
|
-
|
|
142
|
-
|`text_content`
|
|
143
|
-
|`:normalize`
|
|
144
|
-
|
|
145
|
-
|`structural_whitespace`
|
|
146
|
-
|`:normalize`
|
|
147
|
-
|
|
148
|
-
|`attribute_whitespace`
|
|
149
|
-
|`:normalize`
|
|
150
|
-
|
|
151
|
-
|`attribute_order`
|
|
152
|
-
|`:ignore`
|
|
153
|
-
|
|
154
|
-
|`attribute_values`
|
|
155
|
-
|`:strict`
|
|
156
|
-
|
|
157
|
-
|`comments`
|
|
158
|
-
|`:ignore`
|
|
159
|
-
|===
|
|
160
|
-
|
|
161
|
-
Default diff mode: `:by_line` (line-based diff)
|
|
162
|
-
|
|
163
|
-
=== HTML-specific features
|
|
164
|
-
|
|
165
|
-
**Format detection**: Automatically detects HTML5, HTML4, or XHTML based on
|
|
166
|
-
DOCTYPE and structure.
|
|
167
|
-
|
|
168
|
-
**Whitespace handling**: HTML whitespace is collapsed per CSS rendering rules.
|
|
169
|
-
Empty text nodes between elements are removed.
|
|
170
|
-
|
|
171
|
-
**Attribute order**: HTML attributes are inherently unordered per the HTML
|
|
172
|
-
specification, so default is `:ignore`.
|
|
173
|
-
|
|
174
|
-
**Special tags**: Comments in `<style>` and `<script>` tags are normalized
|
|
175
|
-
specially to handle CSS/JavaScript syntax.
|
|
176
|
-
|
|
177
|
-
== JSON format
|
|
178
|
-
|
|
179
|
-
=== Canonicalization
|
|
180
|
-
|
|
181
|
-
Canon provides JSON canonicalization with sorted keys at all nesting levels.
|
|
182
|
-
|
|
183
|
-
**Key features:**
|
|
184
|
-
|
|
185
|
-
* Alphabetically sorted object keys
|
|
186
|
-
* Consistent indentation (configurable)
|
|
187
|
-
* Proper escape sequences
|
|
188
|
-
* No trailing commas
|
|
189
|
-
* Unicode normalization
|
|
190
|
-
|
|
191
|
-
.JSON canonicalization example
|
|
192
|
-
[example]
|
|
193
|
-
====
|
|
194
|
-
[source,ruby]
|
|
195
|
-
----
|
|
196
|
-
json = '{"z":3,"a":1,"nested":{"y":2,"x":1}}'
|
|
197
|
-
|
|
198
|
-
Canon.format(json, :json)
|
|
199
|
-
# => {"a":1,"nested":{"x":1,"y":2},"z":3}
|
|
200
|
-
# Keys sorted at all levels
|
|
201
|
-
----
|
|
202
|
-
====
|
|
203
|
-
|
|
204
|
-
=== Format defaults
|
|
205
|
-
|
|
206
|
-
[cols="1,1"]
|
|
207
|
-
|===
|
|
208
|
-
|Dimension |Default Behavior
|
|
209
|
-
|
|
210
|
-
|`text_content`
|
|
211
|
-
|`:strict`
|
|
212
|
-
|
|
213
|
-
|`structural_whitespace`
|
|
214
|
-
|`:strict`
|
|
215
|
-
|
|
216
|
-
|`key_order`
|
|
217
|
-
|`:strict`
|
|
218
|
-
|===
|
|
219
|
-
|
|
220
|
-
Default diff mode: `:by_object` (tree-based semantic diff)
|
|
221
|
-
|
|
222
|
-
=== JSON-specific features
|
|
223
|
-
|
|
224
|
-
**Key ordering**: Object keys are sorted alphabetically for consistent
|
|
225
|
-
comparison.
|
|
226
|
-
|
|
227
|
-
**Type preservation**: Distinguishes between numbers, strings, booleans, and
|
|
228
|
-
null.
|
|
229
|
-
|
|
230
|
-
**Nested structures**: Handles deeply nested objects and arrays.
|
|
231
|
-
|
|
232
|
-
**No comments**: Standard JSON does not support comments.
|
|
233
|
-
|
|
234
|
-
== YAML format
|
|
235
|
-
|
|
236
|
-
=== Canonicalization
|
|
237
|
-
|
|
238
|
-
Canon provides YAML canonicalization with sorted keys and standard formatting.
|
|
239
|
-
|
|
240
|
-
**Key features:**
|
|
241
|
-
|
|
242
|
-
* Alphabetically sorted mapping keys
|
|
243
|
-
* Consistent indentation
|
|
244
|
-
* Standard YAML 1.2 format
|
|
245
|
-
* Comment preservation (optional)
|
|
246
|
-
* Anchor and alias handling
|
|
247
|
-
|
|
248
|
-
.YAML canonicalization example
|
|
249
|
-
[example]
|
|
250
|
-
====
|
|
251
|
-
[source,ruby]
|
|
252
|
-
----
|
|
253
|
-
yaml = <<~YAML
|
|
254
|
-
z: 3
|
|
255
|
-
a: 1
|
|
256
|
-
nested:
|
|
257
|
-
y: 2
|
|
258
|
-
x: 1
|
|
259
|
-
YAML
|
|
260
|
-
|
|
261
|
-
Canon.format(yaml, :yaml)
|
|
262
|
-
# => Keys sorted at all levels
|
|
263
|
-
----
|
|
264
|
-
====
|
|
265
|
-
|
|
266
|
-
=== Format defaults
|
|
267
|
-
|
|
268
|
-
[cols="1,1"]
|
|
269
|
-
|===
|
|
270
|
-
|Dimension |Default Behavior
|
|
271
|
-
|
|
272
|
-
|`text_content`
|
|
273
|
-
|`:strict`
|
|
274
|
-
|
|
275
|
-
|`structural_whitespace`
|
|
276
|
-
|`:strict`
|
|
277
|
-
|
|
278
|
-
|`key_order`
|
|
279
|
-
|`:strict`
|
|
280
|
-
|
|
281
|
-
|`comments`
|
|
282
|
-
|`:strict`
|
|
283
|
-
|===
|
|
284
|
-
|
|
285
|
-
Default diff mode: `:by_object` (tree-based semantic diff)
|
|
286
|
-
|
|
287
|
-
=== YAML-specific features
|
|
288
|
-
|
|
289
|
-
**Comment support**: YAML comments are preserved and can be compared.
|
|
290
|
-
|
|
291
|
-
**Key ordering**: Mapping keys are sorted alphabetically for consistent output.
|
|
292
|
-
|
|
293
|
-
**Type detection**: YAML's rich type system is preserved (strings, numbers,
|
|
294
|
-
booleans, dates, etc.).
|
|
295
|
-
|
|
296
|
-
**Anchors and aliases**: YAML anchors (`&`) and aliases (`*`) are properly
|
|
297
|
-
handled.
|
|
298
|
-
|
|
299
|
-
== Format detection
|
|
300
|
-
|
|
301
|
-
Canon automatically detects format based on file extensions:
|
|
302
|
-
|
|
303
|
-
[cols="1,1"]
|
|
304
|
-
|===
|
|
305
|
-
|Extension |Format
|
|
306
|
-
|
|
307
|
-
|`.xml`
|
|
308
|
-
|XML
|
|
309
|
-
|
|
310
|
-
|`.html`, `.htm`
|
|
311
|
-
|HTML
|
|
312
|
-
|
|
313
|
-
|`.json`
|
|
314
|
-
|JSON
|
|
315
|
-
|
|
316
|
-
|`.yaml`, `.yml`
|
|
317
|
-
|YAML
|
|
318
|
-
|===
|
|
319
|
-
|
|
320
|
-
You can override auto-detection by explicitly specifying the format:
|
|
321
|
-
|
|
322
|
-
.Explicit format specification
|
|
323
|
-
[example]
|
|
324
|
-
====
|
|
325
|
-
[source,ruby]
|
|
326
|
-
----
|
|
327
|
-
# Ruby API
|
|
328
|
-
Canon.format(content, :xml)
|
|
329
|
-
|
|
330
|
-
# CLI
|
|
331
|
-
$ canon format file.txt --format xml
|
|
332
|
-
|
|
333
|
-
# Comparison
|
|
334
|
-
Canon::Comparison.equivalent?(doc1, doc2, format: :xml)
|
|
335
|
-
----
|
|
336
|
-
====
|
|
337
|
-
|
|
338
|
-
== Format comparison matrix
|
|
339
|
-
|
|
340
|
-
[cols="1,1,1,1,1"]
|
|
341
|
-
|===
|
|
342
|
-
|Feature |XML |HTML |JSON |YAML
|
|
343
|
-
|
|
344
|
-
|Canonicalization standard
|
|
345
|
-
|W3C C14N 1.1
|
|
346
|
-
|Custom
|
|
347
|
-
|Custom
|
|
348
|
-
|YAML 1.2
|
|
349
|
-
|
|
350
|
-
|Comment support
|
|
351
|
-
|Yes
|
|
352
|
-
|Yes
|
|
353
|
-
|No
|
|
354
|
-
|Yes
|
|
355
|
-
|
|
356
|
-
|Attribute/key ordering
|
|
357
|
-
|Strict default
|
|
358
|
-
|Ignored default
|
|
359
|
-
|Strict default
|
|
360
|
-
|Strict default
|
|
361
|
-
|
|
362
|
-
|Default diff mode
|
|
363
|
-
|by-object
|
|
364
|
-
|by-line
|
|
365
|
-
|by-object
|
|
366
|
-
|by-object
|
|
367
|
-
|
|
368
|
-
|Whitespace handling
|
|
369
|
-
|Strict default
|
|
370
|
-
|Normalized default
|
|
371
|
-
|Strict default
|
|
372
|
-
|Strict default
|
|
373
|
-
|
|
374
|
-
|Namespace support
|
|
375
|
-
|Yes
|
|
376
|
-
|Limited (XHTML)
|
|
377
|
-
|No
|
|
378
|
-
|No
|
|
379
|
-
|===
|
|
380
|
-
|
|
381
|
-
== Working with multiple formats
|
|
382
|
-
|
|
383
|
-
Canon's unified API works consistently across all formats:
|
|
384
|
-
|
|
385
|
-
.Unified API examples
|
|
386
|
-
[example]
|
|
387
|
-
====
|
|
388
|
-
[source,ruby]
|
|
389
|
-
----
|
|
390
|
-
# Format any content
|
|
391
|
-
Canon.format(xml_content, :xml)
|
|
392
|
-
Canon.format(html_content, :html)
|
|
393
|
-
Canon.format(json_content, :json)
|
|
394
|
-
Canon.format(yaml_content, :yaml)
|
|
395
|
-
|
|
396
|
-
# Compare any format
|
|
397
|
-
Canon::Comparison.equivalent?(xml1, xml2)
|
|
398
|
-
Canon::Comparison.equivalent?(html1, html2)
|
|
399
|
-
Canon::Comparison.equivalent?(json1, json2)
|
|
400
|
-
Canon::Comparison.equivalent?(yaml1, yaml2)
|
|
401
|
-
|
|
402
|
-
# RSpec matchers
|
|
403
|
-
expect(actual_xml).to be_xml_equivalent_to(expected_xml)
|
|
404
|
-
expect(actual_html).to be_html_equivalent_to(expected_html)
|
|
405
|
-
expect(actual_json).to be_json_equivalent_to(expected_json)
|
|
406
|
-
expect(actual_yaml).to be_yaml_equivalent_to(expected_yaml)
|
|
407
|
-
----
|
|
408
|
-
====
|
|
409
|
-
|
|
410
|
-
== Format-specific comparators
|
|
411
|
-
|
|
412
|
-
You can use format-specific comparator classes directly:
|
|
413
|
-
|
|
414
|
-
.Format-specific comparators
|
|
415
|
-
[example]
|
|
416
|
-
====
|
|
417
|
-
[source,ruby]
|
|
418
|
-
----
|
|
419
|
-
# XML comparator
|
|
420
|
-
Canon::Comparison::XmlComparator.equivalent?(xml1, xml2,
|
|
421
|
-
match: { attribute_order: :ignore }
|
|
422
|
-
)
|
|
423
|
-
|
|
424
|
-
# HTML comparator
|
|
425
|
-
Canon::Comparison::HtmlComparator.equivalent?(html1, html2,
|
|
426
|
-
match_profile: :rendered
|
|
427
|
-
)
|
|
428
|
-
|
|
429
|
-
# JSON comparator
|
|
430
|
-
Canon::Comparison::JsonComparator.equivalent?(json1, json2,
|
|
431
|
-
match: { key_order: :ignore }
|
|
432
|
-
)
|
|
433
|
-
|
|
434
|
-
# YAML comparator
|
|
435
|
-
Canon::Comparison::YamlComparator.equivalent?(yaml1, yaml2,
|
|
436
|
-
match: { comments: :ignore }
|
|
437
|
-
)
|
|
438
|
-
----
|
|
439
|
-
====
|
|
440
|
-
|
|
441
|
-
== See also
|
|
442
|
-
|
|
443
|
-
* link:RUBY_API[Ruby API documentation]
|
|
444
|
-
* link:CLI[Command-line interface]
|
|
445
|
-
* link:MATCH_OPTIONS[Match options reference]
|
|
446
|
-
* link:MODES[Diff modes]
|
|
447
|
-
* link:PREPROCESSING[Preprocessing options]
|