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
@@ -0,0 +1,192 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Core
|
3
|
+
class Configuration
|
4
|
+
attr_reader(
|
5
|
+
:extra_diff_formatter_classes,
|
6
|
+
:extra_differ_classes,
|
7
|
+
:extra_inspection_tree_builder_classes,
|
8
|
+
:extra_operation_tree_builder_classes,
|
9
|
+
:extra_operation_tree_classes
|
10
|
+
)
|
11
|
+
attr_accessor(
|
12
|
+
:actual_color,
|
13
|
+
:border_color,
|
14
|
+
:color_enabled,
|
15
|
+
:diff_elision_enabled,
|
16
|
+
:diff_elision_maximum,
|
17
|
+
:elision_marker_color,
|
18
|
+
:expected_color,
|
19
|
+
:header_color,
|
20
|
+
:key_enabled
|
21
|
+
)
|
22
|
+
|
23
|
+
def initialize(options = {})
|
24
|
+
@actual_color = :yellow
|
25
|
+
@border_color = :blue
|
26
|
+
@color_enabled = color_enabled_by_default?
|
27
|
+
@diff_elision_enabled = false
|
28
|
+
@diff_elision_maximum = 0
|
29
|
+
@elision_marker_color = :cyan
|
30
|
+
@expected_color = :magenta
|
31
|
+
@extra_diff_formatter_classes = [].freeze
|
32
|
+
@extra_differ_classes = [].freeze
|
33
|
+
@extra_inspection_tree_builder_classes = [].freeze
|
34
|
+
@extra_operation_tree_builder_classes = [].freeze
|
35
|
+
@extra_operation_tree_classes = [].freeze
|
36
|
+
@header_color = :white
|
37
|
+
@key_enabled = true
|
38
|
+
|
39
|
+
merge!(options)
|
40
|
+
end
|
41
|
+
|
42
|
+
def initialize_dup(original)
|
43
|
+
super
|
44
|
+
@extra_differ_classes = original.extra_differ_classes.dup.freeze
|
45
|
+
@extra_operation_tree_builder_classes =
|
46
|
+
original.extra_operation_tree_builder_classes.dup.freeze
|
47
|
+
@extra_operation_tree_classes =
|
48
|
+
original.extra_operation_tree_classes.dup.freeze
|
49
|
+
@extra_inspection_tree_builder_classes =
|
50
|
+
original.extra_inspection_tree_builder_classes.dup.freeze
|
51
|
+
end
|
52
|
+
|
53
|
+
def color_enabled?
|
54
|
+
@color_enabled
|
55
|
+
end
|
56
|
+
|
57
|
+
def diff_elision_enabled?
|
58
|
+
@diff_elision_enabled
|
59
|
+
end
|
60
|
+
|
61
|
+
def key_enabled?
|
62
|
+
@key_enabled
|
63
|
+
end
|
64
|
+
|
65
|
+
def merge!(configuration_or_options)
|
66
|
+
options =
|
67
|
+
if configuration_or_options.is_a?(self.class)
|
68
|
+
configuration_or_options.to_h
|
69
|
+
else
|
70
|
+
configuration_or_options
|
71
|
+
end
|
72
|
+
|
73
|
+
options.each { |key, value| instance_variable_set("@#{key}", value) }
|
74
|
+
|
75
|
+
updated
|
76
|
+
end
|
77
|
+
|
78
|
+
def updated
|
79
|
+
SuperDiff::Csi.color_enabled = color_enabled?
|
80
|
+
end
|
81
|
+
|
82
|
+
def add_extra_diff_formatter_classes(*classes)
|
83
|
+
@extra_diff_formatter_classes =
|
84
|
+
(@extra_diff_formatter_classes + classes).freeze
|
85
|
+
end
|
86
|
+
alias_method(
|
87
|
+
:add_extra_diff_formatter_class,
|
88
|
+
:add_extra_diff_formatter_classes
|
89
|
+
)
|
90
|
+
|
91
|
+
def prepend_extra_diff_formatter_classes(*classes)
|
92
|
+
@extra_diff_formatter_classes =
|
93
|
+
(classes + @extra_diff_formatter_classes).freeze
|
94
|
+
end
|
95
|
+
alias_method(
|
96
|
+
:prepend_extra_diff_formatter_class,
|
97
|
+
:prepend_extra_diff_formatter_classes
|
98
|
+
)
|
99
|
+
|
100
|
+
def add_extra_differ_classes(*classes)
|
101
|
+
@extra_differ_classes = (@extra_differ_classes + classes).freeze
|
102
|
+
end
|
103
|
+
alias_method :add_extra_differ_class, :add_extra_differ_classes
|
104
|
+
|
105
|
+
def prepend_extra_differ_classes(*classes)
|
106
|
+
@extra_differ_classes = (classes + @extra_differ_classes).freeze
|
107
|
+
end
|
108
|
+
alias_method :prepend_extra_differ_class, :prepend_extra_differ_classes
|
109
|
+
|
110
|
+
def add_extra_inspection_tree_builder_classes(*classes)
|
111
|
+
@extra_inspection_tree_builder_classes =
|
112
|
+
(@extra_inspection_tree_builder_classes + classes).freeze
|
113
|
+
end
|
114
|
+
alias_method(
|
115
|
+
:add_extra_inspection_tree_builder_class,
|
116
|
+
:add_extra_inspection_tree_builder_classes
|
117
|
+
)
|
118
|
+
|
119
|
+
def prepend_extra_inspection_tree_builder_classes(*classes)
|
120
|
+
@extra_inspection_tree_builder_classes =
|
121
|
+
(classes + @extra_inspection_tree_builder_classes).freeze
|
122
|
+
end
|
123
|
+
alias_method(
|
124
|
+
:prepend_extra_inspection_tree_builder_class,
|
125
|
+
:prepend_extra_inspection_tree_builder_classes
|
126
|
+
)
|
127
|
+
|
128
|
+
def add_extra_operation_tree_builder_classes(*classes)
|
129
|
+
@extra_operation_tree_builder_classes =
|
130
|
+
(@extra_operation_tree_builder_classes + classes).freeze
|
131
|
+
end
|
132
|
+
alias_method(
|
133
|
+
:add_extra_operation_tree_builder_class,
|
134
|
+
:add_extra_operation_tree_builder_classes
|
135
|
+
)
|
136
|
+
|
137
|
+
def prepend_extra_operation_tree_builder_classes(*classes)
|
138
|
+
@extra_operation_tree_builder_classes =
|
139
|
+
(classes + @extra_operation_tree_builder_classes).freeze
|
140
|
+
end
|
141
|
+
alias_method(
|
142
|
+
:prepend_extra_operation_tree_builder_class,
|
143
|
+
:prepend_extra_operation_tree_builder_classes
|
144
|
+
)
|
145
|
+
|
146
|
+
def add_extra_operation_tree_classes(*classes)
|
147
|
+
@extra_operation_tree_classes =
|
148
|
+
(@extra_operation_tree_classes + classes).freeze
|
149
|
+
end
|
150
|
+
alias_method(
|
151
|
+
:add_extra_operation_tree_class,
|
152
|
+
:add_extra_operation_tree_classes
|
153
|
+
)
|
154
|
+
|
155
|
+
def prepend_extra_operation_tree_classes(*classes)
|
156
|
+
@extra_operation_tree_classes =
|
157
|
+
(classes + @extra_operation_tree_classes).freeze
|
158
|
+
end
|
159
|
+
alias_method(
|
160
|
+
:prepend_extra_operation_tree_class,
|
161
|
+
:prepend_extra_operation_tree_classes
|
162
|
+
)
|
163
|
+
|
164
|
+
def to_h
|
165
|
+
{
|
166
|
+
actual_color: actual_color,
|
167
|
+
border_color: border_color,
|
168
|
+
color_enabled: color_enabled?,
|
169
|
+
diff_elision_enabled: diff_elision_enabled?,
|
170
|
+
diff_elision_maximum: diff_elision_maximum,
|
171
|
+
elision_marker_color: elision_marker_color,
|
172
|
+
expected_color: expected_color,
|
173
|
+
extra_diff_formatter_classes: extra_diff_formatter_classes.dup,
|
174
|
+
extra_differ_classes: extra_differ_classes.dup,
|
175
|
+
extra_inspection_tree_builder_classes:
|
176
|
+
extra_inspection_tree_builder_classes.dup,
|
177
|
+
extra_operation_tree_builder_classes:
|
178
|
+
extra_operation_tree_builder_classes.dup,
|
179
|
+
extra_operation_tree_classes: extra_operation_tree_classes.dup,
|
180
|
+
header_color: header_color,
|
181
|
+
key_enabled: key_enabled?
|
182
|
+
}
|
183
|
+
end
|
184
|
+
|
185
|
+
private
|
186
|
+
|
187
|
+
def color_enabled_by_default?
|
188
|
+
ENV["CI"] == "true" || $stdout.respond_to?(:tty?) && $stdout.tty?
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Core
|
3
|
+
class DifferDispatcher
|
4
|
+
extend AttrExtras.mixin
|
5
|
+
|
6
|
+
method_object(
|
7
|
+
:expected,
|
8
|
+
:actual,
|
9
|
+
[:available_classes, indent_level: 0, raise_if_nothing_applies: true]
|
10
|
+
)
|
11
|
+
|
12
|
+
def call
|
13
|
+
if resolved_class
|
14
|
+
resolved_class.call(expected, actual, indent_level: indent_level)
|
15
|
+
elsif raise_if_nothing_applies?
|
16
|
+
raise NoDifferAvailableError.create(expected, actual)
|
17
|
+
else
|
18
|
+
""
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
attr_query :raise_if_nothing_applies?
|
25
|
+
|
26
|
+
def resolved_class
|
27
|
+
available_classes.find { |klass| klass.applies_to?(expected, actual) }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Core
|
3
|
+
class GemVersion
|
4
|
+
def initialize(version)
|
5
|
+
@version = Gem::Version.new(version.to_s)
|
6
|
+
end
|
7
|
+
|
8
|
+
def <(other)
|
9
|
+
compare?(:<, other)
|
10
|
+
end
|
11
|
+
|
12
|
+
def <=(other)
|
13
|
+
compare?(:<=, other)
|
14
|
+
end
|
15
|
+
|
16
|
+
def ==(other)
|
17
|
+
compare?(:==, other)
|
18
|
+
end
|
19
|
+
|
20
|
+
def >=(other)
|
21
|
+
compare?(:>=, other)
|
22
|
+
end
|
23
|
+
|
24
|
+
def >(other)
|
25
|
+
compare?(:>, other)
|
26
|
+
end
|
27
|
+
|
28
|
+
def =~(other)
|
29
|
+
Gem::Requirement.new(other).satisfied_by?(version)
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_s
|
33
|
+
version.to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
attr_reader :version
|
39
|
+
|
40
|
+
def compare?(operator, other_version)
|
41
|
+
Gem::Requirement.new("#{operator} #{other_version}").satisfied_by?(
|
42
|
+
version
|
43
|
+
)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Core
|
3
|
+
module Helpers
|
4
|
+
extend self
|
5
|
+
|
6
|
+
# TODO: Simplify this
|
7
|
+
def style(*args, color_enabled: true, **opts, &block)
|
8
|
+
klass =
|
9
|
+
if color_enabled && Csi.color_enabled?
|
10
|
+
Csi::ColorizedDocument
|
11
|
+
else
|
12
|
+
Csi::UncolorizedDocument
|
13
|
+
end
|
14
|
+
|
15
|
+
document = klass.new.extend(ColorizedDocumentExtensions)
|
16
|
+
|
17
|
+
if block
|
18
|
+
document.__send__(:evaluate_block, &block)
|
19
|
+
else
|
20
|
+
document.colorize(*args, **opts)
|
21
|
+
end
|
22
|
+
|
23
|
+
document
|
24
|
+
end
|
25
|
+
|
26
|
+
def plural_type_for(value)
|
27
|
+
case value
|
28
|
+
when Numeric
|
29
|
+
"numbers"
|
30
|
+
when String
|
31
|
+
"strings"
|
32
|
+
when Symbol
|
33
|
+
"symbols"
|
34
|
+
else
|
35
|
+
"objects"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def jruby?
|
40
|
+
defined?(JRUBY_VERSION)
|
41
|
+
end
|
42
|
+
|
43
|
+
def ruby_version_matches?(version_string)
|
44
|
+
Gem::Requirement.new(version_string).satisfied_by?(
|
45
|
+
Gem::Version.new(RUBY_VERSION)
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
if jruby?
|
50
|
+
def object_address_for(object)
|
51
|
+
# Source: <https://github.com/jruby/jruby/blob/master/core/src/main/java/org/jruby/RubyBasicObject.java>
|
52
|
+
"0x%x" % object.hash
|
53
|
+
end
|
54
|
+
elsif ruby_version_matches?(">= 2.7.0")
|
55
|
+
require "json"
|
56
|
+
require "objspace"
|
57
|
+
|
58
|
+
def object_address_for(object)
|
59
|
+
# Sources: <https://bugs.ruby-lang.org/issues/15408> and <https://bugs.ruby-lang.org/issues/15626#Object-ID>
|
60
|
+
json = JSON.parse(ObjectSpace.dump(object))
|
61
|
+
json.is_a?(Hash) ? "0x%016x" % Integer(json["address"], 16) : ""
|
62
|
+
end
|
63
|
+
else
|
64
|
+
def object_address_for(object)
|
65
|
+
"0x%016x" % (object.object_id * 2)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def with_slice_of_array_replaced(array, range, replacement)
|
70
|
+
beginning =
|
71
|
+
if range.begin > 0
|
72
|
+
array[Range.new(0, range.begin - 1)]
|
73
|
+
else
|
74
|
+
[]
|
75
|
+
end
|
76
|
+
|
77
|
+
ending =
|
78
|
+
if range.end <= array.length - 1
|
79
|
+
array[Range.new(range.end + 1, array.length - 1)]
|
80
|
+
else
|
81
|
+
[]
|
82
|
+
end
|
83
|
+
|
84
|
+
beginning + [replacement] + ending
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Core
|
3
|
+
module ImplementationChecks
|
4
|
+
protected def unimplemented_instance_method!
|
5
|
+
raise(
|
6
|
+
NotImplementedError,
|
7
|
+
"#{self.class} must implement ##{caller_locations(1, 1).first.label}",
|
8
|
+
caller(1)
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
protected def unimplemented_class_method!
|
13
|
+
raise(
|
14
|
+
NotImplementedError,
|
15
|
+
"#{self} must implement .#{caller_locations(1, 1).first.label}",
|
16
|
+
caller(1)
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module SuperDiff
|
2
|
-
module
|
2
|
+
module Core
|
3
3
|
class InspectionTree
|
4
4
|
include Enumerable
|
5
5
|
|
@@ -10,7 +10,7 @@ module SuperDiff
|
|
10
10
|
evaluate_block(&block) if block
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
InspectionTreeNodes.registry.each do |node_class|
|
14
14
|
define_method(node_class.method_name) do |*args, **options, &block|
|
15
15
|
add_node(node_class, *args, **options, &block)
|
16
16
|
end
|
@@ -59,7 +59,7 @@ module SuperDiff
|
|
59
59
|
insert_separated_list(array) do |t, value|
|
60
60
|
# Have to do these shenanigans so that if value is a hash, Ruby
|
61
61
|
# doesn't try to interpret it as keyword args
|
62
|
-
if
|
62
|
+
if Helpers.ruby_version_matches?(">= 2.7.1")
|
63
63
|
t.add_inspection_of(value, **{})
|
64
64
|
else
|
65
65
|
t.add_inspection_of(*[value, {}])
|
@@ -86,7 +86,7 @@ module SuperDiff
|
|
86
86
|
|
87
87
|
# Have to do these shenanigans so that if hash[key] is a hash, Ruby
|
88
88
|
# doesn't try to interpret it as keyword args
|
89
|
-
if
|
89
|
+
if Helpers.ruby_version_matches?(">= 2.7.1")
|
90
90
|
t1.add_inspection_of(hash[key], **{})
|
91
91
|
else
|
92
92
|
t1.add_inspection_of(*[hash[key], {}])
|
@@ -148,11 +148,12 @@ module SuperDiff
|
|
148
148
|
def call
|
149
149
|
if rendering.is_a?(Array)
|
150
150
|
concat_with_lines
|
151
|
-
elsif rendering.is_a?(
|
151
|
+
elsif rendering.is_a?(PrefixForNextInspectionTreeNode)
|
152
152
|
add_to_prefix
|
153
153
|
elsif tiered_lines.any?
|
154
154
|
add_to_last_line
|
155
|
-
elsif index < nodes.size - 1 ||
|
155
|
+
elsif index < nodes.size - 1 ||
|
156
|
+
rendering.is_a?(PreludeForNextInspectionTreeNode)
|
156
157
|
add_to_prelude
|
157
158
|
else
|
158
159
|
add_to_lines
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Core
|
3
|
+
class InspectionTreeBuilderDispatcher
|
4
|
+
extend AttrExtras.mixin
|
5
|
+
|
6
|
+
method_object :object, [:available_classes]
|
7
|
+
|
8
|
+
def call
|
9
|
+
if resolved_class
|
10
|
+
resolved_class.call(object)
|
11
|
+
else
|
12
|
+
raise NoInspectionTreeBuilderAvailableError.create(object)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def resolved_class
|
19
|
+
available_classes.find { |klass| klass.applies_to?(object) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module SuperDiff
|
2
|
-
module
|
3
|
-
module
|
2
|
+
module Core
|
3
|
+
module InspectionTreeNodes
|
4
4
|
class AsLinesWhenRenderingToLines < Base
|
5
5
|
def self.node_name
|
6
6
|
:as_lines_when_rendering_to_lines
|
@@ -27,7 +27,13 @@ module SuperDiff
|
|
27
27
|
def render_to_string(object)
|
28
28
|
# TODO: This happens a lot, can we simplify this?
|
29
29
|
string =
|
30
|
-
(
|
30
|
+
(
|
31
|
+
if block
|
32
|
+
render_to_string_in_subtree(object)
|
33
|
+
else
|
34
|
+
immediate_value.to_s
|
35
|
+
end
|
36
|
+
)
|
31
37
|
|
32
38
|
add_comma? ? string + "," : string
|
33
39
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module SuperDiff
|
2
|
-
module
|
3
|
-
module
|
2
|
+
module Core
|
3
|
+
module InspectionTreeNodes
|
4
4
|
class AsPrefixWhenRenderingToLines < Base
|
5
5
|
def self.name
|
6
6
|
:as_prefix_when_rendering_to_lines
|
@@ -15,7 +15,7 @@ module SuperDiff
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def render_to_lines(object, **)
|
18
|
-
|
18
|
+
PrefixForNextInspectionTreeNode.new(render_to_string(object))
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module SuperDiff
|
2
|
-
module
|
3
|
-
module
|
2
|
+
module Core
|
3
|
+
module InspectionTreeNodes
|
4
4
|
class AsPreludeWhenRenderingToLines < Base
|
5
5
|
def self.name
|
6
6
|
:as_prelude_when_rendering_to_lines
|
@@ -15,7 +15,7 @@ module SuperDiff
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def render_to_lines(object, **)
|
18
|
-
|
18
|
+
PreludeForNextInspectionTreeNode.new(render_to_string(object))
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_single_line.rb
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
module SuperDiff
|
2
|
-
module
|
3
|
-
module
|
2
|
+
module Core
|
3
|
+
module InspectionTreeNodes
|
4
4
|
class AsSingleLine < Base
|
5
5
|
def self.node_name
|
6
6
|
:as_single_line
|
@@ -16,7 +16,7 @@ module SuperDiff
|
|
16
16
|
|
17
17
|
def render_to_lines(object, type:, indentation_level:)
|
18
18
|
[
|
19
|
-
|
19
|
+
Line.new(
|
20
20
|
type: type,
|
21
21
|
indentation_level: indentation_level,
|
22
22
|
value: render_to_string(object)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module SuperDiff
|
2
|
-
module
|
3
|
-
module
|
2
|
+
module Core
|
3
|
+
module InspectionTreeNodes
|
4
4
|
class Inspection < Base
|
5
5
|
def self.node_name
|
6
6
|
:inspection
|
@@ -13,11 +13,9 @@ module SuperDiff
|
|
13
13
|
def render_to_string(object)
|
14
14
|
value = (block ? evaluate_block(object) : immediate_value)
|
15
15
|
|
16
|
-
|
17
|
-
value
|
18
|
-
) do |already_seen|
|
16
|
+
RecursionGuard.guarding_recursion_of(value) do |already_seen|
|
19
17
|
if already_seen
|
20
|
-
|
18
|
+
RecursionGuard::PLACEHOLDER
|
21
19
|
else
|
22
20
|
SuperDiff.inspect_object(value, as_lines: false)
|
23
21
|
end
|
@@ -27,15 +25,13 @@ module SuperDiff
|
|
27
25
|
def render_to_lines(object, type:, indentation_level:)
|
28
26
|
value = (block ? evaluate_block(object) : immediate_value)
|
29
27
|
|
30
|
-
|
31
|
-
value
|
32
|
-
) do |already_seen|
|
28
|
+
RecursionGuard.guarding_recursion_of(value) do |already_seen|
|
33
29
|
if already_seen
|
34
30
|
[
|
35
|
-
SuperDiff::Line.new(
|
31
|
+
SuperDiff::Core::Line.new(
|
36
32
|
type: type,
|
37
33
|
indentation_level: indentation_level,
|
38
|
-
value:
|
34
|
+
value: RecursionGuard::PLACEHOLDER
|
39
35
|
)
|
40
36
|
]
|
41
37
|
else
|