super_diff 0.11.0 → 0.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -166
- data/lib/super_diff/active_record/differs/active_record_relation.rb +1 -1
- data/lib/super_diff/active_record/inspection_tree_builders/active_record_model.rb +57 -0
- data/lib/super_diff/active_record/inspection_tree_builders/active_record_relation.rb +34 -0
- data/lib/super_diff/active_record/inspection_tree_builders.rb +14 -0
- data/lib/super_diff/active_record/monkey_patches.rb +6 -3
- data/lib/super_diff/active_record/object_inspection.rb +16 -4
- data/lib/super_diff/active_record/operation_tree_builders/active_record_model.rb +6 -2
- data/lib/super_diff/active_record/operation_tree_builders/active_record_relation.rb +1 -1
- data/lib/super_diff/active_record/operation_tree_flatteners/active_record_relation.rb +1 -1
- data/lib/super_diff/active_record/operation_trees/active_record_relation.rb +1 -1
- data/lib/super_diff/active_record.rb +12 -16
- data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +1 -1
- data/lib/super_diff/active_support/inspection_tree_builders/hash_with_indifferent_access.rb +44 -0
- data/lib/super_diff/active_support/inspection_tree_builders/ordered_options.rb +44 -0
- data/lib/super_diff/active_support/inspection_tree_builders.rb +14 -0
- data/lib/super_diff/active_support/object_inspection.rb +16 -4
- data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +1 -1
- data/lib/super_diff/active_support/operation_tree_flatteners/hash_with_indifferent_access.rb +1 -1
- data/lib/super_diff/active_support/operation_trees/hash_with_indifferent_access.rb +1 -1
- data/lib/super_diff/active_support.rb +11 -15
- data/lib/super_diff/basic/diff_formatters/collection.rb +135 -0
- data/lib/super_diff/basic/diff_formatters/multiline_string.rb +34 -0
- data/lib/super_diff/basic/diff_formatters.rb +11 -0
- data/lib/super_diff/basic/differs/array.rb +17 -0
- data/lib/super_diff/basic/differs/custom_object.rb +19 -0
- data/lib/super_diff/basic/differs/date_like.rb +17 -0
- data/lib/super_diff/basic/differs/default_object.rb +24 -0
- data/lib/super_diff/basic/differs/hash.rb +17 -0
- data/lib/super_diff/basic/differs/multiline_string.rb +18 -0
- data/lib/super_diff/basic/differs/time_like.rb +17 -0
- data/lib/super_diff/basic/differs.rb +24 -0
- data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/array.rb +3 -3
- data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/custom_object.rb +3 -3
- data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/date_like.rb +3 -3
- data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/default_object.rb +5 -7
- data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/hash.rb +3 -3
- data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/primitive.rb +3 -3
- data/lib/super_diff/{object_inspection → basic}/inspection_tree_builders/time_like.rb +3 -3
- data/lib/super_diff/basic/inspection_tree_builders.rb +20 -0
- data/lib/super_diff/basic/operation_tree_builders/array.rb +111 -0
- data/lib/super_diff/basic/operation_tree_builders/custom_object.rb +42 -0
- data/lib/super_diff/basic/operation_tree_builders/date_like.rb +17 -0
- data/lib/super_diff/basic/operation_tree_builders/default_object.rb +117 -0
- data/lib/super_diff/basic/operation_tree_builders/hash.rb +222 -0
- data/lib/super_diff/basic/operation_tree_builders/multiline_string.rb +90 -0
- data/lib/super_diff/basic/operation_tree_builders/time_like.rb +26 -0
- data/lib/super_diff/basic/operation_tree_builders.rb +34 -0
- data/lib/super_diff/basic/operation_tree_flatteners/array.rb +17 -0
- data/lib/super_diff/basic/operation_tree_flatteners/collection.rb +140 -0
- data/lib/super_diff/basic/operation_tree_flatteners/custom_object.rb +30 -0
- data/lib/super_diff/basic/operation_tree_flatteners/default_object.rb +32 -0
- data/lib/super_diff/basic/operation_tree_flatteners/hash.rb +35 -0
- data/lib/super_diff/basic/operation_tree_flatteners/multiline_string.rb +20 -0
- data/lib/super_diff/basic/operation_tree_flatteners.rb +24 -0
- data/lib/super_diff/basic/operation_trees/array.rb +17 -0
- data/lib/super_diff/basic/operation_trees/custom_object.rb +17 -0
- data/lib/super_diff/basic/operation_trees/default_object.rb +42 -0
- data/lib/super_diff/basic/operation_trees/hash.rb +17 -0
- data/lib/super_diff/basic/operation_trees/multiline_string.rb +17 -0
- data/lib/super_diff/basic/operation_trees.rb +25 -0
- data/lib/super_diff/basic.rb +48 -0
- data/lib/super_diff/{differs/base.rb → core/abstract_differ.rb} +2 -2
- data/lib/super_diff/core/abstract_inspection_tree_builder.rb +26 -0
- data/lib/super_diff/{operation_trees/base.rb → core/abstract_operation_tree.rb} +6 -2
- data/lib/super_diff/{operation_tree_builders/base.rb → core/abstract_operation_tree_builder.rb} +4 -8
- data/lib/super_diff/{operation_tree_flatteners/base.rb → core/abstract_operation_tree_flattener.rb} +2 -2
- data/lib/super_diff/{operations → core}/binary_operation.rb +1 -1
- data/lib/super_diff/core/colorized_document_extensions.rb +20 -0
- data/lib/super_diff/core/configuration.rb +192 -0
- data/lib/super_diff/core/differ_dispatcher.rb +31 -0
- data/lib/super_diff/core/gem_version.rb +47 -0
- data/lib/super_diff/core/helpers.rb +88 -0
- data/lib/super_diff/core/implementation_checks.rb +21 -0
- data/lib/super_diff/{object_inspection → core}/inspection_tree.rb +7 -6
- data/lib/super_diff/core/inspection_tree_builder_dispatcher.rb +23 -0
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_lines_when_rendering_to_lines.rb +9 -3
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_prefix_when_rendering_to_lines.rb +3 -3
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_prelude_when_rendering_to_lines.rb +3 -3
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_single_line.rb +3 -3
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/base.rb +2 -2
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/inspection.rb +7 -11
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/nesting.rb +2 -2
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/only_when.rb +2 -2
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/text.rb +2 -2
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_empty.rb +2 -2
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_non_empty.rb +2 -2
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_rendering_to_lines.rb +2 -2
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_rendering_to_string.rb +2 -2
- data/lib/super_diff/core/inspection_tree_nodes.rb +55 -0
- data/lib/super_diff/core/line.rb +85 -0
- data/lib/super_diff/{errors → core}/no_differ_available_error.rb +1 -1
- data/lib/super_diff/core/no_inspection_tree_builder_available_error.rb +21 -0
- data/lib/super_diff/core/no_operation_tree_available_error.rb +20 -0
- data/lib/super_diff/core/no_operation_tree_builder_available_error.rb +24 -0
- data/lib/super_diff/{operation_tree_builders/main.rb → core/operation_tree_builder_dispatcher.rb} +9 -13
- data/lib/super_diff/core/operation_tree_finder.rb +27 -0
- data/lib/super_diff/core/prefix_for_next_inspection_tree_node.rb +6 -0
- data/lib/super_diff/core/prelude_for_next_inspection_tree_node.rb +6 -0
- data/lib/super_diff/core/recursion_guard.rb +52 -0
- data/lib/super_diff/core/tiered_lines.rb +6 -0
- data/lib/super_diff/core/tiered_lines_elider.rb +472 -0
- data/lib/super_diff/core/tiered_lines_formatter.rb +77 -0
- data/lib/super_diff/{operations → core}/unary_operation.rb +1 -1
- data/lib/super_diff/core.rb +69 -0
- data/lib/super_diff/differs.rb +19 -12
- data/lib/super_diff/equality_matchers/array.rb +3 -3
- data/lib/super_diff/equality_matchers/default.rb +8 -3
- data/lib/super_diff/equality_matchers/hash.rb +3 -3
- data/lib/super_diff/equality_matchers/multiline_string.rb +3 -3
- data/lib/super_diff/equality_matchers/primitive.rb +3 -3
- data/lib/super_diff/equality_matchers/singleline_string.rb +2 -2
- data/lib/super_diff/errors.rb +12 -8
- data/lib/super_diff/object_inspection.rb +63 -14
- data/lib/super_diff/operation_tree_builders.rb +19 -15
- data/lib/super_diff/operation_tree_flatteners.rb +19 -16
- data/lib/super_diff/operation_trees.rb +19 -9
- data/lib/super_diff/operations.rb +12 -2
- data/lib/super_diff/rspec/augmented_matcher.rb +1 -1
- data/lib/super_diff/rspec/differ.rb +4 -5
- data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +1 -1
- 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/object_having_attributes.rb +1 -1
- data/lib/super_diff/rspec/inspection_tree_builders/collection_containing_exactly.rb +34 -0
- data/lib/super_diff/rspec/inspection_tree_builders/collection_including.rb +40 -0
- data/lib/super_diff/rspec/inspection_tree_builders/double.rb +100 -0
- data/lib/super_diff/rspec/inspection_tree_builders/generic_describable_matcher.rb +17 -0
- data/lib/super_diff/rspec/inspection_tree_builders/hash_including.rb +40 -0
- data/lib/super_diff/rspec/inspection_tree_builders/instance_of.rb +25 -0
- data/lib/super_diff/rspec/inspection_tree_builders/kind_of.rb +25 -0
- data/lib/super_diff/rspec/inspection_tree_builders/object_having_attributes.rb +34 -0
- data/lib/super_diff/rspec/inspection_tree_builders/primitive.rb +9 -0
- data/lib/super_diff/rspec/inspection_tree_builders/value_within.rb +30 -0
- data/lib/super_diff/rspec/inspection_tree_builders.rb +40 -0
- data/lib/super_diff/rspec/object_inspection.rb +14 -4
- data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +4 -4
- data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +1 -1
- data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +1 -1
- data/lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb +2 -2
- data/lib/super_diff/rspec.rb +20 -18
- data/lib/super_diff/version.rb +1 -1
- data/lib/super_diff.rb +69 -21
- data/spec/examples.txt +704 -543
- data/spec/support/integration/helpers.rb +4 -1
- data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +1 -1
- data/spec/support/models/active_record/person.rb +8 -1
- data/spec/support/shared_examples/active_record.rb +5 -5
- data/spec/support/unit/helpers.rb +12 -1
- data/spec/support/unit/matchers/be_deprecated_in_favor_of.rb +39 -0
- data/spec/unit/active_record/object_inspection_spec.rb +5 -5
- data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/array_spec.rb +8 -8
- data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/custom_object_spec.rb +9 -9
- data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/default_object_spec.rb +9 -9
- data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/hash_spec.rb +8 -8
- data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/multiline_string_spec.rb +4 -4
- data/spec/unit/{helpers_spec.rb → core/helpers_spec.rb} +2 -2
- data/spec/unit/{tiered_lines_elider_spec.rb → core/tiered_lines_elider_spec.rb} +2 -2
- data/spec/unit/{tiered_lines_formatter_spec.rb → core/tiered_lines_formatter_spec.rb} +1 -1
- data/spec/unit/deprecations_spec.rb +176 -0
- data/spec/unit/equality_matchers/main_spec.rb +5 -5
- data/super_diff.gemspec +6 -0
- metadata +127 -115
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model.rb +0 -51
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +0 -36
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +0 -16
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +0 -46
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/ordered_options.rb +0 -46
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +0 -16
- data/lib/super_diff/colorized_document_extensions.rb +0 -18
- data/lib/super_diff/configuration.rb +0 -149
- data/lib/super_diff/diff_formatters/collection.rb +0 -132
- data/lib/super_diff/diff_formatters/multiline_string.rb +0 -31
- data/lib/super_diff/differs/array.rb +0 -15
- data/lib/super_diff/differs/custom_object.rb +0 -17
- data/lib/super_diff/differs/date_like.rb +0 -15
- data/lib/super_diff/differs/default_object.rb +0 -19
- data/lib/super_diff/differs/defaults.rb +0 -13
- data/lib/super_diff/differs/empty.rb +0 -13
- data/lib/super_diff/differs/hash.rb +0 -15
- data/lib/super_diff/differs/main.rb +0 -31
- data/lib/super_diff/differs/multiline_string.rb +0 -16
- data/lib/super_diff/differs/time_like.rb +0 -15
- data/lib/super_diff/gem_version.rb +0 -45
- data/lib/super_diff/helpers.rb +0 -86
- data/lib/super_diff/implementation_checks.rb +0 -19
- data/lib/super_diff/line.rb +0 -83
- data/lib/super_diff/object_inspection/inspection_tree_builders/base.rb +0 -27
- data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +0 -15
- data/lib/super_diff/object_inspection/inspection_tree_builders/main.rb +0 -30
- data/lib/super_diff/object_inspection/inspection_tree_builders.rb +0 -48
- data/lib/super_diff/object_inspection/nodes.rb +0 -50
- data/lib/super_diff/object_inspection/prefix_for_next_node.rb +0 -6
- data/lib/super_diff/object_inspection/prelude_for_next_node.rb +0 -6
- data/lib/super_diff/operation_tree_builders/array.rb +0 -107
- data/lib/super_diff/operation_tree_builders/custom_object.rb +0 -40
- data/lib/super_diff/operation_tree_builders/date_like.rb +0 -15
- data/lib/super_diff/operation_tree_builders/default_object.rb +0 -119
- data/lib/super_diff/operation_tree_builders/defaults.rb +0 -5
- data/lib/super_diff/operation_tree_builders/hash.rb +0 -218
- data/lib/super_diff/operation_tree_builders/multiline_string.rb +0 -86
- data/lib/super_diff/operation_tree_builders/time_like.rb +0 -24
- data/lib/super_diff/operation_tree_flatteners/array.rb +0 -15
- data/lib/super_diff/operation_tree_flatteners/collection.rb +0 -136
- data/lib/super_diff/operation_tree_flatteners/custom_object.rb +0 -28
- data/lib/super_diff/operation_tree_flatteners/default_object.rb +0 -31
- data/lib/super_diff/operation_tree_flatteners/hash.rb +0 -33
- data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +0 -18
- data/lib/super_diff/operation_trees/array.rb +0 -15
- data/lib/super_diff/operation_trees/custom_object.rb +0 -15
- data/lib/super_diff/operation_trees/default_object.rb +0 -40
- data/lib/super_diff/operation_trees/defaults.rb +0 -5
- data/lib/super_diff/operation_trees/hash.rb +0 -15
- data/lib/super_diff/operation_trees/main.rb +0 -35
- data/lib/super_diff/operation_trees/multiline_string.rb +0 -15
- data/lib/super_diff/recursion_guard.rb +0 -50
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_containing_exactly.rb +0 -36
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +0 -42
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +0 -102
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/generic_describable_matcher.rb +0 -19
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +0 -42
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +0 -27
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +0 -27
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/object_having_attributes.rb +0 -36
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/primitive.rb +0 -10
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +0 -32
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +0 -48
- data/lib/super_diff/tiered_lines.rb +0 -4
- data/lib/super_diff/tiered_lines_elider.rb +0 -462
- data/lib/super_diff/tiered_lines_formatter.rb +0 -75
@@ -1,25 +1,21 @@
|
|
1
|
+
require "super_diff/active_support/differs"
|
2
|
+
require "super_diff/active_support/inspection_tree_builders"
|
3
|
+
require "super_diff/active_support/operation_trees"
|
4
|
+
require "super_diff/active_support/operation_tree_builders"
|
5
|
+
require "super_diff/active_support/operation_tree_flatteners"
|
6
|
+
|
1
7
|
module SuperDiff
|
2
8
|
module ActiveSupport
|
3
|
-
autoload :Differs, "super_diff/active_support/differs"
|
4
9
|
autoload :ObjectInspection, "super_diff/active_support/object_inspection"
|
5
|
-
autoload(:OperationTrees, "super_diff/active_support/operation_trees")
|
6
|
-
autoload(
|
7
|
-
:OperationTreeBuilders,
|
8
|
-
"super_diff/active_support/operation_tree_builders"
|
9
|
-
)
|
10
|
-
autoload(
|
11
|
-
:OperationTreeFlatteners,
|
12
|
-
"super_diff/active_support/operation_tree_flatteners"
|
13
|
-
)
|
14
10
|
|
15
11
|
SuperDiff.configure do |config|
|
16
|
-
config.
|
17
|
-
config.
|
12
|
+
config.prepend_extra_differ_classes(Differs::HashWithIndifferentAccess)
|
13
|
+
config.prepend_extra_operation_tree_builder_classes(
|
18
14
|
OperationTreeBuilders::HashWithIndifferentAccess
|
19
15
|
)
|
20
|
-
config.
|
21
|
-
|
22
|
-
|
16
|
+
config.prepend_extra_inspection_tree_builder_classes(
|
17
|
+
InspectionTreeBuilders::HashWithIndifferentAccess,
|
18
|
+
InspectionTreeBuilders::OrderedOptions
|
23
19
|
)
|
24
20
|
end
|
25
21
|
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Basic
|
3
|
+
module DiffFormatters
|
4
|
+
# TODO: Remove
|
5
|
+
class Collection
|
6
|
+
extend AttrExtras.mixin
|
7
|
+
|
8
|
+
ICONS = { delete: "-", insert: "+" }.freeze
|
9
|
+
STYLES = { insert: :actual, delete: :expected, noop: :plain }.freeze
|
10
|
+
|
11
|
+
method_object(
|
12
|
+
%i[
|
13
|
+
open_token!
|
14
|
+
close_token!
|
15
|
+
operation_tree!
|
16
|
+
indent_level!
|
17
|
+
add_comma!
|
18
|
+
collection_prefix!
|
19
|
+
build_item_prefix!
|
20
|
+
]
|
21
|
+
)
|
22
|
+
|
23
|
+
def call
|
24
|
+
lines.join("\n")
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
attr_query :add_comma?
|
30
|
+
|
31
|
+
def lines
|
32
|
+
[
|
33
|
+
" #{indentation}#{collection_prefix}#{open_token}",
|
34
|
+
*contents,
|
35
|
+
" #{indentation}#{close_token}#{comma}"
|
36
|
+
]
|
37
|
+
end
|
38
|
+
|
39
|
+
def contents
|
40
|
+
operation_tree.map do |operation|
|
41
|
+
if operation.name == :change
|
42
|
+
handle_change_operation(operation)
|
43
|
+
else
|
44
|
+
handle_non_change_operation(operation)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def handle_change_operation(operation)
|
50
|
+
SuperDiff::RecursionGuard.guarding_recursion_of(
|
51
|
+
operation.left_collection,
|
52
|
+
operation.right_collection
|
53
|
+
) do |already_seen|
|
54
|
+
if already_seen
|
55
|
+
raise "Infinite recursion!"
|
56
|
+
else
|
57
|
+
operation.child_operations.to_diff(
|
58
|
+
indent_level: indent_level + 1,
|
59
|
+
collection_prefix: build_item_prefix.call(operation),
|
60
|
+
add_comma: operation.should_add_comma_after_displaying?
|
61
|
+
)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def handle_non_change_operation(operation)
|
67
|
+
icon = ICONS.fetch(operation.name, " ")
|
68
|
+
style_name = STYLES.fetch(operation.name, :normal)
|
69
|
+
chunk =
|
70
|
+
build_chunk_for(
|
71
|
+
operation,
|
72
|
+
prefix: build_item_prefix.call(operation),
|
73
|
+
icon: icon
|
74
|
+
)
|
75
|
+
|
76
|
+
chunk << "," if operation.should_add_comma_after_displaying?
|
77
|
+
|
78
|
+
style_chunk(style_name, chunk)
|
79
|
+
end
|
80
|
+
|
81
|
+
def build_chunk_for(operation, prefix:, icon:)
|
82
|
+
if operation.value.equal?(operation.collection)
|
83
|
+
build_chunk_from_string(
|
84
|
+
SuperDiff::RecursionGuard::PLACEHOLDER,
|
85
|
+
prefix: build_item_prefix.call(operation),
|
86
|
+
icon: icon
|
87
|
+
)
|
88
|
+
else
|
89
|
+
build_chunk_by_inspecting(
|
90
|
+
operation.value,
|
91
|
+
prefix: build_item_prefix.call(operation),
|
92
|
+
icon: icon
|
93
|
+
)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def build_chunk_by_inspecting(value, prefix:, icon:)
|
98
|
+
inspection = SuperDiff.inspect_object(value, as_single_line: false)
|
99
|
+
build_chunk_from_string(inspection, prefix: prefix, icon: icon)
|
100
|
+
end
|
101
|
+
|
102
|
+
def build_chunk_from_string(value, prefix:, icon:)
|
103
|
+
value
|
104
|
+
.split("\n")
|
105
|
+
.map
|
106
|
+
.with_index do |line, index|
|
107
|
+
[
|
108
|
+
icon,
|
109
|
+
" ",
|
110
|
+
indentation(offset: 1),
|
111
|
+
(index == 0 ? prefix : ""),
|
112
|
+
line
|
113
|
+
].join
|
114
|
+
end
|
115
|
+
.join("\n")
|
116
|
+
end
|
117
|
+
|
118
|
+
def style_chunk(style_name, chunk)
|
119
|
+
chunk
|
120
|
+
.split("\n")
|
121
|
+
.map { |line| Helpers.style(style_name, line) }
|
122
|
+
.join("\n")
|
123
|
+
end
|
124
|
+
|
125
|
+
def indentation(offset: 0)
|
126
|
+
" " * (indent_level + offset)
|
127
|
+
end
|
128
|
+
|
129
|
+
def comma
|
130
|
+
add_comma? ? "," : ""
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Core
|
3
|
+
module DiffFormatters
|
4
|
+
# TODO: Remove
|
5
|
+
class MultilineString < Base
|
6
|
+
def self.applies_to?(operation_tree)
|
7
|
+
operation_tree.is_a?(OperationTrees::MultilineString)
|
8
|
+
end
|
9
|
+
|
10
|
+
def call
|
11
|
+
lines.join("\n")
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def lines
|
17
|
+
operation_tree.reduce([]) do |array, operation|
|
18
|
+
case operation.name
|
19
|
+
when :change
|
20
|
+
array << Helpers.style(:expected, "- #{operation.left_value}")
|
21
|
+
array << Helpers.style(:actual, "+ #{operation.right_value}")
|
22
|
+
when :delete
|
23
|
+
array << Helpers.style(:expected, "- #{operation.value}")
|
24
|
+
when :insert
|
25
|
+
array << Helpers.style(:actual, "+ #{operation.value}")
|
26
|
+
else
|
27
|
+
array << Helpers.style(:plain, " #{operation.value}")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Basic
|
3
|
+
module Differs
|
4
|
+
class Array < Core::AbstractDiffer
|
5
|
+
def self.applies_to?(expected, actual)
|
6
|
+
expected.is_a?(::Array) && actual.is_a?(::Array)
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def operation_tree_builder_class
|
12
|
+
OperationTreeBuilders::Array
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Basic
|
3
|
+
module Differs
|
4
|
+
class CustomObject < Core::AbstractDiffer
|
5
|
+
def self.applies_to?(expected, actual)
|
6
|
+
expected.class == actual.class &&
|
7
|
+
expected.respond_to?(:attributes_for_super_diff) &&
|
8
|
+
actual.respond_to?(:attributes_for_super_diff)
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def operation_tree_builder_class
|
14
|
+
OperationTreeBuilders::CustomObject
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Basic
|
3
|
+
module Differs
|
4
|
+
class DateLike < Core::AbstractDiffer
|
5
|
+
def self.applies_to?(expected, actual)
|
6
|
+
SuperDiff.date_like?(expected) && SuperDiff.date_like?(actual)
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def operation_tree_builder_class
|
12
|
+
OperationTreeBuilders::DateLike
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Basic
|
3
|
+
module Differs
|
4
|
+
class DefaultObject < Core::AbstractDiffer
|
5
|
+
def self.applies_to?(expected, actual)
|
6
|
+
expected.class == actual.class
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def operation_tree
|
12
|
+
SuperDiff.build_operation_tree_for(
|
13
|
+
expected,
|
14
|
+
actual,
|
15
|
+
extra_operation_tree_builder_classes: [
|
16
|
+
SuperDiff::Basic::OperationTreeBuilders::DefaultObject
|
17
|
+
],
|
18
|
+
raise_if_nothing_applies: true
|
19
|
+
)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Basic
|
3
|
+
module Differs
|
4
|
+
class Hash < Core::AbstractDiffer
|
5
|
+
def self.applies_to?(expected, actual)
|
6
|
+
expected.is_a?(::Hash) && actual.is_a?(::Hash)
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def operation_tree_builder_class
|
12
|
+
OperationTreeBuilders::Hash
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Basic
|
3
|
+
module Differs
|
4
|
+
class MultilineString < Core::AbstractDiffer
|
5
|
+
def self.applies_to?(expected, actual)
|
6
|
+
expected.is_a?(::String) && actual.is_a?(::String) &&
|
7
|
+
(expected.include?("\n") || actual.include?("\n"))
|
8
|
+
end
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
def operation_tree_builder_class
|
13
|
+
OperationTreeBuilders::MultilineString
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Basic
|
3
|
+
module Differs
|
4
|
+
class TimeLike < Core::AbstractDiffer
|
5
|
+
def self.applies_to?(expected, actual)
|
6
|
+
SuperDiff.time_like?(expected) && SuperDiff.time_like?(actual)
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def operation_tree_builder_class
|
12
|
+
OperationTreeBuilders::TimeLike
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Basic
|
3
|
+
module Differs
|
4
|
+
autoload :Array, "super_diff/basic/differs/array"
|
5
|
+
autoload :CustomObject, "super_diff/basic/differs/custom_object"
|
6
|
+
autoload :DateLike, "super_diff/basic/differs/date_like"
|
7
|
+
autoload :DefaultObject, "super_diff/basic/differs/default_object"
|
8
|
+
autoload :Hash, "super_diff/basic/differs/hash"
|
9
|
+
autoload :MultilineString, "super_diff/basic/differs/multiline_string"
|
10
|
+
autoload :TimeLike, "super_diff/basic/differs/time_like"
|
11
|
+
|
12
|
+
class Main
|
13
|
+
def self.call(*args)
|
14
|
+
warn <<~EOT
|
15
|
+
WARNING: SuperDiff::Differs::Main.call(...) is deprecated and will be removed in the next major release.
|
16
|
+
Please use SuperDiff.diff(...) instead.
|
17
|
+
#{caller_locations.join("\n")}
|
18
|
+
EOT
|
19
|
+
SuperDiff.diff(*args)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module SuperDiff
|
2
|
-
module
|
2
|
+
module Basic
|
3
3
|
module InspectionTreeBuilders
|
4
|
-
class Array <
|
4
|
+
class Array < Core::AbstractInspectionTreeBuilder
|
5
5
|
def self.applies_to?(value)
|
6
6
|
value.is_a?(::Array)
|
7
7
|
end
|
8
8
|
|
9
9
|
def call
|
10
|
-
InspectionTree.new do |t1|
|
10
|
+
Core::InspectionTree.new do |t1|
|
11
11
|
t1.only_when empty do |t2|
|
12
12
|
# stree-ignore
|
13
13
|
t2.as_lines_when_rendering_to_lines do |t3|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module SuperDiff
|
2
|
-
module
|
2
|
+
module Basic
|
3
3
|
module InspectionTreeBuilders
|
4
|
-
class CustomObject <
|
4
|
+
class CustomObject < Core::AbstractInspectionTreeBuilder
|
5
5
|
def self.applies_to?(value)
|
6
6
|
value.respond_to?(:attributes_for_super_diff)
|
7
7
|
end
|
8
8
|
|
9
9
|
def call
|
10
|
-
InspectionTree.new do |t1|
|
10
|
+
Core::InspectionTree.new do |t1|
|
11
11
|
t1.as_lines_when_rendering_to_lines(
|
12
12
|
collection_bookend: :open
|
13
13
|
) do |t2|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module SuperDiff
|
2
|
-
module
|
2
|
+
module Basic
|
3
3
|
module InspectionTreeBuilders
|
4
|
-
class DateLike <
|
4
|
+
class DateLike < Core::AbstractInspectionTreeBuilder
|
5
5
|
def self.applies_to?(value)
|
6
6
|
SuperDiff.date_like?(value)
|
7
7
|
end
|
8
8
|
|
9
9
|
def call
|
10
|
-
InspectionTree.new do |t1|
|
10
|
+
Core::InspectionTree.new do |t1|
|
11
11
|
t1.as_lines_when_rendering_to_lines(
|
12
12
|
collection_bookend: :open
|
13
13
|
) do |t2|
|
@@ -1,18 +1,17 @@
|
|
1
1
|
module SuperDiff
|
2
|
-
module
|
2
|
+
module Basic
|
3
3
|
module InspectionTreeBuilders
|
4
|
-
class DefaultObject <
|
4
|
+
class DefaultObject < Core::AbstractInspectionTreeBuilder
|
5
5
|
def self.applies_to?(_value)
|
6
6
|
true
|
7
7
|
end
|
8
8
|
|
9
9
|
def call
|
10
|
-
InspectionTree.new do |t1|
|
10
|
+
Core::InspectionTree.new do |t1|
|
11
11
|
t1.only_when empty do |t2|
|
12
12
|
t2.as_lines_when_rendering_to_lines do |t3|
|
13
13
|
t3.add_text(
|
14
|
-
"#<#{object.class.name}:" +
|
15
|
-
SuperDiff::Helpers.object_address_for(object) + ">"
|
14
|
+
"#<#{object.class.name}:" + object_address_for(object) + ">"
|
16
15
|
)
|
17
16
|
end
|
18
17
|
end
|
@@ -22,8 +21,7 @@ module SuperDiff
|
|
22
21
|
collection_bookend: :open
|
23
22
|
) do |t3|
|
24
23
|
t3.add_text(
|
25
|
-
"#<#{object.class.name}:" +
|
26
|
-
SuperDiff::Helpers.object_address_for(object)
|
24
|
+
"#<#{object.class.name}:" + object_address_for(object)
|
27
25
|
)
|
28
26
|
|
29
27
|
# stree-ignore
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module SuperDiff
|
2
|
-
module
|
2
|
+
module Basic
|
3
3
|
module InspectionTreeBuilders
|
4
|
-
class Hash <
|
4
|
+
class Hash < Core::AbstractInspectionTreeBuilder
|
5
5
|
def self.applies_to?(value)
|
6
6
|
value.is_a?(::Hash)
|
7
7
|
end
|
8
8
|
|
9
9
|
def call
|
10
|
-
InspectionTree.new do |t1|
|
10
|
+
Core::InspectionTree.new do |t1|
|
11
11
|
t1.only_when empty do |t2|
|
12
12
|
# stree-ignore
|
13
13
|
t2.as_lines_when_rendering_to_lines do |t3|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module SuperDiff
|
2
|
-
module
|
2
|
+
module Basic
|
3
3
|
module InspectionTreeBuilders
|
4
|
-
class Primitive <
|
4
|
+
class Primitive < Core::AbstractInspectionTreeBuilder
|
5
5
|
def self.applies_to?(value)
|
6
6
|
SuperDiff.primitive?(value) || value.is_a?(::String)
|
7
7
|
end
|
8
8
|
|
9
9
|
def call
|
10
|
-
InspectionTree.new do |t1|
|
10
|
+
Core::InspectionTree.new do |t1|
|
11
11
|
t1.as_lines_when_rendering_to_lines do |t2|
|
12
12
|
t2.add_text object.inspect
|
13
13
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module SuperDiff
|
2
|
-
module
|
2
|
+
module Basic
|
3
3
|
module InspectionTreeBuilders
|
4
|
-
class TimeLike <
|
4
|
+
class TimeLike < Core::AbstractInspectionTreeBuilder
|
5
5
|
def self.applies_to?(value)
|
6
6
|
SuperDiff.time_like?(value)
|
7
7
|
end
|
8
8
|
|
9
9
|
def call
|
10
|
-
InspectionTree.new do |t1|
|
10
|
+
Core::InspectionTree.new do |t1|
|
11
11
|
t1.as_lines_when_rendering_to_lines(
|
12
12
|
collection_bookend: :open
|
13
13
|
) do |t2|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Basic
|
3
|
+
module InspectionTreeBuilders
|
4
|
+
autoload :Array, "super_diff/basic/inspection_tree_builders/array"
|
5
|
+
autoload(
|
6
|
+
:CustomObject,
|
7
|
+
"super_diff/basic/inspection_tree_builders/custom_object"
|
8
|
+
)
|
9
|
+
autoload(
|
10
|
+
:DefaultObject,
|
11
|
+
"super_diff/basic/inspection_tree_builders/default_object"
|
12
|
+
)
|
13
|
+
autoload :Hash, "super_diff/basic/inspection_tree_builders/hash"
|
14
|
+
autoload :Primitive, "super_diff/basic/inspection_tree_builders/primitive"
|
15
|
+
autoload :String, "super_diff/basic/inspection_tree_builders/string"
|
16
|
+
autoload :TimeLike, "super_diff/basic/inspection_tree_builders/time_like"
|
17
|
+
autoload :DateLike, "super_diff/basic/inspection_tree_builders/date_like"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require "diff-lcs"
|
2
|
+
|
3
|
+
module SuperDiff
|
4
|
+
module Basic
|
5
|
+
module OperationTreeBuilders
|
6
|
+
class Array < Core::AbstractOperationTreeBuilder
|
7
|
+
def self.applies_to?(expected, actual)
|
8
|
+
expected.is_a?(::Array) && actual.is_a?(::Array)
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
Diff::LCS.traverse_balanced(expected, actual, lcs_callbacks)
|
13
|
+
operation_tree
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def lcs_callbacks
|
19
|
+
@_lcs_callbacks ||=
|
20
|
+
LcsCallbacks.new(
|
21
|
+
operation_tree: operation_tree,
|
22
|
+
expected: expected,
|
23
|
+
actual: actual,
|
24
|
+
compare: method(:compare)
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
def operation_tree
|
29
|
+
@_operation_tree ||= OperationTrees::Array.new([])
|
30
|
+
end
|
31
|
+
|
32
|
+
class LcsCallbacks
|
33
|
+
extend AttrExtras.mixin
|
34
|
+
|
35
|
+
pattr_initialize %i[operation_tree! expected! actual! compare!]
|
36
|
+
public :operation_tree
|
37
|
+
|
38
|
+
def match(event)
|
39
|
+
add_noop_operation(event)
|
40
|
+
end
|
41
|
+
|
42
|
+
def discard_a(event)
|
43
|
+
add_delete_operation(event)
|
44
|
+
end
|
45
|
+
|
46
|
+
def discard_b(event)
|
47
|
+
add_insert_operation(event)
|
48
|
+
end
|
49
|
+
|
50
|
+
def change(event)
|
51
|
+
children = compare.(event.old_element, event.new_element)
|
52
|
+
|
53
|
+
if children
|
54
|
+
add_change_operation(event, children)
|
55
|
+
else
|
56
|
+
add_delete_operation(event)
|
57
|
+
add_insert_operation(event)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def add_delete_operation(event)
|
64
|
+
operation_tree << Core::UnaryOperation.new(
|
65
|
+
name: :delete,
|
66
|
+
collection: expected,
|
67
|
+
key: event.old_position,
|
68
|
+
value: event.old_element,
|
69
|
+
index: event.old_position
|
70
|
+
)
|
71
|
+
end
|
72
|
+
|
73
|
+
def add_insert_operation(event)
|
74
|
+
operation_tree << Core::UnaryOperation.new(
|
75
|
+
name: :insert,
|
76
|
+
collection: actual,
|
77
|
+
key: event.new_position,
|
78
|
+
value: event.new_element,
|
79
|
+
index: event.new_position
|
80
|
+
)
|
81
|
+
end
|
82
|
+
|
83
|
+
def add_noop_operation(event)
|
84
|
+
operation_tree << Core::UnaryOperation.new(
|
85
|
+
name: :noop,
|
86
|
+
collection: actual,
|
87
|
+
key: event.new_position,
|
88
|
+
value: event.new_element,
|
89
|
+
index: event.new_position
|
90
|
+
)
|
91
|
+
end
|
92
|
+
|
93
|
+
def add_change_operation(event, children)
|
94
|
+
operation_tree << Core::BinaryOperation.new(
|
95
|
+
name: :change,
|
96
|
+
left_collection: expected,
|
97
|
+
right_collection: actual,
|
98
|
+
left_key: event.old_position,
|
99
|
+
right_key: event.new_position,
|
100
|
+
left_value: event.old_element,
|
101
|
+
right_value: event.new_element,
|
102
|
+
left_index: event.old_position,
|
103
|
+
right_index: event.new_position,
|
104
|
+
children: children
|
105
|
+
)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|