super_diff 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +65 -26
- data/lib/super_diff/active_record/differs/active_record_relation.rb +1 -2
- data/lib/super_diff/active_record/differs.rb +1 -1
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model.rb +5 -13
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +1 -3
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +2 -2
- data/lib/super_diff/active_record/object_inspection.rb +1 -1
- data/lib/super_diff/active_record/operation_tree_builders/active_record_model.rb +1 -2
- data/lib/super_diff/active_record/operation_tree_builders/active_record_relation.rb +1 -2
- data/lib/super_diff/active_record/operation_tree_builders.rb +2 -2
- data/lib/super_diff/active_record/operation_tree_flatteners.rb +1 -1
- data/lib/super_diff/active_record/operation_trees.rb +1 -1
- data/lib/super_diff/active_record.rb +7 -15
- data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +5 -6
- data/lib/super_diff/active_support/differs.rb +1 -1
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +3 -9
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +1 -1
- data/lib/super_diff/active_support/object_inspection.rb +1 -1
- data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +5 -6
- data/lib/super_diff/active_support/operation_tree_builders.rb +1 -1
- data/lib/super_diff/active_support/operation_tree_flatteners.rb +1 -1
- data/lib/super_diff/active_support/operation_trees.rb +1 -1
- data/lib/super_diff/active_support.rb +6 -11
- data/lib/super_diff/colorized_document_extensions.rb +2 -4
- data/lib/super_diff/configuration.rb +14 -8
- data/lib/super_diff/csi/color.rb +4 -4
- data/lib/super_diff/csi/colorized_document.rb +12 -16
- data/lib/super_diff/csi/document.rb +8 -19
- data/lib/super_diff/csi/eight_bit_color.rb +19 -19
- data/lib/super_diff/csi/four_bit_color.rb +82 -31
- data/lib/super_diff/csi/twenty_four_bit_color.rb +12 -11
- data/lib/super_diff/csi/uncolorized_document.rb +2 -6
- data/lib/super_diff/csi.rb +10 -14
- data/lib/super_diff/diff_formatters/collection.rb +35 -41
- data/lib/super_diff/differs/default_object.rb +1 -1
- data/lib/super_diff/differs/defaults.rb +1 -1
- data/lib/super_diff/differs/main.rb +2 -13
- data/lib/super_diff/equality_matchers/array.rb +10 -12
- data/lib/super_diff/equality_matchers/base.rb +1 -1
- data/lib/super_diff/equality_matchers/default.rb +2 -4
- data/lib/super_diff/equality_matchers/defaults.rb +1 -1
- data/lib/super_diff/equality_matchers/hash.rb +10 -12
- data/lib/super_diff/equality_matchers/multiline_string.rb +11 -13
- data/lib/super_diff/equality_matchers/primitive.rb +10 -12
- data/lib/super_diff/equality_matchers/singleline_string.rb +10 -12
- data/lib/super_diff/equality_matchers.rb +1 -1
- data/lib/super_diff/errors.rb +3 -3
- data/lib/super_diff/gem_version.rb +3 -3
- data/lib/super_diff/helpers.rb +10 -10
- data/lib/super_diff/implementation_checks.rb +2 -2
- data/lib/super_diff/line.rb +3 -3
- data/lib/super_diff/object_inspection/inspection_tree.rb +46 -60
- data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +2 -6
- data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +3 -9
- data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +5 -14
- data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +1 -1
- data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +4 -12
- data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +6 -23
- data/lib/super_diff/object_inspection/inspection_tree_builders.rb +9 -9
- data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +8 -20
- data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +1 -5
- data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +1 -5
- data/lib/super_diff/object_inspection/nodes/as_single_line.rb +3 -7
- data/lib/super_diff/object_inspection/nodes/base.rb +9 -14
- data/lib/super_diff/object_inspection/nodes/inspection.rb +26 -34
- data/lib/super_diff/object_inspection/nodes/nesting.rb +1 -1
- data/lib/super_diff/object_inspection/nodes/only_when.rb +2 -6
- data/lib/super_diff/object_inspection/nodes/text.rb +1 -5
- data/lib/super_diff/object_inspection/nodes/when_empty.rb +2 -6
- data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +2 -6
- data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +1 -1
- data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +1 -5
- data/lib/super_diff/object_inspection/nodes.rb +7 -7
- data/lib/super_diff/object_inspection.rb +3 -3
- data/lib/super_diff/operation_tree_builders/array.rb +12 -11
- data/lib/super_diff/operation_tree_builders/base.rb +17 -15
- data/lib/super_diff/operation_tree_builders/custom_object.rb +8 -6
- data/lib/super_diff/operation_tree_builders/default_object.rb +29 -21
- data/lib/super_diff/operation_tree_builders/hash.rb +23 -24
- data/lib/super_diff/operation_tree_builders/main.rb +4 -11
- data/lib/super_diff/operation_tree_builders/multiline_string.rb +3 -3
- data/lib/super_diff/operation_tree_builders/time_like.rb +1 -11
- data/lib/super_diff/operation_tree_builders.rb +1 -1
- data/lib/super_diff/operation_tree_flatteners/base.rb +1 -5
- data/lib/super_diff/operation_tree_flatteners/collection.rb +13 -16
- data/lib/super_diff/operation_tree_flatteners/default_object.rb +1 -2
- data/lib/super_diff/operation_tree_flatteners/hash.rb +2 -10
- data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +2 -1
- data/lib/super_diff/operation_tree_flatteners.rb +3 -3
- data/lib/super_diff/operation_trees/base.rb +3 -5
- data/lib/super_diff/operation_trees/default_object.rb +1 -3
- data/lib/super_diff/operations/binary_operation.rb +2 -2
- data/lib/super_diff/operations/unary_operation.rb +1 -1
- data/lib/super_diff/rails.rb +2 -1
- data/lib/super_diff/recursion_guard.rb +5 -4
- data/lib/super_diff/rspec/augmented_matcher.rb +4 -5
- data/lib/super_diff/rspec/differ.rb +6 -13
- data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +3 -2
- data/lib/super_diff/rspec/differs/collection_including.rb +1 -1
- data/lib/super_diff/rspec/differs/hash_including.rb +1 -1
- data/lib/super_diff/rspec/differs.rb +3 -3
- data/lib/super_diff/rspec/matcher_text_builders/base.rb +13 -15
- data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +5 -7
- data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +3 -5
- data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +1 -5
- data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +2 -6
- data/lib/super_diff/rspec/matcher_text_builders.rb +5 -8
- data/lib/super_diff/rspec/matcher_text_template.rb +13 -16
- data/lib/super_diff/rspec/monkey_patches.rb +122 -116
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +8 -6
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +11 -16
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +2 -1
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +8 -6
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +8 -6
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +9 -9
- data/lib/super_diff/rspec/object_inspection.rb +1 -1
- data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +11 -10
- data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +7 -6
- data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +11 -10
- data/lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb +22 -17
- data/lib/super_diff/rspec/operation_tree_builders.rb +4 -4
- data/lib/super_diff/rspec.rb +11 -13
- data/lib/super_diff/tiered_lines_elider.rb +87 -115
- data/lib/super_diff/tiered_lines_formatter.rb +5 -9
- data/lib/super_diff/version.rb +1 -1
- data/lib/super_diff.rb +4 -9
- data/spec/examples.txt +493 -485
- data/spec/integration/rails/active_record_spec.rb +3 -1
- data/spec/integration/rails/engines_spec.rb +20 -0
- data/spec/integration/rails/hash_with_indifferent_access_spec.rb +3 -1
- data/spec/integration/rspec/be_falsey_matcher_spec.rb +40 -35
- data/spec/integration/rspec/be_matcher_spec.rb +360 -320
- data/spec/integration/rspec/be_nil_matcher_spec.rb +38 -34
- data/spec/integration/rspec/be_predicate_matcher_spec.rb +376 -359
- data/spec/integration/rspec/be_truthy_matcher_spec.rb +38 -33
- data/spec/integration/rspec/contain_exactly_matcher_spec.rb +242 -239
- data/spec/integration/rspec/eq_matcher_spec.rb +595 -557
- data/spec/integration/rspec/have_attributes_matcher_spec.rb +294 -286
- data/spec/integration/rspec/have_predicate_matcher_spec.rb +291 -297
- data/spec/integration/rspec/include_matcher_spec.rb +317 -215
- data/spec/integration/rspec/match_array_matcher_spec.rb +276 -273
- data/spec/integration/rspec/match_matcher_spec.rb +847 -834
- data/spec/integration/rspec/raise_error_matcher_spec.rb +468 -453
- data/spec/integration/rspec/respond_to_matcher_spec.rb +702 -697
- data/spec/integration/rspec/third_party_matcher_spec.rb +142 -138
- data/spec/integration/rspec/unhandled_errors_spec.rb +88 -84
- data/spec/spec_helper.rb +17 -20
- data/spec/support/command_runner.rb +34 -57
- data/spec/support/integration/helpers.rb +35 -28
- data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +28 -23
- data/spec/support/integration/test_programs/base.rb +12 -17
- data/spec/support/integration/test_programs/plain.rb +6 -0
- data/spec/support/integration/test_programs/rspec_active_record.rb +4 -1
- data/spec/support/integration/test_programs/rspec_active_support.rb +4 -1
- data/spec/support/integration/test_programs/rspec_rails.rb +4 -1
- data/spec/support/integration/test_programs/rspec_rails_engine.rb +30 -0
- data/spec/support/models/active_record/person.rb +6 -4
- data/spec/support/models/active_record/shipping_address.rb +9 -10
- data/spec/support/models/customer.rb +2 -4
- data/spec/support/models/player.rb +3 -6
- data/spec/support/models/shipping_address.rb +4 -13
- data/spec/support/shared_examples/active_record.rb +232 -214
- data/spec/support/shared_examples/active_support.rb +53 -51
- data/spec/support/shared_examples/elided_diffs.rb +405 -381
- data/spec/support/shared_examples/hash_with_indifferent_access.rb +424 -388
- data/spec/support/shared_examples/key.rb +123 -0
- data/spec/support/unit/helpers.rb +1 -3
- data/spec/support/unit/matchers/match_output.rb +12 -13
- data/spec/unit/active_record/object_inspection_spec.rb +222 -206
- data/spec/unit/equality_matchers/main_spec.rb +1049 -984
- data/spec/unit/helpers_spec.rb +14 -21
- data/spec/unit/operation_tree_flatteners/array_spec.rb +557 -524
- data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +619 -601
- data/spec/unit/operation_tree_flatteners/default_object_spec.rb +619 -621
- data/spec/unit/operation_tree_flatteners/hash_spec.rb +595 -556
- data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +102 -92
- data/spec/unit/rspec/matchers/be_compared_to_spec.rb +3 -3
- data/spec/unit/rspec/matchers/be_predicate_spec.rb +3 -3
- data/spec/unit/rspec/matchers/contain_exactly_spec.rb +1 -1
- data/spec/unit/rspec/matchers/have_attributes_spec.rb +1 -1
- data/spec/unit/rspec/matchers/have_predicate_spec.rb +2 -2
- data/spec/unit/rspec/matchers/include_spec.rb +2 -2
- data/spec/unit/rspec/matchers/match_array_spec.rb +2 -2
- data/spec/unit/rspec/matchers/raise_error_spec.rb +5 -5
- data/spec/unit/rspec/matchers/respond_to_spec.rb +23 -16
- data/spec/unit/rspec/object_inspection_spec.rb +349 -324
- data/spec/unit/super_diff_spec.rb +1542 -1449
- data/spec/unit/tiered_lines_elider_spec.rb +3508 -3536
- data/spec/unit/tiered_lines_formatter_spec.rb +54 -116
- data/super_diff.gemspec +13 -12
- metadata +73 -73
- data/spec/tmp/warnings_logger/all_warnings.txt +0 -2
@@ -5,7 +5,7 @@ module SuperDiff
|
|
5
5
|
def self.applies_to?(expected, actual)
|
6
6
|
(
|
7
7
|
SuperDiff::RSpec.a_collection_including_something?(expected) ||
|
8
|
-
|
8
|
+
SuperDiff::RSpec.array_including_something?(expected)
|
9
9
|
) && actual.is_a?(::Array)
|
10
10
|
end
|
11
11
|
|
@@ -18,11 +18,12 @@ module SuperDiff
|
|
18
18
|
private
|
19
19
|
|
20
20
|
def actual_with_extra_items_in_expected_at_end
|
21
|
-
value =
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
value =
|
22
|
+
if SuperDiff::RSpec.a_collection_including_something?(expected)
|
23
|
+
expected.expecteds
|
24
|
+
else
|
25
|
+
expected.instance_variable_get(:@expected)
|
26
|
+
end
|
26
27
|
actual + (value - actual)
|
27
28
|
end
|
28
29
|
end
|
@@ -2,29 +2,30 @@ module SuperDiff
|
|
2
2
|
module RSpec
|
3
3
|
module OperationTreeBuilders
|
4
4
|
class HashIncluding < SuperDiff::OperationTreeBuilders::Hash
|
5
|
+
include ::RSpec::Matchers::Composable
|
6
|
+
|
5
7
|
def self.applies_to?(expected, actual)
|
6
8
|
(
|
7
9
|
SuperDiff::RSpec.a_hash_including_something?(expected) ||
|
8
|
-
|
10
|
+
SuperDiff::RSpec.hash_including_something?(expected)
|
9
11
|
) && actual.is_a?(::Hash)
|
10
12
|
end
|
11
13
|
|
12
14
|
def initialize(expected:, **rest)
|
13
|
-
hash =
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
hash =
|
16
|
+
if SuperDiff::RSpec.a_hash_including_something?(expected)
|
17
|
+
expected.expecteds.first
|
18
|
+
else
|
19
|
+
expected.instance_variable_get(:@expected)
|
20
|
+
end
|
18
21
|
super(expected: hash, **rest)
|
19
22
|
end
|
20
23
|
|
21
24
|
private
|
22
25
|
|
23
26
|
def should_add_noop_operation?(key)
|
24
|
-
!expected.include?(key) ||
|
25
|
-
actual.include?(key) &&
|
26
|
-
expected[key] == actual[key]
|
27
|
-
)
|
27
|
+
!expected.include?(key) ||
|
28
|
+
(actual.include?(key) && values_match?(expected[key], actual[key]))
|
28
29
|
end
|
29
30
|
end
|
30
31
|
end
|
@@ -23,34 +23,39 @@ module SuperDiff
|
|
23
23
|
private
|
24
24
|
|
25
25
|
def establish_expected_and_actual_attributes
|
26
|
-
@expected_attributes =
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
@expected_attributes =
|
27
|
+
attribute_names.reduce({}) do |hash, name|
|
28
|
+
if expected.expected.include?(name)
|
29
|
+
hash.merge(name => expected.expected[name])
|
30
|
+
else
|
31
|
+
hash
|
32
|
+
end
|
31
33
|
end
|
32
|
-
end
|
33
34
|
|
34
|
-
@actual_attributes =
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
@actual_attributes =
|
36
|
+
attribute_names.reduce({}) do |hash, name|
|
37
|
+
if actual.respond_to?(name)
|
38
|
+
hash.merge(name => actual.public_send(name))
|
39
|
+
else
|
40
|
+
hash
|
41
|
+
end
|
39
42
|
end
|
40
|
-
end
|
41
43
|
end
|
42
44
|
|
43
45
|
def should_add_noop_operation?(attribute_name)
|
44
|
-
!expected_attributes.include?(attribute_name) ||
|
45
|
-
|
46
|
-
|
47
|
-
|
46
|
+
!expected_attributes.include?(attribute_name) ||
|
47
|
+
(
|
48
|
+
actual_attributes.include?(attribute_name) &&
|
49
|
+
expected_attributes[attribute_name] ==
|
50
|
+
actual_attributes[attribute_name]
|
51
|
+
)
|
48
52
|
end
|
49
53
|
|
50
54
|
def should_add_insert_operation?(attribute_name)
|
51
55
|
expected_attributes.include?(attribute_name) &&
|
52
56
|
actual_attributes.include?(attribute_name) &&
|
53
|
-
expected_attributes[attribute_name] !=
|
57
|
+
expected_attributes[attribute_name] !=
|
58
|
+
actual_attributes[attribute_name]
|
54
59
|
end
|
55
60
|
end
|
56
61
|
end
|
@@ -3,19 +3,19 @@ module SuperDiff
|
|
3
3
|
module OperationTreeBuilders
|
4
4
|
autoload(
|
5
5
|
:CollectionContainingExactly,
|
6
|
-
"super_diff/rspec/operation_tree_builders/collection_containing_exactly"
|
6
|
+
"super_diff/rspec/operation_tree_builders/collection_containing_exactly"
|
7
7
|
)
|
8
8
|
autoload(
|
9
9
|
:CollectionIncluding,
|
10
|
-
"super_diff/rspec/operation_tree_builders/collection_including"
|
10
|
+
"super_diff/rspec/operation_tree_builders/collection_including"
|
11
11
|
)
|
12
12
|
autoload(
|
13
13
|
:HashIncluding,
|
14
|
-
"super_diff/rspec/operation_tree_builders/hash_including"
|
14
|
+
"super_diff/rspec/operation_tree_builders/hash_including"
|
15
15
|
)
|
16
16
|
autoload(
|
17
17
|
:ObjectHavingAttributes,
|
18
|
-
"super_diff/rspec/operation_tree_builders/object_having_attributes"
|
18
|
+
"super_diff/rspec/operation_tree_builders/object_having_attributes"
|
19
19
|
)
|
20
20
|
end
|
21
21
|
end
|
data/lib/super_diff/rspec.rb
CHANGED
@@ -20,10 +20,8 @@ module SuperDiff
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def self.a_hash_including_something?(value)
|
23
|
-
fuzzy_object?(value) &&
|
24
|
-
value.
|
25
|
-
value.expecteds.one? &&
|
26
|
-
value.expecteds.first.is_a?(::Hash)
|
23
|
+
fuzzy_object?(value) && value.respond_to?(:expecteds) &&
|
24
|
+
value.expecteds.one? && value.expecteds.first.is_a?(::Hash)
|
27
25
|
end
|
28
26
|
|
29
27
|
# HINT: `a_hash_including` is an alias of `include` in the rspec-expectations gem.
|
@@ -33,8 +31,7 @@ module SuperDiff
|
|
33
31
|
end
|
34
32
|
|
35
33
|
def self.a_collection_including_something?(value)
|
36
|
-
fuzzy_object?(value) &&
|
37
|
-
value.respond_to?(:expecteds) &&
|
34
|
+
fuzzy_object?(value) && value.respond_to?(:expecteds) &&
|
38
35
|
!(value.expecteds.one? && value.expecteds.first.is_a?(::Hash))
|
39
36
|
end
|
40
37
|
|
@@ -84,10 +81,11 @@ module SuperDiff
|
|
84
81
|
end
|
85
82
|
|
86
83
|
def self.rspec_version
|
87
|
-
@_rspec_version ||=
|
88
|
-
|
89
|
-
|
90
|
-
|
84
|
+
@_rspec_version ||=
|
85
|
+
begin
|
86
|
+
require "rspec/core/version"
|
87
|
+
GemVersion.new(::RSpec::Core::Version::STRING)
|
88
|
+
end
|
91
89
|
end
|
92
90
|
|
93
91
|
SuperDiff.configuration.tap do |config|
|
@@ -95,14 +93,14 @@ module SuperDiff
|
|
95
93
|
Differs::CollectionContainingExactly,
|
96
94
|
Differs::CollectionIncluding,
|
97
95
|
Differs::HashIncluding,
|
98
|
-
Differs::ObjectHavingAttributes
|
96
|
+
Differs::ObjectHavingAttributes
|
99
97
|
)
|
100
98
|
|
101
99
|
config.add_extra_operation_tree_builder_classes(
|
102
100
|
OperationTreeBuilders::CollectionContainingExactly,
|
103
101
|
OperationTreeBuilders::CollectionIncluding,
|
104
102
|
OperationTreeBuilders::HashIncluding,
|
105
|
-
OperationTreeBuilders::ObjectHavingAttributes
|
103
|
+
OperationTreeBuilders::ObjectHavingAttributes
|
106
104
|
)
|
107
105
|
|
108
106
|
config.add_extra_inspection_tree_builder_classes(
|
@@ -114,7 +112,7 @@ module SuperDiff
|
|
114
112
|
ObjectInspection::InspectionTreeBuilders::KindOf,
|
115
113
|
ObjectInspection::InspectionTreeBuilders::ObjectHavingAttributes,
|
116
114
|
# ObjectInspection::InspectionTreeBuilders::Primitive,
|
117
|
-
ObjectInspection::InspectionTreeBuilders::ValueWithin
|
115
|
+
ObjectInspection::InspectionTreeBuilders::ValueWithin
|
118
116
|
)
|
119
117
|
end
|
120
118
|
end
|
@@ -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