canon 0.1.9 → 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.
@@ -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
- # 2.5. Original Input Strings (ONLY if verbose_diff is enabled)
333
- if @verbose_diff && comparison_result.is_a?(Canon::Comparison::ComparisonResult)
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 << format_original_strings(original1, original2)
367
+ output << format_line_numbered_inputs(original1, original2)
337
368
  end
338
369
  end
339
370
 
340
- # 3. Main diff output (by-line or by-object) - ALWAYS
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 for display (RSpec-style)
432
- # Shows the actual strings that were passed in before any preprocessing
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 of original strings
437
- def format_original_strings(original1, original2)
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 INPUT STRINGS", :cyan, :bold)
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 (as string):", :yellow, :bold)
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("Actual (as string):", :yellow, :bold)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Canon
4
- VERSION = "0.1.9"
4
+ VERSION = "0.1.11"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-01-20 00:00:00.000000000 Z
11
+ date: 2026-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: diff-lcs
@@ -257,6 +257,7 @@ files:
257
257
  - lib/canon/diff/formatting_detector.rb
258
258
  - lib/canon/diff/node_serializer.rb
259
259
  - lib/canon/diff/path_builder.rb
260
+ - lib/canon/diff/xml_serialization_formatter.rb
260
261
  - lib/canon/diff_formatter.rb
261
262
  - lib/canon/diff_formatter/by_line/base_formatter.rb
262
263
  - lib/canon/diff_formatter/by_line/html_formatter.rb