super_diff 0.3.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (189) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +104 -73
  3. data/lib/super_diff.rb +20 -11
  4. data/lib/super_diff/active_record.rb +21 -23
  5. data/lib/super_diff/active_record/diff_formatters/active_record_relation.rb +3 -3
  6. data/lib/super_diff/active_record/differs/active_record_relation.rb +3 -5
  7. data/lib/super_diff/active_record/monkey_patches.rb +9 -0
  8. data/lib/super_diff/active_record/object_inspection/inspectors/active_record_model.rb +32 -22
  9. data/lib/super_diff/active_record/object_inspection/inspectors/active_record_relation.rb +17 -7
  10. data/lib/super_diff/active_record/operation_tree_builders.rb +14 -0
  11. data/lib/super_diff/active_record/{operational_sequencers → operation_tree_builders}/active_record_model.rb +2 -2
  12. data/lib/super_diff/active_record/{operational_sequencers → operation_tree_builders}/active_record_relation.rb +4 -4
  13. data/lib/super_diff/active_record/{operation_sequences.rb → operation_trees.rb} +2 -2
  14. data/lib/super_diff/active_record/{operation_sequences → operation_trees}/active_record_relation.rb +2 -2
  15. data/lib/super_diff/active_support.rb +16 -19
  16. data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +3 -3
  17. data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +3 -5
  18. data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +17 -7
  19. data/lib/super_diff/active_support/operation_tree_builders.rb +10 -0
  20. data/lib/super_diff/active_support/{operational_sequencers → operation_tree_builders}/hash_with_indifferent_access.rb +2 -2
  21. data/lib/super_diff/active_support/{operation_sequences.rb → operation_trees.rb} +2 -2
  22. data/lib/super_diff/active_support/{operation_sequences → operation_trees}/hash_with_indifferent_access.rb +2 -2
  23. data/lib/super_diff/configuration.rb +60 -0
  24. data/lib/super_diff/csi.rb +4 -0
  25. data/lib/super_diff/diff_formatters.rb +3 -3
  26. data/lib/super_diff/diff_formatters/array.rb +3 -3
  27. data/lib/super_diff/diff_formatters/base.rb +3 -2
  28. data/lib/super_diff/diff_formatters/collection.rb +2 -2
  29. data/lib/super_diff/diff_formatters/custom_object.rb +3 -3
  30. data/lib/super_diff/diff_formatters/default_object.rb +6 -8
  31. data/lib/super_diff/diff_formatters/defaults.rb +10 -0
  32. data/lib/super_diff/diff_formatters/hash.rb +3 -3
  33. data/lib/super_diff/diff_formatters/main.rb +41 -0
  34. data/lib/super_diff/diff_formatters/multiline_string.rb +3 -3
  35. data/lib/super_diff/differs.rb +4 -11
  36. data/lib/super_diff/differs/array.rb +2 -11
  37. data/lib/super_diff/differs/base.rb +20 -3
  38. data/lib/super_diff/differs/custom_object.rb +2 -11
  39. data/lib/super_diff/differs/default_object.rb +2 -8
  40. data/lib/super_diff/differs/defaults.rb +12 -0
  41. data/lib/super_diff/differs/hash.rb +2 -11
  42. data/lib/super_diff/differs/main.rb +48 -0
  43. data/lib/super_diff/differs/multiline_string.rb +2 -14
  44. data/lib/super_diff/differs/time_like.rb +15 -0
  45. data/lib/super_diff/equality_matchers.rb +3 -9
  46. data/lib/super_diff/equality_matchers/array.rb +1 -7
  47. data/lib/super_diff/equality_matchers/base.rb +1 -1
  48. data/lib/super_diff/equality_matchers/default.rb +2 -8
  49. data/lib/super_diff/equality_matchers/defaults.rb +12 -0
  50. data/lib/super_diff/equality_matchers/hash.rb +1 -7
  51. data/lib/super_diff/equality_matchers/main.rb +21 -0
  52. data/lib/super_diff/equality_matchers/multiline_string.rb +1 -7
  53. data/lib/super_diff/errors.rb +16 -0
  54. data/lib/super_diff/errors/no_diff_formatter_available_error.rb +21 -0
  55. data/lib/super_diff/errors/no_differ_available_error.rb +24 -0
  56. data/lib/super_diff/errors/no_operational_sequencer_available_error.rb +22 -0
  57. data/lib/super_diff/implementation_checks.rb +19 -0
  58. data/lib/super_diff/object_inspection.rb +1 -10
  59. data/lib/super_diff/object_inspection/inspection_tree.rb +6 -2
  60. data/lib/super_diff/object_inspection/inspectors.rb +5 -1
  61. data/lib/super_diff/object_inspection/inspectors/array.rb +20 -10
  62. data/lib/super_diff/object_inspection/inspectors/base.rb +36 -0
  63. data/lib/super_diff/object_inspection/inspectors/custom_object.rb +24 -14
  64. data/lib/super_diff/object_inspection/inspectors/default_object.rb +44 -30
  65. data/lib/super_diff/object_inspection/inspectors/defaults.rb +15 -0
  66. data/lib/super_diff/object_inspection/inspectors/hash.rb +20 -10
  67. data/lib/super_diff/object_inspection/inspectors/main.rb +35 -0
  68. data/lib/super_diff/object_inspection/inspectors/primitive.rb +20 -5
  69. data/lib/super_diff/object_inspection/inspectors/string.rb +15 -5
  70. data/lib/super_diff/object_inspection/inspectors/time_like.rb +23 -0
  71. data/lib/super_diff/object_inspection/nodes/inspection.rb +9 -2
  72. data/lib/super_diff/operation_tree_builders.rb +18 -0
  73. data/lib/super_diff/{operational_sequencers → operation_tree_builders}/array.rb +38 -59
  74. data/lib/super_diff/operation_tree_builders/base.rb +98 -0
  75. data/lib/super_diff/{operational_sequencers → operation_tree_builders}/custom_object.rb +3 -3
  76. data/lib/super_diff/{operational_sequencers → operation_tree_builders}/default_object.rb +8 -3
  77. data/lib/super_diff/operation_tree_builders/defaults.rb +5 -0
  78. data/lib/super_diff/operation_tree_builders/hash.rb +226 -0
  79. data/lib/super_diff/operation_tree_builders/main.rb +42 -0
  80. data/lib/super_diff/{operational_sequencers → operation_tree_builders}/multiline_string.rb +3 -3
  81. data/lib/super_diff/operation_tree_builders/time_like.rb +34 -0
  82. data/lib/super_diff/operation_trees.rb +13 -0
  83. data/lib/super_diff/{operation_sequences → operation_trees}/array.rb +5 -1
  84. data/lib/super_diff/operation_trees/base.rb +31 -0
  85. data/lib/super_diff/{operation_sequences → operation_trees}/custom_object.rb +5 -1
  86. data/lib/super_diff/{operation_sequences → operation_trees}/default_object.rb +10 -8
  87. data/lib/super_diff/operation_trees/defaults.rb +5 -0
  88. data/lib/super_diff/{operation_sequences → operation_trees}/hash.rb +5 -1
  89. data/lib/super_diff/operation_trees/main.rb +35 -0
  90. data/lib/super_diff/operation_trees/multiline_string.rb +18 -0
  91. data/lib/super_diff/operations/unary_operation.rb +3 -0
  92. data/lib/super_diff/rspec.rb +54 -22
  93. data/lib/super_diff/rspec/augmented_matcher.rb +1 -1
  94. data/lib/super_diff/rspec/differ.rb +2 -17
  95. data/lib/super_diff/rspec/differs.rb +9 -3
  96. data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +3 -8
  97. data/lib/super_diff/rspec/differs/collection_including.rb +18 -0
  98. data/lib/super_diff/rspec/differs/hash_including.rb +18 -0
  99. data/lib/super_diff/rspec/differs/object_having_attributes.rb +17 -0
  100. data/lib/super_diff/rspec/matcher_text_builders.rb +4 -0
  101. data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +26 -7
  102. data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +61 -0
  103. data/lib/super_diff/rspec/matcher_text_builders/match.rb +1 -1
  104. data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +13 -1
  105. data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +1 -1
  106. data/lib/super_diff/rspec/matcher_text_template.rb +1 -1
  107. data/lib/super_diff/rspec/monkey_patches.rb +226 -115
  108. data/lib/super_diff/rspec/object_inspection.rb +0 -1
  109. data/lib/super_diff/rspec/object_inspection/inspectors.rb +22 -6
  110. data/lib/super_diff/rspec/object_inspection/inspectors/collection_containing_exactly.rb +17 -8
  111. data/lib/super_diff/rspec/object_inspection/inspectors/collection_including.rb +28 -0
  112. data/lib/super_diff/rspec/object_inspection/inspectors/hash_including.rb +31 -0
  113. data/lib/super_diff/rspec/object_inspection/inspectors/instance_of.rb +23 -0
  114. data/lib/super_diff/rspec/object_inspection/inspectors/kind_of.rb +23 -0
  115. data/lib/super_diff/rspec/object_inspection/inspectors/object_having_attributes.rb +31 -0
  116. data/lib/super_diff/rspec/object_inspection/inspectors/primitive.rb +13 -0
  117. data/lib/super_diff/rspec/object_inspection/inspectors/value_within.rb +29 -0
  118. data/lib/super_diff/rspec/operation_tree_builders.rb +22 -0
  119. data/lib/super_diff/rspec/{operational_sequencers → operation_tree_builders}/collection_containing_exactly.rb +6 -6
  120. data/lib/super_diff/rspec/{operational_sequencers/partial_array.rb → operation_tree_builders/collection_including.rb} +4 -3
  121. data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +25 -0
  122. data/lib/super_diff/rspec/{operational_sequencers/partial_object.rb → operation_tree_builders/object_having_attributes.rb} +5 -11
  123. data/lib/super_diff/version.rb +1 -1
  124. data/spec/examples.txt +5 -350
  125. data/spec/integration/rails/active_record_spec.rb +1 -1
  126. data/spec/integration/rails/hash_with_indifferent_access_spec.rb +1 -1
  127. data/spec/integration/rspec/be_predicate_matcher_spec.rb +111 -59
  128. data/spec/integration/rspec/eq_matcher_spec.rb +1 -1
  129. data/spec/integration/rspec/have_attributes_matcher_spec.rb +354 -227
  130. data/spec/integration/rspec/have_predicate_matcher_spec.rb +484 -0
  131. data/spec/integration/rspec/include_matcher_spec.rb +2 -2
  132. data/spec/integration/rspec/match_array_matcher_spec.rb +372 -0
  133. data/spec/integration/rspec/match_matcher_spec.rb +8 -8
  134. data/spec/integration/rspec/raise_error_matcher_spec.rb +605 -226
  135. data/spec/integration/rspec/third_party_matcher_spec.rb +241 -0
  136. data/spec/integration/rspec/unhandled_errors_spec.rb +110 -58
  137. data/spec/spec_helper.rb +18 -7
  138. data/spec/support/command_runner.rb +3 -0
  139. data/spec/support/integration/helpers.rb +14 -90
  140. data/spec/support/integration/matchers.rb +143 -0
  141. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +14 -29
  142. data/spec/support/integration/test_programs/base.rb +120 -0
  143. data/spec/support/integration/test_programs/plain.rb +13 -0
  144. data/spec/support/integration/test_programs/rspec_active_record.rb +17 -0
  145. data/spec/support/integration/test_programs/rspec_rails.rb +17 -0
  146. data/spec/support/models/active_record/person.rb +4 -11
  147. data/spec/support/models/active_record/query.rb +15 -0
  148. data/spec/support/models/active_record/shipping_address.rb +10 -14
  149. data/spec/support/object_id.rb +27 -0
  150. data/spec/support/ruby_versions.rb +4 -0
  151. data/spec/support/shared_examples/active_record.rb +71 -0
  152. data/spec/support/shared_examples/hash_with_indifferent_access.rb +724 -208
  153. data/spec/unit/{equality_matcher_spec.rb → equality_matchers/main_spec.rb} +165 -9
  154. data/spec/unit/object_inspection_spec.rb +94 -18
  155. data/spec/unit/rspec/matchers/have_predicate_spec.rb +21 -0
  156. data/spec/unit/rspec/matchers/match_array_spec.rb +11 -0
  157. data/spec/unit/rspec/matchers/raise_error_spec.rb +16 -0
  158. data/super_diff.gemspec +4 -6
  159. metadata +99 -82
  160. data/lib/super_diff/active_record/object_inspection/map_extension.rb +0 -18
  161. data/lib/super_diff/active_record/operational_sequencers.rb +0 -14
  162. data/lib/super_diff/active_support/object_inspection/map_extension.rb +0 -15
  163. data/lib/super_diff/active_support/operational_sequencers.rb +0 -10
  164. data/lib/super_diff/diff_formatter.rb +0 -32
  165. data/lib/super_diff/differ.rb +0 -51
  166. data/lib/super_diff/differs/time.rb +0 -24
  167. data/lib/super_diff/equality_matcher.rb +0 -32
  168. data/lib/super_diff/no_differ_available_error.rb +0 -22
  169. data/lib/super_diff/no_operational_sequencer_available_error.rb +0 -20
  170. data/lib/super_diff/object_inspection/inspector.rb +0 -27
  171. data/lib/super_diff/object_inspection/inspectors/time.rb +0 -13
  172. data/lib/super_diff/object_inspection/map.rb +0 -30
  173. data/lib/super_diff/operation_sequences.rb +0 -9
  174. data/lib/super_diff/operation_sequences/base.rb +0 -11
  175. data/lib/super_diff/operational_sequencer.rb +0 -48
  176. data/lib/super_diff/operational_sequencers.rb +0 -17
  177. data/lib/super_diff/operational_sequencers/base.rb +0 -89
  178. data/lib/super_diff/operational_sequencers/hash.rb +0 -85
  179. data/lib/super_diff/operational_sequencers/time_like.rb +0 -30
  180. data/lib/super_diff/rspec/configuration.rb +0 -31
  181. data/lib/super_diff/rspec/differs/partial_array.rb +0 -22
  182. data/lib/super_diff/rspec/differs/partial_hash.rb +0 -22
  183. data/lib/super_diff/rspec/differs/partial_object.rb +0 -22
  184. data/lib/super_diff/rspec/object_inspection/inspectors/partial_array.rb +0 -22
  185. data/lib/super_diff/rspec/object_inspection/inspectors/partial_hash.rb +0 -21
  186. data/lib/super_diff/rspec/object_inspection/inspectors/partial_object.rb +0 -21
  187. data/lib/super_diff/rspec/object_inspection/map_extension.rb +0 -23
  188. data/lib/super_diff/rspec/operational_sequencers.rb +0 -22
  189. data/lib/super_diff/rspec/operational_sequencers/partial_hash.rb +0 -32
