super_diff 0.10.0 → 0.12.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.
Potentially problematic release.
This version of super_diff might be problematic. Click here for more details.
- 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 -14
- 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/basic/inspection_tree_builders/array.rb +53 -0
- data/lib/super_diff/basic/inspection_tree_builders/custom_object.rb +41 -0
- data/lib/super_diff/basic/inspection_tree_builders/date_like.rb +51 -0
- data/lib/super_diff/basic/inspection_tree_builders/default_object.rb +77 -0
- data/lib/super_diff/basic/inspection_tree_builders/hash.rb +63 -0
- data/lib/super_diff/basic/inspection_tree_builders/primitive.rb +19 -0
- data/lib/super_diff/basic/inspection_tree_builders/time_like.rb +58 -0
- 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 +33 -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 +32 -26
- 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 +12 -5
- 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/{errors/no_operational_sequencer_available_error.rb → core/no_operation_tree_builder_available_error.rb} +6 -4
- 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 -11
- 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 -12
- data/lib/super_diff/object_inspection.rb +63 -14
- data/lib/super_diff/operation_tree_builders.rb +19 -14
- 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/matcher_text_builders/raise_error.rb +3 -7
- data/lib/super_diff/rspec/monkey_patches.rb +59 -8
- 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 +28 -25
- data/lib/super_diff/version.rb +1 -1
- data/lib/super_diff.rb +78 -21
- data/spec/examples.txt +704 -493
- data/spec/integration/rails/engines_spec.rb +8 -3
- data/spec/integration/rspec/contain_exactly_matcher_spec.rb +19 -19
- data/spec/integration/rspec/eq_matcher_spec.rb +111 -39
- data/spec/integration/rspec/generic_describable_matchers_spec.rb +177 -0
- data/spec/integration/rspec/have_attributes_matcher_spec.rb +25 -25
- data/spec/integration/rspec/include_matcher_spec.rb +23 -23
- data/spec/integration/rspec/magic_metadata_spec.rb +51 -0
- data/spec/integration/rspec/match_array_matcher_spec.rb +30 -30
- data/spec/integration/rspec/match_matcher_spec.rb +93 -93
- data/spec/integration/rspec/raise_error_matcher_spec.rb +813 -69
- data/spec/internal/log/test.log +0 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/support/integration/helpers.rb +19 -11
- data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +1 -1
- data/spec/support/integration/matchers.rb +34 -0
- data/spec/support/integration/test_programs/base.rb +6 -6
- data/spec/support/integration/test_programs/rspec_rails_engine.rb +3 -13
- data/spec/support/models/active_record/person.rb +8 -1
- data/spec/support/shared_examples/active_record.rb +38 -38
- data/spec/support/shared_examples/active_support.rb +125 -4
- data/spec/support/shared_examples/elided_diffs.rb +48 -48
- data/spec/support/shared_examples/hash_with_indifferent_access.rb +88 -88
- data/spec/support/shared_examples/key.rb +10 -10
- 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/active_support/object_inspection_spec.rb +170 -0
- 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/spec/unit/rspec/matchers/raise_error_spec.rb +43 -11
- data/spec/unit/rspec/object_inspection/rspec_matcher_spec.rb +91 -0
- data/spec/unit/rspec/object_inspection_spec.rb +2 -2
- data/spec/unit/super_diff_spec.rb +64 -0
- data/super_diff.gemspec +6 -0
- metadata +137 -112
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model.rb +0 -39
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +0 -27
- 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 -31
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +0 -12
- 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/default_object.rb +0 -19
- data/lib/super_diff/differs/defaults.rb +0 -12
- 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/errors/no_diff_formatter_available_error.rb +0 -21
- 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/array.rb +0 -34
- data/lib/super_diff/object_inspection/inspection_tree_builders/base.rb +0 -27
- data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +0 -31
- data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +0 -54
- data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +0 -14
- data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +0 -38
- data/lib/super_diff/object_inspection/inspection_tree_builders/main.rb +0 -30
- data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +0 -21
- data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +0 -47
- data/lib/super_diff/object_inspection/inspection_tree_builders.rb +0 -44
- 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/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 -29
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +0 -36
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +0 -98
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +0 -37
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +0 -28
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +0 -28
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/object_having_attributes.rb +0 -29
- 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 -33
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +0 -44
- 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
@@ -0,0 +1,26 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Basic
|
3
|
+
module OperationTreeBuilders
|
4
|
+
class TimeLike < CustomObject
|
5
|
+
def self.applies_to?(expected, actual)
|
6
|
+
SuperDiff.time_like?(expected) && SuperDiff.time_like?(actual)
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def attribute_names
|
12
|
+
base = %w[year month day hour min sec subsec zone utc_offset]
|
13
|
+
|
14
|
+
# If timezones are different, also show a normalized timestamp at the
|
15
|
+
# end of the diff to help visualize why they are different moments in
|
16
|
+
# time.
|
17
|
+
if actual.zone != expected.zone
|
18
|
+
base + ["utc"]
|
19
|
+
else
|
20
|
+
base
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Basic
|
3
|
+
module OperationTreeBuilders
|
4
|
+
autoload :Array, "super_diff/basic/operation_tree_builders/array"
|
5
|
+
autoload(
|
6
|
+
:CustomObject,
|
7
|
+
"super_diff/basic/operation_tree_builders/custom_object"
|
8
|
+
)
|
9
|
+
autoload(
|
10
|
+
:DefaultObject,
|
11
|
+
"super_diff/basic/operation_tree_builders/default_object"
|
12
|
+
)
|
13
|
+
autoload :Hash, "super_diff/basic/operation_tree_builders/hash"
|
14
|
+
# TODO: Where is this used?
|
15
|
+
autoload(
|
16
|
+
:MultilineString,
|
17
|
+
"super_diff/basic/operation_tree_builders/multiline_string"
|
18
|
+
)
|
19
|
+
autoload :TimeLike, "super_diff/basic/operation_tree_builders/time_like"
|
20
|
+
autoload :DateLike, "super_diff/basic/operation_tree_builders/date_like"
|
21
|
+
|
22
|
+
class Main
|
23
|
+
def self.call(*args)
|
24
|
+
warn <<~EOT
|
25
|
+
WARNING: SuperDiff::OperationTreeBuilders::Main.call(...) is deprecated and will be removed in the next major release.
|
26
|
+
Please use SuperDiff.build_operation_tree_for(...) instead.
|
27
|
+
#{caller_locations.join("\n")}
|
28
|
+
EOT
|
29
|
+
SuperDiff.build_operation_tree_for(*args)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Basic
|
3
|
+
module OperationTreeFlatteners
|
4
|
+
class Collection < Core::AbstractOperationTreeFlattener
|
5
|
+
protected
|
6
|
+
|
7
|
+
def build_tiered_lines
|
8
|
+
[
|
9
|
+
Core::Line.new(
|
10
|
+
type: :noop,
|
11
|
+
indentation_level: indentation_level,
|
12
|
+
value: open_token,
|
13
|
+
collection_bookend: :open
|
14
|
+
),
|
15
|
+
*inner_lines,
|
16
|
+
Core::Line.new(
|
17
|
+
type: :noop,
|
18
|
+
indentation_level: indentation_level,
|
19
|
+
value: close_token,
|
20
|
+
collection_bookend: :close
|
21
|
+
)
|
22
|
+
]
|
23
|
+
end
|
24
|
+
|
25
|
+
def inner_lines
|
26
|
+
@_inner_lines ||=
|
27
|
+
operation_tree.flat_map do |operation|
|
28
|
+
lines =
|
29
|
+
if operation.name == :change
|
30
|
+
build_lines_for_change_operation(operation)
|
31
|
+
else
|
32
|
+
build_lines_for_non_change_operation(operation)
|
33
|
+
end
|
34
|
+
|
35
|
+
maybe_add_prefix_at_beginning_of_lines(
|
36
|
+
maybe_add_comma_at_end_of_lines(lines, operation),
|
37
|
+
operation
|
38
|
+
)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def maybe_add_prefix_at_beginning_of_lines(lines, operation)
|
43
|
+
if add_prefix_at_beginning_of_lines?(operation)
|
44
|
+
add_prefix_at_beginning_of_lines(lines, operation)
|
45
|
+
else
|
46
|
+
lines
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def add_prefix_at_beginning_of_lines?(operation)
|
51
|
+
!!item_prefix_for(operation)
|
52
|
+
end
|
53
|
+
|
54
|
+
def add_prefix_at_beginning_of_lines(lines, operation)
|
55
|
+
[lines[0].prefixed_with(item_prefix_for(operation))] + lines[1..-1]
|
56
|
+
end
|
57
|
+
|
58
|
+
def maybe_add_comma_at_end_of_lines(lines, operation)
|
59
|
+
if last_item_in_collection?(operation)
|
60
|
+
lines
|
61
|
+
else
|
62
|
+
add_comma_at_end_of_lines(lines)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def last_item_in_collection?(operation)
|
67
|
+
if operation.name == :change
|
68
|
+
operation.left_index == operation.left_collection.size - 1 &&
|
69
|
+
operation.right_index == operation.right_collection.size - 1
|
70
|
+
else
|
71
|
+
operation.index == operation.collection.size - 1
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def add_comma_at_end_of_lines(lines)
|
76
|
+
lines[0..-2] + [lines[-1].with_comma]
|
77
|
+
end
|
78
|
+
|
79
|
+
def build_lines_for_change_operation(operation)
|
80
|
+
Core::RecursionGuard.guarding_recursion_of(
|
81
|
+
operation.left_collection,
|
82
|
+
operation.right_collection
|
83
|
+
) do |already_seen|
|
84
|
+
if already_seen
|
85
|
+
raise InfiniteRecursionError
|
86
|
+
else
|
87
|
+
operation.children.flatten(
|
88
|
+
indentation_level: indentation_level + 1
|
89
|
+
)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def build_lines_for_non_change_operation(operation)
|
95
|
+
indentation_level = @indentation_level + 1
|
96
|
+
|
97
|
+
if recursive_operation?(operation)
|
98
|
+
[
|
99
|
+
Core::Line.new(
|
100
|
+
type: operation.name,
|
101
|
+
indentation_level: indentation_level,
|
102
|
+
value: Core::RecursionGuard::PLACEHOLDER
|
103
|
+
)
|
104
|
+
]
|
105
|
+
else
|
106
|
+
build_lines_from_inspection_of(
|
107
|
+
operation.value,
|
108
|
+
type: operation.name,
|
109
|
+
indentation_level: indentation_level
|
110
|
+
)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def recursive_operation?(operation)
|
115
|
+
operation.value.equal?(operation.collection) ||
|
116
|
+
Core::RecursionGuard.already_seen?(operation.value)
|
117
|
+
end
|
118
|
+
|
119
|
+
def item_prefix_for(_operation)
|
120
|
+
""
|
121
|
+
end
|
122
|
+
|
123
|
+
def build_lines_from_inspection_of(value, type:, indentation_level:)
|
124
|
+
SuperDiff.inspect_object(
|
125
|
+
value,
|
126
|
+
as_lines: true,
|
127
|
+
type: type,
|
128
|
+
indentation_level: indentation_level
|
129
|
+
)
|
130
|
+
end
|
131
|
+
|
132
|
+
class InfiniteRecursionError < StandardError
|
133
|
+
def initialize(_message = nil)
|
134
|
+
super("Unhandled recursive data structure encountered!")
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Basic
|
3
|
+
module OperationTreeFlatteners
|
4
|
+
class CustomObject < Collection
|
5
|
+
protected
|
6
|
+
|
7
|
+
def open_token
|
8
|
+
"#<%<class>s {" % { class: operation_tree.underlying_object.class }
|
9
|
+
end
|
10
|
+
|
11
|
+
def close_token
|
12
|
+
"}>"
|
13
|
+
end
|
14
|
+
|
15
|
+
def item_prefix_for(operation)
|
16
|
+
key =
|
17
|
+
# Note: We could have used the right_key here too, they're both the
|
18
|
+
# same keys
|
19
|
+
if operation.respond_to?(:left_key)
|
20
|
+
operation.left_key
|
21
|
+
else
|
22
|
+
operation.key
|
23
|
+
end
|
24
|
+
|
25
|
+
"#{key}: "
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Basic
|
3
|
+
module OperationTreeFlatteners
|
4
|
+
class DefaultObject < Collection
|
5
|
+
protected
|
6
|
+
|
7
|
+
def open_token
|
8
|
+
"#<#{operation_tree.underlying_object.class.name}:" +
|
9
|
+
Core::Helpers.object_address_for(operation_tree.underlying_object) +
|
10
|
+
" {"
|
11
|
+
end
|
12
|
+
|
13
|
+
def close_token
|
14
|
+
"}>"
|
15
|
+
end
|
16
|
+
|
17
|
+
def item_prefix_for(operation)
|
18
|
+
key =
|
19
|
+
# Note: We could have used the right_key here too, they're both the
|
20
|
+
# same keys
|
21
|
+
if operation.respond_to?(:left_key)
|
22
|
+
operation.left_key
|
23
|
+
else
|
24
|
+
operation.key
|
25
|
+
end
|
26
|
+
|
27
|
+
"@#{key}="
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Basic
|
3
|
+
module OperationTreeFlatteners
|
4
|
+
class Hash < Collection
|
5
|
+
protected
|
6
|
+
|
7
|
+
def open_token
|
8
|
+
"{"
|
9
|
+
end
|
10
|
+
|
11
|
+
def close_token
|
12
|
+
"}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def item_prefix_for(operation)
|
16
|
+
key = key_for(operation)
|
17
|
+
|
18
|
+
format_keys_as_kwargs? ? "#{key}: " : "#{key.inspect} => "
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def format_keys_as_kwargs?
|
24
|
+
operation_tree.all? { |operation| key_for(operation).is_a?(Symbol) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def key_for(operation)
|
28
|
+
# Note: We could have used the right_key here too, they're both the
|
29
|
+
# same keys
|
30
|
+
operation.respond_to?(:left_key) ? operation.left_key : operation.key
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Basic
|
3
|
+
module OperationTreeFlatteners
|
4
|
+
class MultilineString < Core::AbstractOperationTreeFlattener
|
5
|
+
def build_tiered_lines
|
6
|
+
operation_tree.map do |operation|
|
7
|
+
Core::Line.new(
|
8
|
+
type: operation.name,
|
9
|
+
indentation_level: indentation_level,
|
10
|
+
# TODO: Test that quotes and things don't get escaped but escape
|
11
|
+
# characters do
|
12
|
+
value:
|
13
|
+
operation.value.inspect[1..-2].gsub(/\\"/, '"').gsub(/\\'/, "'")
|
14
|
+
)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Basic
|
3
|
+
module OperationTreeFlatteners
|
4
|
+
autoload :Array, "super_diff/basic/operation_tree_flatteners/array"
|
5
|
+
autoload(
|
6
|
+
:Collection,
|
7
|
+
"super_diff/basic/operation_tree_flatteners/collection"
|
8
|
+
)
|
9
|
+
autoload(
|
10
|
+
:CustomObject,
|
11
|
+
"super_diff/basic/operation_tree_flatteners/custom_object"
|
12
|
+
)
|
13
|
+
autoload(
|
14
|
+
:DefaultObject,
|
15
|
+
"super_diff/basic/operation_tree_flatteners/default_object"
|
16
|
+
)
|
17
|
+
autoload :Hash, "super_diff/basic/operation_tree_flatteners/hash"
|
18
|
+
autoload(
|
19
|
+
:MultilineString,
|
20
|
+
"super_diff/basic/operation_tree_flatteners/multiline_string"
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Basic
|
3
|
+
module OperationTrees
|
4
|
+
class Array < Core::AbstractOperationTree
|
5
|
+
def self.applies_to?(value)
|
6
|
+
value.is_a?(::Array)
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def operation_tree_flattener_class
|
12
|
+
OperationTreeFlatteners::Array
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Basic
|
3
|
+
module OperationTrees
|
4
|
+
class CustomObject < DefaultObject
|
5
|
+
def self.applies_to?(value)
|
6
|
+
value.respond_to?(:attributes_for_super_diff)
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def operation_tree_flattener_class
|
12
|
+
OperationTreeFlatteners::CustomObject
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Basic
|
3
|
+
module OperationTrees
|
4
|
+
class DefaultObject < Core::AbstractOperationTree
|
5
|
+
def self.applies_to?(*)
|
6
|
+
true
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_reader :underlying_object
|
10
|
+
|
11
|
+
def initialize(operations, underlying_object:)
|
12
|
+
super(operations)
|
13
|
+
@underlying_object = underlying_object
|
14
|
+
end
|
15
|
+
|
16
|
+
def pretty_print(pp)
|
17
|
+
pp.text "#<#{self.class.name} "
|
18
|
+
pp.nest(1) do
|
19
|
+
pp.breakable
|
20
|
+
pp.text ":operations=>"
|
21
|
+
pp.group(1, "[", "]") do
|
22
|
+
pp.breakable
|
23
|
+
pp.seplist(self) { |value| pp.pp value }
|
24
|
+
end
|
25
|
+
pp.comma_breakable
|
26
|
+
pp.text ":underlying_object=>"
|
27
|
+
pp.object_address_group underlying_object do
|
28
|
+
# do nothing
|
29
|
+
end
|
30
|
+
end
|
31
|
+
pp.text ">"
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
|
36
|
+
def operation_tree_flattener_class
|
37
|
+
OperationTreeFlatteners::DefaultObject
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Basic
|
3
|
+
module OperationTrees
|
4
|
+
class Hash < Core::AbstractOperationTree
|
5
|
+
def self.applies_to?(value)
|
6
|
+
value.is_a?(::Hash)
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def operation_tree_flattener_class
|
12
|
+
OperationTreeFlatteners::Hash
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Basic
|
3
|
+
module OperationTrees
|
4
|
+
class MultilineString < Core::AbstractOperationTree
|
5
|
+
def self.applies_to?(value)
|
6
|
+
value.is_a?(::String) && value.is_a?(::String)
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def operation_tree_flattener_class
|
12
|
+
OperationTreeFlatteners::MultilineString
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Basic
|
3
|
+
module OperationTrees
|
4
|
+
autoload :Array, "super_diff/basic/operation_trees/array"
|
5
|
+
autoload :CustomObject, "super_diff/basic/operation_trees/custom_object"
|
6
|
+
autoload :DefaultObject, "super_diff/basic/operation_trees/default_object"
|
7
|
+
autoload :Hash, "super_diff/basic/operation_trees/hash"
|
8
|
+
autoload(
|
9
|
+
:MultilineString,
|
10
|
+
"super_diff/basic/operation_trees/multiline_string"
|
11
|
+
)
|
12
|
+
|
13
|
+
class Main
|
14
|
+
def self.call(*args)
|
15
|
+
warn <<~EOT
|
16
|
+
WARNING: SuperDiff::OperationTrees::Main.call(...) is deprecated and will be removed in the next major release.
|
17
|
+
Please use SuperDiff.find_operation_tree_for(...) instead.
|
18
|
+
#{caller_locations.join("\n")}
|
19
|
+
EOT
|
20
|
+
SuperDiff.find_operation_tree_for(*args)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "super_diff/basic/differs"
|
2
|
+
require "super_diff/basic/inspection_tree_builders"
|
3
|
+
require "super_diff/basic/operation_tree_builders"
|
4
|
+
require "super_diff/basic/operation_tree_flatteners"
|
5
|
+
require "super_diff/basic/operation_trees"
|
6
|
+
|
7
|
+
module SuperDiff
|
8
|
+
module Basic
|
9
|
+
autoload :DiffFormatters, "super_diff/basic/diff_formatters"
|
10
|
+
|
11
|
+
SuperDiff.configuration.tap do |config|
|
12
|
+
config.add_extra_differ_classes(
|
13
|
+
Differs::Array,
|
14
|
+
Differs::Hash,
|
15
|
+
Differs::TimeLike,
|
16
|
+
Differs::DateLike,
|
17
|
+
Differs::MultilineString,
|
18
|
+
Differs::CustomObject,
|
19
|
+
Differs::DefaultObject
|
20
|
+
)
|
21
|
+
|
22
|
+
config.add_extra_inspection_tree_builder_classes(
|
23
|
+
InspectionTreeBuilders::CustomObject,
|
24
|
+
InspectionTreeBuilders::Array,
|
25
|
+
InspectionTreeBuilders::Hash,
|
26
|
+
InspectionTreeBuilders::Primitive,
|
27
|
+
InspectionTreeBuilders::TimeLike,
|
28
|
+
InspectionTreeBuilders::DateLike,
|
29
|
+
InspectionTreeBuilders::DefaultObject
|
30
|
+
)
|
31
|
+
|
32
|
+
config.add_extra_operation_tree_builder_classes(
|
33
|
+
OperationTreeBuilders::Array,
|
34
|
+
OperationTreeBuilders::Hash,
|
35
|
+
OperationTreeBuilders::TimeLike,
|
36
|
+
OperationTreeBuilders::DateLike,
|
37
|
+
OperationTreeBuilders::CustomObject
|
38
|
+
)
|
39
|
+
|
40
|
+
config.add_extra_operation_tree_classes(
|
41
|
+
OperationTrees::Array,
|
42
|
+
OperationTrees::Hash,
|
43
|
+
OperationTrees::CustomObject,
|
44
|
+
OperationTrees::DefaultObject
|
45
|
+
)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Core
|
3
|
+
class AbstractInspectionTreeBuilder
|
4
|
+
extend AttrExtras.mixin
|
5
|
+
extend ImplementationChecks
|
6
|
+
include ImplementationChecks
|
7
|
+
include Helpers
|
8
|
+
|
9
|
+
def self.applies_to?(_value)
|
10
|
+
unimplemented_class_method!
|
11
|
+
end
|
12
|
+
|
13
|
+
method_object :object
|
14
|
+
|
15
|
+
def call
|
16
|
+
unimplemented_instance_method!
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
def inspection_tree
|
22
|
+
unimplemented_instance_method!
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require "forwardable"
|
2
2
|
|
3
3
|
module SuperDiff
|
4
|
-
module
|
5
|
-
class
|
4
|
+
module Core
|
5
|
+
class AbstractOperationTree
|
6
6
|
def self.applies_to?(*)
|
7
7
|
unimplemented_class_method!
|
8
8
|
end
|
@@ -46,6 +46,10 @@ module SuperDiff
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
+
def ==(other)
|
50
|
+
other.is_a?(self.class) && other.to_a == to_a
|
51
|
+
end
|
52
|
+
|
49
53
|
private
|
50
54
|
|
51
55
|
attr_reader :operations
|
data/lib/super_diff/{operation_tree_builders/base.rb → core/abstract_operation_tree_builder.rb}
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
module SuperDiff
|
2
|
-
module
|
3
|
-
class
|
2
|
+
module Core
|
3
|
+
class AbstractOperationTreeBuilder
|
4
4
|
def self.applies_to?(_expected, _actual)
|
5
5
|
raise NotImplementedError
|
6
6
|
end
|
@@ -48,7 +48,7 @@ module SuperDiff
|
|
48
48
|
possible_comparison_of(delete_operation, insert_operation)
|
49
49
|
)
|
50
50
|
operation_tree.delete(delete_operation)
|
51
|
-
operation_tree <<
|
51
|
+
operation_tree << BinaryOperation.new(
|
52
52
|
name: :change,
|
53
53
|
left_collection: delete_operation.collection,
|
54
54
|
right_collection: insert_operation.collection,
|
@@ -89,11 +89,7 @@ module SuperDiff
|
|
89
89
|
end
|
90
90
|
|
91
91
|
def compare(expected, actual)
|
92
|
-
|
93
|
-
expected: expected,
|
94
|
-
actual: actual,
|
95
|
-
all_or_nothing: false
|
96
|
-
)
|
92
|
+
SuperDiff.build_operation_tree_for(expected, actual)
|
97
93
|
end
|
98
94
|
end
|
99
95
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Core
|
3
|
+
module ColorizedDocumentExtensions
|
4
|
+
def self.extended(extendee)
|
5
|
+
extendee.singleton_class.class_eval { alias_method :normal, :text }
|
6
|
+
end
|
7
|
+
|
8
|
+
%i[actual border elision_marker expected header].each do |method_name|
|
9
|
+
define_method(method_name) do |*args, **opts, &block|
|
10
|
+
colorize(
|
11
|
+
*args,
|
12
|
+
**opts,
|
13
|
+
fg: SuperDiff.configuration.public_send("#{method_name}_color"),
|
14
|
+
&block
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|