super_diff 0.6.2 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -1
- data/lib/super_diff/active_record/differs/active_record_relation.rb +3 -13
- data/lib/super_diff/active_record/object_inspection/{inspectors → inspection_tree_builders}/active_record_model.rb +19 -20
- data/lib/super_diff/active_record/object_inspection/{inspectors → inspection_tree_builders}/active_record_relation.rb +9 -8
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +16 -0
- data/lib/super_diff/active_record/object_inspection.rb +2 -6
- data/lib/super_diff/active_record/operation_tree_flatteners/active_record_relation.rb +17 -0
- data/lib/super_diff/active_record/operation_tree_flatteners.rb +10 -0
- data/lib/super_diff/active_record/operation_trees/active_record_relation.rb +8 -7
- data/lib/super_diff/active_record.rb +7 -7
- data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +3 -13
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +37 -0
- data/lib/super_diff/active_support/object_inspection/{inspectors.rb → inspection_tree_builders.rb} +2 -2
- data/lib/super_diff/active_support/object_inspection.rb +2 -6
- data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +17 -0
- data/lib/super_diff/active_support/operation_tree_flatteners/hash_with_indifferent_access.rb +17 -0
- data/lib/super_diff/active_support/operation_tree_flatteners.rb +10 -0
- data/lib/super_diff/active_support/operation_trees/hash_with_indifferent_access.rb +4 -7
- data/lib/super_diff/active_support.rb +8 -8
- data/lib/super_diff/colorized_document_extensions.rb +9 -6
- data/lib/super_diff/configuration.rb +81 -8
- data/lib/super_diff/csi/four_bit_color.rb +0 -2
- data/lib/super_diff/csi.rb +1 -2
- data/lib/super_diff/differs/array.rb +1 -1
- data/lib/super_diff/differs/base.rb +3 -21
- data/lib/super_diff/differs/custom_object.rb +1 -1
- data/lib/super_diff/differs/default_object.rb +1 -1
- data/lib/super_diff/differs/hash.rb +1 -1
- data/lib/super_diff/differs/main.rb +1 -7
- data/lib/super_diff/differs/multiline_string.rb +1 -1
- data/lib/super_diff/differs/time_like.rb +1 -1
- data/lib/super_diff/equality_matchers/array.rb +2 -2
- data/lib/super_diff/equality_matchers/default.rb +2 -2
- data/lib/super_diff/equality_matchers/hash.rb +2 -2
- data/lib/super_diff/equality_matchers/multiline_string.rb +2 -2
- data/lib/super_diff/equality_matchers/primitive.rb +4 -7
- data/lib/super_diff/equality_matchers/singleline_string.rb +2 -2
- data/lib/super_diff/helpers.rb +56 -2
- data/lib/super_diff/line.rb +83 -0
- data/lib/super_diff/object_inspection/inspection_tree.rb +183 -81
- data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +38 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/base.rb +27 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +37 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +63 -0
- data/lib/super_diff/object_inspection/{inspectors → inspection_tree_builders}/defaults.rb +1 -2
- data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +46 -0
- data/lib/super_diff/object_inspection/{inspectors → inspection_tree_builders}/main.rb +5 -10
- data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +21 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +64 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders.rb +44 -0
- data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +97 -0
- data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +27 -0
- data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +27 -0
- data/lib/super_diff/object_inspection/nodes/as_single_line.rb +33 -0
- data/lib/super_diff/object_inspection/nodes/base.rb +55 -20
- data/lib/super_diff/object_inspection/nodes/inspection.rb +47 -7
- data/lib/super_diff/object_inspection/nodes/nesting.rb +16 -5
- data/lib/super_diff/object_inspection/nodes/only_when.rb +54 -0
- data/lib/super_diff/object_inspection/nodes/text.rb +16 -2
- data/lib/super_diff/object_inspection/nodes/when_empty.rb +21 -6
- data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +20 -5
- data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +27 -0
- data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +27 -0
- data/lib/super_diff/object_inspection/nodes.rb +33 -32
- data/lib/super_diff/object_inspection/prefix_for_next_node.rb +6 -0
- data/lib/super_diff/object_inspection/prelude_for_next_node.rb +6 -0
- data/lib/super_diff/object_inspection.rb +12 -1
- data/lib/super_diff/operation_tree_builders/array.rb +7 -10
- data/lib/super_diff/operation_tree_builders/base.rb +6 -6
- data/lib/super_diff/operation_tree_builders/custom_object.rb +5 -2
- data/lib/super_diff/operation_tree_builders/default_object.rb +1 -1
- data/lib/super_diff/operation_tree_builders/defaults.rb +1 -1
- data/lib/super_diff/operation_tree_builders/hash.rb +1 -8
- data/lib/super_diff/operation_tree_builders/multiline_string.rb +2 -6
- data/lib/super_diff/operation_tree_builders/time_like.rb +2 -2
- data/lib/super_diff/operation_tree_flatteners/array.rb +15 -0
- data/lib/super_diff/operation_tree_flatteners/base.rb +54 -0
- data/lib/super_diff/operation_tree_flatteners/collection.rb +139 -0
- data/lib/super_diff/operation_tree_flatteners/custom_object.rb +28 -0
- data/lib/super_diff/operation_tree_flatteners/default_object.rb +32 -0
- data/lib/super_diff/operation_tree_flatteners/hash.rb +41 -0
- data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +17 -0
- data/lib/super_diff/operation_tree_flatteners.rb +20 -0
- data/lib/super_diff/operation_trees/array.rb +4 -7
- data/lib/super_diff/operation_trees/base.rb +39 -16
- data/lib/super_diff/operation_trees/custom_object.rb +4 -8
- data/lib/super_diff/operation_trees/default_object.rb +28 -13
- data/lib/super_diff/operation_trees/hash.rb +4 -7
- data/lib/super_diff/operation_trees/main.rb +1 -1
- data/lib/super_diff/operation_trees/multiline_string.rb +4 -7
- data/lib/super_diff/operations/binary_operation.rb +1 -6
- data/lib/super_diff/operations/unary_operation.rb +2 -30
- data/lib/super_diff/recursion_guard.rb +3 -3
- data/lib/super_diff/rspec/differs/collection_including.rb +4 -2
- data/lib/super_diff/rspec/differs/hash_including.rb +4 -2
- data/lib/super_diff/rspec/monkey_patches.rb +2 -2
- data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/collection_containing_exactly.rb +9 -8
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +34 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +103 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +36 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +26 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +26 -0
- data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/object_having_attributes.rb +10 -12
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/primitive.rb +10 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +33 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +44 -0
- data/lib/super_diff/rspec/object_inspection.rb +4 -1
- data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +0 -3
- data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +10 -3
- data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +10 -3
- data/lib/super_diff/rspec.rb +34 -13
- data/lib/super_diff/tiered_lines.rb +4 -0
- data/lib/super_diff/tiered_lines_elider.rb +490 -0
- data/lib/super_diff/tiered_lines_formatter.rb +79 -0
- data/lib/super_diff/version.rb +1 -1
- data/lib/super_diff.rb +28 -6
- data/spec/examples.txt +482 -403
- data/spec/integration/rails/active_support_spec.rb +19 -0
- data/spec/integration/rspec/contain_exactly_matcher_spec.rb +12 -6
- data/spec/integration/rspec/eq_matcher_spec.rb +33 -87
- data/spec/integration/rspec/have_attributes_matcher_spec.rb +17 -8
- data/spec/integration/rspec/match_array_matcher_spec.rb +14 -7
- data/spec/integration/rspec/match_matcher_spec.rb +93 -5
- data/spec/spec_helper.rb +4 -1
- data/spec/support/command_runner.rb +15 -25
- data/spec/support/helpers.rb +21 -0
- data/spec/support/integration/helpers.rb +2 -0
- data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +3 -3
- data/spec/support/integration/test_programs/base.rb +36 -10
- data/spec/support/shared_examples/active_record.rb +3 -2
- data/spec/support/shared_examples/active_support.rb +65 -0
- data/spec/support/shared_examples/elided_diffs.rb +914 -0
- data/spec/support/shared_examples/hash_with_indifferent_access.rb +16 -16
- data/spec/support/unit/helpers.rb +15 -0
- data/spec/support/unit/matchers/match_output.rb +41 -0
- data/spec/tmp/warnings_logger/all_warnings.txt +2 -0
- data/spec/unit/active_record/object_inspection_spec.rb +273 -0
- data/spec/unit/equality_matchers/main_spec.rb +55 -75
- data/spec/unit/helpers_spec.rb +75 -0
- data/spec/unit/operation_tree_flatteners/array_spec.rb +604 -0
- data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +667 -0
- data/spec/unit/operation_tree_flatteners/default_object_spec.rb +687 -0
- data/spec/unit/operation_tree_flatteners/hash_spec.rb +632 -0
- data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +121 -0
- data/spec/unit/rspec/object_inspection_spec.rb +446 -0
- data/spec/unit/super_diff_spec.rb +1530 -800
- data/spec/unit/tiered_lines_elider_spec.rb +6356 -0
- data/spec/unit/tiered_lines_formatter_spec.rb +193 -0
- metadata +91 -52
- data/lib/super_diff/active_record/diff_formatters/active_record_relation.rb +0 -23
- data/lib/super_diff/active_record/diff_formatters.rb +0 -10
- data/lib/super_diff/active_record/object_inspection/inspectors.rb +0 -16
- data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +0 -36
- data/lib/super_diff/active_support/diff_formatters.rb +0 -10
- data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +0 -28
- data/lib/super_diff/diff_formatters/array.rb +0 -21
- data/lib/super_diff/diff_formatters/base.rb +0 -33
- data/lib/super_diff/diff_formatters/custom_object.rb +0 -30
- data/lib/super_diff/diff_formatters/default_object.rb +0 -46
- data/lib/super_diff/diff_formatters/defaults.rb +0 -10
- data/lib/super_diff/diff_formatters/hash.rb +0 -34
- data/lib/super_diff/diff_formatters/main.rb +0 -41
- data/lib/super_diff/diff_formatters.rb +0 -14
- data/lib/super_diff/object_inspection/inspectors/array.rb +0 -32
- data/lib/super_diff/object_inspection/inspectors/base.rb +0 -36
- data/lib/super_diff/object_inspection/inspectors/custom_object.rb +0 -37
- data/lib/super_diff/object_inspection/inspectors/default_object.rb +0 -61
- data/lib/super_diff/object_inspection/inspectors/hash.rb +0 -32
- data/lib/super_diff/object_inspection/inspectors/primitive.rb +0 -28
- data/lib/super_diff/object_inspection/inspectors/string.rb +0 -23
- data/lib/super_diff/object_inspection/inspectors/time_like.rb +0 -23
- data/lib/super_diff/object_inspection/inspectors.rb +0 -23
- data/lib/super_diff/object_inspection/nodes/break.rb +0 -15
- data/lib/super_diff/object_inspection/nodes/when_multiline.rb +0 -22
- data/lib/super_diff/object_inspection/nodes/when_singleline.rb +0 -24
- data/lib/super_diff/rspec/object_inspection/inspectors/collection_including.rb +0 -28
- data/lib/super_diff/rspec/object_inspection/inspectors/hash_including.rb +0 -31
- data/lib/super_diff/rspec/object_inspection/inspectors/instance_of.rb +0 -23
- data/lib/super_diff/rspec/object_inspection/inspectors/kind_of.rb +0 -23
- data/lib/super_diff/rspec/object_inspection/inspectors/primitive.rb +0 -13
- data/lib/super_diff/rspec/object_inspection/inspectors/value_within.rb +0 -29
- data/lib/super_diff/rspec/object_inspection/inspectors.rb +0 -40
- data/spec/combustion/Gemfile.lock +0 -173
- data/spec/support/object_id.rb +0 -27
- data/spec/support/ruby_versions.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3338e91a7e03a6c0447a56b0c612653bd8f56f27a95ebeba081546dea8fdc7da
|
4
|
+
data.tar.gz: c840b79a7dd98e31cce823df4bdb67b704dec07ae340c889c86d38bae735ea41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78535779a6e462100afb0ec019ea0b1241e5f6710c40005150d3d8784d34227dc0b549de20fe3dbbc453b6563903df78fc21925701f8d5c7f0d3d466c8345641
|
7
|
+
data.tar.gz: 5a049b0606ae5ff5ac18978e8591ede3edcdcecf6e48eb58ced6655527b481bf2f4a17623c981b902c5ea86295e3dc9bd633905502113edbc162724edd475389
|
data/README.md
CHANGED
@@ -202,7 +202,6 @@ SuperDiff.configure do |config|
|
|
202
202
|
config.add_extra_differ_class(YourDiffer)
|
203
203
|
config.add_extra_operation_tree_builder_class(YourOperationTreeBuilder)
|
204
204
|
config.add_extra_operation_tree_class(YourOperationTree)
|
205
|
-
config.add_extra_diff_formatter_class(YourDiffFormatter)
|
206
205
|
end
|
207
206
|
```
|
208
207
|
|
@@ -7,20 +7,10 @@ module SuperDiff
|
|
7
7
|
actual.is_a?(::ActiveRecord::Relation)
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
DiffFormatters::ActiveRecordRelation.call(
|
12
|
-
operation_tree,
|
13
|
-
indent_level: indent_level,
|
14
|
-
)
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
10
|
+
protected
|
18
11
|
|
19
|
-
def
|
20
|
-
OperationTreeBuilders::ActiveRecordRelation
|
21
|
-
expected: expected,
|
22
|
-
actual: actual,
|
23
|
-
)
|
12
|
+
def operation_tree_builder_class
|
13
|
+
OperationTreeBuilders::ActiveRecordRelation
|
24
14
|
end
|
25
15
|
end
|
26
16
|
end
|
@@ -1,44 +1,43 @@
|
|
1
1
|
module SuperDiff
|
2
2
|
module ActiveRecord
|
3
3
|
module ObjectInspection
|
4
|
-
module
|
5
|
-
class ActiveRecordModel < SuperDiff::ObjectInspection::
|
4
|
+
module InspectionTreeBuilders
|
5
|
+
class ActiveRecordModel < SuperDiff::ObjectInspection::InspectionTreeBuilders::Base
|
6
6
|
def self.applies_to?(value)
|
7
7
|
value.is_a?(::ActiveRecord::Base)
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
def inspection_tree
|
10
|
+
def call
|
13
11
|
SuperDiff::ObjectInspection::InspectionTree.new do
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
as_lines_when_rendering_to_lines(collection_bookend: :open) do
|
13
|
+
add_text do |object|
|
14
|
+
"#<#{object.class} "
|
15
|
+
end
|
17
16
|
|
18
|
-
|
19
|
-
|
17
|
+
when_rendering_to_lines do
|
18
|
+
add_text "{"
|
19
|
+
end
|
20
20
|
end
|
21
21
|
|
22
22
|
nested do |object|
|
23
|
-
add_break
|
24
|
-
|
25
23
|
insert_separated_list(
|
26
24
|
["id"] + (object.attributes.keys.sort - ["id"]),
|
27
|
-
separator: ",",
|
28
25
|
) do |name|
|
29
|
-
|
30
|
-
|
26
|
+
as_prefix_when_rendering_to_lines do
|
27
|
+
add_text "#{name}: "
|
28
|
+
end
|
29
|
+
|
31
30
|
add_inspection_of object.read_attribute(name)
|
32
31
|
end
|
33
32
|
end
|
34
33
|
|
35
|
-
|
34
|
+
as_lines_when_rendering_to_lines(collection_bookend: :close) do
|
35
|
+
when_rendering_to_lines do
|
36
|
+
add_text "}"
|
37
|
+
end
|
36
38
|
|
37
|
-
|
38
|
-
add_text "}"
|
39
|
+
add_text ">"
|
39
40
|
end
|
40
|
-
|
41
|
-
add_text ">"
|
42
41
|
end
|
43
42
|
end
|
44
43
|
end
|
@@ -1,24 +1,25 @@
|
|
1
1
|
module SuperDiff
|
2
2
|
module ActiveRecord
|
3
3
|
module ObjectInspection
|
4
|
-
module
|
5
|
-
class ActiveRecordRelation < SuperDiff::ObjectInspection::
|
4
|
+
module InspectionTreeBuilders
|
5
|
+
class ActiveRecordRelation < SuperDiff::ObjectInspection::InspectionTreeBuilders::Base
|
6
6
|
def self.applies_to?(value)
|
7
7
|
value.is_a?(::ActiveRecord::Relation)
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
def inspection_tree
|
10
|
+
def call
|
13
11
|
SuperDiff::ObjectInspection::InspectionTree.new do
|
14
|
-
|
12
|
+
as_lines_when_rendering_to_lines(collection_bookend: :open) do
|
13
|
+
add_text "#<ActiveRecord::Relation ["
|
14
|
+
end
|
15
15
|
|
16
16
|
nested do |array|
|
17
17
|
insert_array_inspection_of(array)
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
as_lines_when_rendering_to_lines(collection_bookend: :close) do
|
21
|
+
add_text "]>"
|
22
|
+
end
|
22
23
|
end
|
23
24
|
end
|
24
25
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module ActiveRecord
|
3
|
+
module ObjectInspection
|
4
|
+
module InspectionTreeBuilders
|
5
|
+
autoload(
|
6
|
+
:ActiveRecordModel,
|
7
|
+
"super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model",
|
8
|
+
)
|
9
|
+
autoload(
|
10
|
+
:ActiveRecordRelation,
|
11
|
+
"super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation",
|
12
|
+
)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -2,12 +2,8 @@ module SuperDiff
|
|
2
2
|
module ActiveRecord
|
3
3
|
module ObjectInspection
|
4
4
|
autoload(
|
5
|
-
:
|
6
|
-
"super_diff/active_record/object_inspection/
|
7
|
-
)
|
8
|
-
autoload(
|
9
|
-
:MapExtension,
|
10
|
-
"super_diff/active_record/object_inspection/map_extension",
|
5
|
+
:InspectionTreeBuilders,
|
6
|
+
"super_diff/active_record/object_inspection/inspection_tree_builders",
|
11
7
|
)
|
12
8
|
end
|
13
9
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module ActiveRecord
|
3
|
+
module OperationTreeFlatteners
|
4
|
+
class ActiveRecordRelation < SuperDiff::OperationTreeFlatteners::Collection
|
5
|
+
protected
|
6
|
+
|
7
|
+
def open_token
|
8
|
+
"#<ActiveRecord::Relation ["
|
9
|
+
end
|
10
|
+
|
11
|
+
def close_token
|
12
|
+
"]>"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -2,13 +2,14 @@ module SuperDiff
|
|
2
2
|
module ActiveRecord
|
3
3
|
module OperationTrees
|
4
4
|
class ActiveRecordRelation < SuperDiff::OperationTrees::Array
|
5
|
-
def
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
def self.applies_to?(value)
|
6
|
+
value.is_a?(ActiveRecord::Relation)
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def operation_tree_flattener_class
|
12
|
+
OperationTreeFlatteners::ActiveRecordRelation
|
12
13
|
end
|
13
14
|
end
|
14
15
|
end
|
@@ -2,7 +2,6 @@ require "super_diff/active_support"
|
|
2
2
|
|
3
3
|
module SuperDiff
|
4
4
|
module ActiveRecord
|
5
|
-
autoload :DiffFormatters, "super_diff/active_record/diff_formatters"
|
6
5
|
autoload :Differs, "super_diff/active_record/differs"
|
7
6
|
autoload(
|
8
7
|
:ObjectInspection,
|
@@ -16,6 +15,10 @@ module SuperDiff
|
|
16
15
|
:OperationTreeBuilders,
|
17
16
|
"super_diff/active_record/operation_tree_builders",
|
18
17
|
)
|
18
|
+
autoload(
|
19
|
+
:OperationTreeFlatteners,
|
20
|
+
"super_diff/active_record/operation_tree_flatteners",
|
21
|
+
)
|
19
22
|
|
20
23
|
SuperDiff.configure do |config|
|
21
24
|
config.add_extra_differ_classes(
|
@@ -25,12 +28,9 @@ module SuperDiff
|
|
25
28
|
OperationTreeBuilders::ActiveRecordModel,
|
26
29
|
OperationTreeBuilders::ActiveRecordRelation,
|
27
30
|
)
|
28
|
-
config.
|
29
|
-
|
30
|
-
|
31
|
-
config.add_extra_inspector_classes(
|
32
|
-
ObjectInspection::Inspectors::ActiveRecordModel,
|
33
|
-
ObjectInspection::Inspectors::ActiveRecordRelation,
|
31
|
+
config.add_extra_inspection_tree_builder_classes(
|
32
|
+
ObjectInspection::InspectionTreeBuilders::ActiveRecordModel,
|
33
|
+
ObjectInspection::InspectionTreeBuilders::ActiveRecordRelation,
|
34
34
|
)
|
35
35
|
end
|
36
36
|
end
|
@@ -13,20 +13,10 @@ module SuperDiff
|
|
13
13
|
)
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
DiffFormatters::HashWithIndifferentAccess.call(
|
18
|
-
operation_tree,
|
19
|
-
indent_level: indent_level,
|
20
|
-
)
|
21
|
-
end
|
16
|
+
protected
|
22
17
|
|
23
|
-
|
24
|
-
|
25
|
-
def operation_tree
|
26
|
-
OperationTreeBuilders::HashWithIndifferentAccess.call(
|
27
|
-
expected: expected,
|
28
|
-
actual: actual,
|
29
|
-
)
|
18
|
+
def operation_tree_builder_class
|
19
|
+
OperationTreeBuilders::HashWithIndifferentAccess
|
30
20
|
end
|
31
21
|
end
|
32
22
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module ActiveSupport
|
3
|
+
module ObjectInspection
|
4
|
+
module InspectionTreeBuilders
|
5
|
+
class HashWithIndifferentAccess < SuperDiff::ObjectInspection::InspectionTreeBuilders::Base
|
6
|
+
def self.applies_to?(value)
|
7
|
+
value.is_a?(::HashWithIndifferentAccess)
|
8
|
+
end
|
9
|
+
|
10
|
+
def call
|
11
|
+
SuperDiff::ObjectInspection::InspectionTree.new do
|
12
|
+
as_lines_when_rendering_to_lines(collection_bookend: :open) do
|
13
|
+
add_text "#<HashWithIndifferentAccess {"
|
14
|
+
end
|
15
|
+
|
16
|
+
when_rendering_to_string do
|
17
|
+
add_text " "
|
18
|
+
end
|
19
|
+
|
20
|
+
nested do |hash|
|
21
|
+
insert_hash_inspection_of(hash)
|
22
|
+
end
|
23
|
+
|
24
|
+
when_rendering_to_string do
|
25
|
+
add_text " "
|
26
|
+
end
|
27
|
+
|
28
|
+
as_lines_when_rendering_to_lines(collection_bookend: :close) do
|
29
|
+
add_text "}>"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/super_diff/active_support/object_inspection/{inspectors.rb → inspection_tree_builders.rb}
RENAMED
@@ -1,10 +1,10 @@
|
|
1
1
|
module SuperDiff
|
2
2
|
module ActiveSupport
|
3
3
|
module ObjectInspection
|
4
|
-
module
|
4
|
+
module InspectionTreeBuilders
|
5
5
|
autoload(
|
6
6
|
:HashWithIndifferentAccess,
|
7
|
-
"super_diff/active_support/object_inspection/
|
7
|
+
"super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access",
|
8
8
|
)
|
9
9
|
end
|
10
10
|
end
|
@@ -2,12 +2,8 @@ module SuperDiff
|
|
2
2
|
module ActiveSupport
|
3
3
|
module ObjectInspection
|
4
4
|
autoload(
|
5
|
-
:
|
6
|
-
"super_diff/active_support/object_inspection/
|
7
|
-
)
|
8
|
-
autoload(
|
9
|
-
:MapExtension,
|
10
|
-
"super_diff/active_support/object_inspection/map_extension",
|
5
|
+
:InspectionTreeBuilders,
|
6
|
+
"super_diff/active_support/object_inspection/inspection_tree_builders",
|
11
7
|
)
|
12
8
|
end
|
13
9
|
end
|
@@ -2,6 +2,17 @@ module SuperDiff
|
|
2
2
|
module ActiveSupport
|
3
3
|
module OperationTreeBuilders
|
4
4
|
class HashWithIndifferentAccess < SuperDiff::OperationTreeBuilders::Hash
|
5
|
+
def self.applies_to?(expected, actual)
|
6
|
+
(
|
7
|
+
expected.is_a?(::HashWithIndifferentAccess) &&
|
8
|
+
actual.is_a?(::Hash)
|
9
|
+
) ||
|
10
|
+
(
|
11
|
+
expected.is_a?(::Hash) &&
|
12
|
+
actual.is_a?(::HashWithIndifferentAccess)
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
5
16
|
def initialize(expected:, actual:, **rest)
|
6
17
|
super
|
7
18
|
|
@@ -15,6 +26,12 @@ module SuperDiff
|
|
15
26
|
@actual = actual.to_h
|
16
27
|
end
|
17
28
|
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
def build_operation_tree
|
33
|
+
OperationTrees::HashWithIndifferentAccess.new([])
|
34
|
+
end
|
18
35
|
end
|
19
36
|
end
|
20
37
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module ActiveSupport
|
3
|
+
module OperationTreeFlatteners
|
4
|
+
class HashWithIndifferentAccess < SuperDiff::OperationTreeFlatteners::Hash
|
5
|
+
protected
|
6
|
+
|
7
|
+
def open_token
|
8
|
+
"#<HashWithIndifferentAccess {"
|
9
|
+
end
|
10
|
+
|
11
|
+
def close_token
|
12
|
+
"}>"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -2,13 +2,10 @@ module SuperDiff
|
|
2
2
|
module ActiveSupport
|
3
3
|
module OperationTrees
|
4
4
|
class HashWithIndifferentAccess < SuperDiff::OperationTrees::Base
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
collection_prefix: collection_prefix,
|
10
|
-
add_comma: add_comma,
|
11
|
-
)
|
5
|
+
protected
|
6
|
+
|
7
|
+
def operation_tree_flattener_class
|
8
|
+
OperationTreeFlatteners::HashWithIndifferentAccess
|
12
9
|
end
|
13
10
|
end
|
14
11
|
end
|
@@ -1,15 +1,18 @@
|
|
1
1
|
module SuperDiff
|
2
2
|
module ActiveSupport
|
3
|
-
autoload :DiffFormatters, "super_diff/active_support/diff_formatters"
|
4
3
|
autoload :Differs, "super_diff/active_support/differs"
|
5
4
|
autoload :ObjectInspection, "super_diff/active_support/object_inspection"
|
5
|
+
autoload(
|
6
|
+
:OperationTrees,
|
7
|
+
"super_diff/active_support/operation_trees",
|
8
|
+
)
|
6
9
|
autoload(
|
7
10
|
:OperationTreeBuilders,
|
8
11
|
"super_diff/active_support/operation_tree_builders",
|
9
12
|
)
|
10
13
|
autoload(
|
11
|
-
:
|
12
|
-
"super_diff/active_support/
|
14
|
+
:OperationTreeFlatteners,
|
15
|
+
"super_diff/active_support/operation_tree_flatteners",
|
13
16
|
)
|
14
17
|
|
15
18
|
SuperDiff.configure do |config|
|
@@ -19,11 +22,8 @@ module SuperDiff
|
|
19
22
|
config.add_extra_operation_tree_builder_classes(
|
20
23
|
OperationTreeBuilders::HashWithIndifferentAccess,
|
21
24
|
)
|
22
|
-
config.
|
23
|
-
|
24
|
-
)
|
25
|
-
config.add_extra_inspector_classes(
|
26
|
-
ObjectInspection::Inspectors::HashWithIndifferentAccess,
|
25
|
+
config.add_extra_inspection_tree_builder_classes(
|
26
|
+
ObjectInspection::InspectionTreeBuilders::HashWithIndifferentAccess,
|
27
27
|
)
|
28
28
|
end
|
29
29
|
end
|
@@ -6,12 +6,15 @@ module SuperDiff
|
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
[:actual, :border, :elision_marker, :expected, :header].each do |method_name|
|
10
|
+
define_method(method_name) do |*args, **opts, &block|
|
11
|
+
colorize(
|
12
|
+
*args,
|
13
|
+
**opts,
|
14
|
+
fg: SuperDiff.configuration.public_send("#{method_name}_color"),
|
15
|
+
&block
|
16
|
+
)
|
17
|
+
end
|
15
18
|
end
|
16
19
|
end
|
17
20
|
end
|
@@ -3,27 +3,74 @@ module SuperDiff
|
|
3
3
|
attr_reader(
|
4
4
|
:extra_diff_formatter_classes,
|
5
5
|
:extra_differ_classes,
|
6
|
-
:
|
6
|
+
:extra_inspection_tree_builder_classes,
|
7
7
|
:extra_operation_tree_builder_classes,
|
8
8
|
:extra_operation_tree_classes,
|
9
9
|
)
|
10
10
|
attr_accessor(
|
11
11
|
:actual_color,
|
12
12
|
:border_color,
|
13
|
+
:diff_elision_enabled,
|
14
|
+
:diff_elision_maximum,
|
15
|
+
:elision_marker_color,
|
13
16
|
:expected_color,
|
14
17
|
:header_color,
|
15
18
|
)
|
16
19
|
|
17
|
-
def initialize
|
20
|
+
def initialize(options = {})
|
18
21
|
@actual_color = :yellow
|
19
22
|
@border_color = :blue
|
23
|
+
@color_enabled = color_enabled_by_default?
|
24
|
+
@diff_elision_enabled = false
|
25
|
+
@diff_elision_maximum = 0
|
26
|
+
@elision_marker_color = :cyan
|
20
27
|
@expected_color = :magenta
|
21
28
|
@extra_diff_formatter_classes = [].freeze
|
22
29
|
@extra_differ_classes = [].freeze
|
23
|
-
@
|
30
|
+
@extra_inspection_tree_builder_classes = [].freeze
|
24
31
|
@extra_operation_tree_builder_classes = [].freeze
|
25
32
|
@extra_operation_tree_classes = [].freeze
|
26
33
|
@header_color = :white
|
34
|
+
|
35
|
+
merge!(options)
|
36
|
+
end
|
37
|
+
|
38
|
+
def initialize_dup(original)
|
39
|
+
super
|
40
|
+
@extra_differ_classes = original.extra_differ_classes.dup.freeze
|
41
|
+
@extra_operation_tree_builder_classes =
|
42
|
+
original.extra_operation_tree_builder_classes.dup.freeze
|
43
|
+
@extra_operation_tree_classes =
|
44
|
+
original.extra_operation_tree_classes.dup.freeze
|
45
|
+
@extra_inspection_tree_builder_classes =
|
46
|
+
original.extra_inspection_tree_builder_classes.dup.freeze
|
47
|
+
end
|
48
|
+
|
49
|
+
def color_enabled?
|
50
|
+
@color_enabled
|
51
|
+
end
|
52
|
+
|
53
|
+
def diff_elision_enabled?
|
54
|
+
@diff_elision_enabled
|
55
|
+
end
|
56
|
+
|
57
|
+
def merge!(configuration_or_options)
|
58
|
+
options =
|
59
|
+
if configuration_or_options.is_a?(self.class)
|
60
|
+
configuration_or_options.to_h
|
61
|
+
else
|
62
|
+
configuration_or_options
|
63
|
+
end
|
64
|
+
|
65
|
+
options.each do |key, value|
|
66
|
+
instance_variable_set("@#{key}", value)
|
67
|
+
end
|
68
|
+
|
69
|
+
updated
|
70
|
+
end
|
71
|
+
|
72
|
+
def updated
|
73
|
+
SuperDiff::Csi.color_enabled = color_enabled?
|
27
74
|
end
|
28
75
|
|
29
76
|
def add_extra_diff_formatter_classes(*classes)
|
@@ -40,13 +87,13 @@ module SuperDiff
|
|
40
87
|
end
|
41
88
|
alias_method :add_extra_differ_class, :add_extra_differ_classes
|
42
89
|
|
43
|
-
def
|
44
|
-
@
|
45
|
-
(@
|
90
|
+
def add_extra_inspection_tree_builder_classes(*classes)
|
91
|
+
@extra_inspection_tree_builder_classes =
|
92
|
+
(@extra_inspection_tree_builder_classes + classes).freeze
|
46
93
|
end
|
47
94
|
alias_method(
|
48
|
-
:
|
49
|
-
:
|
95
|
+
:add_extra_inspection_tree_builder_class,
|
96
|
+
:add_extra_inspection_tree_builder_classes,
|
50
97
|
)
|
51
98
|
|
52
99
|
def add_extra_operation_tree_builder_classes(*classes)
|
@@ -66,5 +113,31 @@ module SuperDiff
|
|
66
113
|
:add_extra_operation_tree_class,
|
67
114
|
:add_extra_operation_tree_classes,
|
68
115
|
)
|
116
|
+
|
117
|
+
def to_h
|
118
|
+
{
|
119
|
+
actual_color: actual_color,
|
120
|
+
border_color: border_color,
|
121
|
+
color_enabled: color_enabled?,
|
122
|
+
diff_elision_enabled: diff_elision_enabled?,
|
123
|
+
diff_elision_maximum: diff_elision_maximum,
|
124
|
+
elision_marker_color: elision_marker_color,
|
125
|
+
expected_color: expected_color,
|
126
|
+
extra_diff_formatter_classes: extra_diff_formatter_classes.dup,
|
127
|
+
extra_differ_classes: extra_differ_classes.dup,
|
128
|
+
extra_inspection_tree_builder_classes:
|
129
|
+
extra_inspection_tree_builder_classes.dup,
|
130
|
+
extra_operation_tree_builder_classes:
|
131
|
+
extra_operation_tree_builder_classes.dup,
|
132
|
+
extra_operation_tree_classes: extra_operation_tree_classes.dup,
|
133
|
+
header_color: header_color,
|
134
|
+
}
|
135
|
+
end
|
136
|
+
|
137
|
+
private
|
138
|
+
|
139
|
+
def color_enabled_by_default?
|
140
|
+
ENV["CI"] == "true" || $stdout.respond_to?(:tty?) && $stdout.tty?
|
141
|
+
end
|
69
142
|
end
|
70
143
|
end
|
data/lib/super_diff/csi.rb
CHANGED