@@ -1,14 +0,0 @@
1
- module SuperDiff
2
- module ActiveRecord
3
- module OperationalSequencers
4
- autoload(
5
- :ActiveRecordModel,
6
- "super_diff/active_record/operational_sequencers/active_record_model",
7
- )
8
- autoload(
9
- :ActiveRecordRelation,
10
- "super_diff/active_record/operational_sequencers/active_record_relation",
11
- )
12
- end
13
- end
14
- end
@@ -1,15 +0,0 @@
1
- module SuperDiff
2
- module ActiveSupport
3
- module ObjectInspection
4
- module MapExtension
5
- def call(object)
6
- if object.is_a?(::HashWithIndifferentAccess)
7
- Inspectors::HashWithIndifferentAccess
8
- else
9
- super
10
- end
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,10 +0,0 @@
1
- module SuperDiff
2
- module ActiveSupport
3
- module OperationalSequencers
4
- autoload(
5
- :HashWithIndifferentAccess,
6
- "super_diff/active_support/operational_sequencers/hash_with_indifferent_access",
7
- )
8
- end
9
- end
10
- end
@@ -1,32 +0,0 @@
1
- module SuperDiff
2
- class DiffFormatter
3
- extend AttrExtras.mixin
4
-
5
- method_object(
6
- :operations,
7
- [
8
- :indent_level!,
9
- add_comma: false,
10
- extra_classes: [],
11
- ],
12
- )
13
-
14
- def call
15
- resolved_class.call(
16
- operations,
17
- indent_level: indent_level,
18
- add_comma: add_comma?,
19
- )
20
- end
21
-
22
- private
23
-
24
- attr_query :add_comma?
25
-
26
- def resolved_class
27
- (DiffFormatters::DEFAULTS + extra_classes).find do |klass|
28
- klass.applies_to?(operations)
29
- end
30
- end
31
- end
32
- end
@@ -1,51 +0,0 @@
1
- module SuperDiff
2
- class Differ
3
- extend AttrExtras.mixin
4
-
5
- method_object(
6
- :expected,
7
- :actual,
8
- [
9
- indent_level: 0,
10
- index_in_collection: nil,
11
- omit_empty: false,
12
- extra_classes: [],
13
- extra_operational_sequencer_classes: [],
14
- extra_diff_formatter_classes: [],
15
- ],
16
- )
17
-
18
- def call
19
- if resolved_class
20
- resolved_class.call(
21
- expected,
22
- actual,
23
- indent_level: indent_level,
24
- index_in_collection: index_in_collection,
25
- extra_operational_sequencer_classes: extra_operational_sequencer_classes,
26
- extra_diff_formatter_classes: extra_diff_formatter_classes,
27
- )
28
- else
29
- raise NoDifferAvailableError.create(expected, actual)
30
- end
31
- end
32
-
33
- private
34
-
35
- attr_query :omit_empty?
36
-
37
- def resolved_class
38
- available_classes.find { |klass| klass.applies_to?(expected, actual) }
39
- end
40
-
41
- def available_classes
42
- classes = extra_classes + Differs::DEFAULTS
43
-
44
- if omit_empty?
45
- classes - [Differs::Empty]
46
- else
47
- classes
48
- end
49
- end
50
- end
51
- end
@@ -1,24 +0,0 @@
1
- module SuperDiff
2
- module Differs
3
- class Time < Base
4
- def self.applies_to?(expected, actual)
5
- OperationalSequencers::TimeLike.applies_to?(expected, actual)
6
- end
7
-
8
- def call
9
- operations.to_diff(indent_level: indent_level)
10
- end
11
-
12
- private
13
-
14
- def operations
15
- OperationalSequencers::TimeLike.call(
16
- expected: expected,
17
- actual: actual,
18
- extra_operational_sequencer_classes: extra_operational_sequencer_classes,
19
- extra_diff_formatter_classes: extra_diff_formatter_classes,
20
- )
21
- end
22
- end
23
- end
24
- end
@@ -1,32 +0,0 @@
1
- module SuperDiff
2
- class EqualityMatcher
3
- extend AttrExtras.mixin
4
-
5
- method_object(
6
- [
7
- :expected!,
8
- :actual!,
9
- extra_classes: [],
10
- extra_operational_sequencer_classes: [],
11
- extra_diff_formatter_classes: [],
12
- ],
13
- )
14
-
15
- def call
16
- resolved_class.call(
17
- expected: expected,
18
- actual: actual,
19
- extra_operational_sequencer_classes: extra_operational_sequencer_classes,
20
- extra_diff_formatter_classes: extra_diff_formatter_classes,
21
- )
22
- end
23
-
24
- private
25
-
26
- def resolved_class
27
- (EqualityMatchers::DEFAULTS + extra_classes).find do |klass|
28
- klass.applies_to?(expected) && klass.applies_to?(actual)
29
- end
30
- end
31
- end
32
- end
@@ -1,22 +0,0 @@
1
- module SuperDiff
2
- class NoDifferAvailableError < StandardError
3
- def self.create(expected, actual)
4
- allocate.tap do |error|
5
- error.expected = expected
6
- error.actual = actual
7
- error.__send__(:initialize)
8
- end
9
- end
10
-
11
- attr_accessor :expected, :actual
12
-
13
- def initialize
14
- super(<<-MESSAGE)
15
- There is no differ available to handle an "expected" value of type
16
- #{expected.class}
17
- and an "actual" value of type
18
- #{actual.class}.
19
- MESSAGE
20
- end
21
- end
22
- end
@@ -1,20 +0,0 @@
1
- module SuperDiff
2
- class NoOperationalSequencerAvailableError < StandardError
3
- def self.create(expected, actual)
4
- allocate.tap do |error|
5
- error.expected = expected
6
- error.actual = actual
7
- error.__send__(:initialize)
8
- end
9
- end
10
-
11
- attr_accessor :expected, :actual
12
-
13
- def initialize
14
- super(<<-MESSAGE)
15
- There is no operational sequencer available to handle an "expected" value of
16
- type #{expected.class} and an "actual" value of type #{actual.class}.
17
- MESSAGE
18
- end
19
- end
20
- end
@@ -1,27 +0,0 @@
1
- module SuperDiff
2
- module ObjectInspection
3
- class Inspector
4
- extend AttrExtras.mixin
5
-
6
- method_object :map, :object, [:indent_level!, :as_single_line!]
7
-
8
- def call
9
- SuperDiff::RecursionGuard.substituting_recursion_of(object) do
10
- inspector.evaluate(
11
- object,
12
- as_single_line: as_single_line,
13
- indent_level: indent_level,
14
- )
15
- end
16
- end
17
-
18
- private
19
-
20
- attr_query :as_single_line?
21
-
22
- def inspector
23
- @_inspector ||= map.call(object)
24
- end
25
- end
26
- end
27
- end
@@ -1,13 +0,0 @@
1
- module SuperDiff
2
- module ObjectInspection
3
- module Inspectors
4
- TIME_FORMAT = "%Y-%m-%d %H:%M:%S.%3N %Z %:z".freeze
5
-
6
- Time = InspectionTree.new do
7
- add_text do |time|
8
- "#{time.strftime(TIME_FORMAT)} (#{time.class})"
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,30 +0,0 @@
1
- module SuperDiff
2
- module ObjectInspection
3
- class Map
4
- def prepend(mod)
5
- singleton_class.prepend(mod)
6
- end
7
-
8
- def call(object)
9
- if object.respond_to?(:attributes_for_super_diff)
10
- Inspectors::CustomObject
11
- else
12
- case object
13
- when Array
14
- Inspectors::Array
15
- when Hash
16
- Inspectors::Hash
17
- when String
18
- Inspectors::String
19
- when Time
20
- Inspectors::Time
21
- when true, false, nil, Symbol, Numeric, Regexp, Class
22
- Inspectors::Primitive
23
- else
24
- Inspectors::DefaultObject
25
- end
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,9 +0,0 @@
1
- module SuperDiff
2
- module OperationSequences
3
- autoload :Array, "super_diff/operation_sequences/array"
4
- autoload :Base, "super_diff/operation_sequences/base"
5
- autoload :CustomObject, "super_diff/operation_sequences/custom_object"
6
- autoload :DefaultObject, "super_diff/operation_sequences/default_object"
7
- autoload :Hash, "super_diff/operation_sequences/hash"
8
- end
9
- end
@@ -1,11 +0,0 @@
1
- module SuperDiff
2
- module OperationSequences
3
- class Base < SimpleDelegator
4
- # rubocop:disable Lint/UnusedMethodArgument
5
- def to_diff(indent_level:, add_comma: false, collection_prefix: nil)
6
- raise NotImplementedError
7
- end
8
- # rubocop:enable Lint/UnusedMethodArgument
9
- end
10
- end
11
- end
@@ -1,48 +0,0 @@
1
- module SuperDiff
2
- class OperationalSequencer
3
- extend AttrExtras.mixin
4
-
5
- method_object(
6
- [
7
- :expected!,
8
- :actual!,
9
- :all_or_nothing!,
10
- extra_classes: [],
11
- extra_diff_formatter_classes: [],
12
- ],
13
- )
14
-
15
- def call
16
- if resolved_class
17
- resolved_class.call(
18
- expected: expected,
19
- actual: actual,
20
- extra_operational_sequencer_classes: extra_classes,
21
- extra_diff_formatter_classes: extra_diff_formatter_classes,
22
- )
23
- elsif all_or_nothing?
24
- raise NoOperationalSequencerAvailableError.create(expected, actual)
25
- else
26
- nil
27
- end
28
- end
29
-
30
- private
31
-
32
- attr_query :all_or_nothing?
33
-
34
- def resolved_class
35
- available_classes.find { |klass| klass.applies_to?(expected, actual) }
36
- end
37
-
38
- def available_classes
39
- classes = extra_classes + OperationalSequencers::DEFAULTS
40
-
41
- if all_or_nothing?
42
- classes + [OperationalSequencers::DefaultObject]
43
- else
44
- classes
45
- end
46
- end
47
- end
48
- end
@@ -1,17 +0,0 @@
1
- module SuperDiff
2
- module OperationalSequencers
3
- autoload :Array, "super_diff/operational_sequencers/array"
4
- autoload :Base, "super_diff/operational_sequencers/base"
5
- autoload :CustomObject, "super_diff/operational_sequencers/custom_object"
6
- autoload :DefaultObject, "super_diff/operational_sequencers/default_object"
7
- autoload :Hash, "super_diff/operational_sequencers/hash"
8
- # TODO: Where is this used?
9
- autoload(
10
- :MultilineString,
11
- "super_diff/operational_sequencers/multiline_string",
12
- )
13
- autoload :TimeLike, "super_diff/operational_sequencers/time_like"
14
-
15
- DEFAULTS = [Array, Hash, CustomObject].freeze
16
- end
17
- end
@@ -1,89 +0,0 @@
1
- module SuperDiff
2
- module OperationalSequencers
3
- class Base
4
- def self.applies_to?(_expected, _actual)
5
- raise NotImplementedError
6
- end
7
-
8
- extend AttrExtras.mixin
9
-
10
- method_object(
11
- [
12
- :expected!,
13
- :actual!,
14
- extra_operational_sequencer_classes: [],
15
- extra_diff_formatter_classes: [],
16
- ],
17
- )
18
-
19
- def call
20
- i = 0
21
- operations = build_operation_sequencer
22
-
23
- while i < unary_operations.length
24
- operation = unary_operations[i]
25
- next_operation = unary_operations[i + 1]
26
- child_operations = possible_comparison_of(operation, next_operation)
27
-
28
- if child_operations
29
- operations << Operations::BinaryOperation.new(
30
- name: :change,
31
- left_collection: operation.collection,
32
- right_collection: next_operation.collection,
33
- left_key: operation.key,
34
- right_key: operation.key,
35
- left_value: operation.collection[operation.key],
36
- right_value: next_operation.collection[operation.key],
37
- left_index: operation.index,
38
- right_index: operation.index,
39
- child_operations: child_operations,
40
- )
41
- i += 2
42
- else
43
- operations << operation
44
- i += 1
45
- end
46
- end
47
-
48
- operations
49
- end
50
-
51
- protected
52
-
53
- def unary_operations
54
- raise NotImplementedError
55
- end
56
-
57
- def build_operation_sequencer
58
- raise NotImplementedError
59
- end
60
-
61
- private
62
-
63
- def possible_comparison_of(operation, next_operation)
64
- if should_compare?(operation, next_operation)
65
- sequence(operation.value, next_operation.value)
66
- else
67
- nil
68
- end
69
- end
70
-
71
- def should_compare?(operation, next_operation)
72
- next_operation &&
73
- operation.name == :delete &&
74
- next_operation.name == :insert &&
75
- next_operation.index == operation.index
76
- end
77
-
78
- def sequence(expected, actual)
79
- OperationalSequencer.call(
80
- expected: expected,
81
- actual: actual,
82
- all_or_nothing: false,
83
- extra_classes: extra_operational_sequencer_classes,
84
- extra_diff_formatter_classes: extra_diff_formatter_classes,
85
- )
86
- end
87
- end
88
- end
89
- end