super_diff 0.6.2 → 0.9.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/README.md +0 -1
- data/lib/super_diff/active_record/differs/active_record_relation.rb +3 -13
- data/lib/super_diff/active_record/object_inspection/{inspectors → inspection_tree_builders}/active_record_model.rb +19 -20
- data/lib/super_diff/active_record/object_inspection/{inspectors → inspection_tree_builders}/active_record_relation.rb +9 -8
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +16 -0
- data/lib/super_diff/active_record/object_inspection.rb +2 -6
- data/lib/super_diff/active_record/operation_tree_flatteners/active_record_relation.rb +17 -0
- data/lib/super_diff/active_record/operation_tree_flatteners.rb +10 -0
- data/lib/super_diff/active_record/operation_trees/active_record_relation.rb +8 -7
- data/lib/super_diff/active_record.rb +7 -7
- data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +3 -13
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +37 -0
- data/lib/super_diff/active_support/object_inspection/{inspectors.rb → inspection_tree_builders.rb} +2 -2
- data/lib/super_diff/active_support/object_inspection.rb +2 -6
- data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +17 -0
- data/lib/super_diff/active_support/operation_tree_flatteners/hash_with_indifferent_access.rb +17 -0
- data/lib/super_diff/active_support/operation_tree_flatteners.rb +10 -0
- data/lib/super_diff/active_support/operation_trees/hash_with_indifferent_access.rb +4 -7
- data/lib/super_diff/active_support.rb +8 -8
- data/lib/super_diff/colorized_document_extensions.rb +9 -6
- data/lib/super_diff/configuration.rb +81 -8
- data/lib/super_diff/csi/four_bit_color.rb +0 -2
- data/lib/super_diff/csi.rb +1 -2
- data/lib/super_diff/differs/array.rb +1 -1
- data/lib/super_diff/differs/base.rb +3 -21
- data/lib/super_diff/differs/custom_object.rb +1 -1
- data/lib/super_diff/differs/default_object.rb +1 -1
- data/lib/super_diff/differs/hash.rb +1 -1
- data/lib/super_diff/differs/main.rb +1 -7
- data/lib/super_diff/differs/multiline_string.rb +1 -1
- data/lib/super_diff/differs/time_like.rb +1 -1
- data/lib/super_diff/equality_matchers/array.rb +2 -2
- data/lib/super_diff/equality_matchers/default.rb +2 -2
- data/lib/super_diff/equality_matchers/hash.rb +2 -2
- data/lib/super_diff/equality_matchers/multiline_string.rb +2 -2
- data/lib/super_diff/equality_matchers/primitive.rb +4 -7
- data/lib/super_diff/equality_matchers/singleline_string.rb +2 -2
- data/lib/super_diff/helpers.rb +56 -2
- data/lib/super_diff/line.rb +83 -0
- data/lib/super_diff/object_inspection/inspection_tree.rb +183 -81
- data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +38 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/base.rb +27 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +37 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +63 -0
- data/lib/super_diff/object_inspection/{inspectors → inspection_tree_builders}/defaults.rb +1 -2
- data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +46 -0
- data/lib/super_diff/object_inspection/{inspectors → inspection_tree_builders}/main.rb +5 -10
- data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +21 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +64 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders.rb +44 -0
- data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +97 -0
- data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +27 -0
- data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +27 -0
- data/lib/super_diff/object_inspection/nodes/as_single_line.rb +33 -0
- data/lib/super_diff/object_inspection/nodes/base.rb +55 -20
- data/lib/super_diff/object_inspection/nodes/inspection.rb +47 -7
- data/lib/super_diff/object_inspection/nodes/nesting.rb +16 -5
- data/lib/super_diff/object_inspection/nodes/only_when.rb +54 -0
- data/lib/super_diff/object_inspection/nodes/text.rb +16 -2
- data/lib/super_diff/object_inspection/nodes/when_empty.rb +21 -6
- data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +20 -5
- data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +27 -0
- data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +27 -0
- data/lib/super_diff/object_inspection/nodes.rb +33 -32
- data/lib/super_diff/object_inspection/prefix_for_next_node.rb +6 -0
- data/lib/super_diff/object_inspection/prelude_for_next_node.rb +6 -0
- data/lib/super_diff/object_inspection.rb +12 -1
- data/lib/super_diff/operation_tree_builders/array.rb +7 -10
- data/lib/super_diff/operation_tree_builders/base.rb +6 -6
- data/lib/super_diff/operation_tree_builders/custom_object.rb +5 -2
- data/lib/super_diff/operation_tree_builders/default_object.rb +1 -1
- data/lib/super_diff/operation_tree_builders/defaults.rb +1 -1
- data/lib/super_diff/operation_tree_builders/hash.rb +1 -8
- data/lib/super_diff/operation_tree_builders/multiline_string.rb +2 -6
- data/lib/super_diff/operation_tree_builders/time_like.rb +2 -2
- data/lib/super_diff/operation_tree_flatteners/array.rb +15 -0
- data/lib/super_diff/operation_tree_flatteners/base.rb +54 -0
- data/lib/super_diff/operation_tree_flatteners/collection.rb +139 -0
- data/lib/super_diff/operation_tree_flatteners/custom_object.rb +28 -0
- data/lib/super_diff/operation_tree_flatteners/default_object.rb +32 -0
- data/lib/super_diff/operation_tree_flatteners/hash.rb +41 -0
- data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +17 -0
- data/lib/super_diff/operation_tree_flatteners.rb +20 -0
- data/lib/super_diff/operation_trees/array.rb +4 -7
- data/lib/super_diff/operation_trees/base.rb +39 -16
- data/lib/super_diff/operation_trees/custom_object.rb +4 -8
- data/lib/super_diff/operation_trees/default_object.rb +28 -13
- data/lib/super_diff/operation_trees/hash.rb +4 -7
- data/lib/super_diff/operation_trees/main.rb +1 -1
- data/lib/super_diff/operation_trees/multiline_string.rb +4 -7
- data/lib/super_diff/operations/binary_operation.rb +1 -6
- data/lib/super_diff/operations/unary_operation.rb +2 -30
- data/lib/super_diff/recursion_guard.rb +3 -3
- data/lib/super_diff/rspec/differs/collection_including.rb +4 -2
- data/lib/super_diff/rspec/differs/hash_including.rb +4 -2
- data/lib/super_diff/rspec/monkey_patches.rb +2 -2
- data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/collection_containing_exactly.rb +9 -8
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +34 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +103 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +36 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +26 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +26 -0
- data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/object_having_attributes.rb +10 -12
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/primitive.rb +10 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +33 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +44 -0
- data/lib/super_diff/rspec/object_inspection.rb +4 -1
- data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +0 -3
- data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +10 -3
- data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +10 -3
- data/lib/super_diff/rspec.rb +34 -13
- data/lib/super_diff/tiered_lines.rb +4 -0
- data/lib/super_diff/tiered_lines_elider.rb +490 -0
- data/lib/super_diff/tiered_lines_formatter.rb +79 -0
- data/lib/super_diff/version.rb +1 -1
- data/lib/super_diff.rb +28 -6
- data/spec/examples.txt +482 -403
- data/spec/integration/rails/active_support_spec.rb +19 -0
- data/spec/integration/rspec/contain_exactly_matcher_spec.rb +12 -6
- data/spec/integration/rspec/eq_matcher_spec.rb +33 -87
- data/spec/integration/rspec/have_attributes_matcher_spec.rb +17 -8
- data/spec/integration/rspec/match_array_matcher_spec.rb +14 -7
- data/spec/integration/rspec/match_matcher_spec.rb +93 -5
- data/spec/spec_helper.rb +4 -1
- data/spec/support/command_runner.rb +15 -25
- data/spec/support/helpers.rb +21 -0
- data/spec/support/integration/helpers.rb +2 -0
- data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +3 -3
- data/spec/support/integration/test_programs/base.rb +36 -10
- data/spec/support/shared_examples/active_record.rb +3 -2
- data/spec/support/shared_examples/active_support.rb +65 -0
- data/spec/support/shared_examples/elided_diffs.rb +914 -0
- data/spec/support/shared_examples/hash_with_indifferent_access.rb +16 -16
- data/spec/support/unit/helpers.rb +15 -0
- data/spec/support/unit/matchers/match_output.rb +41 -0
- data/spec/tmp/warnings_logger/all_warnings.txt +2 -0
- data/spec/unit/active_record/object_inspection_spec.rb +273 -0
- data/spec/unit/equality_matchers/main_spec.rb +55 -75
- data/spec/unit/helpers_spec.rb +75 -0
- data/spec/unit/operation_tree_flatteners/array_spec.rb +604 -0
- data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +667 -0
- data/spec/unit/operation_tree_flatteners/default_object_spec.rb +687 -0
- data/spec/unit/operation_tree_flatteners/hash_spec.rb +632 -0
- data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +121 -0
- data/spec/unit/rspec/object_inspection_spec.rb +446 -0
- data/spec/unit/super_diff_spec.rb +1530 -800
- data/spec/unit/tiered_lines_elider_spec.rb +6356 -0
- data/spec/unit/tiered_lines_formatter_spec.rb +193 -0
- metadata +91 -52
- data/lib/super_diff/active_record/diff_formatters/active_record_relation.rb +0 -23
- data/lib/super_diff/active_record/diff_formatters.rb +0 -10
- data/lib/super_diff/active_record/object_inspection/inspectors.rb +0 -16
- data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +0 -36
- data/lib/super_diff/active_support/diff_formatters.rb +0 -10
- data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +0 -28
- data/lib/super_diff/diff_formatters/array.rb +0 -21
- data/lib/super_diff/diff_formatters/base.rb +0 -33
- data/lib/super_diff/diff_formatters/custom_object.rb +0 -30
- data/lib/super_diff/diff_formatters/default_object.rb +0 -46
- data/lib/super_diff/diff_formatters/defaults.rb +0 -10
- data/lib/super_diff/diff_formatters/hash.rb +0 -34
- data/lib/super_diff/diff_formatters/main.rb +0 -41
- data/lib/super_diff/diff_formatters.rb +0 -14
- data/lib/super_diff/object_inspection/inspectors/array.rb +0 -32
- data/lib/super_diff/object_inspection/inspectors/base.rb +0 -36
- data/lib/super_diff/object_inspection/inspectors/custom_object.rb +0 -37
- data/lib/super_diff/object_inspection/inspectors/default_object.rb +0 -61
- data/lib/super_diff/object_inspection/inspectors/hash.rb +0 -32
- data/lib/super_diff/object_inspection/inspectors/primitive.rb +0 -28
- data/lib/super_diff/object_inspection/inspectors/string.rb +0 -23
- data/lib/super_diff/object_inspection/inspectors/time_like.rb +0 -23
- data/lib/super_diff/object_inspection/inspectors.rb +0 -23
- data/lib/super_diff/object_inspection/nodes/break.rb +0 -15
- data/lib/super_diff/object_inspection/nodes/when_multiline.rb +0 -22
- data/lib/super_diff/object_inspection/nodes/when_singleline.rb +0 -24
- data/lib/super_diff/rspec/object_inspection/inspectors/collection_including.rb +0 -28
- data/lib/super_diff/rspec/object_inspection/inspectors/hash_including.rb +0 -31
- data/lib/super_diff/rspec/object_inspection/inspectors/instance_of.rb +0 -23
- data/lib/super_diff/rspec/object_inspection/inspectors/kind_of.rb +0 -23
- data/lib/super_diff/rspec/object_inspection/inspectors/primitive.rb +0 -13
- data/lib/super_diff/rspec/object_inspection/inspectors/value_within.rb +0 -29
- data/lib/super_diff/rspec/object_inspection/inspectors.rb +0 -40
- data/spec/combustion/Gemfile.lock +0 -173
- data/spec/support/object_id.rb +0 -27
- data/spec/support/ruby_versions.rb +0 -11
@@ -1,48 +1,49 @@
|
|
1
1
|
module SuperDiff
|
2
2
|
module ObjectInspection
|
3
3
|
module Nodes
|
4
|
-
autoload :Base, "super_diff/object_inspection/nodes/base"
|
5
|
-
autoload :Break, "super_diff/object_inspection/nodes/break"
|
6
|
-
autoload :Inspection, "super_diff/object_inspection/nodes/inspection"
|
7
|
-
autoload :Nesting, "super_diff/object_inspection/nodes/nesting"
|
8
|
-
autoload :Text, "super_diff/object_inspection/nodes/text"
|
9
4
|
autoload(
|
10
|
-
:
|
11
|
-
"super_diff/object_inspection/nodes/
|
5
|
+
:AsLinesWhenRenderingToLines,
|
6
|
+
"super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines",
|
12
7
|
)
|
13
8
|
autoload(
|
14
|
-
:
|
15
|
-
"super_diff/object_inspection/nodes/
|
9
|
+
:AsPrefixWhenRenderingToLines,
|
10
|
+
"super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines",
|
16
11
|
)
|
17
12
|
autoload(
|
18
|
-
:
|
19
|
-
"super_diff/object_inspection/nodes/
|
13
|
+
:AsPreludeWhenRenderingToLines,
|
14
|
+
"super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines",
|
20
15
|
)
|
21
16
|
autoload(
|
22
|
-
:
|
23
|
-
"super_diff/object_inspection/nodes/
|
17
|
+
:AsSingleLine,
|
18
|
+
"super_diff/object_inspection/nodes/as_single_line",
|
19
|
+
)
|
20
|
+
autoload :Base, "super_diff/object_inspection/nodes/base"
|
21
|
+
autoload :Inspection, "super_diff/object_inspection/nodes/inspection"
|
22
|
+
autoload :Nesting, "super_diff/object_inspection/nodes/nesting"
|
23
|
+
autoload :OnlyWhen, "super_diff/object_inspection/nodes/only_when"
|
24
|
+
autoload :Text, "super_diff/object_inspection/nodes/text"
|
25
|
+
autoload(
|
26
|
+
:WhenRenderingToLines,
|
27
|
+
"super_diff/object_inspection/nodes/when_rendering_to_lines",
|
28
|
+
)
|
29
|
+
autoload(
|
30
|
+
:WhenRenderingToString,
|
31
|
+
"super_diff/object_inspection/nodes/when_rendering_to_string",
|
24
32
|
)
|
25
|
-
|
26
|
-
def self.fetch(type)
|
27
|
-
registry.fetch(type) do
|
28
|
-
raise(
|
29
|
-
KeyError,
|
30
|
-
"#{type.inspect} is not included in ObjectInspection::Nodes.registry!",
|
31
|
-
)
|
32
|
-
end
|
33
|
-
end
|
34
33
|
|
35
34
|
def self.registry
|
36
|
-
@_registry ||=
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
35
|
+
@_registry ||= [
|
36
|
+
AsLinesWhenRenderingToLines,
|
37
|
+
AsPrefixWhenRenderingToLines,
|
38
|
+
AsPreludeWhenRenderingToLines,
|
39
|
+
AsSingleLine,
|
40
|
+
Inspection,
|
41
|
+
Nesting,
|
42
|
+
OnlyWhen,
|
43
|
+
Text,
|
44
|
+
WhenRenderingToLines,
|
45
|
+
WhenRenderingToString,
|
46
|
+
]
|
46
47
|
end
|
47
48
|
end
|
48
49
|
end
|
@@ -1,7 +1,18 @@
|
|
1
1
|
module SuperDiff
|
2
2
|
module ObjectInspection
|
3
3
|
autoload :InspectionTree, "super_diff/object_inspection/inspection_tree"
|
4
|
-
autoload
|
4
|
+
autoload(
|
5
|
+
:InspectionTreeBuilders,
|
6
|
+
"super_diff/object_inspection/inspection_tree_builders",
|
7
|
+
)
|
5
8
|
autoload :Nodes, "super_diff/object_inspection/nodes"
|
9
|
+
autoload(
|
10
|
+
:PrefixForNextNode,
|
11
|
+
"super_diff/object_inspection/prefix_for_next_node",
|
12
|
+
)
|
13
|
+
autoload(
|
14
|
+
:PreludeForNextNode,
|
15
|
+
"super_diff/object_inspection/prelude_for_next_node",
|
16
|
+
)
|
6
17
|
end
|
7
18
|
end
|
@@ -17,7 +17,7 @@ module SuperDiff
|
|
17
17
|
operation_tree: operation_tree,
|
18
18
|
expected: expected,
|
19
19
|
actual: actual,
|
20
|
-
|
20
|
+
compare: method(:compare),
|
21
21
|
)
|
22
22
|
end
|
23
23
|
|
@@ -28,7 +28,7 @@ module SuperDiff
|
|
28
28
|
class LcsCallbacks
|
29
29
|
extend AttrExtras.mixin
|
30
30
|
|
31
|
-
pattr_initialize [:operation_tree!, :expected!, :actual!, :
|
31
|
+
pattr_initialize [:operation_tree!, :expected!, :actual!, :compare!]
|
32
32
|
public :operation_tree
|
33
33
|
|
34
34
|
def match(event)
|
@@ -44,10 +44,10 @@ module SuperDiff
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def change(event)
|
47
|
-
|
47
|
+
children = compare.(event.old_element, event.new_element)
|
48
48
|
|
49
|
-
if
|
50
|
-
add_change_operation(event,
|
49
|
+
if children
|
50
|
+
add_change_operation(event, children)
|
51
51
|
else
|
52
52
|
add_delete_operation(event)
|
53
53
|
add_insert_operation(event)
|
@@ -63,7 +63,6 @@ module SuperDiff
|
|
63
63
|
key: event.old_position,
|
64
64
|
value: event.old_element,
|
65
65
|
index: event.old_position,
|
66
|
-
index_in_collection: expected.index(event.old_element),
|
67
66
|
)
|
68
67
|
end
|
69
68
|
|
@@ -74,7 +73,6 @@ module SuperDiff
|
|
74
73
|
key: event.new_position,
|
75
74
|
value: event.new_element,
|
76
75
|
index: event.new_position,
|
77
|
-
index_in_collection: actual.index(event.new_element),
|
78
76
|
)
|
79
77
|
end
|
80
78
|
|
@@ -85,11 +83,10 @@ module SuperDiff
|
|
85
83
|
key: event.new_position,
|
86
84
|
value: event.new_element,
|
87
85
|
index: event.new_position,
|
88
|
-
index_in_collection: actual.index(event.new_element),
|
89
86
|
)
|
90
87
|
end
|
91
88
|
|
92
|
-
def add_change_operation(event,
|
89
|
+
def add_change_operation(event, children)
|
93
90
|
operation_tree << Operations::BinaryOperation.new(
|
94
91
|
name: :change,
|
95
92
|
left_collection: expected,
|
@@ -100,7 +97,7 @@ module SuperDiff
|
|
100
97
|
right_value: event.new_element,
|
101
98
|
left_index: event.old_position,
|
102
99
|
right_index: event.new_position,
|
103
|
-
|
100
|
+
children: children,
|
104
101
|
)
|
105
102
|
end
|
106
103
|
end
|
@@ -39,7 +39,7 @@ module SuperDiff
|
|
39
39
|
)
|
40
40
|
unmatched_delete_operations.delete(delete_operation)
|
41
41
|
|
42
|
-
if (
|
42
|
+
if (children = possible_comparison_of(
|
43
43
|
delete_operation,
|
44
44
|
insert_operation,
|
45
45
|
))
|
@@ -52,9 +52,9 @@ module SuperDiff
|
|
52
52
|
right_key: insert_operation.key,
|
53
53
|
left_value: delete_operation.collection[operation.key],
|
54
54
|
right_value: insert_operation.collection[operation.key],
|
55
|
-
left_index: delete_operation.
|
56
|
-
right_index: insert_operation.
|
57
|
-
|
55
|
+
left_index: delete_operation.index,
|
56
|
+
right_index: insert_operation.index,
|
57
|
+
children: children,
|
58
58
|
)
|
59
59
|
else
|
60
60
|
operation_tree << insert_operation
|
@@ -73,7 +73,7 @@ module SuperDiff
|
|
73
73
|
|
74
74
|
def possible_comparison_of(operation, next_operation)
|
75
75
|
if should_compare?(operation, next_operation)
|
76
|
-
|
76
|
+
compare(operation.value, next_operation.value)
|
77
77
|
else
|
78
78
|
nil
|
79
79
|
end
|
@@ -86,7 +86,7 @@ module SuperDiff
|
|
86
86
|
next_operation.key == operation.key
|
87
87
|
end
|
88
88
|
|
89
|
-
def
|
89
|
+
def compare(expected, actual)
|
90
90
|
OperationTreeBuilders::Main.call(
|
91
91
|
expected: expected,
|
92
92
|
actual: actual,
|
@@ -7,9 +7,12 @@ module SuperDiff
|
|
7
7
|
actual.respond_to?(:attributes_for_super_diff)
|
8
8
|
end
|
9
9
|
|
10
|
+
protected
|
11
|
+
|
10
12
|
def build_operation_tree
|
11
|
-
#
|
12
|
-
|
13
|
+
# NOTE: It doesn't matter whether we use expected or actual here,
|
14
|
+
# because all we care about is the name of the class
|
15
|
+
OperationTrees::CustomObject.new([], underlying_object: actual)
|
13
16
|
end
|
14
17
|
|
15
18
|
def attribute_names
|
@@ -25,7 +25,7 @@ module SuperDiff
|
|
25
25
|
def build_operation_tree
|
26
26
|
# XXX This assumes that `expected` and `actual` are the same
|
27
27
|
# TODO: Does this need to be find_operation_tree_for?
|
28
|
-
OperationTrees::DefaultObject.new([],
|
28
|
+
OperationTrees::DefaultObject.new([], underlying_object: actual)
|
29
29
|
end
|
30
30
|
|
31
31
|
def find_operation_tree_for(value)
|
@@ -53,7 +53,7 @@ module SuperDiff
|
|
53
53
|
ev2, av2 = expected[ek], actual[ek]
|
54
54
|
|
55
55
|
if (
|
56
|
-
(!actual.include?(ek) ||
|
56
|
+
(!actual.include?(ek) || ev2 != av2) &&
|
57
57
|
operations.none? { |operation|
|
58
58
|
[:delete, :noop].include?(operation.name) &&
|
59
59
|
operation.key == ek
|
@@ -65,7 +65,6 @@ module SuperDiff
|
|
65
65
|
key: ek,
|
66
66
|
value: ev2,
|
67
67
|
index: ei2,
|
68
|
-
index_in_collection: ei2,
|
69
68
|
)
|
70
69
|
end
|
71
70
|
end
|
@@ -77,7 +76,6 @@ module SuperDiff
|
|
77
76
|
key: ak,
|
78
77
|
value: av,
|
79
78
|
index: ai,
|
80
|
-
index_in_collection: ai,
|
81
79
|
)
|
82
80
|
else
|
83
81
|
# (If we're here, it probably means that the key in 'actual' isn't
|
@@ -133,7 +131,6 @@ module SuperDiff
|
|
133
131
|
key: ek,
|
134
132
|
value: ev,
|
135
133
|
index: ei2,
|
136
|
-
index_in_collection: ei2,
|
137
134
|
)
|
138
135
|
end
|
139
136
|
|
@@ -148,7 +145,6 @@ module SuperDiff
|
|
148
145
|
key: ak,
|
149
146
|
value: av,
|
150
147
|
index: ai,
|
151
|
-
index_in_collection: ai,
|
152
148
|
)
|
153
149
|
end
|
154
150
|
end
|
@@ -169,7 +165,6 @@ module SuperDiff
|
|
169
165
|
key: ak,
|
170
166
|
value: expected[ak],
|
171
167
|
index: ei,
|
172
|
-
index_in_collection: ei,
|
173
168
|
)
|
174
169
|
end
|
175
170
|
|
@@ -184,7 +179,6 @@ module SuperDiff
|
|
184
179
|
key: ak,
|
185
180
|
value: av,
|
186
181
|
index: ai,
|
187
|
-
index_in_collection: ai,
|
188
182
|
)
|
189
183
|
end
|
190
184
|
end
|
@@ -207,7 +201,6 @@ module SuperDiff
|
|
207
201
|
key: ek,
|
208
202
|
value: ev,
|
209
203
|
index: ei,
|
210
|
-
index_in_collection: ei,
|
211
204
|
)
|
212
205
|
end
|
213
206
|
|
@@ -38,12 +38,8 @@ module SuperDiff
|
|
38
38
|
|
39
39
|
attr_reader :sequence_matcher, :original_expected, :original_actual
|
40
40
|
|
41
|
-
def split_into_lines(
|
42
|
-
|
43
|
-
split(/(\r?\n)/).
|
44
|
-
each_slice(2).
|
45
|
-
map(&:join).
|
46
|
-
map { |line| line.inspect[1..-2] }
|
41
|
+
def split_into_lines(string)
|
42
|
+
string.scan(/.+(?:\r|\n|\r\n|\Z)/)
|
47
43
|
end
|
48
44
|
|
49
45
|
def opcodes
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module OperationTreeFlatteners
|
3
|
+
class Base
|
4
|
+
include ImplementationChecks
|
5
|
+
extend AttrExtras.mixin
|
6
|
+
|
7
|
+
method_object :operation_tree, [indentation_level: 0]
|
8
|
+
|
9
|
+
def call
|
10
|
+
beginning_lines + middle_lines + ending_lines
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
|
15
|
+
def build_tiered_lines
|
16
|
+
unimplemented_instance_method!
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def beginning_lines
|
22
|
+
if tiered_lines.empty?
|
23
|
+
[]
|
24
|
+
elsif indentation_level > 0
|
25
|
+
[tiered_lines[0]]
|
26
|
+
else
|
27
|
+
[tiered_lines[0].with_complete_bookend(:open)]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def middle_lines
|
32
|
+
if tiered_lines.empty?
|
33
|
+
[]
|
34
|
+
else
|
35
|
+
tiered_lines[1..-2]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def ending_lines
|
40
|
+
if tiered_lines.empty?
|
41
|
+
[]
|
42
|
+
elsif indentation_level > 0
|
43
|
+
[tiered_lines[-1]]
|
44
|
+
else
|
45
|
+
[tiered_lines[-1].with_complete_bookend(:close)]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def tiered_lines
|
50
|
+
@_tiered_lines ||= build_tiered_lines
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module OperationTreeFlatteners
|
3
|
+
class Collection < Base
|
4
|
+
protected
|
5
|
+
|
6
|
+
def build_tiered_lines
|
7
|
+
[
|
8
|
+
Line.new(
|
9
|
+
type: :noop,
|
10
|
+
indentation_level: indentation_level,
|
11
|
+
value: open_token,
|
12
|
+
collection_bookend: :open,
|
13
|
+
),
|
14
|
+
*inner_lines,
|
15
|
+
Line.new(
|
16
|
+
type: :noop,
|
17
|
+
indentation_level: indentation_level,
|
18
|
+
value: close_token,
|
19
|
+
collection_bookend: :close,
|
20
|
+
),
|
21
|
+
]
|
22
|
+
end
|
23
|
+
|
24
|
+
def inner_lines
|
25
|
+
@_inner_lines ||= operation_tree.
|
26
|
+
flat_map do |operation|
|
27
|
+
lines =
|
28
|
+
if operation.name == :change
|
29
|
+
build_lines_for_change_operation(operation)
|
30
|
+
else
|
31
|
+
build_lines_for_non_change_operation(operation)
|
32
|
+
end
|
33
|
+
|
34
|
+
maybe_add_prefix_at_beginning_of_lines(
|
35
|
+
maybe_add_comma_at_end_of_lines(lines, operation),
|
36
|
+
operation,
|
37
|
+
)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def maybe_add_prefix_at_beginning_of_lines(lines, operation)
|
42
|
+
if add_prefix_at_beginning_of_lines?(operation)
|
43
|
+
add_prefix_at_beginning_of_lines(lines, operation)
|
44
|
+
else
|
45
|
+
lines
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def add_prefix_at_beginning_of_lines?(operation)
|
50
|
+
!!item_prefix_for(operation)
|
51
|
+
end
|
52
|
+
|
53
|
+
def add_prefix_at_beginning_of_lines(lines, operation)
|
54
|
+
[lines[0].prefixed_with(item_prefix_for(operation))] +
|
55
|
+
lines[1..-1]
|
56
|
+
end
|
57
|
+
|
58
|
+
def maybe_add_comma_at_end_of_lines(lines, operation)
|
59
|
+
if last_item_in_collection?(operation)
|
60
|
+
lines
|
61
|
+
else
|
62
|
+
add_comma_at_end_of_lines(lines)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def last_item_in_collection?(operation)
|
67
|
+
if operation.name == :change
|
68
|
+
operation.left_index == operation.left_collection.size - 1 &&
|
69
|
+
operation.right_index == operation.right_collection.size - 1
|
70
|
+
else
|
71
|
+
operation.index == operation.collection.size - 1
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def add_comma_at_end_of_lines(lines)
|
76
|
+
lines[0..-2] + [lines[-1].with_comma]
|
77
|
+
end
|
78
|
+
|
79
|
+
def build_lines_for_change_operation(operation)
|
80
|
+
SuperDiff::RecursionGuard.guarding_recursion_of(
|
81
|
+
operation.left_collection,
|
82
|
+
operation.right_collection,
|
83
|
+
) do |already_seen|
|
84
|
+
if already_seen
|
85
|
+
raise InfiniteRecursionError
|
86
|
+
else
|
87
|
+
operation.children.flatten(
|
88
|
+
indentation_level: indentation_level + 1,
|
89
|
+
)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def build_lines_for_non_change_operation(operation)
|
95
|
+
indentation_level = @indentation_level + 1
|
96
|
+
|
97
|
+
if recursive_operation?(operation)
|
98
|
+
[
|
99
|
+
Line.new(
|
100
|
+
type: operation.name,
|
101
|
+
indentation_level: indentation_level,
|
102
|
+
value: SuperDiff::RecursionGuard::PLACEHOLDER,
|
103
|
+
),
|
104
|
+
]
|
105
|
+
else
|
106
|
+
build_lines_from_inspection_of(
|
107
|
+
operation.value,
|
108
|
+
type: operation.name,
|
109
|
+
indentation_level: indentation_level,
|
110
|
+
)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def recursive_operation?(operation)
|
115
|
+
operation.value.equal?(operation.collection) ||
|
116
|
+
SuperDiff::RecursionGuard.already_seen?(operation.value)
|
117
|
+
end
|
118
|
+
|
119
|
+
def item_prefix_for(_operation)
|
120
|
+
""
|
121
|
+
end
|
122
|
+
|
123
|
+
def build_lines_from_inspection_of(value, type:, indentation_level:)
|
124
|
+
SuperDiff.inspect_object(
|
125
|
+
value,
|
126
|
+
as_lines: true,
|
127
|
+
type: type,
|
128
|
+
indentation_level: indentation_level,
|
129
|
+
)
|
130
|
+
end
|
131
|
+
|
132
|
+
class InfiniteRecursionError < StandardError
|
133
|
+
def initialize(_message = nil)
|
134
|
+
super("Unhandled recursive data structure encountered!")
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module OperationTreeFlatteners
|
3
|
+
class CustomObject < Collection
|
4
|
+
protected
|
5
|
+
|
6
|
+
def open_token
|
7
|
+
"#<%<class>s {" % { class: operation_tree.underlying_object.class }
|
8
|
+
end
|
9
|
+
|
10
|
+
def close_token
|
11
|
+
"}>"
|
12
|
+
end
|
13
|
+
|
14
|
+
def item_prefix_for(operation)
|
15
|
+
key =
|
16
|
+
# Note: We could have used the right_key here too, they're both the
|
17
|
+
# same keys
|
18
|
+
if operation.respond_to?(:left_key)
|
19
|
+
operation.left_key
|
20
|
+
else
|
21
|
+
operation.key
|
22
|
+
end
|
23
|
+
|
24
|
+
"#{key}: "
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module OperationTreeFlatteners
|
3
|
+
class DefaultObject < Collection
|
4
|
+
protected
|
5
|
+
|
6
|
+
def open_token
|
7
|
+
"#<#{operation_tree.underlying_object.class.name}:" +
|
8
|
+
SuperDiff::Helpers.object_address_for(
|
9
|
+
operation_tree.underlying_object
|
10
|
+
) +
|
11
|
+
" {"
|
12
|
+
end
|
13
|
+
|
14
|
+
def close_token
|
15
|
+
"}>"
|
16
|
+
end
|
17
|
+
|
18
|
+
def item_prefix_for(operation)
|
19
|
+
key =
|
20
|
+
# Note: We could have used the right_key here too, they're both the
|
21
|
+
# same keys
|
22
|
+
if operation.respond_to?(:left_key)
|
23
|
+
operation.left_key
|
24
|
+
else
|
25
|
+
operation.key
|
26
|
+
end
|
27
|
+
|
28
|
+
"@#{key}="
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module OperationTreeFlatteners
|
3
|
+
class Hash < Collection
|
4
|
+
protected
|
5
|
+
|
6
|
+
def open_token
|
7
|
+
"{"
|
8
|
+
end
|
9
|
+
|
10
|
+
def close_token
|
11
|
+
"}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def item_prefix_for(operation)
|
15
|
+
key = key_for(operation)
|
16
|
+
|
17
|
+
if format_keys_as_kwargs?
|
18
|
+
"#{key}: "
|
19
|
+
else
|
20
|
+
"#{key.inspect} => "
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def format_keys_as_kwargs?
|
27
|
+
operation_tree.all? { |operation| key_for(operation).is_a?(Symbol) }
|
28
|
+
end
|
29
|
+
|
30
|
+
def key_for(operation)
|
31
|
+
# Note: We could have used the right_key here too, they're both the
|
32
|
+
# same keys
|
33
|
+
if operation.respond_to?(:left_key)
|
34
|
+
operation.left_key
|
35
|
+
else
|
36
|
+
operation.key
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module OperationTreeFlatteners
|
3
|
+
class MultilineString < Base
|
4
|
+
def build_tiered_lines
|
5
|
+
operation_tree.map do |operation|
|
6
|
+
Line.new(
|
7
|
+
type: operation.name,
|
8
|
+
indentation_level: indentation_level,
|
9
|
+
# TODO: Test that quotes and things don't get escaped but escape
|
10
|
+
# characters do
|
11
|
+
value: operation.value.inspect[1..-2].gsub(/\\"/, '"').gsub(/\\'/, "'")
|
12
|
+
)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|