canon 0.2.11 → 0.3.0
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 +62 -25
- data/CLAUDE.md +197 -0
- data/Rakefile +5 -2
- data/lib/canon/cache.rb +3 -1
- data/lib/canon/cli.rb +0 -3
- data/lib/canon/commands/diff_command.rb +1 -8
- data/lib/canon/commands/format_command.rb +0 -4
- data/lib/canon/commands.rb +9 -0
- data/lib/canon/comparison/child_realignment.rb +0 -2
- data/lib/canon/comparison/compare_profile.rb +30 -36
- data/lib/canon/comparison/comparison_result.rb +1 -4
- data/lib/canon/comparison/diff_node_builder.rb +353 -0
- data/lib/canon/comparison/dimensions/dimension.rb +51 -0
- data/lib/canon/comparison/dimensions/dimension_set.rb +49 -0
- data/lib/canon/comparison/dimensions/registry.rb +101 -60
- data/lib/canon/comparison/dimensions.rb +15 -46
- data/lib/canon/comparison/format_detector.rb +27 -29
- data/lib/canon/comparison/html_comparator.rb +20 -143
- data/lib/canon/comparison/html_compare_profile.rb +15 -18
- data/lib/canon/comparison/json_comparator.rb +4 -165
- data/lib/canon/comparison/json_parser.rb +0 -2
- data/lib/canon/comparison/markup_comparator.rb +14 -210
- data/lib/canon/comparison/match_options/base_resolver.rb +18 -29
- data/lib/canon/comparison/match_options/json_resolver.rb +4 -28
- data/lib/canon/comparison/match_options/xml_resolver.rb +4 -45
- data/lib/canon/comparison/match_options/yaml_resolver.rb +4 -30
- data/lib/canon/comparison/match_options.rb +13 -88
- data/lib/canon/comparison/node_inspector.rb +5 -9
- data/lib/canon/comparison/pipeline.rb +269 -0
- data/lib/canon/comparison/profile_definition.rb +0 -2
- data/lib/canon/comparison/ruby_object_comparator.rb +1 -1
- data/lib/canon/comparison/strategies/match_strategy_factory.rb +9 -58
- data/lib/canon/comparison/strategies/semantic_tree_match_strategy.rb +4 -11
- data/lib/canon/comparison/strategies.rb +16 -0
- data/lib/canon/comparison/xml_comparator/attribute_comparator.rb +1 -4
- data/lib/canon/comparison/xml_comparator/attribute_filter.rb +0 -3
- data/lib/canon/comparison/xml_comparator/child_comparison.rb +0 -6
- data/lib/canon/comparison/xml_comparator/namespace_comparator.rb +1 -6
- data/lib/canon/comparison/xml_comparator/node_parser.rb +3 -7
- data/lib/canon/comparison/xml_comparator.rb +4 -492
- data/lib/canon/comparison/xml_comparator_helpers.rb +21 -0
- data/lib/canon/comparison/xml_node_comparison.rb +6 -121
- data/lib/canon/comparison/yaml_comparator.rb +0 -3
- data/lib/canon/comparison.rb +144 -267
- data/lib/canon/config/config_dsl.rb +159 -0
- data/lib/canon/config/env_provider.rb +0 -3
- data/lib/canon/config/env_schema.rb +48 -58
- data/lib/canon/config/profile_loader.rb +0 -1
- data/lib/canon/config.rb +116 -468
- data/lib/canon/diff/diff_block_builder.rb +0 -2
- data/lib/canon/diff/diff_classifier.rb +0 -5
- data/lib/canon/diff/diff_context.rb +0 -2
- data/lib/canon/diff/diff_context_builder.rb +0 -2
- data/lib/canon/diff/diff_line_builder.rb +0 -3
- data/lib/canon/diff/diff_node_enricher.rb +0 -4
- data/lib/canon/diff/diff_node_mapper.rb +0 -4
- data/lib/canon/diff/diff_report_builder.rb +0 -4
- data/lib/canon/diff/formatting_detector.rb +0 -1
- data/lib/canon/diff/node_serializer.rb +0 -7
- data/lib/canon/diff.rb +39 -0
- data/lib/canon/diff_formatter/by_line/base_formatter.rb +5 -19
- data/lib/canon/diff_formatter/by_line/html_formatter.rb +8 -21
- data/lib/canon/diff_formatter/by_line/json_formatter.rb +0 -3
- data/lib/canon/diff_formatter/by_line/simple_formatter.rb +0 -3
- data/lib/canon/diff_formatter/by_line/xml_formatter.rb +7 -26
- data/lib/canon/diff_formatter/by_line/yaml_formatter.rb +0 -3
- data/lib/canon/diff_formatter/by_line_formatter.rb +1 -2
- data/lib/canon/diff_formatter/by_object/base_formatter.rb +8 -15
- data/lib/canon/diff_formatter/by_object/json_formatter.rb +0 -2
- data/lib/canon/diff_formatter/by_object/xml_formatter.rb +0 -2
- data/lib/canon/diff_formatter/by_object/yaml_formatter.rb +0 -2
- data/lib/canon/diff_formatter/debug_output.rb +0 -2
- data/lib/canon/diff_formatter/diff_detail_formatter/dimension_formatter.rb +24 -58
- data/lib/canon/diff_formatter/diff_detail_formatter/location_extractor.rb +0 -2
- data/lib/canon/diff_formatter/diff_detail_formatter/node_utils.rb +3 -4
- data/lib/canon/diff_formatter/diff_detail_formatter/text_utils.rb +1 -7
- data/lib/canon/diff_formatter/diff_detail_formatter.rb +0 -7
- data/lib/canon/diff_formatter/diff_detail_formatter_helpers.rb +23 -0
- data/lib/canon/diff_formatter/theme.rb +2 -2
- data/lib/canon/diff_formatter.rb +13 -13
- data/lib/canon/formatters/html4_formatter.rb +0 -2
- data/lib/canon/formatters/html5_formatter.rb +0 -2
- data/lib/canon/formatters/html_formatter.rb +0 -3
- data/lib/canon/formatters/json_formatter.rb +0 -1
- data/lib/canon/formatters/xml_formatter.rb +0 -4
- data/lib/canon/formatters/yaml_formatter.rb +0 -1
- data/lib/canon/formatters.rb +16 -0
- data/lib/canon/html/data_model.rb +0 -10
- data/lib/canon/html/nokogiri_support.rb +60 -0
- data/lib/canon/html.rb +5 -3
- data/lib/canon/options/cli_generator.rb +0 -2
- data/lib/canon/options/registry.rb +0 -2
- data/lib/canon/options.rb +9 -0
- data/lib/canon/pretty_printer/html.rb +0 -1
- data/lib/canon/pretty_printer/xml.rb +6 -1
- data/lib/canon/pretty_printer/xml_normalized.rb +5 -7
- data/lib/canon/pretty_printer.rb +12 -0
- data/lib/canon/tree_diff/adapters/html_adapter.rb +1 -1
- data/lib/canon/tree_diff/adapters.rb +14 -0
- data/lib/canon/tree_diff/core/attribute_comparator.rb +0 -6
- data/lib/canon/tree_diff/core/node_signature.rb +1 -1
- data/lib/canon/tree_diff/core/tree_node.rb +13 -5
- data/lib/canon/tree_diff/core.rb +17 -0
- data/lib/canon/tree_diff/matchers/hash_matcher.rb +0 -7
- data/lib/canon/tree_diff/matchers/similarity_matcher.rb +1 -5
- data/lib/canon/tree_diff/matchers/structural_propagator.rb +1 -5
- data/lib/canon/tree_diff/matchers.rb +15 -0
- data/lib/canon/tree_diff/operation_converter.rb +0 -8
- data/lib/canon/tree_diff/operation_converter_helpers/metadata_enricher.rb +2 -12
- data/lib/canon/tree_diff/operation_converter_helpers/post_processor.rb +13 -7
- data/lib/canon/tree_diff/operation_converter_helpers/reason_builder.rb +2 -2
- data/lib/canon/tree_diff/operation_converter_helpers/update_change_handler.rb +4 -6
- data/lib/canon/tree_diff/operation_converter_helpers.rb +18 -0
- data/lib/canon/tree_diff/operations/operation_detector.rb +2 -5
- data/lib/canon/tree_diff/operations.rb +13 -0
- data/lib/canon/tree_diff.rb +26 -27
- data/lib/canon/validators/base_validator.rb +0 -2
- data/lib/canon/validators/html_validator.rb +0 -1
- data/lib/canon/validators/json_validator.rb +0 -1
- data/lib/canon/validators/xml_validator.rb +0 -1
- data/lib/canon/validators/yaml_validator.rb +0 -1
- data/lib/canon/validators.rb +12 -0
- data/lib/canon/version.rb +1 -1
- data/lib/canon/xml/c14n.rb +0 -4
- data/lib/canon/xml/data_model.rb +206 -43
- data/lib/canon/xml/line_range_mapper.rb +0 -2
- data/lib/canon/xml/nodes/attribute_node.rb +0 -2
- data/lib/canon/xml/nodes/comment_node.rb +0 -2
- data/lib/canon/xml/nodes/element_node.rb +0 -2
- data/lib/canon/xml/nodes/namespace_node.rb +0 -2
- data/lib/canon/xml/nodes/processing_instruction_node.rb +0 -2
- data/lib/canon/xml/nodes/root_node.rb +0 -2
- data/lib/canon/xml/nodes/text_node.rb +0 -2
- data/lib/canon/xml/nodes.rb +19 -0
- data/lib/canon/xml/processor.rb +10 -7
- data/lib/canon/xml/sax/moxml_driver.rb +58 -0
- data/lib/canon/xml/sax/nokogiri_driver.rb +54 -0
- data/lib/canon/xml/sax.rb +37 -0
- data/lib/canon/xml/sax_builder.rb +31 -27
- data/lib/canon/xml.rb +34 -0
- data/lib/canon/xml_backend.rb +40 -19
- data/lib/canon/xml_parsing.rb +89 -116
- data/lib/canon.rb +26 -17
- data/lib/tasks/benchmark_runner.rb +4 -0
- data/lib/tasks/performance.rake +2 -58
- data/lib/tasks/performance_comparator.rb +132 -65
- data/lib/tasks/performance_helpers.rb +4 -249
- data/lib/tasks/performance_report.rb +313 -0
- metadata +31 -13
- data/lib/canon/comparison/dimensions/attribute_order_dimension.rb +0 -64
- data/lib/canon/comparison/dimensions/attribute_presence_dimension.rb +0 -64
- data/lib/canon/comparison/dimensions/attribute_values_dimension.rb +0 -167
- data/lib/canon/comparison/dimensions/base_dimension.rb +0 -107
- data/lib/canon/comparison/dimensions/comments_dimension.rb +0 -117
- data/lib/canon/comparison/dimensions/element_position_dimension.rb +0 -86
- data/lib/canon/comparison/dimensions/structural_whitespace_dimension.rb +0 -115
- data/lib/canon/comparison/dimensions/text_content_dimension.rb +0 -102
- data/lib/canon/comparison/xml_comparator/diff_node_builder.rb +0 -300
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative "diff_line"
|
|
4
3
|
require "set"
|
|
5
4
|
|
|
6
5
|
module Canon
|
|
@@ -159,8 +158,6 @@ module Canon
|
|
|
159
158
|
# @param diff_lines [Array<DiffLine>] The diff lines to update
|
|
160
159
|
# @param lcs_diffs [Array<Diff::LCS::Change>] The LCS changes
|
|
161
160
|
def apply_block_formatting!(diff_lines, lcs_diffs)
|
|
162
|
-
require_relative "formatting_detector"
|
|
163
|
-
|
|
164
161
|
blocks = group_change_blocks(lcs_diffs)
|
|
165
162
|
|
|
166
163
|
blocks.each do |block|
|
|
@@ -265,7 +262,6 @@ module Canon
|
|
|
265
262
|
# @param line2 [String] Second line
|
|
266
263
|
# @return [Boolean] true if formatting-only difference
|
|
267
264
|
def formatting_only_line?(line1, line2)
|
|
268
|
-
require_relative "formatting_detector"
|
|
269
265
|
FormattingDetector.formatting_only?(line1, line2)
|
|
270
266
|
end
|
|
271
267
|
|
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative "../xml/data_model"
|
|
4
|
-
require_relative "../xml/nodes/text_node"
|
|
5
|
-
require_relative "../xml/nodes/comment_node"
|
|
6
|
-
require_relative "../xml/nodes/element_node"
|
|
7
|
-
require_relative "../xml/nodes/processing_instruction_node"
|
|
8
|
-
require_relative "../xml/nodes/root_node"
|
|
9
|
-
|
|
10
3
|
module Canon
|
|
11
4
|
module Diff
|
|
12
5
|
# Serializes nodes from different parsing libraries into canonical strings
|
data/lib/canon/diff.rb
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Canon
|
|
4
|
+
# Diff representation and pipeline construction.
|
|
5
|
+
#
|
|
6
|
+
# This namespace holds the structural artifacts produced by the diff
|
|
7
|
+
# pipeline — DiffNode, DiffLine, DiffBlock, DiffContext, DiffReport —
|
|
8
|
+
# plus the builders that assemble them (DiffNodeMapper, DiffLineBuilder,
|
|
9
|
+
# DiffBlockBuilder, DiffContextBuilder, DiffReportBuilder) and the
|
|
10
|
+
# supporting services (PathBuilder, NodeSerializer, DiffClassifier,
|
|
11
|
+
# FormattingDetector, SourceLocator, TextDecomposer, DiffCharRange,
|
|
12
|
+
# DiffNodeEnricher, XmlSerializationFormatter).
|
|
13
|
+
#
|
|
14
|
+
# All children are autoloaded from this file — never `require_relative`
|
|
15
|
+
# them from sibling files. Reference the constant and let autoload
|
|
16
|
+
# resolve it on first use.
|
|
17
|
+
module Diff
|
|
18
|
+
autoload :DiffBlock, "canon/diff/diff_block"
|
|
19
|
+
autoload :DiffBlockBuilder, "canon/diff/diff_block_builder"
|
|
20
|
+
autoload :DiffCharRange, "canon/diff/diff_char_range"
|
|
21
|
+
autoload :DiffClassifier, "canon/diff/diff_classifier"
|
|
22
|
+
autoload :DiffContext, "canon/diff/diff_context"
|
|
23
|
+
autoload :DiffContextBuilder, "canon/diff/diff_context_builder"
|
|
24
|
+
autoload :DiffLine, "canon/diff/diff_line"
|
|
25
|
+
autoload :DiffLineBuilder, "canon/diff/diff_line_builder"
|
|
26
|
+
autoload :DiffNode, "canon/diff/diff_node"
|
|
27
|
+
autoload :DiffNodeEnricher, "canon/diff/diff_node_enricher"
|
|
28
|
+
autoload :DiffNodeMapper, "canon/diff/diff_node_mapper"
|
|
29
|
+
autoload :DiffReport, "canon/diff/diff_report"
|
|
30
|
+
autoload :DiffReportBuilder, "canon/diff/diff_report_builder"
|
|
31
|
+
autoload :FormattingDetector, "canon/diff/formatting_detector"
|
|
32
|
+
autoload :NodeSerializer, "canon/diff/node_serializer"
|
|
33
|
+
autoload :PathBuilder, "canon/diff/path_builder"
|
|
34
|
+
autoload :SourceLocator, "canon/diff/source_locator"
|
|
35
|
+
autoload :TextDecomposer, "canon/diff/text_decomposer"
|
|
36
|
+
autoload :XmlSerializationFormatter,
|
|
37
|
+
"canon/diff/xml_serialization_formatter"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
require "diff/lcs" unless RUBY_ENGINE == "opal"
|
|
4
4
|
require "diff/lcs/hunk" unless RUBY_ENGINE == "opal"
|
|
5
|
-
require_relative "../debug_output"
|
|
6
|
-
require_relative "../theme"
|
|
7
5
|
|
|
8
6
|
module Canon
|
|
9
7
|
class DiffFormatter
|
|
@@ -22,10 +20,8 @@ module Canon
|
|
|
22
20
|
def self.for_format(format, **options)
|
|
23
21
|
case format
|
|
24
22
|
when :xml
|
|
25
|
-
require_relative "xml_formatter"
|
|
26
23
|
XmlFormatter.new(**options)
|
|
27
24
|
when :html, :html4, :html5
|
|
28
|
-
require_relative "html_formatter"
|
|
29
25
|
# Determine HTML version from format
|
|
30
26
|
version = case format
|
|
31
27
|
when :html5 then :html5
|
|
@@ -34,18 +30,15 @@ module Canon
|
|
|
34
30
|
end
|
|
35
31
|
HtmlFormatter.new(html_version: version, **options)
|
|
36
32
|
when :json
|
|
37
|
-
require_relative "json_formatter"
|
|
38
33
|
JsonFormatter.new(**options)
|
|
39
34
|
when :yaml
|
|
40
|
-
require_relative "yaml_formatter"
|
|
41
35
|
YamlFormatter.new(**options)
|
|
42
36
|
else
|
|
43
|
-
require_relative "simple_formatter"
|
|
44
37
|
SimpleFormatter.new(**options)
|
|
45
38
|
end
|
|
46
39
|
end
|
|
47
40
|
|
|
48
|
-
# rubocop:disable Metrics/ParameterLists
|
|
41
|
+
# rubocop:disable-next Metrics/ParameterLists
|
|
49
42
|
def initialize(use_color: true, context_lines: 3,
|
|
50
43
|
diff_grouping_lines: nil, visualization_map: nil,
|
|
51
44
|
show_diffs: :all, differences: [],
|
|
@@ -65,7 +58,6 @@ module Canon
|
|
|
65
58
|
@theme = theme
|
|
66
59
|
@character_visualization = character_visualization
|
|
67
60
|
end
|
|
68
|
-
# rubocop:enable Metrics/ParameterLists
|
|
69
61
|
|
|
70
62
|
# Get the resolved theme hash
|
|
71
63
|
# @return [Hash] Theme hash
|
|
@@ -279,7 +271,7 @@ module Canon
|
|
|
279
271
|
|
|
280
272
|
differences.select do |diff|
|
|
281
273
|
# Handle both DiffNode objects and legacy Hash format
|
|
282
|
-
is_normative = if diff.
|
|
274
|
+
is_normative = if diff.is_a?(Canon::Diff::DiffNode)
|
|
283
275
|
diff.normative?
|
|
284
276
|
elsif diff.is_a?(Hash) && diff.key?(:normative)
|
|
285
277
|
diff[:normative]
|
|
@@ -394,8 +386,6 @@ module Canon
|
|
|
394
386
|
# @param diffs [Array] LCS diff array
|
|
395
387
|
# @return [Array<Canon::Diff::DiffBlock>] Array of diff blocks
|
|
396
388
|
def identify_diff_blocks(diffs)
|
|
397
|
-
require_relative "../../diff/diff_block"
|
|
398
|
-
|
|
399
389
|
blocks = []
|
|
400
390
|
current_start = nil
|
|
401
391
|
current_types = []
|
|
@@ -467,8 +457,6 @@ module Canon
|
|
|
467
457
|
# @return [Array<Canon::Diff::DiffContext>] Array of diff contexts
|
|
468
458
|
def expand_contexts_with_context_lines(contexts, context_lines,
|
|
469
459
|
total_lines)
|
|
470
|
-
require_relative "../../diff/diff_context"
|
|
471
|
-
|
|
472
460
|
contexts.map do |context|
|
|
473
461
|
first_block = context.first
|
|
474
462
|
last_block = context.last
|
|
@@ -736,10 +724,8 @@ module Canon
|
|
|
736
724
|
next unless match.status == :matched
|
|
737
725
|
|
|
738
726
|
[match.elem1, match.elem2].compact.each do |elem|
|
|
739
|
-
next unless elem.respond_to?(:children)
|
|
740
|
-
|
|
741
727
|
elem.children.each do |child|
|
|
742
|
-
children.add(child) if
|
|
728
|
+
children.add(child) if Canon::Comparison::NodeInspector.element_node?(child)
|
|
743
729
|
end
|
|
744
730
|
end
|
|
745
731
|
end
|
|
@@ -778,8 +764,8 @@ module Canon
|
|
|
778
764
|
return true if elements_with_semantic_diffs.include?(element)
|
|
779
765
|
|
|
780
766
|
# Check all descendants
|
|
781
|
-
if
|
|
782
|
-
|
|
767
|
+
if Canon::Comparison::NodeInspector.element_node?(element)
|
|
768
|
+
Canon::Comparison::NodeInspector.children(element).any? do |child|
|
|
783
769
|
has_semantic_diff_in_subtree?(child, elements_with_semantic_diffs)
|
|
784
770
|
end
|
|
785
771
|
else
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative "base_formatter"
|
|
4
|
-
require_relative "../legend"
|
|
5
3
|
require "set"
|
|
6
4
|
|
|
7
5
|
module Canon
|
|
@@ -12,7 +10,7 @@ module Canon
|
|
|
12
10
|
class HtmlFormatter < BaseFormatter
|
|
13
11
|
attr_reader :html_version
|
|
14
12
|
|
|
15
|
-
# rubocop:disable Metrics/ParameterLists
|
|
13
|
+
# rubocop:disable-next Metrics/ParameterLists
|
|
16
14
|
def initialize(use_color: true, context_lines: 3,
|
|
17
15
|
diff_grouping_lines: nil, visualization_map: nil,
|
|
18
16
|
html_version: :html4, show_diffs: :all, differences: [],
|
|
@@ -27,7 +25,6 @@ module Canon
|
|
|
27
25
|
character_visualization: character_visualization)
|
|
28
26
|
@html_version = html_version
|
|
29
27
|
end
|
|
30
|
-
# rubocop:enable Metrics/ParameterLists
|
|
31
28
|
|
|
32
29
|
# Format DOM-guided HTML diff
|
|
33
30
|
#
|
|
@@ -53,11 +50,6 @@ module Canon
|
|
|
53
50
|
return ""
|
|
54
51
|
end
|
|
55
52
|
|
|
56
|
-
require_relative "../../html/data_model"
|
|
57
|
-
require_relative "../../xml/element_matcher"
|
|
58
|
-
require_relative "../../xml/line_range_mapper"
|
|
59
|
-
require_relative "../../pretty_printer/html"
|
|
60
|
-
|
|
61
53
|
output = []
|
|
62
54
|
|
|
63
55
|
begin
|
|
@@ -107,7 +99,6 @@ module Canon
|
|
|
107
99
|
end
|
|
108
100
|
|
|
109
101
|
output << ""
|
|
110
|
-
require_relative "simple_formatter"
|
|
111
102
|
simple = SimpleFormatter.new(
|
|
112
103
|
use_color: @use_color,
|
|
113
104
|
context_lines: @context_lines,
|
|
@@ -122,9 +113,6 @@ module Canon
|
|
|
122
113
|
|
|
123
114
|
# Format using new DiffReportBuilder pipeline
|
|
124
115
|
def format_with_pipeline(doc1, doc2)
|
|
125
|
-
require_relative "../../diff/diff_node_mapper"
|
|
126
|
-
require_relative "../../diff/diff_report_builder"
|
|
127
|
-
|
|
128
116
|
# Layer 2: Map DiffNodes to DiffLines
|
|
129
117
|
diff_lines = Canon::Diff::DiffNodeMapper.map(@differences, doc1, doc2)
|
|
130
118
|
|
|
@@ -350,15 +338,14 @@ module Canon
|
|
|
350
338
|
|
|
351
339
|
# Second pass: skip children of elements with diffs
|
|
352
340
|
elements_with_diffs.each do |elem|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
end
|
|
360
|
-
current = current.respond_to?(:parent) ? current.parent : nil
|
|
341
|
+
current = Canon::Comparison::NodeInspector.parent(elem)
|
|
342
|
+
while current
|
|
343
|
+
if Canon::Comparison::NodeInspector.element_node?(current) &&
|
|
344
|
+
elements_with_diffs.include?(current)
|
|
345
|
+
elements_to_skip.add(elem)
|
|
346
|
+
break
|
|
361
347
|
end
|
|
348
|
+
current = Canon::Comparison::NodeInspector.parent(current)
|
|
362
349
|
end
|
|
363
350
|
end
|
|
364
351
|
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative "base_formatter"
|
|
4
|
-
require_relative "../legend"
|
|
5
3
|
require "strscan"
|
|
6
4
|
|
|
7
5
|
module Canon
|
|
@@ -38,7 +36,6 @@ module Canon
|
|
|
38
36
|
output << colorize(
|
|
39
37
|
"Warning: JSON parsing failed (#{e.message}), using simple diff", :yellow
|
|
40
38
|
)
|
|
41
|
-
require_relative "simple_formatter"
|
|
42
39
|
simple = SimpleFormatter.new(
|
|
43
40
|
use_color: @use_color,
|
|
44
41
|
context_lines: @context_lines,
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative "base_formatter"
|
|
4
|
-
require_relative "../legend"
|
|
5
|
-
require_relative "../../tree_diff/core/xml_entity_decoder"
|
|
6
3
|
require "set"
|
|
7
4
|
require "strscan"
|
|
8
5
|
|
|
@@ -44,10 +41,6 @@ module Canon
|
|
|
44
41
|
return ""
|
|
45
42
|
end
|
|
46
43
|
|
|
47
|
-
require_relative "../../diff/diff_node_enricher"
|
|
48
|
-
require_relative "../../diff/diff_line_builder"
|
|
49
|
-
require_relative "../../diff/diff_report_builder"
|
|
50
|
-
|
|
51
44
|
# Compute line number width BEFORE formatting
|
|
52
45
|
compute_line_num_width(doc1, doc2)
|
|
53
46
|
|
|
@@ -201,10 +194,6 @@ module Canon
|
|
|
201
194
|
return ""
|
|
202
195
|
end
|
|
203
196
|
|
|
204
|
-
require_relative "../../xml/data_model"
|
|
205
|
-
require_relative "../../xml/element_matcher"
|
|
206
|
-
require_relative "../../xml/line_range_mapper"
|
|
207
|
-
|
|
208
197
|
output = []
|
|
209
198
|
|
|
210
199
|
begin
|
|
@@ -247,7 +236,6 @@ module Canon
|
|
|
247
236
|
end
|
|
248
237
|
|
|
249
238
|
output << ""
|
|
250
|
-
require_relative "simple_formatter"
|
|
251
239
|
simple = SimpleFormatter.new(
|
|
252
240
|
use_color: @use_color,
|
|
253
241
|
context_lines: @context_lines,
|
|
@@ -622,15 +610,14 @@ module Canon
|
|
|
622
610
|
|
|
623
611
|
# Second pass: skip children of elements with diffs
|
|
624
612
|
elements_with_diffs.each do |elem|
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
end
|
|
632
|
-
current = current.respond_to?(:parent) ? current.parent : nil
|
|
613
|
+
current = Canon::Comparison::NodeInspector.parent(elem)
|
|
614
|
+
while current
|
|
615
|
+
if Canon::Comparison::NodeInspector.element_node?(current) &&
|
|
616
|
+
elements_with_diffs.include?(current)
|
|
617
|
+
elements_to_skip.add(elem)
|
|
618
|
+
break
|
|
633
619
|
end
|
|
620
|
+
current = Canon::Comparison::NodeInspector.parent(current)
|
|
634
621
|
end
|
|
635
622
|
end
|
|
636
623
|
|
|
@@ -721,8 +708,6 @@ module Canon
|
|
|
721
708
|
|
|
722
709
|
# Identify contiguous diff blocks
|
|
723
710
|
def identify_diff_blocks(diffs)
|
|
724
|
-
require_relative "../../diff/diff_block"
|
|
725
|
-
|
|
726
711
|
blocks = []
|
|
727
712
|
current_start = nil
|
|
728
713
|
current_types = []
|
|
@@ -784,8 +769,6 @@ module Canon
|
|
|
784
769
|
# Expand contexts with context lines
|
|
785
770
|
def expand_contexts_with_context_lines(contexts, context_lines,
|
|
786
771
|
total_lines)
|
|
787
|
-
require_relative "../../diff/diff_context"
|
|
788
|
-
|
|
789
772
|
contexts.map do |context|
|
|
790
773
|
first_block = context.first
|
|
791
774
|
last_block = context.last
|
|
@@ -803,8 +786,6 @@ module Canon
|
|
|
803
786
|
|
|
804
787
|
# Format a context
|
|
805
788
|
def format_context(context, diffs, base_line1, base_line2)
|
|
806
|
-
require_relative "../../diff/formatting_detector"
|
|
807
|
-
|
|
808
789
|
# Pre-compute block-level formatting for multi-line changes
|
|
809
790
|
formatting_indices = detect_block_formatting(context, diffs)
|
|
810
791
|
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative "base_formatter"
|
|
4
|
-
require_relative "../legend"
|
|
5
3
|
require "strscan"
|
|
6
4
|
|
|
7
5
|
module Canon
|
|
@@ -37,7 +35,6 @@ module Canon
|
|
|
37
35
|
output << colorize(
|
|
38
36
|
"Warning: YAML parsing failed (#{e.message}), using simple diff", :yellow
|
|
39
37
|
)
|
|
40
|
-
require_relative "simple_formatter"
|
|
41
38
|
simple = SimpleFormatter.new(
|
|
42
39
|
use_color: @use_color,
|
|
43
40
|
context_lines: @context_lines,
|
|
@@ -9,7 +9,7 @@ module Canon
|
|
|
9
9
|
# Receives preprocessed document strings from the DiffFormatter facade
|
|
10
10
|
# and delegates to format-specific ByLine formatters (XML, HTML, JSON, YAML).
|
|
11
11
|
class ByLineFormatter
|
|
12
|
-
# rubocop:disable Metrics/ParameterLists
|
|
12
|
+
# rubocop:disable-next Metrics/ParameterLists
|
|
13
13
|
def initialize(use_color:, visualization_map:, context_lines:,
|
|
14
14
|
diff_grouping_lines:, show_diffs:, character_visualization:,
|
|
15
15
|
legacy_terminal:, diff_mode:)
|
|
@@ -22,7 +22,6 @@ module Canon
|
|
|
22
22
|
@legacy_terminal = legacy_terminal
|
|
23
23
|
@diff_mode = diff_mode
|
|
24
24
|
end
|
|
25
|
-
# rubocop:enable Metrics/ParameterLists
|
|
26
25
|
|
|
27
26
|
# Format a line-by-line diff between two documents.
|
|
28
27
|
#
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "set"
|
|
4
|
-
require_relative "../theme"
|
|
5
4
|
|
|
6
5
|
module Canon
|
|
7
6
|
class DiffFormatter
|
|
@@ -76,19 +75,16 @@ show_diffs: :all, theme: nil)
|
|
|
76
75
|
show_diffs: :all, theme: nil)
|
|
77
76
|
case format
|
|
78
77
|
when :xml, :html
|
|
79
|
-
require_relative "xml_formatter"
|
|
80
78
|
XmlFormatter.new(use_color: use_color,
|
|
81
79
|
visualization_map: visualization_map,
|
|
82
80
|
show_diffs: show_diffs,
|
|
83
81
|
theme: theme)
|
|
84
82
|
when :json
|
|
85
|
-
require_relative "json_formatter"
|
|
86
83
|
JsonFormatter.new(use_color: use_color,
|
|
87
84
|
visualization_map: visualization_map,
|
|
88
85
|
show_diffs: show_diffs,
|
|
89
86
|
theme: theme)
|
|
90
87
|
when :yaml
|
|
91
|
-
require_relative "yaml_formatter"
|
|
92
88
|
YamlFormatter.new(use_color: use_color,
|
|
93
89
|
visualization_map: visualization_map,
|
|
94
90
|
show_diffs: show_diffs,
|
|
@@ -221,23 +217,20 @@ show_diffs: :all, theme: nil)
|
|
|
221
217
|
current = node
|
|
222
218
|
visited = Set.new
|
|
223
219
|
|
|
224
|
-
while current
|
|
225
|
-
# Prevent infinite loops by tracking visited nodes
|
|
220
|
+
while current
|
|
226
221
|
break if visited.include?(current.object_id)
|
|
227
222
|
|
|
228
223
|
visited << current.object_id
|
|
229
224
|
|
|
230
|
-
|
|
225
|
+
break if Canon::Comparison::NodeInspector.document?(current) ||
|
|
226
|
+
Canon::Comparison::NodeInspector.document_fragment?(current)
|
|
227
|
+
|
|
228
|
+
name = Canon::Comparison::NodeInspector.name(current)
|
|
229
|
+
break if name.nil?
|
|
231
230
|
|
|
232
|
-
|
|
233
|
-
break if current.is_a?(Nokogiri::XML::Document) ||
|
|
234
|
-
current.is_a?(Nokogiri::HTML4::Document) ||
|
|
235
|
-
current.is_a?(Nokogiri::HTML5::Document) ||
|
|
236
|
-
current.is_a?(Nokogiri::XML::DocumentFragment) ||
|
|
237
|
-
current.is_a?(Nokogiri::HTML4::DocumentFragment) ||
|
|
238
|
-
current.is_a?(Nokogiri::HTML5::DocumentFragment)
|
|
231
|
+
parts.unshift(name) unless name.empty?
|
|
239
232
|
|
|
240
|
-
current =
|
|
233
|
+
current = Canon::Comparison::NodeInspector.parent(current)
|
|
241
234
|
end
|
|
242
235
|
|
|
243
236
|
parts.empty? ? diff_node.dimension.to_s : parts.join(".")
|