super_diff 0.9.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +65 -26
- data/lib/super_diff/active_record/differs/active_record_relation.rb +1 -2
- data/lib/super_diff/active_record/differs.rb +1 -1
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model.rb +22 -18
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +14 -7
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +2 -2
- data/lib/super_diff/active_record/object_inspection.rb +1 -1
- data/lib/super_diff/active_record/operation_tree_builders/active_record_model.rb +1 -2
- data/lib/super_diff/active_record/operation_tree_builders/active_record_relation.rb +1 -2
- data/lib/super_diff/active_record/operation_tree_builders.rb +2 -2
- data/lib/super_diff/active_record/operation_tree_flatteners.rb +1 -1
- data/lib/super_diff/active_record/operation_trees.rb +1 -1
- data/lib/super_diff/active_record.rb +7 -15
- data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +5 -6
- data/lib/super_diff/active_support/differs.rb +1 -1
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +20 -11
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/ordered_options.rb +46 -0
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +5 -1
- data/lib/super_diff/active_support/object_inspection.rb +1 -1
- data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +5 -6
- data/lib/super_diff/active_support/operation_tree_builders.rb +1 -1
- data/lib/super_diff/active_support/operation_tree_flatteners.rb +1 -1
- data/lib/super_diff/active_support/operation_trees.rb +1 -1
- data/lib/super_diff/active_support.rb +6 -10
- data/lib/super_diff/colorized_document_extensions.rb +2 -4
- data/lib/super_diff/configuration.rb +14 -8
- data/lib/super_diff/csi/color.rb +4 -4
- data/lib/super_diff/csi/colorized_document.rb +12 -16
- data/lib/super_diff/csi/document.rb +8 -19
- data/lib/super_diff/csi/eight_bit_color.rb +19 -19
- data/lib/super_diff/csi/four_bit_color.rb +82 -31
- data/lib/super_diff/csi/twenty_four_bit_color.rb +12 -11
- data/lib/super_diff/csi/uncolorized_document.rb +2 -6
- data/lib/super_diff/csi.rb +10 -14
- data/lib/super_diff/diff_formatters/collection.rb +35 -41
- data/lib/super_diff/differs/date_like.rb +15 -0
- data/lib/super_diff/differs/default_object.rb +1 -1
- data/lib/super_diff/differs/defaults.rb +2 -1
- data/lib/super_diff/differs/main.rb +2 -13
- data/lib/super_diff/differs.rb +1 -0
- data/lib/super_diff/equality_matchers/array.rb +10 -12
- data/lib/super_diff/equality_matchers/base.rb +1 -1
- data/lib/super_diff/equality_matchers/default.rb +2 -4
- data/lib/super_diff/equality_matchers/defaults.rb +1 -1
- data/lib/super_diff/equality_matchers/hash.rb +10 -12
- data/lib/super_diff/equality_matchers/multiline_string.rb +11 -13
- data/lib/super_diff/equality_matchers/primitive.rb +10 -12
- data/lib/super_diff/equality_matchers/singleline_string.rb +10 -12
- data/lib/super_diff/equality_matchers.rb +1 -1
- data/lib/super_diff/errors.rb +2 -6
- data/lib/super_diff/gem_version.rb +3 -3
- data/lib/super_diff/helpers.rb +10 -10
- data/lib/super_diff/implementation_checks.rb +2 -2
- data/lib/super_diff/line.rb +3 -3
- data/lib/super_diff/object_inspection/inspection_tree.rb +64 -73
- data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +29 -14
- data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +17 -13
- data/lib/super_diff/object_inspection/inspection_tree_builders/date_like.rb +51 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +43 -27
- data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +2 -1
- data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +35 -18
- data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +3 -5
- data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +30 -36
- data/lib/super_diff/object_inspection/inspection_tree_builders.rb +13 -9
- data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +11 -22
- data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +1 -5
- data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +1 -5
- data/lib/super_diff/object_inspection/nodes/as_single_line.rb +3 -7
- data/lib/super_diff/object_inspection/nodes/base.rb +9 -14
- data/lib/super_diff/object_inspection/nodes/inspection.rb +26 -34
- data/lib/super_diff/object_inspection/nodes/nesting.rb +1 -1
- data/lib/super_diff/object_inspection/nodes/only_when.rb +2 -6
- data/lib/super_diff/object_inspection/nodes/text.rb +1 -5
- data/lib/super_diff/object_inspection/nodes/when_empty.rb +2 -6
- data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +2 -6
- data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +1 -1
- data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +1 -5
- data/lib/super_diff/object_inspection/nodes.rb +7 -7
- data/lib/super_diff/object_inspection.rb +3 -3
- data/lib/super_diff/operation_tree_builders/array.rb +12 -11
- data/lib/super_diff/operation_tree_builders/base.rb +17 -15
- data/lib/super_diff/operation_tree_builders/custom_object.rb +8 -6
- data/lib/super_diff/operation_tree_builders/date_like.rb +15 -0
- data/lib/super_diff/operation_tree_builders/default_object.rb +29 -21
- data/lib/super_diff/operation_tree_builders/defaults.rb +1 -1
- data/lib/super_diff/operation_tree_builders/hash.rb +23 -24
- data/lib/super_diff/operation_tree_builders/main.rb +4 -11
- data/lib/super_diff/operation_tree_builders/multiline_string.rb +3 -3
- data/lib/super_diff/operation_tree_builders/time_like.rb +1 -11
- data/lib/super_diff/operation_tree_builders.rb +2 -1
- data/lib/super_diff/operation_tree_flatteners/base.rb +1 -5
- data/lib/super_diff/operation_tree_flatteners/collection.rb +13 -16
- data/lib/super_diff/operation_tree_flatteners/default_object.rb +1 -2
- data/lib/super_diff/operation_tree_flatteners/hash.rb +2 -10
- data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +2 -1
- data/lib/super_diff/operation_tree_flatteners.rb +3 -3
- data/lib/super_diff/operation_trees/base.rb +3 -5
- data/lib/super_diff/operation_trees/default_object.rb +1 -3
- data/lib/super_diff/operations/binary_operation.rb +2 -2
- data/lib/super_diff/operations/unary_operation.rb +1 -1
- data/lib/super_diff/rails.rb +2 -1
- data/lib/super_diff/recursion_guard.rb +5 -4
- data/lib/super_diff/rspec/augmented_matcher.rb +4 -5
- data/lib/super_diff/rspec/differ.rb +6 -13
- data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +3 -2
- data/lib/super_diff/rspec/differs/collection_including.rb +1 -1
- data/lib/super_diff/rspec/differs/hash_including.rb +1 -1
- data/lib/super_diff/rspec/differs.rb +3 -3
- data/lib/super_diff/rspec/matcher_text_builders/base.rb +13 -15
- data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +5 -7
- data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +3 -5
- data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +2 -10
- data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +2 -6
- data/lib/super_diff/rspec/matcher_text_builders.rb +5 -8
- data/lib/super_diff/rspec/matcher_text_template.rb +13 -16
- data/lib/super_diff/rspec/monkey_patches.rb +180 -123
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_containing_exactly.rb +14 -7
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +21 -13
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +35 -36
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/generic_describable_matcher.rb +19 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +21 -15
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +11 -10
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +11 -10
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/object_having_attributes.rb +14 -7
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +10 -11
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +13 -9
- data/lib/super_diff/rspec/object_inspection.rb +1 -1
- data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +11 -10
- data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +7 -6
- data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +11 -10
- data/lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb +22 -17
- data/lib/super_diff/rspec/operation_tree_builders.rb +4 -4
- data/lib/super_diff/rspec.rb +17 -18
- data/lib/super_diff/tiered_lines_elider.rb +87 -115
- data/lib/super_diff/tiered_lines_formatter.rb +5 -9
- data/lib/super_diff/version.rb +1 -1
- data/lib/super_diff.rb +13 -9
- data/spec/examples.txt +541 -483
- data/spec/integration/rails/active_record_spec.rb +3 -1
- data/spec/integration/rails/engines_spec.rb +25 -0
- data/spec/integration/rails/hash_with_indifferent_access_spec.rb +3 -1
- data/spec/integration/rspec/be_falsey_matcher_spec.rb +40 -35
- data/spec/integration/rspec/be_matcher_spec.rb +360 -320
- data/spec/integration/rspec/be_nil_matcher_spec.rb +38 -34
- data/spec/integration/rspec/be_predicate_matcher_spec.rb +376 -359
- data/spec/integration/rspec/be_truthy_matcher_spec.rb +38 -33
- data/spec/integration/rspec/contain_exactly_matcher_spec.rb +257 -254
- data/spec/integration/rspec/eq_matcher_spec.rb +695 -585
- data/spec/integration/rspec/generic_describable_matchers_spec.rb +177 -0
- data/spec/integration/rspec/have_attributes_matcher_spec.rb +312 -304
- data/spec/integration/rspec/have_predicate_matcher_spec.rb +291 -297
- data/spec/integration/rspec/include_matcher_spec.rb +327 -225
- data/spec/integration/rspec/magic_metadata_spec.rb +51 -0
- data/spec/integration/rspec/match_array_matcher_spec.rb +294 -291
- data/spec/integration/rspec/match_matcher_spec.rb +916 -903
- data/spec/integration/rspec/raise_error_matcher_spec.rb +1208 -449
- data/spec/integration/rspec/respond_to_matcher_spec.rb +702 -697
- data/spec/integration/rspec/third_party_matcher_spec.rb +142 -138
- data/spec/integration/rspec/unhandled_errors_spec.rb +88 -84
- data/spec/internal/log/test.log +0 -0
- data/spec/spec_helper.rb +20 -20
- data/spec/support/command_runner.rb +34 -57
- data/spec/support/integration/helpers.rb +44 -32
- data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +28 -23
- data/spec/support/integration/matchers.rb +34 -0
- data/spec/support/integration/test_programs/base.rb +17 -22
- data/spec/support/integration/test_programs/plain.rb +6 -0
- data/spec/support/integration/test_programs/rspec_active_record.rb +4 -1
- data/spec/support/integration/test_programs/rspec_active_support.rb +4 -1
- data/spec/support/integration/test_programs/rspec_rails.rb +4 -1
- data/spec/support/integration/test_programs/rspec_rails_engine.rb +20 -0
- data/spec/support/models/active_record/person.rb +6 -4
- data/spec/support/models/active_record/shipping_address.rb +9 -10
- data/spec/support/models/customer.rb +2 -4
- data/spec/support/models/player.rb +3 -6
- data/spec/support/models/shipping_address.rb +4 -13
- data/spec/support/shared_examples/active_record.rb +258 -240
- data/spec/support/shared_examples/active_support.rb +174 -51
- data/spec/support/shared_examples/elided_diffs.rb +447 -423
- data/spec/support/shared_examples/hash_with_indifferent_access.rb +500 -464
- data/spec/support/shared_examples/key.rb +123 -0
- data/spec/support/unit/helpers.rb +1 -3
- data/spec/support/unit/matchers/match_output.rb +12 -13
- data/spec/unit/active_record/object_inspection_spec.rb +222 -206
- data/spec/unit/active_support/object_inspection_spec.rb +170 -0
- data/spec/unit/equality_matchers/main_spec.rb +1049 -984
- data/spec/unit/helpers_spec.rb +14 -21
- data/spec/unit/operation_tree_flatteners/array_spec.rb +557 -524
- data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +619 -601
- data/spec/unit/operation_tree_flatteners/default_object_spec.rb +619 -621
- data/spec/unit/operation_tree_flatteners/hash_spec.rb +595 -556
- data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +102 -92
- data/spec/unit/rspec/matchers/be_compared_to_spec.rb +3 -3
- data/spec/unit/rspec/matchers/be_predicate_spec.rb +3 -3
- data/spec/unit/rspec/matchers/contain_exactly_spec.rb +1 -1
- data/spec/unit/rspec/matchers/have_attributes_spec.rb +1 -1
- data/spec/unit/rspec/matchers/have_predicate_spec.rb +2 -2
- data/spec/unit/rspec/matchers/include_spec.rb +2 -2
- data/spec/unit/rspec/matchers/match_array_spec.rb +2 -2
- data/spec/unit/rspec/matchers/raise_error_spec.rb +43 -11
- data/spec/unit/rspec/matchers/respond_to_spec.rb +23 -16
- data/spec/unit/rspec/object_inspection/rspec_matcher_spec.rb +91 -0
- data/spec/unit/rspec/object_inspection_spec.rb +351 -326
- data/spec/unit/super_diff_spec.rb +1594 -1437
- data/spec/unit/tiered_lines_elider_spec.rb +3508 -3536
- data/spec/unit/tiered_lines_formatter_spec.rb +54 -116
- data/super_diff.gemspec +13 -12
- metadata +88 -75
- data/lib/super_diff/errors/no_diff_formatter_available_error.rb +0 -21
- data/lib/super_diff/errors/no_operational_sequencer_available_error.rb +0 -22
- data/spec/tmp/warnings_logger/all_warnings.txt +0 -2
@@ -8,11 +8,7 @@ module SuperDiff
|
|
8
8
|
method_object :lines
|
9
9
|
|
10
10
|
def call
|
11
|
-
|
12
|
-
lines
|
13
|
-
else
|
14
|
-
elided_lines
|
15
|
-
end
|
11
|
+
all_lines_are_changed_or_unchanged? ? lines : elided_lines
|
16
12
|
end
|
17
13
|
|
18
14
|
private
|
@@ -22,9 +18,11 @@ module SuperDiff
|
|
22
18
|
end
|
23
19
|
|
24
20
|
def elided_lines
|
25
|
-
boxes_to_elide
|
26
|
-
|
27
|
-
|
21
|
+
boxes_to_elide
|
22
|
+
.reverse
|
23
|
+
.reduce(lines) do |lines_with_elisions, box|
|
24
|
+
with_box_elided(box, lines_with_elisions)
|
25
|
+
end
|
28
26
|
end
|
29
27
|
|
30
28
|
def boxes_to_elide
|
@@ -35,9 +33,7 @@ module SuperDiff
|
|
35
33
|
end
|
36
34
|
|
37
35
|
def panes_to_consider_for_eliding
|
38
|
-
panes.select
|
39
|
-
pane.type == :clean && pane.range.size > maximum
|
40
|
-
end
|
36
|
+
panes.select { |pane| pane.type == :clean && pane.range.size > maximum }
|
41
37
|
end
|
42
38
|
|
43
39
|
def panes
|
@@ -45,24 +41,26 @@ module SuperDiff
|
|
45
41
|
end
|
46
42
|
|
47
43
|
def padded_dirty_panes
|
48
|
-
@_padded_dirty_panes ||=
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
44
|
+
@_padded_dirty_panes ||=
|
45
|
+
combine_congruent_panes(
|
46
|
+
dirty_panes
|
47
|
+
.map(&:padded)
|
48
|
+
.map { |pane| pane.capped_to(0, lines.size - 1) }
|
49
|
+
)
|
53
50
|
end
|
54
51
|
|
55
52
|
def dirty_panes
|
56
|
-
@_dirty_panes ||=
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
panes
|
62
|
-
|
63
|
-
|
53
|
+
@_dirty_panes ||=
|
54
|
+
lines
|
55
|
+
.each_with_index
|
56
|
+
.select { |line, index| line.type != :noop }
|
57
|
+
.reduce([]) do |panes, (_, index)|
|
58
|
+
if !panes.empty? && panes.last.range.end == index - 1
|
59
|
+
panes[0..-2] + [panes[-1].extended_to(index)]
|
60
|
+
else
|
61
|
+
panes + [Pane.new(type: :dirty, range: index..index)]
|
62
|
+
end
|
64
63
|
end
|
65
|
-
end
|
66
64
|
end
|
67
65
|
|
68
66
|
def with_box_elided(box, lines)
|
@@ -92,7 +90,7 @@ module SuperDiff
|
|
92
90
|
with_subset_of_lines_elided(
|
93
91
|
lines,
|
94
92
|
range: box.range,
|
95
|
-
indentation_level: box.indentation_level
|
93
|
+
indentation_level: box.indentation_level
|
96
94
|
)
|
97
95
|
end
|
98
96
|
end
|
@@ -106,26 +104,25 @@ module SuperDiff
|
|
106
104
|
end
|
107
105
|
|
108
106
|
def all_indentation_levels
|
109
|
-
lines
|
110
|
-
map(&:indentation_level)
|
111
|
-
select { |indentation_level| indentation_level > 0 }
|
112
|
-
uniq
|
107
|
+
lines
|
108
|
+
.map(&:indentation_level)
|
109
|
+
.select { |indentation_level| indentation_level > 0 }
|
110
|
+
.uniq
|
113
111
|
end
|
114
112
|
|
115
113
|
def find_boxes_to_elide_within(pane)
|
116
114
|
set_of_boxes =
|
117
115
|
normalized_box_groups_at_decreasing_indentation_levels_within(pane)
|
118
116
|
|
119
|
-
total_size_before_eliding =
|
120
|
-
reject(&:complete_bookend?).
|
121
|
-
size
|
117
|
+
total_size_before_eliding =
|
118
|
+
lines[pane.range].reject(&:complete_bookend?).size
|
122
119
|
|
123
120
|
if total_size_before_eliding > maximum
|
124
121
|
if maximum > 0
|
125
122
|
set_of_boxes.find do |boxes|
|
126
123
|
total_size_after_eliding =
|
127
124
|
total_size_before_eliding -
|
128
|
-
|
125
|
+
boxes.sum { |box| box.range.size - SIZE_OF_ELISION }
|
129
126
|
total_size_after_eliding <= maximum
|
130
127
|
end
|
131
128
|
else
|
@@ -137,22 +134,21 @@ module SuperDiff
|
|
137
134
|
end
|
138
135
|
|
139
136
|
def normalized_box_groups_at_decreasing_indentation_levels_within(pane)
|
140
|
-
box_groups_at_decreasing_indentation_levels_within(pane).
|
141
|
-
|
142
|
-
|
137
|
+
box_groups_at_decreasing_indentation_levels_within(pane).map(
|
138
|
+
&method(:filter_out_boxes_fully_contained_in_others)
|
139
|
+
).map(&method(:combine_congruent_boxes))
|
143
140
|
end
|
144
141
|
|
145
142
|
def box_groups_at_decreasing_indentation_levels_within(pane)
|
146
|
-
boxes_within_pane = boxes.select
|
147
|
-
box.fits_fully_within?(pane)
|
148
|
-
end
|
143
|
+
boxes_within_pane = boxes.select { |box| box.fits_fully_within?(pane) }
|
149
144
|
|
150
|
-
possible_indentation_levels =
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
145
|
+
possible_indentation_levels =
|
146
|
+
boxes_within_pane
|
147
|
+
.map(&:indentation_level)
|
148
|
+
.select { |indentation_level| indentation_level > 0 }
|
149
|
+
.uniq
|
150
|
+
.sort
|
151
|
+
.reverse
|
156
152
|
|
157
153
|
possible_indentation_levels.map do |indentation_level|
|
158
154
|
boxes_within_pane.select do |box|
|
@@ -162,9 +158,10 @@ module SuperDiff
|
|
162
158
|
end
|
163
159
|
|
164
160
|
def filter_out_boxes_fully_contained_in_others(boxes)
|
165
|
-
sorted_boxes =
|
166
|
-
|
167
|
-
|
161
|
+
sorted_boxes =
|
162
|
+
boxes.sort_by do |box|
|
163
|
+
[box.indentation_level, box.range.begin, box.range.end]
|
164
|
+
end
|
168
165
|
|
169
166
|
boxes.reject do |box2|
|
170
167
|
sorted_boxes.any? do |box1|
|
@@ -185,14 +182,14 @@ module SuperDiff
|
|
185
182
|
criterion = on
|
186
183
|
spannables.reduce([]) do |combined_spannables, spannable|
|
187
184
|
if (
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
185
|
+
!combined_spannables.empty? &&
|
186
|
+
spannable.range.begin <=
|
187
|
+
combined_spannables.last.range.end + 1 &&
|
188
|
+
spannable.public_send(criterion) ==
|
189
|
+
combined_spannables.last.public_send(criterion)
|
190
|
+
)
|
191
|
+
combined_spannables[0..-2] +
|
192
|
+
[combined_spannables[-1].extended_to(spannable.range.end)]
|
196
193
|
else
|
197
194
|
combined_spannables + [spannable]
|
198
195
|
end
|
@@ -213,10 +210,8 @@ module SuperDiff
|
|
213
210
|
|
214
211
|
with_subset_of_lines_elided(
|
215
212
|
lines,
|
216
|
-
range:
|
217
|
-
box.range.begin,
|
218
|
-
box.range.begin + amount_to_elide - 1,
|
219
|
-
),
|
213
|
+
range:
|
214
|
+
Range.new(box.range.begin, box.range.begin + amount_to_elide - 1),
|
220
215
|
indentation_level: box.indentation_level
|
221
216
|
)
|
222
217
|
end
|
@@ -252,14 +247,16 @@ module SuperDiff
|
|
252
247
|
end
|
253
248
|
|
254
249
|
opening_length, closing_length =
|
255
|
-
half_of_maximum,
|
250
|
+
half_of_maximum,
|
251
|
+
half_of_maximum + remainder
|
256
252
|
|
257
253
|
with_subset_of_lines_elided(
|
258
254
|
lines,
|
259
|
-
range:
|
260
|
-
|
261
|
-
|
262
|
-
|
255
|
+
range:
|
256
|
+
Range.new(
|
257
|
+
box.range.begin + opening_length,
|
258
|
+
box.range.end - closing_length
|
259
|
+
),
|
263
260
|
indentation_level: box.indentation_level
|
264
261
|
)
|
265
262
|
end
|
@@ -270,8 +267,8 @@ module SuperDiff
|
|
270
267
|
range,
|
271
268
|
Elision.new(
|
272
269
|
indentation_level: indentation_level,
|
273
|
-
children: lines[range].map(&:as_elided)
|
274
|
-
)
|
270
|
+
children: lines[range].map(&:as_elided)
|
271
|
+
)
|
275
272
|
)
|
276
273
|
end
|
277
274
|
|
@@ -282,7 +279,7 @@ module SuperDiff
|
|
282
279
|
class BuildPanes
|
283
280
|
extend AttrExtras.mixin
|
284
281
|
|
285
|
-
method_object [
|
282
|
+
method_object %i[dirty_panes! lines!]
|
286
283
|
|
287
284
|
def call
|
288
285
|
beginning + middle + ending
|
@@ -291,19 +288,13 @@ module SuperDiff
|
|
291
288
|
private
|
292
289
|
|
293
290
|
def beginning
|
294
|
-
if (
|
295
|
-
dirty_panes.empty? ||
|
296
|
-
dirty_panes.first.range.begin == 0
|
297
|
-
)
|
291
|
+
if (dirty_panes.empty? || dirty_panes.first.range.begin == 0)
|
298
292
|
[]
|
299
293
|
else
|
300
294
|
[
|
301
295
|
Pane.new(
|
302
296
|
type: :clean,
|
303
|
-
range: Range.new(
|
304
|
-
0,
|
305
|
-
dirty_panes.first.range.begin - 1
|
306
|
-
)
|
297
|
+
range: Range.new(0, dirty_panes.first.range.begin - 1)
|
307
298
|
)
|
308
299
|
]
|
309
300
|
end
|
@@ -313,43 +304,30 @@ module SuperDiff
|
|
313
304
|
if dirty_panes.size == 1
|
314
305
|
dirty_panes
|
315
306
|
else
|
316
|
-
dirty_panes
|
317
|
-
each_with_index
|
318
|
-
each_cons(2)
|
319
|
-
reduce([]) do |panes, ((pane1, _), (pane2, index2))|
|
307
|
+
dirty_panes
|
308
|
+
.each_with_index
|
309
|
+
.each_cons(2)
|
310
|
+
.reduce([]) do |panes, ((pane1, _), (pane2, index2))|
|
320
311
|
panes +
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
pane1.range.end + 1,
|
327
|
-
pane2.range.begin - 1,
|
312
|
+
[
|
313
|
+
pane1,
|
314
|
+
Pane.new(
|
315
|
+
type: :clean,
|
316
|
+
range: Range.new(pane1.range.end + 1, pane2.range.begin - 1)
|
328
317
|
)
|
329
|
-
)
|
330
|
-
] + (
|
331
|
-
index2 == dirty_panes.size - 1 ?
|
332
|
-
[pane2] :
|
333
|
-
[]
|
334
|
-
)
|
318
|
+
] + (index2 == dirty_panes.size - 1 ? [pane2] : [])
|
335
319
|
end
|
336
320
|
end
|
337
321
|
end
|
338
322
|
|
339
323
|
def ending
|
340
|
-
if (
|
341
|
-
dirty_panes.empty? ||
|
342
|
-
dirty_panes.last.range.end >= lines.size - 1
|
343
|
-
)
|
324
|
+
if (dirty_panes.empty? || dirty_panes.last.range.end >= lines.size - 1)
|
344
325
|
[]
|
345
326
|
else
|
346
327
|
[
|
347
328
|
Pane.new(
|
348
329
|
type: :clean,
|
349
|
-
range: Range.new(
|
350
|
-
dirty_panes.last.range.end + 1,
|
351
|
-
lines.size - 1
|
352
|
-
)
|
330
|
+
range: Range.new(dirty_panes.last.range.end + 1, lines.size - 1)
|
353
331
|
)
|
354
332
|
]
|
355
333
|
end
|
@@ -359,26 +337,20 @@ module SuperDiff
|
|
359
337
|
class Pane
|
360
338
|
extend AttrExtras.mixin
|
361
339
|
|
362
|
-
rattr_initialize [
|
340
|
+
rattr_initialize %i[type! range!]
|
363
341
|
|
364
342
|
def extended_to(new_end)
|
365
343
|
self.class.new(type: type, range: range.begin..new_end)
|
366
344
|
end
|
367
345
|
|
368
346
|
def padded
|
369
|
-
self.class.new(
|
370
|
-
type: type,
|
371
|
-
range: Range.new(range.begin, range.end)
|
372
|
-
)
|
347
|
+
self.class.new(type: type, range: Range.new(range.begin, range.end))
|
373
348
|
end
|
374
349
|
|
375
350
|
def capped_to(beginning, ending)
|
376
351
|
new_beginning = range.begin < beginning ? beginning : range.begin
|
377
352
|
new_ending = range.end > ending ? ending : range.end
|
378
|
-
self.class.new(
|
379
|
-
type: type,
|
380
|
-
range: Range.new(new_beginning, new_ending),
|
381
|
-
)
|
353
|
+
self.class.new(type: type, range: Range.new(new_beginning, new_ending))
|
382
354
|
end
|
383
355
|
end
|
384
356
|
|
@@ -427,14 +399,14 @@ module SuperDiff
|
|
427
399
|
def open_new_collection_box(line, index)
|
428
400
|
open_collection_boxes << Box.new(
|
429
401
|
indentation_level: line.indentation_level,
|
430
|
-
range: index..index
|
402
|
+
range: index..index
|
431
403
|
)
|
432
404
|
end
|
433
405
|
|
434
406
|
def record_item_box(line, index)
|
435
407
|
final_boxes << Box.new(
|
436
408
|
indentation_level: line.indentation_level,
|
437
|
-
range: index..index
|
409
|
+
range: index..index
|
438
410
|
)
|
439
411
|
end
|
440
412
|
end
|
@@ -442,7 +414,7 @@ module SuperDiff
|
|
442
414
|
class Box
|
443
415
|
extend AttrExtras.mixin
|
444
416
|
|
445
|
-
rattr_initialize [
|
417
|
+
rattr_initialize %i[indentation_level! range!]
|
446
418
|
|
447
419
|
def fully_contains?(other)
|
448
420
|
range.begin <= other.range.begin && range.end >= other.range.end
|
@@ -464,7 +436,7 @@ module SuperDiff
|
|
464
436
|
class Elision
|
465
437
|
extend AttrExtras.mixin
|
466
438
|
|
467
|
-
rattr_initialize [
|
439
|
+
rattr_initialize %i[indentation_level! children!]
|
468
440
|
|
469
441
|
def type
|
470
442
|
:elision
|
@@ -15,7 +15,7 @@ module SuperDiff
|
|
15
15
|
formattable_lines.each do |formattable_line|
|
16
16
|
doc.public_send(
|
17
17
|
"#{formattable_line.color}_line",
|
18
|
-
formattable_line.content
|
18
|
+
formattable_line.content
|
19
19
|
)
|
20
20
|
end
|
21
21
|
end
|
@@ -34,7 +34,7 @@ module SuperDiff
|
|
34
34
|
delete: :expected,
|
35
35
|
insert: :actual,
|
36
36
|
elision: :elision_marker,
|
37
|
-
noop: :plain
|
37
|
+
noop: :plain
|
38
38
|
}.freeze
|
39
39
|
|
40
40
|
pattr_initialize :line
|
@@ -47,7 +47,7 @@ module SuperDiff
|
|
47
47
|
COLORS.fetch(line.type) do
|
48
48
|
raise(
|
49
49
|
KeyError,
|
50
|
-
"Couldn't find color for line type #{line.type.inspect}!"
|
50
|
+
"Couldn't find color for line type #{line.type.inspect}!"
|
51
51
|
)
|
52
52
|
end
|
53
53
|
end
|
@@ -58,7 +58,7 @@ module SuperDiff
|
|
58
58
|
ICONS.fetch(line.type) do
|
59
59
|
raise(
|
60
60
|
KeyError,
|
61
|
-
"Couldn't find icon for line type #{line.type.inspect}!"
|
61
|
+
"Couldn't find icon for line type #{line.type.inspect}!"
|
62
62
|
)
|
63
63
|
end
|
64
64
|
end
|
@@ -68,11 +68,7 @@ module SuperDiff
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def possible_comma
|
71
|
-
|
72
|
-
","
|
73
|
-
else
|
74
|
-
""
|
75
|
-
end
|
71
|
+
line.add_comma? ? "," : ""
|
76
72
|
end
|
77
73
|
end
|
78
74
|
end
|
data/lib/super_diff/version.rb
CHANGED
data/lib/super_diff.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require "attr_extras/explicit"
|
2
2
|
require "diff-lcs"
|
3
3
|
require "patience_diff"
|
4
|
+
require "date"
|
4
5
|
|
5
6
|
module SuperDiff
|
6
7
|
autoload(
|
7
8
|
:ColorizedDocumentExtensions,
|
8
|
-
"super_diff/colorized_document_extensions"
|
9
|
+
"super_diff/colorized_document_extensions"
|
9
10
|
)
|
10
11
|
autoload :OperationTreeFlatteners, "super_diff/operation_tree_flatteners"
|
11
12
|
autoload :Configuration, "super_diff/configuration"
|
@@ -39,9 +40,8 @@ module SuperDiff
|
|
39
40
|
|
40
41
|
def self.inspect_object(object, as_lines:, **rest)
|
41
42
|
SuperDiff::RecursionGuard.guarding_recursion_of(object) do
|
42
|
-
inspection_tree =
|
43
|
-
object
|
44
|
-
)
|
43
|
+
inspection_tree =
|
44
|
+
ObjectInspection::InspectionTreeBuilders::Main.call(object)
|
45
45
|
|
46
46
|
if as_lines
|
47
47
|
inspection_tree.render_to_lines(object, **rest)
|
@@ -58,6 +58,14 @@ module SuperDiff
|
|
58
58
|
value.is_a?(Time)
|
59
59
|
end
|
60
60
|
|
61
|
+
def self.date_like?(value)
|
62
|
+
# Check for ActiveSupport's #acts_like_date? for their date-like objects
|
63
|
+
# In case class is both time-like and date-like, we should treat it as
|
64
|
+
# time-like. This is governed by the order of `Differs::DEFAULTS` entries
|
65
|
+
(value.respond_to?(:acts_like_date?) && value.acts_like_date?) ||
|
66
|
+
value.is_a?(Date)
|
67
|
+
end
|
68
|
+
|
61
69
|
def self.primitive?(value)
|
62
70
|
case value
|
63
71
|
when true, false, nil, Symbol, Numeric, Regexp, Class
|
@@ -68,11 +76,7 @@ module SuperDiff
|
|
68
76
|
end
|
69
77
|
|
70
78
|
def self.insert_overrides(target_module, mod = nil, &block)
|
71
|
-
|
72
|
-
target_module.prepend(mod)
|
73
|
-
else
|
74
|
-
target_module.prepend(Module.new(&block))
|
75
|
-
end
|
79
|
+
mod ? target_module.prepend(mod) : target_module.prepend(Module.new(&block))
|
76
80
|
end
|
77
81
|
|
78
82
|
def self.insert_singleton_overrides(target_module, mod = nil, &block)
|