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