super_diff 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +65 -26
- data/lib/super_diff/active_record/differs/active_record_relation.rb +1 -2
- data/lib/super_diff/active_record/differs.rb +1 -1
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model.rb +5 -13
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +1 -3
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +2 -2
- data/lib/super_diff/active_record/object_inspection.rb +1 -1
- data/lib/super_diff/active_record/operation_tree_builders/active_record_model.rb +1 -2
- data/lib/super_diff/active_record/operation_tree_builders/active_record_relation.rb +1 -2
- data/lib/super_diff/active_record/operation_tree_builders.rb +2 -2
- data/lib/super_diff/active_record/operation_tree_flatteners.rb +1 -1
- data/lib/super_diff/active_record/operation_trees.rb +1 -1
- data/lib/super_diff/active_record.rb +7 -15
- data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +5 -6
- data/lib/super_diff/active_support/differs.rb +1 -1
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +3 -9
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +1 -1
- data/lib/super_diff/active_support/object_inspection.rb +1 -1
- data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +5 -6
- data/lib/super_diff/active_support/operation_tree_builders.rb +1 -1
- data/lib/super_diff/active_support/operation_tree_flatteners.rb +1 -1
- data/lib/super_diff/active_support/operation_trees.rb +1 -1
- data/lib/super_diff/active_support.rb +6 -11
- data/lib/super_diff/colorized_document_extensions.rb +2 -4
- data/lib/super_diff/configuration.rb +14 -8
- data/lib/super_diff/csi/color.rb +4 -4
- data/lib/super_diff/csi/colorized_document.rb +12 -16
- data/lib/super_diff/csi/document.rb +8 -19
- data/lib/super_diff/csi/eight_bit_color.rb +19 -19
- data/lib/super_diff/csi/four_bit_color.rb +82 -31
- data/lib/super_diff/csi/twenty_four_bit_color.rb +12 -11
- data/lib/super_diff/csi/uncolorized_document.rb +2 -6
- data/lib/super_diff/csi.rb +10 -14
- data/lib/super_diff/diff_formatters/collection.rb +35 -41
- data/lib/super_diff/differs/default_object.rb +1 -1
- data/lib/super_diff/differs/defaults.rb +1 -1
- data/lib/super_diff/differs/main.rb +2 -13
- data/lib/super_diff/equality_matchers/array.rb +10 -12
- data/lib/super_diff/equality_matchers/base.rb +1 -1
- data/lib/super_diff/equality_matchers/default.rb +2 -4
- data/lib/super_diff/equality_matchers/defaults.rb +1 -1
- data/lib/super_diff/equality_matchers/hash.rb +10 -12
- data/lib/super_diff/equality_matchers/multiline_string.rb +11 -13
- data/lib/super_diff/equality_matchers/primitive.rb +10 -12
- data/lib/super_diff/equality_matchers/singleline_string.rb +10 -12
- data/lib/super_diff/equality_matchers.rb +1 -1
- data/lib/super_diff/errors.rb +3 -3
- data/lib/super_diff/gem_version.rb +3 -3
- data/lib/super_diff/helpers.rb +10 -10
- data/lib/super_diff/implementation_checks.rb +2 -2
- data/lib/super_diff/line.rb +3 -3
- data/lib/super_diff/object_inspection/inspection_tree.rb +46 -60
- data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +2 -6
- data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +3 -9
- data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +5 -14
- data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +1 -1
- data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +4 -12
- data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +6 -23
- data/lib/super_diff/object_inspection/inspection_tree_builders.rb +9 -9
- data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +8 -20
- data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +1 -5
- data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +1 -5
- data/lib/super_diff/object_inspection/nodes/as_single_line.rb +3 -7
- data/lib/super_diff/object_inspection/nodes/base.rb +9 -14
- data/lib/super_diff/object_inspection/nodes/inspection.rb +26 -34
- data/lib/super_diff/object_inspection/nodes/nesting.rb +1 -1
- data/lib/super_diff/object_inspection/nodes/only_when.rb +2 -6
- data/lib/super_diff/object_inspection/nodes/text.rb +1 -5
- data/lib/super_diff/object_inspection/nodes/when_empty.rb +2 -6
- data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +2 -6
- data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +1 -1
- data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +1 -5
- data/lib/super_diff/object_inspection/nodes.rb +7 -7
- data/lib/super_diff/object_inspection.rb +3 -3
- data/lib/super_diff/operation_tree_builders/array.rb +12 -11
- data/lib/super_diff/operation_tree_builders/base.rb +17 -15
- data/lib/super_diff/operation_tree_builders/custom_object.rb +8 -6
- data/lib/super_diff/operation_tree_builders/default_object.rb +29 -21
- data/lib/super_diff/operation_tree_builders/hash.rb +23 -24
- data/lib/super_diff/operation_tree_builders/main.rb +4 -11
- data/lib/super_diff/operation_tree_builders/multiline_string.rb +3 -3
- data/lib/super_diff/operation_tree_builders/time_like.rb +1 -11
- data/lib/super_diff/operation_tree_builders.rb +1 -1
- data/lib/super_diff/operation_tree_flatteners/base.rb +1 -5
- data/lib/super_diff/operation_tree_flatteners/collection.rb +13 -16
- data/lib/super_diff/operation_tree_flatteners/default_object.rb +1 -2
- data/lib/super_diff/operation_tree_flatteners/hash.rb +2 -10
- data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +2 -1
- data/lib/super_diff/operation_tree_flatteners.rb +3 -3
- data/lib/super_diff/operation_trees/base.rb +3 -5
- data/lib/super_diff/operation_trees/default_object.rb +1 -3
- data/lib/super_diff/operations/binary_operation.rb +2 -2
- data/lib/super_diff/operations/unary_operation.rb +1 -1
- data/lib/super_diff/rails.rb +2 -1
- data/lib/super_diff/recursion_guard.rb +5 -4
- data/lib/super_diff/rspec/augmented_matcher.rb +4 -5
- data/lib/super_diff/rspec/differ.rb +6 -13
- data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +3 -2
- data/lib/super_diff/rspec/differs/collection_including.rb +1 -1
- data/lib/super_diff/rspec/differs/hash_including.rb +1 -1
- data/lib/super_diff/rspec/differs.rb +3 -3
- data/lib/super_diff/rspec/matcher_text_builders/base.rb +13 -15
- data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +5 -7
- data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +3 -5
- data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +1 -5
- data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +2 -6
- data/lib/super_diff/rspec/matcher_text_builders.rb +5 -8
- data/lib/super_diff/rspec/matcher_text_template.rb +13 -16
- data/lib/super_diff/rspec/monkey_patches.rb +122 -116
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +8 -6
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +11 -16
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +2 -1
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +8 -6
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +8 -6
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +9 -9
- data/lib/super_diff/rspec/object_inspection.rb +1 -1
- data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +11 -10
- data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +7 -6
- data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +11 -10
- data/lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb +22 -17
- data/lib/super_diff/rspec/operation_tree_builders.rb +4 -4
- data/lib/super_diff/rspec.rb +11 -13
- data/lib/super_diff/tiered_lines_elider.rb +87 -115
- data/lib/super_diff/tiered_lines_formatter.rb +5 -9
- data/lib/super_diff/version.rb +1 -1
- data/lib/super_diff.rb +4 -9
- data/spec/examples.txt +493 -485
- data/spec/integration/rails/active_record_spec.rb +3 -1
- data/spec/integration/rails/engines_spec.rb +20 -0
- data/spec/integration/rails/hash_with_indifferent_access_spec.rb +3 -1
- data/spec/integration/rspec/be_falsey_matcher_spec.rb +40 -35
- data/spec/integration/rspec/be_matcher_spec.rb +360 -320
- data/spec/integration/rspec/be_nil_matcher_spec.rb +38 -34
- data/spec/integration/rspec/be_predicate_matcher_spec.rb +376 -359
- data/spec/integration/rspec/be_truthy_matcher_spec.rb +38 -33
- data/spec/integration/rspec/contain_exactly_matcher_spec.rb +242 -239
- data/spec/integration/rspec/eq_matcher_spec.rb +595 -557
- data/spec/integration/rspec/have_attributes_matcher_spec.rb +294 -286
- data/spec/integration/rspec/have_predicate_matcher_spec.rb +291 -297
- data/spec/integration/rspec/include_matcher_spec.rb +317 -215
- data/spec/integration/rspec/match_array_matcher_spec.rb +276 -273
- data/spec/integration/rspec/match_matcher_spec.rb +847 -834
- data/spec/integration/rspec/raise_error_matcher_spec.rb +468 -453
- data/spec/integration/rspec/respond_to_matcher_spec.rb +702 -697
- data/spec/integration/rspec/third_party_matcher_spec.rb +142 -138
- data/spec/integration/rspec/unhandled_errors_spec.rb +88 -84
- data/spec/spec_helper.rb +17 -20
- data/spec/support/command_runner.rb +34 -57
- data/spec/support/integration/helpers.rb +35 -28
- data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +28 -23
- data/spec/support/integration/test_programs/base.rb +12 -17
- data/spec/support/integration/test_programs/plain.rb +6 -0
- data/spec/support/integration/test_programs/rspec_active_record.rb +4 -1
- data/spec/support/integration/test_programs/rspec_active_support.rb +4 -1
- data/spec/support/integration/test_programs/rspec_rails.rb +4 -1
- data/spec/support/integration/test_programs/rspec_rails_engine.rb +30 -0
- data/spec/support/models/active_record/person.rb +6 -4
- data/spec/support/models/active_record/shipping_address.rb +9 -10
- data/spec/support/models/customer.rb +2 -4
- data/spec/support/models/player.rb +3 -6
- data/spec/support/models/shipping_address.rb +4 -13
- data/spec/support/shared_examples/active_record.rb +232 -214
- data/spec/support/shared_examples/active_support.rb +53 -51
- data/spec/support/shared_examples/elided_diffs.rb +405 -381
- data/spec/support/shared_examples/hash_with_indifferent_access.rb +424 -388
- data/spec/support/shared_examples/key.rb +123 -0
- data/spec/support/unit/helpers.rb +1 -3
- data/spec/support/unit/matchers/match_output.rb +12 -13
- data/spec/unit/active_record/object_inspection_spec.rb +222 -206
- data/spec/unit/equality_matchers/main_spec.rb +1049 -984
- data/spec/unit/helpers_spec.rb +14 -21
- data/spec/unit/operation_tree_flatteners/array_spec.rb +557 -524
- data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +619 -601
- data/spec/unit/operation_tree_flatteners/default_object_spec.rb +619 -621
- data/spec/unit/operation_tree_flatteners/hash_spec.rb +595 -556
- data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +102 -92
- data/spec/unit/rspec/matchers/be_compared_to_spec.rb +3 -3
- data/spec/unit/rspec/matchers/be_predicate_spec.rb +3 -3
- data/spec/unit/rspec/matchers/contain_exactly_spec.rb +1 -1
- data/spec/unit/rspec/matchers/have_attributes_spec.rb +1 -1
- data/spec/unit/rspec/matchers/have_predicate_spec.rb +2 -2
- data/spec/unit/rspec/matchers/include_spec.rb +2 -2
- data/spec/unit/rspec/matchers/match_array_spec.rb +2 -2
- data/spec/unit/rspec/matchers/raise_error_spec.rb +5 -5
- data/spec/unit/rspec/matchers/respond_to_spec.rb +23 -16
- data/spec/unit/rspec/object_inspection_spec.rb +349 -324
- data/spec/unit/super_diff_spec.rb +1542 -1449
- data/spec/unit/tiered_lines_elider_spec.rb +3508 -3536
- data/spec/unit/tiered_lines_formatter_spec.rb +54 -116
- data/super_diff.gemspec +13 -12
- metadata +73 -73
- data/spec/tmp/warnings_logger/all_warnings.txt +0 -2
@@ -18,11 +18,7 @@ module SuperDiff
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def render_to_string(object)
|
21
|
-
|
22
|
-
render_to_string_in_subtree(object)
|
23
|
-
else
|
24
|
-
""
|
25
|
-
end
|
21
|
+
test_passes? ? render_to_string_in_subtree(object) : ""
|
26
22
|
end
|
27
23
|
|
28
24
|
def render_to_lines(object, type:, indentation_level:)
|
@@ -30,7 +26,7 @@ module SuperDiff
|
|
30
26
|
render_to_lines_in_subtree(
|
31
27
|
object,
|
32
28
|
type: type,
|
33
|
-
indentation_level: indentation_level
|
29
|
+
indentation_level: indentation_level
|
34
30
|
)
|
35
31
|
else
|
36
32
|
[]
|
@@ -11,11 +11,7 @@ module SuperDiff
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def render_to_string(object)
|
14
|
-
|
15
|
-
render_to_string_in_subtree(object)
|
16
|
-
else
|
17
|
-
""
|
18
|
-
end
|
14
|
+
empty?(object) ? render_to_string_in_subtree(object) : ""
|
19
15
|
end
|
20
16
|
|
21
17
|
def render_to_lines(object, type:, indentation_level:)
|
@@ -23,7 +19,7 @@ module SuperDiff
|
|
23
19
|
render_to_lines_in_subtree(
|
24
20
|
object,
|
25
21
|
type: type,
|
26
|
-
indentation_level: indentation_level
|
22
|
+
indentation_level: indentation_level
|
27
23
|
)
|
28
24
|
else
|
29
25
|
[]
|
@@ -11,11 +11,7 @@ module SuperDiff
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def render_to_string(object)
|
14
|
-
|
15
|
-
""
|
16
|
-
else
|
17
|
-
render_to_string_in_subtree(object)
|
18
|
-
end
|
14
|
+
empty?(object) ? "" : render_to_string_in_subtree(object)
|
19
15
|
end
|
20
16
|
|
21
17
|
def render_to_lines(object, type:, indentation_level:)
|
@@ -25,7 +21,7 @@ module SuperDiff
|
|
25
21
|
render_to_lines_in_subtree(
|
26
22
|
object,
|
27
23
|
type: type,
|
28
|
-
indentation_level: indentation_level
|
24
|
+
indentation_level: indentation_level
|
29
25
|
)
|
30
26
|
end
|
31
27
|
end
|
@@ -11,11 +11,7 @@ module SuperDiff
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def render_to_string(object)
|
14
|
-
|
15
|
-
render_to_string_in_subtree(object)
|
16
|
-
else
|
17
|
-
immediate_value.to_s
|
18
|
-
end
|
14
|
+
block ? render_to_string_in_subtree(object) : immediate_value.to_s
|
19
15
|
end
|
20
16
|
|
21
17
|
def render_to_lines(*, **)
|
@@ -3,19 +3,19 @@ module SuperDiff
|
|
3
3
|
module Nodes
|
4
4
|
autoload(
|
5
5
|
:AsLinesWhenRenderingToLines,
|
6
|
-
"super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines"
|
6
|
+
"super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines"
|
7
7
|
)
|
8
8
|
autoload(
|
9
9
|
:AsPrefixWhenRenderingToLines,
|
10
|
-
"super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines"
|
10
|
+
"super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines"
|
11
11
|
)
|
12
12
|
autoload(
|
13
13
|
:AsPreludeWhenRenderingToLines,
|
14
|
-
"super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines"
|
14
|
+
"super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines"
|
15
15
|
)
|
16
16
|
autoload(
|
17
17
|
:AsSingleLine,
|
18
|
-
"super_diff/object_inspection/nodes/as_single_line"
|
18
|
+
"super_diff/object_inspection/nodes/as_single_line"
|
19
19
|
)
|
20
20
|
autoload :Base, "super_diff/object_inspection/nodes/base"
|
21
21
|
autoload :Inspection, "super_diff/object_inspection/nodes/inspection"
|
@@ -24,11 +24,11 @@ module SuperDiff
|
|
24
24
|
autoload :Text, "super_diff/object_inspection/nodes/text"
|
25
25
|
autoload(
|
26
26
|
:WhenRenderingToLines,
|
27
|
-
"super_diff/object_inspection/nodes/when_rendering_to_lines"
|
27
|
+
"super_diff/object_inspection/nodes/when_rendering_to_lines"
|
28
28
|
)
|
29
29
|
autoload(
|
30
30
|
:WhenRenderingToString,
|
31
|
-
"super_diff/object_inspection/nodes/when_rendering_to_string"
|
31
|
+
"super_diff/object_inspection/nodes/when_rendering_to_string"
|
32
32
|
)
|
33
33
|
|
34
34
|
def self.registry
|
@@ -42,7 +42,7 @@ module SuperDiff
|
|
42
42
|
OnlyWhen,
|
43
43
|
Text,
|
44
44
|
WhenRenderingToLines,
|
45
|
-
WhenRenderingToString
|
45
|
+
WhenRenderingToString
|
46
46
|
]
|
47
47
|
end
|
48
48
|
end
|
@@ -3,16 +3,16 @@ module SuperDiff
|
|
3
3
|
autoload :InspectionTree, "super_diff/object_inspection/inspection_tree"
|
4
4
|
autoload(
|
5
5
|
:InspectionTreeBuilders,
|
6
|
-
"super_diff/object_inspection/inspection_tree_builders"
|
6
|
+
"super_diff/object_inspection/inspection_tree_builders"
|
7
7
|
)
|
8
8
|
autoload :Nodes, "super_diff/object_inspection/nodes"
|
9
9
|
autoload(
|
10
10
|
:PrefixForNextNode,
|
11
|
-
"super_diff/object_inspection/prefix_for_next_node"
|
11
|
+
"super_diff/object_inspection/prefix_for_next_node"
|
12
12
|
)
|
13
13
|
autoload(
|
14
14
|
:PreludeForNextNode,
|
15
|
-
"super_diff/object_inspection/prelude_for_next_node"
|
15
|
+
"super_diff/object_inspection/prelude_for_next_node"
|
16
16
|
)
|
17
17
|
end
|
18
18
|
end
|
@@ -13,12 +13,13 @@ module SuperDiff
|
|
13
13
|
private
|
14
14
|
|
15
15
|
def lcs_callbacks
|
16
|
-
@_lcs_callbacks ||=
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
@_lcs_callbacks ||=
|
17
|
+
LcsCallbacks.new(
|
18
|
+
operation_tree: operation_tree,
|
19
|
+
expected: expected,
|
20
|
+
actual: actual,
|
21
|
+
compare: method(:compare)
|
22
|
+
)
|
22
23
|
end
|
23
24
|
|
24
25
|
def operation_tree
|
@@ -28,7 +29,7 @@ module SuperDiff
|
|
28
29
|
class LcsCallbacks
|
29
30
|
extend AttrExtras.mixin
|
30
31
|
|
31
|
-
pattr_initialize [
|
32
|
+
pattr_initialize %i[operation_tree! expected! actual! compare!]
|
32
33
|
public :operation_tree
|
33
34
|
|
34
35
|
def match(event)
|
@@ -62,7 +63,7 @@ module SuperDiff
|
|
62
63
|
collection: expected,
|
63
64
|
key: event.old_position,
|
64
65
|
value: event.old_element,
|
65
|
-
index: event.old_position
|
66
|
+
index: event.old_position
|
66
67
|
)
|
67
68
|
end
|
68
69
|
|
@@ -72,7 +73,7 @@ module SuperDiff
|
|
72
73
|
collection: actual,
|
73
74
|
key: event.new_position,
|
74
75
|
value: event.new_element,
|
75
|
-
index: event.new_position
|
76
|
+
index: event.new_position
|
76
77
|
)
|
77
78
|
end
|
78
79
|
|
@@ -82,7 +83,7 @@ module SuperDiff
|
|
82
83
|
collection: actual,
|
83
84
|
key: event.new_position,
|
84
85
|
value: event.new_element,
|
85
|
-
index: event.new_position
|
86
|
+
index: event.new_position
|
86
87
|
)
|
87
88
|
end
|
88
89
|
|
@@ -97,7 +98,7 @@ module SuperDiff
|
|
97
98
|
right_value: event.new_element,
|
98
99
|
left_index: event.old_position,
|
99
100
|
right_index: event.new_position,
|
100
|
-
children: children
|
101
|
+
children: children
|
101
102
|
)
|
102
103
|
end
|
103
104
|
end
|
@@ -8,7 +8,7 @@ module SuperDiff
|
|
8
8
|
extend AttrExtras.mixin
|
9
9
|
include ImplementationChecks
|
10
10
|
|
11
|
-
method_object [
|
11
|
+
method_object %i[expected! actual!]
|
12
12
|
|
13
13
|
def call
|
14
14
|
operation_tree
|
@@ -33,16 +33,20 @@ module SuperDiff
|
|
33
33
|
|
34
34
|
unary_operations.each_with_index do |operation, index|
|
35
35
|
if (
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
operation.name == :insert &&
|
37
|
+
(
|
38
|
+
delete_operation =
|
39
|
+
unmatched_delete_operations.find do |op|
|
40
|
+
op.key == operation.key
|
41
|
+
end
|
42
|
+
) && (insert_operation = operation)
|
43
|
+
)
|
40
44
|
unmatched_delete_operations.delete(delete_operation)
|
41
45
|
|
42
|
-
if (
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
+
if (
|
47
|
+
children =
|
48
|
+
possible_comparison_of(delete_operation, insert_operation)
|
49
|
+
)
|
46
50
|
operation_tree.delete(delete_operation)
|
47
51
|
operation_tree << Operations::BinaryOperation.new(
|
48
52
|
name: :change,
|
@@ -54,7 +58,7 @@ module SuperDiff
|
|
54
58
|
right_value: insert_operation.collection[operation.key],
|
55
59
|
left_index: delete_operation.index,
|
56
60
|
right_index: insert_operation.index,
|
57
|
-
children: children
|
61
|
+
children: children
|
58
62
|
)
|
59
63
|
else
|
60
64
|
operation_tree << insert_operation
|
@@ -80,17 +84,15 @@ module SuperDiff
|
|
80
84
|
end
|
81
85
|
|
82
86
|
def should_compare?(operation, next_operation)
|
83
|
-
next_operation &&
|
84
|
-
|
85
|
-
next_operation.name == :insert &&
|
86
|
-
next_operation.key == operation.key
|
87
|
+
next_operation && operation.name == :delete &&
|
88
|
+
next_operation.name == :insert && next_operation.key == operation.key
|
87
89
|
end
|
88
90
|
|
89
91
|
def compare(expected, actual)
|
90
92
|
OperationTreeBuilders::Main.call(
|
91
93
|
expected: expected,
|
92
94
|
actual: actual,
|
93
|
-
all_or_nothing: false
|
95
|
+
all_or_nothing: false
|
94
96
|
)
|
95
97
|
end
|
96
98
|
end
|
@@ -25,13 +25,15 @@ module SuperDiff
|
|
25
25
|
attr_reader :expected_attributes, :actual_attributes
|
26
26
|
|
27
27
|
def establish_expected_and_actual_attributes
|
28
|
-
@expected_attributes =
|
29
|
-
|
30
|
-
|
28
|
+
@expected_attributes =
|
29
|
+
attribute_names.reduce({}) do |hash, name|
|
30
|
+
hash.merge(name => expected.public_send(name))
|
31
|
+
end
|
31
32
|
|
32
|
-
@actual_attributes =
|
33
|
-
|
34
|
-
|
33
|
+
@actual_attributes =
|
34
|
+
attribute_names.reduce({}) do |hash, name|
|
35
|
+
hash.merge(name => actual.public_send(name))
|
36
|
+
end
|
35
37
|
end
|
36
38
|
end
|
37
39
|
end
|
@@ -33,8 +33,9 @@ module SuperDiff
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def attribute_names
|
36
|
-
(
|
37
|
-
|
36
|
+
(
|
37
|
+
expected.instance_variables.sort & actual.instance_variables.sort
|
38
|
+
).map { |variable_name| variable_name[1..-1] }
|
38
39
|
end
|
39
40
|
|
40
41
|
private
|
@@ -42,13 +43,15 @@ module SuperDiff
|
|
42
43
|
attr_reader :expected_attributes, :actual_attributes
|
43
44
|
|
44
45
|
def establish_expected_and_actual_attributes
|
45
|
-
@expected_attributes =
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
46
|
+
@expected_attributes =
|
47
|
+
attribute_names.reduce({}) do |hash, name|
|
48
|
+
hash.merge(name => expected.instance_variable_get("@#{name}"))
|
49
|
+
end
|
50
|
+
|
51
|
+
@actual_attributes =
|
52
|
+
attribute_names.reduce({}) do |hash, name|
|
53
|
+
hash.merge(name => actual.instance_variable_get("@#{name}"))
|
54
|
+
end
|
52
55
|
end
|
53
56
|
|
54
57
|
def possibly_add_noop_operation_to(operations, attribute_name)
|
@@ -58,7 +61,7 @@ module SuperDiff
|
|
58
61
|
collection: actual_attributes,
|
59
62
|
key: attribute_name,
|
60
63
|
index: attribute_names.index(attribute_name),
|
61
|
-
value: actual_attributes[attribute_name]
|
64
|
+
value: actual_attributes[attribute_name]
|
62
65
|
)
|
63
66
|
end
|
64
67
|
end
|
@@ -66,7 +69,8 @@ module SuperDiff
|
|
66
69
|
def should_add_noop_operation?(attribute_name)
|
67
70
|
expected_attributes.include?(attribute_name) &&
|
68
71
|
actual_attributes.include?(attribute_name) &&
|
69
|
-
expected_attributes[attribute_name] ==
|
72
|
+
expected_attributes[attribute_name] ==
|
73
|
+
actual_attributes[attribute_name]
|
70
74
|
end
|
71
75
|
|
72
76
|
def possibly_add_delete_operation_to(operations, attribute_name)
|
@@ -76,16 +80,18 @@ module SuperDiff
|
|
76
80
|
collection: expected_attributes,
|
77
81
|
key: attribute_name,
|
78
82
|
index: attribute_names.index(attribute_name),
|
79
|
-
value: expected_attributes[attribute_name]
|
83
|
+
value: expected_attributes[attribute_name]
|
80
84
|
)
|
81
85
|
end
|
82
86
|
end
|
83
87
|
|
84
88
|
def should_add_delete_operation?(attribute_name)
|
85
|
-
expected_attributes.include?(attribute_name) &&
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
+
expected_attributes.include?(attribute_name) &&
|
90
|
+
(
|
91
|
+
!actual_attributes.include?(attribute_name) ||
|
92
|
+
expected_attributes[attribute_name] !=
|
93
|
+
actual_attributes[attribute_name]
|
94
|
+
)
|
89
95
|
end
|
90
96
|
|
91
97
|
def possibly_add_insert_operation_to(operations, attribute_name)
|
@@ -95,16 +101,18 @@ module SuperDiff
|
|
95
101
|
collection: actual_attributes,
|
96
102
|
key: attribute_name,
|
97
103
|
index: attribute_names.index(attribute_name),
|
98
|
-
value: actual_attributes[attribute_name]
|
104
|
+
value: actual_attributes[attribute_name]
|
99
105
|
)
|
100
106
|
end
|
101
107
|
end
|
102
108
|
|
103
109
|
def should_add_insert_operation?(attribute_name)
|
104
|
-
!expected_attributes.include?(attribute_name) ||
|
105
|
-
|
106
|
-
|
107
|
-
|
110
|
+
!expected_attributes.include?(attribute_name) ||
|
111
|
+
(
|
112
|
+
actual_attributes.include?(attribute_name) &&
|
113
|
+
expected_attributes[attribute_name] !=
|
114
|
+
actual_attributes[attribute_name]
|
115
|
+
)
|
108
116
|
end
|
109
117
|
end
|
110
118
|
end
|
@@ -53,18 +53,18 @@ module SuperDiff
|
|
53
53
|
ev2, av2 = expected[ek], actual[ek]
|
54
54
|
|
55
55
|
if (
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
56
|
+
(!actual.include?(ek) || ev2 != av2) &&
|
57
|
+
operations.none? do |operation|
|
58
|
+
%i[delete noop].include?(operation.name) &&
|
59
|
+
operation.key == ek
|
60
|
+
end
|
61
|
+
)
|
62
62
|
operations << Operations::UnaryOperation.new(
|
63
63
|
name: :delete,
|
64
64
|
collection: expected,
|
65
65
|
key: ek,
|
66
66
|
value: ev2,
|
67
|
-
index: ei2
|
67
|
+
index: ei2
|
68
68
|
)
|
69
69
|
end
|
70
70
|
end
|
@@ -75,16 +75,16 @@ module SuperDiff
|
|
75
75
|
collection: actual,
|
76
76
|
key: ak,
|
77
77
|
value: av,
|
78
|
-
index: ai
|
78
|
+
index: ai
|
79
79
|
)
|
80
80
|
else
|
81
81
|
# (If we're here, it probably means that the key in 'actual' isn't
|
82
82
|
# present in 'expected' or the values don't match.)
|
83
83
|
|
84
84
|
if (
|
85
|
-
|
86
|
-
|
87
|
-
|
85
|
+
(operations.empty? || operations.last.name == :noop) &&
|
86
|
+
(ai == 0 || eks.include?(aks[ai - 1]))
|
87
|
+
)
|
88
88
|
# If we go from a match in the last iteration to a missing or
|
89
89
|
# extra key in this one, or we're at the first key in 'actual' and
|
90
90
|
# it's missing or extra, look for deletes in the 'expected' hash
|
@@ -113,10 +113,10 @@ module SuperDiff
|
|
113
113
|
# handled in some future iteration of the 'actual' loop.
|
114
114
|
break
|
115
115
|
elsif (
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
116
|
+
aks[ai + 1..-1].any? do |k|
|
117
|
+
expected.include?(k) && expected[k] != actual[k]
|
118
|
+
end
|
119
|
+
)
|
120
120
|
# While we backtracked a bit to iterate over 'expected', we
|
121
121
|
# now have to look ahead. If we will end up encountering a
|
122
122
|
# insert that matches this delete later, stop and go back to
|
@@ -130,7 +130,7 @@ module SuperDiff
|
|
130
130
|
collection: expected,
|
131
131
|
key: ek,
|
132
132
|
value: ev,
|
133
|
-
index: ei2
|
133
|
+
index: ei2
|
134
134
|
)
|
135
135
|
end
|
136
136
|
|
@@ -144,17 +144,16 @@ module SuperDiff
|
|
144
144
|
collection: actual,
|
145
145
|
key: ak,
|
146
146
|
value: av,
|
147
|
-
index: ai
|
147
|
+
index: ai
|
148
148
|
)
|
149
149
|
end
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
153
153
|
if (
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
)
|
154
|
+
expected.include?(ak) && ev != av &&
|
155
|
+
operations.none? { |op| op.name == :delete && op.key == ak }
|
156
|
+
)
|
158
157
|
# If we're here, it means that we didn't encounter any delete
|
159
158
|
# operations above for whatever reason and so we need to add a
|
160
159
|
# delete to represent the fact that the value for this key has
|
@@ -164,7 +163,7 @@ module SuperDiff
|
|
164
163
|
collection: expected,
|
165
164
|
key: ak,
|
166
165
|
value: expected[ak],
|
167
|
-
index: ei
|
166
|
+
index: ei
|
168
167
|
)
|
169
168
|
end
|
170
169
|
|
@@ -178,7 +177,7 @@ module SuperDiff
|
|
178
177
|
collection: actual,
|
179
178
|
key: ak,
|
180
179
|
value: av,
|
181
|
-
index: ai
|
180
|
+
index: ai
|
182
181
|
)
|
183
182
|
end
|
184
183
|
end
|
@@ -200,7 +199,7 @@ module SuperDiff
|
|
200
199
|
collection: expected,
|
201
200
|
key: ek,
|
202
201
|
value: ev,
|
203
|
-
index: ei
|
202
|
+
index: ei
|
204
203
|
)
|
205
204
|
end
|
206
205
|
|
@@ -3,14 +3,11 @@ module SuperDiff
|
|
3
3
|
class Main
|
4
4
|
extend AttrExtras.mixin
|
5
5
|
|
6
|
-
method_object [
|
6
|
+
method_object %i[expected! actual! all_or_nothing!]
|
7
7
|
|
8
8
|
def call
|
9
9
|
if resolved_class
|
10
|
-
resolved_class.call(
|
11
|
-
expected: expected,
|
12
|
-
actual: actual,
|
13
|
-
)
|
10
|
+
resolved_class.call(expected: expected, actual: actual)
|
14
11
|
elsif all_or_nothing?
|
15
12
|
raise NoOperationTreeBuilderAvailableError.create(expected, actual)
|
16
13
|
else
|
@@ -29,13 +26,9 @@ module SuperDiff
|
|
29
26
|
def available_classes
|
30
27
|
classes =
|
31
28
|
SuperDiff.configuration.extra_operation_tree_builder_classes +
|
32
|
-
|
29
|
+
DEFAULTS
|
33
30
|
|
34
|
-
|
35
|
-
classes + [DefaultObject]
|
36
|
-
else
|
37
|
-
classes
|
38
|
-
end
|
31
|
+
all_or_nothing? ? classes + [DefaultObject] : classes
|
39
32
|
end
|
40
33
|
end
|
41
34
|
end
|
@@ -53,7 +53,7 @@ module SuperDiff
|
|
53
53
|
collection: expected,
|
54
54
|
key: index,
|
55
55
|
index: index,
|
56
|
-
value: expected[index]
|
56
|
+
value: expected[index]
|
57
57
|
)
|
58
58
|
end
|
59
59
|
end
|
@@ -65,7 +65,7 @@ module SuperDiff
|
|
65
65
|
collection: actual,
|
66
66
|
key: index,
|
67
67
|
index: index,
|
68
|
-
value: actual[index]
|
68
|
+
value: actual[index]
|
69
69
|
)
|
70
70
|
end
|
71
71
|
end
|
@@ -77,7 +77,7 @@ module SuperDiff
|
|
77
77
|
collection: actual,
|
78
78
|
key: index,
|
79
79
|
index: index,
|
80
|
-
value: actual[index]
|
80
|
+
value: actual[index]
|
81
81
|
)
|
82
82
|
end
|
83
83
|
end
|
@@ -8,17 +8,7 @@ module SuperDiff
|
|
8
8
|
protected
|
9
9
|
|
10
10
|
def attribute_names
|
11
|
-
base = [
|
12
|
-
"year",
|
13
|
-
"month",
|
14
|
-
"day",
|
15
|
-
"hour",
|
16
|
-
"min",
|
17
|
-
"sec",
|
18
|
-
"subsec",
|
19
|
-
"zone",
|
20
|
-
"utc_offset",
|
21
|
-
]
|
11
|
+
base = %w[year month day hour min sec subsec zone utc_offset]
|
22
12
|
|
23
13
|
# If timezones are different, also show a normalized timestamp at the
|
24
14
|
# end of the diff to help visualize why they are different moments in
|
@@ -9,7 +9,7 @@ module SuperDiff
|
|
9
9
|
# TODO: Where is this used?
|
10
10
|
autoload(
|
11
11
|
:MultilineString,
|
12
|
-
"super_diff/operation_tree_builders/multiline_string"
|
12
|
+
"super_diff/operation_tree_builders/multiline_string"
|
13
13
|
)
|
14
14
|
autoload :TimeLike, "super_diff/operation_tree_builders/time_like"
|
15
15
|
end
|