super_diff 0.5.3 → 0.8.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 +46 -20
- data/lib/super_diff.rb +46 -7
- data/lib/super_diff/active_record.rb +7 -7
- data/lib/super_diff/active_record/differs/active_record_relation.rb +3 -13
- data/lib/super_diff/active_record/object_inspection.rb +2 -6
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +16 -0
- 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/operation_tree_flatteners.rb +10 -0
- data/lib/super_diff/active_record/operation_tree_flatteners/active_record_relation.rb +17 -0
- data/lib/super_diff/active_record/operation_trees/active_record_relation.rb +8 -7
- data/lib/super_diff/active_support.rb +8 -8
- data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +3 -13
- data/lib/super_diff/active_support/object_inspection.rb +2 -6
- data/lib/super_diff/active_support/object_inspection/{inspectors.rb → inspection_tree_builders.rb} +2 -2
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +37 -0
- 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.rb +10 -0
- data/lib/super_diff/active_support/operation_tree_flatteners/hash_with_indifferent_access.rb +17 -0
- data/lib/super_diff/active_support/operation_trees/hash_with_indifferent_access.rb +4 -7
- data/lib/super_diff/colorized_document_extensions.rb +9 -6
- data/lib/super_diff/configuration.rb +102 -19
- data/lib/super_diff/csi.rb +1 -1
- data/lib/super_diff/csi/four_bit_color.rb +0 -2
- data/lib/super_diff/diff_formatters/collection.rb +2 -2
- data/lib/super_diff/diff_formatters/multiline_string.rb +4 -4
- 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 +4 -4
- data/lib/super_diff/equality_matchers/default.rb +4 -4
- data/lib/super_diff/equality_matchers/hash.rb +4 -4
- data/lib/super_diff/equality_matchers/multiline_string.rb +4 -4
- data/lib/super_diff/equality_matchers/primitive.rb +6 -9
- data/lib/super_diff/equality_matchers/singleline_string.rb +4 -4
- data/lib/super_diff/gem_version.rb +45 -0
- data/lib/super_diff/helpers.rb +52 -2
- data/lib/super_diff/line.rb +83 -0
- data/lib/super_diff/object_inspection.rb +12 -9
- data/lib/super_diff/object_inspection/inspection_tree.rb +183 -81
- data/lib/super_diff/object_inspection/inspection_tree_builders.rb +44 -0
- 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/nodes.rb +33 -32
- 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/prefix_for_next_node.rb +6 -0
- data/lib/super_diff/object_inspection/prelude_for_next_node.rb +6 -0
- 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.rb +20 -0
- 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_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.rb +41 -13
- 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/matcher_text_builders/base.rb +7 -7
- data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +6 -6
- data/lib/super_diff/rspec/matcher_text_builders/contain_exactly.rb +1 -1
- data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +4 -4
- data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +1 -1
- data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +5 -5
- data/lib/super_diff/rspec/monkey_patches.rb +353 -306
- data/lib/super_diff/rspec/object_inspection.rb +4 -1
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +44 -0
- 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/operation_tree_builders/collection_containing_exactly.rb +12 -4
- 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/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/spec/examples.txt +407 -5
- data/spec/integration/rails/active_support_spec.rb +19 -0
- data/spec/integration/rspec/be_falsey_matcher_spec.rb +10 -10
- data/spec/integration/rspec/be_matcher_spec.rb +100 -100
- data/spec/integration/rspec/be_nil_matcher_spec.rb +10 -10
- data/spec/integration/rspec/be_predicate_matcher_spec.rb +103 -103
- data/spec/integration/rspec/be_truthy_matcher_spec.rb +10 -10
- data/spec/integration/rspec/contain_exactly_matcher_spec.rb +113 -107
- data/spec/integration/rspec/eq_matcher_spec.rb +223 -277
- data/spec/integration/rspec/have_attributes_matcher_spec.rb +138 -129
- data/spec/integration/rspec/have_predicate_matcher_spec.rb +65 -65
- data/spec/integration/rspec/include_matcher_spec.rb +73 -73
- data/spec/integration/rspec/match_array_matcher_spec.rb +126 -119
- data/spec/integration/rspec/match_matcher_spec.rb +362 -274
- data/spec/integration/rspec/raise_error_matcher_spec.rb +86 -86
- data/spec/integration/rspec/respond_to_matcher_spec.rb +240 -240
- data/spec/integration/rspec/third_party_matcher_spec.rb +8 -8
- data/spec/integration/rspec/unhandled_errors_spec.rb +5 -5
- data/spec/spec_helper.rb +33 -13
- data/spec/support/command_runner.rb +15 -25
- data/spec/support/helpers.rb +21 -0
- data/spec/support/integration/helpers.rb +8 -2
- data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +4 -4
- data/spec/support/integration/test_programs/base.rb +38 -10
- data/spec/support/integration/test_programs/rspec_active_record.rb +1 -1
- data/spec/support/integration/test_programs/rspec_active_support.rb +17 -0
- data/spec/support/integration/test_programs/rspec_rails.rb +1 -1
- data/spec/support/shared_examples/active_record.rb +109 -108
- 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 +196 -232
- data/spec/support/unit/helpers.rb +15 -0
- data/spec/support/unit/matchers/match_output.rb +41 -0
- data/spec/unit/active_record/object_inspection_spec.rb +273 -0
- data/spec/unit/equality_matchers/main_spec.rb +445 -465
- data/spec/unit/helpers_spec.rb +61 -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 +1958 -0
- data/spec/unit/tiered_lines_elider_spec.rb +6356 -0
- data/spec/unit/tiered_lines_formatter_spec.rb +193 -0
- data/super_diff.gemspec +1 -1
- metadata +95 -50
- data/lib/super_diff/active_record/diff_formatters.rb +0 -10
- data/lib/super_diff/active_record/diff_formatters/active_record_relation.rb +0 -23
- data/lib/super_diff/active_record/object_inspection/inspectors.rb +0 -16
- data/lib/super_diff/active_support/diff_formatters.rb +0 -10
- data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +0 -36
- data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +0 -28
- data/lib/super_diff/diff_formatters.rb +0 -14
- 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/object_inspection/inspectors.rb +0 -23
- 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/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.rb +0 -40
- 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/spec/support/object_id.rb +0 -27
- data/spec/support/ruby_versions.rb +0 -11
- data/spec/unit/object_inspection_spec.rb +0 -1168
@@ -0,0 +1,632 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe SuperDiff::OperationTreeFlatteners::Hash do
|
4
|
+
context "given an empty tree" do
|
5
|
+
it "returns a set of lines which are simply the open token and close token" do
|
6
|
+
expect(described_class.call([])).to match([
|
7
|
+
an_object_having_attributes(
|
8
|
+
type: :noop,
|
9
|
+
indentation_level: 0,
|
10
|
+
prefix: "",
|
11
|
+
value: %({),
|
12
|
+
collection_bookend: :open,
|
13
|
+
complete_bookend: :open,
|
14
|
+
),
|
15
|
+
an_object_having_attributes(
|
16
|
+
type: :noop,
|
17
|
+
indentation_level: 0,
|
18
|
+
prefix: "",
|
19
|
+
value: %(}),
|
20
|
+
collection_bookend: :close,
|
21
|
+
complete_bookend: :close,
|
22
|
+
),
|
23
|
+
])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "given a tree of only noops" do
|
28
|
+
it "returns a series of lines from inspecting each value, creating multiple lines upon encountering inner data structures" do
|
29
|
+
collection = Array.new(3) { :some_value }
|
30
|
+
operation_tree = SuperDiff::OperationTrees::Hash.new([
|
31
|
+
double(
|
32
|
+
:operation,
|
33
|
+
name: :noop,
|
34
|
+
collection: collection,
|
35
|
+
key: :foo,
|
36
|
+
value: "bar",
|
37
|
+
index: 0,
|
38
|
+
),
|
39
|
+
double(
|
40
|
+
:operation,
|
41
|
+
name: :noop,
|
42
|
+
collection: collection,
|
43
|
+
key: :baz,
|
44
|
+
value: { one: "fish", two: "fish" },
|
45
|
+
index: 1,
|
46
|
+
),
|
47
|
+
double(
|
48
|
+
:operation,
|
49
|
+
name: :noop,
|
50
|
+
collection: collection,
|
51
|
+
key: :qux,
|
52
|
+
value: "blargh",
|
53
|
+
index: 2,
|
54
|
+
),
|
55
|
+
])
|
56
|
+
|
57
|
+
flattened_operation_tree = described_class.call(operation_tree)
|
58
|
+
|
59
|
+
expect(flattened_operation_tree).to match([
|
60
|
+
an_object_having_attributes(
|
61
|
+
type: :noop,
|
62
|
+
indentation_level: 0,
|
63
|
+
prefix: "",
|
64
|
+
value: %({),
|
65
|
+
collection_bookend: :open,
|
66
|
+
complete_bookend: :open,
|
67
|
+
add_comma: false,
|
68
|
+
),
|
69
|
+
an_object_having_attributes(
|
70
|
+
type: :noop,
|
71
|
+
indentation_level: 1,
|
72
|
+
prefix: %(foo: ),
|
73
|
+
value: %("bar"),
|
74
|
+
add_comma: true,
|
75
|
+
),
|
76
|
+
an_object_having_attributes(
|
77
|
+
type: :noop,
|
78
|
+
indentation_level: 1,
|
79
|
+
prefix: %(baz: ),
|
80
|
+
value: %({),
|
81
|
+
collection_bookend: :open,
|
82
|
+
complete_bookend: nil,
|
83
|
+
add_comma: false,
|
84
|
+
),
|
85
|
+
an_object_having_attributes(
|
86
|
+
type: :noop,
|
87
|
+
indentation_level: 2,
|
88
|
+
prefix: %(one: ),
|
89
|
+
value: %("fish"),
|
90
|
+
add_comma: true,
|
91
|
+
),
|
92
|
+
an_object_having_attributes(
|
93
|
+
type: :noop,
|
94
|
+
indentation_level: 2,
|
95
|
+
prefix: %(two: ),
|
96
|
+
value: %("fish"),
|
97
|
+
add_comma: false,
|
98
|
+
),
|
99
|
+
an_object_having_attributes(
|
100
|
+
type: :noop,
|
101
|
+
indentation_level: 1,
|
102
|
+
prefix: "",
|
103
|
+
value: %(}),
|
104
|
+
collection_bookend: :close,
|
105
|
+
complete_bookend: nil,
|
106
|
+
add_comma: true,
|
107
|
+
),
|
108
|
+
an_object_having_attributes(
|
109
|
+
type: :noop,
|
110
|
+
indentation_level: 1,
|
111
|
+
prefix: %(qux: ),
|
112
|
+
value: %("blargh"),
|
113
|
+
add_comma: false,
|
114
|
+
),
|
115
|
+
an_object_having_attributes(
|
116
|
+
type: :noop,
|
117
|
+
indentation_level: 0,
|
118
|
+
prefix: "",
|
119
|
+
value: %(}),
|
120
|
+
collection_bookend: :close,
|
121
|
+
complete_bookend: :close,
|
122
|
+
add_comma: false,
|
123
|
+
),
|
124
|
+
])
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context "given a one-dimensional tree of noops, inserts, and deletes" do
|
129
|
+
it "returns a series of lines from inspecting each value, creating multiple lines upon encountering inner data structures" do
|
130
|
+
expected = Array.new(3) { :some_value }
|
131
|
+
actual = Array.new(4) { :some_value }
|
132
|
+
operation_tree = SuperDiff::OperationTrees::Hash.new([
|
133
|
+
double(
|
134
|
+
:operation,
|
135
|
+
name: :delete,
|
136
|
+
collection: expected,
|
137
|
+
key: :foo,
|
138
|
+
value: "bar",
|
139
|
+
index: 0,
|
140
|
+
),
|
141
|
+
double(
|
142
|
+
:operation,
|
143
|
+
name: :insert,
|
144
|
+
collection: actual,
|
145
|
+
key: :foo,
|
146
|
+
value: "czar",
|
147
|
+
index: 0,
|
148
|
+
),
|
149
|
+
double(
|
150
|
+
:operation,
|
151
|
+
name: :noop,
|
152
|
+
collection: actual,
|
153
|
+
key: :baz,
|
154
|
+
value: { :one => "fish", "two" => "fish" },
|
155
|
+
index: 1,
|
156
|
+
),
|
157
|
+
double(
|
158
|
+
:operation,
|
159
|
+
name: :noop,
|
160
|
+
collection: actual,
|
161
|
+
key: :qux,
|
162
|
+
value: "blargh",
|
163
|
+
index: 2,
|
164
|
+
),
|
165
|
+
double(
|
166
|
+
:operation,
|
167
|
+
name: :insert,
|
168
|
+
collection: actual,
|
169
|
+
key: :sing,
|
170
|
+
value: "song",
|
171
|
+
index: 3,
|
172
|
+
),
|
173
|
+
])
|
174
|
+
|
175
|
+
flattened_operation_tree = described_class.call(operation_tree)
|
176
|
+
|
177
|
+
expect(flattened_operation_tree).to match([
|
178
|
+
an_object_having_attributes(
|
179
|
+
type: :noop,
|
180
|
+
indentation_level: 0,
|
181
|
+
prefix: "",
|
182
|
+
value: %({),
|
183
|
+
collection_bookend: :open,
|
184
|
+
complete_bookend: :open,
|
185
|
+
add_comma: false,
|
186
|
+
),
|
187
|
+
an_object_having_attributes(
|
188
|
+
type: :delete,
|
189
|
+
indentation_level: 1,
|
190
|
+
prefix: %(foo: ),
|
191
|
+
value: %("bar"),
|
192
|
+
add_comma: true,
|
193
|
+
),
|
194
|
+
an_object_having_attributes(
|
195
|
+
type: :insert,
|
196
|
+
indentation_level: 1,
|
197
|
+
prefix: %(foo: ),
|
198
|
+
value: %("czar"),
|
199
|
+
add_comma: true,
|
200
|
+
),
|
201
|
+
an_object_having_attributes(
|
202
|
+
type: :noop,
|
203
|
+
indentation_level: 1,
|
204
|
+
prefix: %(baz: ),
|
205
|
+
value: %({),
|
206
|
+
collection_bookend: :open,
|
207
|
+
complete_bookend: nil,
|
208
|
+
add_comma: false,
|
209
|
+
),
|
210
|
+
an_object_having_attributes(
|
211
|
+
type: :noop,
|
212
|
+
indentation_level: 2,
|
213
|
+
prefix: %(:one => ),
|
214
|
+
value: %("fish"),
|
215
|
+
add_comma: true,
|
216
|
+
),
|
217
|
+
an_object_having_attributes(
|
218
|
+
type: :noop,
|
219
|
+
indentation_level: 2,
|
220
|
+
prefix: %("two" => ),
|
221
|
+
value: %("fish"),
|
222
|
+
add_comma: false,
|
223
|
+
),
|
224
|
+
an_object_having_attributes(
|
225
|
+
type: :noop,
|
226
|
+
indentation_level: 1,
|
227
|
+
prefix: "",
|
228
|
+
value: %(}),
|
229
|
+
collection_bookend: :close,
|
230
|
+
complete_bookend: nil,
|
231
|
+
add_comma: true,
|
232
|
+
),
|
233
|
+
an_object_having_attributes(
|
234
|
+
type: :noop,
|
235
|
+
indentation_level: 1,
|
236
|
+
prefix: %(qux: ),
|
237
|
+
value: %("blargh"),
|
238
|
+
add_comma: true,
|
239
|
+
),
|
240
|
+
an_object_having_attributes(
|
241
|
+
type: :insert,
|
242
|
+
indentation_level: 1,
|
243
|
+
prefix: %(sing: ),
|
244
|
+
value: %("song"),
|
245
|
+
add_comma: false,
|
246
|
+
),
|
247
|
+
an_object_having_attributes(
|
248
|
+
type: :noop,
|
249
|
+
indentation_level: 0,
|
250
|
+
prefix: "",
|
251
|
+
value: %(}),
|
252
|
+
collection_bookend: :close,
|
253
|
+
complete_bookend: :close,
|
254
|
+
add_comma: false,
|
255
|
+
),
|
256
|
+
])
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
context "given a multi-dimensional tree of operations" do
|
261
|
+
it "splits change operations into multiple lines" do
|
262
|
+
collection = Array.new(3) { :some_value }
|
263
|
+
subcollection = Array.new(2) { :some_value }
|
264
|
+
operation_tree = SuperDiff::OperationTrees::Hash.new([
|
265
|
+
double(
|
266
|
+
:operation,
|
267
|
+
name: :noop,
|
268
|
+
collection: collection,
|
269
|
+
key: :foo,
|
270
|
+
value: "bar",
|
271
|
+
index: 0,
|
272
|
+
),
|
273
|
+
double(
|
274
|
+
:operation,
|
275
|
+
name: :change,
|
276
|
+
left_collection: collection,
|
277
|
+
left_key: :baz,
|
278
|
+
left_index: 1,
|
279
|
+
right_collection: collection,
|
280
|
+
right_key: :baz,
|
281
|
+
right_index: 1,
|
282
|
+
children: SuperDiff::OperationTrees::Hash.new([
|
283
|
+
double(
|
284
|
+
:operation,
|
285
|
+
name: :noop,
|
286
|
+
collection: subcollection,
|
287
|
+
key: :one,
|
288
|
+
value: "fish",
|
289
|
+
index: 0,
|
290
|
+
),
|
291
|
+
double(
|
292
|
+
:operation,
|
293
|
+
name: :delete,
|
294
|
+
collection: subcollection,
|
295
|
+
key: :two,
|
296
|
+
value: "fish",
|
297
|
+
index: 1,
|
298
|
+
),
|
299
|
+
double(
|
300
|
+
:operation,
|
301
|
+
name: :insert,
|
302
|
+
collection: subcollection,
|
303
|
+
key: :blue,
|
304
|
+
value: "fish",
|
305
|
+
index: 1,
|
306
|
+
),
|
307
|
+
]),
|
308
|
+
),
|
309
|
+
double(
|
310
|
+
:operation,
|
311
|
+
name: :noop,
|
312
|
+
collection: collection,
|
313
|
+
key: :qux,
|
314
|
+
value: "blargh",
|
315
|
+
index: 2,
|
316
|
+
),
|
317
|
+
])
|
318
|
+
|
319
|
+
flattened_operation_tree = described_class.call(operation_tree)
|
320
|
+
|
321
|
+
expect(flattened_operation_tree).to match([
|
322
|
+
an_object_having_attributes(
|
323
|
+
type: :noop,
|
324
|
+
indentation_level: 0,
|
325
|
+
prefix: "",
|
326
|
+
value: %({),
|
327
|
+
collection_bookend: :open,
|
328
|
+
complete_bookend: :open,
|
329
|
+
add_comma: false,
|
330
|
+
),
|
331
|
+
an_object_having_attributes(
|
332
|
+
type: :noop,
|
333
|
+
indentation_level: 1,
|
334
|
+
prefix: %(foo: ),
|
335
|
+
value: %("bar"),
|
336
|
+
add_comma: true,
|
337
|
+
),
|
338
|
+
an_object_having_attributes(
|
339
|
+
type: :noop,
|
340
|
+
indentation_level: 1,
|
341
|
+
prefix: %(baz: ),
|
342
|
+
value: %({),
|
343
|
+
collection_bookend: :open,
|
344
|
+
complete_bookend: nil,
|
345
|
+
add_comma: false,
|
346
|
+
),
|
347
|
+
an_object_having_attributes(
|
348
|
+
type: :noop,
|
349
|
+
indentation_level: 2,
|
350
|
+
prefix: %(one: ),
|
351
|
+
value: %("fish"),
|
352
|
+
add_comma: true,
|
353
|
+
),
|
354
|
+
an_object_having_attributes(
|
355
|
+
type: :delete,
|
356
|
+
indentation_level: 2,
|
357
|
+
prefix: %(two: ),
|
358
|
+
value: %("fish"),
|
359
|
+
add_comma: false,
|
360
|
+
),
|
361
|
+
an_object_having_attributes(
|
362
|
+
type: :insert,
|
363
|
+
indentation_level: 2,
|
364
|
+
prefix: %(blue: ),
|
365
|
+
value: %("fish"),
|
366
|
+
add_comma: false,
|
367
|
+
),
|
368
|
+
an_object_having_attributes(
|
369
|
+
type: :noop,
|
370
|
+
indentation_level: 1,
|
371
|
+
prefix: "",
|
372
|
+
value: %(}),
|
373
|
+
collection_bookend: :close,
|
374
|
+
complete_bookend: nil,
|
375
|
+
add_comma: true,
|
376
|
+
),
|
377
|
+
an_object_having_attributes(
|
378
|
+
type: :noop,
|
379
|
+
indentation_level: 1,
|
380
|
+
prefix: %(qux: ),
|
381
|
+
value: %("blargh"),
|
382
|
+
add_comma: false,
|
383
|
+
),
|
384
|
+
an_object_having_attributes(
|
385
|
+
type: :noop,
|
386
|
+
indentation_level: 0,
|
387
|
+
prefix: "",
|
388
|
+
value: %(}),
|
389
|
+
collection_bookend: :close,
|
390
|
+
complete_bookend: :close,
|
391
|
+
add_comma: false,
|
392
|
+
),
|
393
|
+
])
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
397
|
+
context "given a single-dimensional tree that contains a reference to itself" do
|
398
|
+
it "replaces the reference with a static placeholder" do
|
399
|
+
left_collection = Array.new(3) { :some_value }
|
400
|
+
right_collection = Array.new(2) { :some_value }.tap do |collection|
|
401
|
+
collection << right_collection
|
402
|
+
end
|
403
|
+
|
404
|
+
operation_tree = SuperDiff::OperationTrees::Hash.new([
|
405
|
+
double(
|
406
|
+
:operation,
|
407
|
+
name: :noop,
|
408
|
+
collection: right_collection,
|
409
|
+
key: :foo,
|
410
|
+
value: "bar",
|
411
|
+
index: 0,
|
412
|
+
),
|
413
|
+
double(
|
414
|
+
:operation,
|
415
|
+
name: :noop,
|
416
|
+
collection: right_collection,
|
417
|
+
key: :baz,
|
418
|
+
value: "qux",
|
419
|
+
index: 1,
|
420
|
+
),
|
421
|
+
double(
|
422
|
+
:operation,
|
423
|
+
name: :delete,
|
424
|
+
collection: left_collection,
|
425
|
+
key: :blargh,
|
426
|
+
value: "zig",
|
427
|
+
index: 2,
|
428
|
+
),
|
429
|
+
double(
|
430
|
+
:operation,
|
431
|
+
name: :insert,
|
432
|
+
collection: right_collection,
|
433
|
+
key: :blargh,
|
434
|
+
value: right_collection,
|
435
|
+
index: 2,
|
436
|
+
),
|
437
|
+
])
|
438
|
+
|
439
|
+
flattened_operation_tree = described_class.call(operation_tree)
|
440
|
+
|
441
|
+
expect(flattened_operation_tree).to match([
|
442
|
+
an_object_having_attributes(
|
443
|
+
type: :noop,
|
444
|
+
indentation_level: 0,
|
445
|
+
prefix: "",
|
446
|
+
value: %({),
|
447
|
+
collection_bookend: :open,
|
448
|
+
complete_bookend: :open,
|
449
|
+
add_comma: false,
|
450
|
+
),
|
451
|
+
an_object_having_attributes(
|
452
|
+
type: :noop,
|
453
|
+
indentation_level: 1,
|
454
|
+
prefix: %(foo: ),
|
455
|
+
value: %("bar"),
|
456
|
+
add_comma: true,
|
457
|
+
),
|
458
|
+
an_object_having_attributes(
|
459
|
+
type: :noop,
|
460
|
+
indentation_level: 1,
|
461
|
+
prefix: %(baz: ),
|
462
|
+
value: %("qux"),
|
463
|
+
add_comma: true,
|
464
|
+
),
|
465
|
+
an_object_having_attributes(
|
466
|
+
type: :delete,
|
467
|
+
indentation_level: 1,
|
468
|
+
prefix: %(blargh: ),
|
469
|
+
value: %("zig"),
|
470
|
+
add_comma: false,
|
471
|
+
),
|
472
|
+
an_object_having_attributes(
|
473
|
+
type: :insert,
|
474
|
+
indentation_level: 1,
|
475
|
+
prefix: %(blargh: ),
|
476
|
+
value: %(∙∙∙),
|
477
|
+
add_comma: false,
|
478
|
+
),
|
479
|
+
an_object_having_attributes(
|
480
|
+
type: :noop,
|
481
|
+
indentation_level: 0,
|
482
|
+
prefix: "",
|
483
|
+
value: %(}),
|
484
|
+
collection_bookend: :close,
|
485
|
+
complete_bookend: :close,
|
486
|
+
add_comma: false,
|
487
|
+
),
|
488
|
+
])
|
489
|
+
end
|
490
|
+
end
|
491
|
+
|
492
|
+
context "given a multi-dimensional tree that contains a reference to itself in an inner level" do
|
493
|
+
it "replaces the reference with a static placeholder" do
|
494
|
+
collection = Array.new(3) { :some_value }
|
495
|
+
left_subcollection = Array.new(2) { :some_value }
|
496
|
+
right_subcollection = Array.new(1) { :some_value }.tap do |coll|
|
497
|
+
coll << right_subcollection
|
498
|
+
end
|
499
|
+
|
500
|
+
operation_tree = SuperDiff::OperationTrees::Hash.new([
|
501
|
+
double(
|
502
|
+
:operation,
|
503
|
+
name: :noop,
|
504
|
+
collection: collection,
|
505
|
+
key: :foo,
|
506
|
+
value: "bar",
|
507
|
+
index: 0,
|
508
|
+
),
|
509
|
+
double(
|
510
|
+
:operation,
|
511
|
+
name: :change,
|
512
|
+
left_collection: collection,
|
513
|
+
left_key: :baz,
|
514
|
+
left_index: 1,
|
515
|
+
right_collection: collection,
|
516
|
+
right_key: :baz,
|
517
|
+
right_index: 1,
|
518
|
+
children: SuperDiff::OperationTrees::Hash.new([
|
519
|
+
double(
|
520
|
+
:operation,
|
521
|
+
name: :noop,
|
522
|
+
collection: right_subcollection,
|
523
|
+
key: :one,
|
524
|
+
value: "fish",
|
525
|
+
index: 0,
|
526
|
+
),
|
527
|
+
double(
|
528
|
+
:operation,
|
529
|
+
name: :delete,
|
530
|
+
collection: left_subcollection,
|
531
|
+
key: :two,
|
532
|
+
value: "fish",
|
533
|
+
index: 1,
|
534
|
+
),
|
535
|
+
double(
|
536
|
+
:operation,
|
537
|
+
name: :insert,
|
538
|
+
collection: right_subcollection,
|
539
|
+
key: :two,
|
540
|
+
value: right_subcollection,
|
541
|
+
index: 1,
|
542
|
+
),
|
543
|
+
]),
|
544
|
+
),
|
545
|
+
double(
|
546
|
+
:operation,
|
547
|
+
name: :noop,
|
548
|
+
collection: collection,
|
549
|
+
key: :qux,
|
550
|
+
value: "blargh",
|
551
|
+
index: 2,
|
552
|
+
),
|
553
|
+
])
|
554
|
+
|
555
|
+
flattened_operation_tree = described_class.call(operation_tree)
|
556
|
+
|
557
|
+
expect(flattened_operation_tree).to match([
|
558
|
+
an_object_having_attributes(
|
559
|
+
type: :noop,
|
560
|
+
indentation_level: 0,
|
561
|
+
prefix: "",
|
562
|
+
value: %({),
|
563
|
+
collection_bookend: :open,
|
564
|
+
complete_bookend: :open,
|
565
|
+
add_comma: false,
|
566
|
+
),
|
567
|
+
an_object_having_attributes(
|
568
|
+
type: :noop,
|
569
|
+
indentation_level: 1,
|
570
|
+
prefix: %(foo: ),
|
571
|
+
value: %("bar"),
|
572
|
+
add_comma: true,
|
573
|
+
),
|
574
|
+
an_object_having_attributes(
|
575
|
+
type: :noop,
|
576
|
+
indentation_level: 1,
|
577
|
+
prefix: %(baz: ),
|
578
|
+
value: %({),
|
579
|
+
collection_bookend: :open,
|
580
|
+
complete_bookend: nil,
|
581
|
+
add_comma: false,
|
582
|
+
),
|
583
|
+
an_object_having_attributes(
|
584
|
+
type: :noop,
|
585
|
+
indentation_level: 2,
|
586
|
+
prefix: %(one: ),
|
587
|
+
value: %("fish"),
|
588
|
+
add_comma: true,
|
589
|
+
),
|
590
|
+
an_object_having_attributes(
|
591
|
+
type: :delete,
|
592
|
+
indentation_level: 2,
|
593
|
+
prefix: %(two: ),
|
594
|
+
value: %("fish"),
|
595
|
+
add_comma: false,
|
596
|
+
),
|
597
|
+
an_object_having_attributes(
|
598
|
+
type: :insert,
|
599
|
+
indentation_level: 2,
|
600
|
+
prefix: %(two: ),
|
601
|
+
value: %(∙∙∙),
|
602
|
+
add_comma: false,
|
603
|
+
),
|
604
|
+
an_object_having_attributes(
|
605
|
+
type: :noop,
|
606
|
+
indentation_level: 1,
|
607
|
+
prefix: "",
|
608
|
+
value: %(}),
|
609
|
+
collection_bookend: :close,
|
610
|
+
complete_bookend: nil,
|
611
|
+
add_comma: true,
|
612
|
+
),
|
613
|
+
an_object_having_attributes(
|
614
|
+
type: :noop,
|
615
|
+
indentation_level: 1,
|
616
|
+
prefix: %(qux: ),
|
617
|
+
value: %("blargh"),
|
618
|
+
add_comma: false,
|
619
|
+
),
|
620
|
+
an_object_having_attributes(
|
621
|
+
type: :noop,
|
622
|
+
indentation_level: 0,
|
623
|
+
prefix: "",
|
624
|
+
value: %(}),
|
625
|
+
collection_bookend: :close,
|
626
|
+
complete_bookend: :close,
|
627
|
+
add_comma: false,
|
628
|
+
),
|
629
|
+
])
|
630
|
+
end
|
631
|
+
end
|
632
|
+
end
|