super_diff 0.9.0 → 0.10.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.
Files changed (193) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +65 -26
  3. data/lib/super_diff/active_record/differs/active_record_relation.rb +1 -2
  4. data/lib/super_diff/active_record/differs.rb +1 -1
  5. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model.rb +5 -13
  6. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +1 -3
  7. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +2 -2
  8. data/lib/super_diff/active_record/object_inspection.rb +1 -1
  9. data/lib/super_diff/active_record/operation_tree_builders/active_record_model.rb +1 -2
  10. data/lib/super_diff/active_record/operation_tree_builders/active_record_relation.rb +1 -2
  11. data/lib/super_diff/active_record/operation_tree_builders.rb +2 -2
  12. data/lib/super_diff/active_record/operation_tree_flatteners.rb +1 -1
  13. data/lib/super_diff/active_record/operation_trees.rb +1 -1
  14. data/lib/super_diff/active_record.rb +7 -15
  15. data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +5 -6
  16. data/lib/super_diff/active_support/differs.rb +1 -1
  17. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +3 -9
  18. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +1 -1
  19. data/lib/super_diff/active_support/object_inspection.rb +1 -1
  20. data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +5 -6
  21. data/lib/super_diff/active_support/operation_tree_builders.rb +1 -1
  22. data/lib/super_diff/active_support/operation_tree_flatteners.rb +1 -1
  23. data/lib/super_diff/active_support/operation_trees.rb +1 -1
  24. data/lib/super_diff/active_support.rb +6 -11
  25. data/lib/super_diff/colorized_document_extensions.rb +2 -4
  26. data/lib/super_diff/configuration.rb +14 -8
  27. data/lib/super_diff/csi/color.rb +4 -4
  28. data/lib/super_diff/csi/colorized_document.rb +12 -16
  29. data/lib/super_diff/csi/document.rb +8 -19
  30. data/lib/super_diff/csi/eight_bit_color.rb +19 -19
  31. data/lib/super_diff/csi/four_bit_color.rb +82 -31
  32. data/lib/super_diff/csi/twenty_four_bit_color.rb +12 -11
  33. data/lib/super_diff/csi/uncolorized_document.rb +2 -6
  34. data/lib/super_diff/csi.rb +10 -14
  35. data/lib/super_diff/diff_formatters/collection.rb +35 -41
  36. data/lib/super_diff/differs/default_object.rb +1 -1
  37. data/lib/super_diff/differs/defaults.rb +1 -1
  38. data/lib/super_diff/differs/main.rb +2 -13
  39. data/lib/super_diff/equality_matchers/array.rb +10 -12
  40. data/lib/super_diff/equality_matchers/base.rb +1 -1
  41. data/lib/super_diff/equality_matchers/default.rb +2 -4
  42. data/lib/super_diff/equality_matchers/defaults.rb +1 -1
  43. data/lib/super_diff/equality_matchers/hash.rb +10 -12
  44. data/lib/super_diff/equality_matchers/multiline_string.rb +11 -13
  45. data/lib/super_diff/equality_matchers/primitive.rb +10 -12
  46. data/lib/super_diff/equality_matchers/singleline_string.rb +10 -12
  47. data/lib/super_diff/equality_matchers.rb +1 -1
  48. data/lib/super_diff/errors.rb +3 -3
  49. data/lib/super_diff/gem_version.rb +3 -3
  50. data/lib/super_diff/helpers.rb +10 -10
  51. data/lib/super_diff/implementation_checks.rb +2 -2
  52. data/lib/super_diff/line.rb +3 -3
  53. data/lib/super_diff/object_inspection/inspection_tree.rb +46 -60
  54. data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +2 -6
  55. data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +3 -9
  56. data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +5 -14
  57. data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +1 -1
  58. data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +4 -12
  59. data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +6 -23
  60. data/lib/super_diff/object_inspection/inspection_tree_builders.rb +9 -9
  61. data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +8 -20
  62. data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +1 -5
  63. data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +1 -5
  64. data/lib/super_diff/object_inspection/nodes/as_single_line.rb +3 -7
  65. data/lib/super_diff/object_inspection/nodes/base.rb +9 -14
  66. data/lib/super_diff/object_inspection/nodes/inspection.rb +26 -34
  67. data/lib/super_diff/object_inspection/nodes/nesting.rb +1 -1
  68. data/lib/super_diff/object_inspection/nodes/only_when.rb +2 -6
  69. data/lib/super_diff/object_inspection/nodes/text.rb +1 -5
  70. data/lib/super_diff/object_inspection/nodes/when_empty.rb +2 -6
  71. data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +2 -6
  72. data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +1 -1
  73. data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +1 -5
  74. data/lib/super_diff/object_inspection/nodes.rb +7 -7
  75. data/lib/super_diff/object_inspection.rb +3 -3
  76. data/lib/super_diff/operation_tree_builders/array.rb +12 -11
  77. data/lib/super_diff/operation_tree_builders/base.rb +17 -15
  78. data/lib/super_diff/operation_tree_builders/custom_object.rb +8 -6
  79. data/lib/super_diff/operation_tree_builders/default_object.rb +29 -21
  80. data/lib/super_diff/operation_tree_builders/hash.rb +23 -24
  81. data/lib/super_diff/operation_tree_builders/main.rb +4 -11
  82. data/lib/super_diff/operation_tree_builders/multiline_string.rb +3 -3
  83. data/lib/super_diff/operation_tree_builders/time_like.rb +1 -11
  84. data/lib/super_diff/operation_tree_builders.rb +1 -1
  85. data/lib/super_diff/operation_tree_flatteners/base.rb +1 -5
  86. data/lib/super_diff/operation_tree_flatteners/collection.rb +13 -16
  87. data/lib/super_diff/operation_tree_flatteners/default_object.rb +1 -2
  88. data/lib/super_diff/operation_tree_flatteners/hash.rb +2 -10
  89. data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +2 -1
  90. data/lib/super_diff/operation_tree_flatteners.rb +3 -3
  91. data/lib/super_diff/operation_trees/base.rb +3 -5
  92. data/lib/super_diff/operation_trees/default_object.rb +1 -3
  93. data/lib/super_diff/operations/binary_operation.rb +2 -2
  94. data/lib/super_diff/operations/unary_operation.rb +1 -1
  95. data/lib/super_diff/rails.rb +2 -1
  96. data/lib/super_diff/recursion_guard.rb +5 -4
  97. data/lib/super_diff/rspec/augmented_matcher.rb +4 -5
  98. data/lib/super_diff/rspec/differ.rb +6 -13
  99. data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +3 -2
  100. data/lib/super_diff/rspec/differs/collection_including.rb +1 -1
  101. data/lib/super_diff/rspec/differs/hash_including.rb +1 -1
  102. data/lib/super_diff/rspec/differs.rb +3 -3
  103. data/lib/super_diff/rspec/matcher_text_builders/base.rb +13 -15
  104. data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +5 -7
  105. data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +3 -5
  106. data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +1 -5
  107. data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +2 -6
  108. data/lib/super_diff/rspec/matcher_text_builders.rb +5 -8
  109. data/lib/super_diff/rspec/matcher_text_template.rb +13 -16
  110. data/lib/super_diff/rspec/monkey_patches.rb +122 -116
  111. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +8 -6
  112. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +11 -16
  113. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +2 -1
  114. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +8 -6
  115. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +8 -6
  116. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +9 -9
  117. data/lib/super_diff/rspec/object_inspection.rb +1 -1
  118. data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +11 -10
  119. data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +7 -6
  120. data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +11 -10
  121. data/lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb +22 -17
  122. data/lib/super_diff/rspec/operation_tree_builders.rb +4 -4
  123. data/lib/super_diff/rspec.rb +11 -13
  124. data/lib/super_diff/tiered_lines_elider.rb +87 -115
  125. data/lib/super_diff/tiered_lines_formatter.rb +5 -9
  126. data/lib/super_diff/version.rb +1 -1
  127. data/lib/super_diff.rb +4 -9
  128. data/spec/examples.txt +493 -485
  129. data/spec/integration/rails/active_record_spec.rb +3 -1
  130. data/spec/integration/rails/engines_spec.rb +20 -0
  131. data/spec/integration/rails/hash_with_indifferent_access_spec.rb +3 -1
  132. data/spec/integration/rspec/be_falsey_matcher_spec.rb +40 -35
  133. data/spec/integration/rspec/be_matcher_spec.rb +360 -320
  134. data/spec/integration/rspec/be_nil_matcher_spec.rb +38 -34
  135. data/spec/integration/rspec/be_predicate_matcher_spec.rb +376 -359
  136. data/spec/integration/rspec/be_truthy_matcher_spec.rb +38 -33
  137. data/spec/integration/rspec/contain_exactly_matcher_spec.rb +242 -239
  138. data/spec/integration/rspec/eq_matcher_spec.rb +595 -557
  139. data/spec/integration/rspec/have_attributes_matcher_spec.rb +294 -286
  140. data/spec/integration/rspec/have_predicate_matcher_spec.rb +291 -297
  141. data/spec/integration/rspec/include_matcher_spec.rb +317 -215
  142. data/spec/integration/rspec/match_array_matcher_spec.rb +276 -273
  143. data/spec/integration/rspec/match_matcher_spec.rb +847 -834
  144. data/spec/integration/rspec/raise_error_matcher_spec.rb +468 -453
  145. data/spec/integration/rspec/respond_to_matcher_spec.rb +702 -697
  146. data/spec/integration/rspec/third_party_matcher_spec.rb +142 -138
  147. data/spec/integration/rspec/unhandled_errors_spec.rb +88 -84
  148. data/spec/spec_helper.rb +17 -20
  149. data/spec/support/command_runner.rb +34 -57
  150. data/spec/support/integration/helpers.rb +35 -28
  151. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +28 -23
  152. data/spec/support/integration/test_programs/base.rb +12 -17
  153. data/spec/support/integration/test_programs/plain.rb +6 -0
  154. data/spec/support/integration/test_programs/rspec_active_record.rb +4 -1
  155. data/spec/support/integration/test_programs/rspec_active_support.rb +4 -1
  156. data/spec/support/integration/test_programs/rspec_rails.rb +4 -1
  157. data/spec/support/integration/test_programs/rspec_rails_engine.rb +30 -0
  158. data/spec/support/models/active_record/person.rb +6 -4
  159. data/spec/support/models/active_record/shipping_address.rb +9 -10
  160. data/spec/support/models/customer.rb +2 -4
  161. data/spec/support/models/player.rb +3 -6
  162. data/spec/support/models/shipping_address.rb +4 -13
  163. data/spec/support/shared_examples/active_record.rb +232 -214
  164. data/spec/support/shared_examples/active_support.rb +53 -51
  165. data/spec/support/shared_examples/elided_diffs.rb +405 -381
  166. data/spec/support/shared_examples/hash_with_indifferent_access.rb +424 -388
  167. data/spec/support/shared_examples/key.rb +123 -0
  168. data/spec/support/unit/helpers.rb +1 -3
  169. data/spec/support/unit/matchers/match_output.rb +12 -13
  170. data/spec/unit/active_record/object_inspection_spec.rb +222 -206
  171. data/spec/unit/equality_matchers/main_spec.rb +1049 -984
  172. data/spec/unit/helpers_spec.rb +14 -21
  173. data/spec/unit/operation_tree_flatteners/array_spec.rb +557 -524
  174. data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +619 -601
  175. data/spec/unit/operation_tree_flatteners/default_object_spec.rb +619 -621
  176. data/spec/unit/operation_tree_flatteners/hash_spec.rb +595 -556
  177. data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +102 -92
  178. data/spec/unit/rspec/matchers/be_compared_to_spec.rb +3 -3
  179. data/spec/unit/rspec/matchers/be_predicate_spec.rb +3 -3
  180. data/spec/unit/rspec/matchers/contain_exactly_spec.rb +1 -1
  181. data/spec/unit/rspec/matchers/have_attributes_spec.rb +1 -1
  182. data/spec/unit/rspec/matchers/have_predicate_spec.rb +2 -2
  183. data/spec/unit/rspec/matchers/include_spec.rb +2 -2
  184. data/spec/unit/rspec/matchers/match_array_spec.rb +2 -2
  185. data/spec/unit/rspec/matchers/raise_error_spec.rb +5 -5
  186. data/spec/unit/rspec/matchers/respond_to_spec.rb +23 -16
  187. data/spec/unit/rspec/object_inspection_spec.rb +349 -324
  188. data/spec/unit/super_diff_spec.rb +1542 -1449
  189. data/spec/unit/tiered_lines_elider_spec.rb +3508 -3536
  190. data/spec/unit/tiered_lines_formatter_spec.rb +54 -116
  191. data/super_diff.gemspec +13 -12
  192. metadata +73 -73
  193. data/spec/tmp/warnings_logger/all_warnings.txt +0 -2
@@ -5,7 +5,7 @@ module SuperDiff
5
5
  def self.applies_to?(expected, actual)
6
6
  (
7
7
  SuperDiff::RSpec.a_collection_including_something?(expected) ||
8
- SuperDiff::RSpec.array_including_something?(expected)
8
+ SuperDiff::RSpec.array_including_something?(expected)
9
9
  ) && actual.is_a?(::Array)
10
10
  end
11
11
 
@@ -18,11 +18,12 @@ module SuperDiff
18
18
  private
19
19
 
20
20
  def actual_with_extra_items_in_expected_at_end
21
- value = if SuperDiff::RSpec.a_collection_including_something?(expected)
22
- expected.expecteds
23
- else
24
- expected.instance_variable_get(:@expected)
25
- end
21
+ value =
22
+ if SuperDiff::RSpec.a_collection_including_something?(expected)
23
+ expected.expecteds
24
+ else
25
+ expected.instance_variable_get(:@expected)
26
+ end
26
27
  actual + (value - actual)
27
28
  end
28
29
  end
@@ -2,29 +2,30 @@ module SuperDiff
2
2
  module RSpec
3
3
  module OperationTreeBuilders
4
4
  class HashIncluding < SuperDiff::OperationTreeBuilders::Hash
5
+ include ::RSpec::Matchers::Composable
6
+
5
7
  def self.applies_to?(expected, actual)
6
8
  (
7
9
  SuperDiff::RSpec.a_hash_including_something?(expected) ||
8
- SuperDiff::RSpec.hash_including_something?(expected)
10
+ SuperDiff::RSpec.hash_including_something?(expected)
9
11
  ) && actual.is_a?(::Hash)
10
12
  end
11
13
 
12
14
  def initialize(expected:, **rest)
13
- hash = if SuperDiff::RSpec.a_hash_including_something?(expected)
14
- expected.expecteds.first
15
- else
16
- expected.instance_variable_get(:@expected)
17
- end
15
+ hash =
16
+ if SuperDiff::RSpec.a_hash_including_something?(expected)
17
+ expected.expecteds.first
18
+ else
19
+ expected.instance_variable_get(:@expected)
20
+ end
18
21
  super(expected: hash, **rest)
19
22
  end
20
23
 
21
24
  private
22
25
 
23
26
  def should_add_noop_operation?(key)
24
- !expected.include?(key) || (
25
- actual.include?(key) &&
26
- expected[key] == actual[key]
27
- )
27
+ !expected.include?(key) ||
28
+ (actual.include?(key) && values_match?(expected[key], actual[key]))
28
29
  end
29
30
  end
30
31
  end
@@ -23,34 +23,39 @@ module SuperDiff
23
23
  private
24
24
 
25
25
  def establish_expected_and_actual_attributes
26
- @expected_attributes = attribute_names.reduce({}) do |hash, name|
27
- if expected.expected.include?(name)
28
- hash.merge(name => expected.expected[name])
29
- else
30
- hash
26
+ @expected_attributes =
27
+ attribute_names.reduce({}) do |hash, name|
28
+ if expected.expected.include?(name)
29
+ hash.merge(name => expected.expected[name])
30
+ else
31
+ hash
32
+ end
31
33
  end
32
- end
33
34
 
34
- @actual_attributes = attribute_names.reduce({}) do |hash, name|
35
- if actual.respond_to?(name)
36
- hash.merge(name => actual.public_send(name))
37
- else
38
- hash
35
+ @actual_attributes =
36
+ attribute_names.reduce({}) do |hash, name|
37
+ if actual.respond_to?(name)
38
+ hash.merge(name => actual.public_send(name))
39
+ else
40
+ hash
41
+ end
39
42
  end
40
- end
41
43
  end
42
44
 
43
45
  def should_add_noop_operation?(attribute_name)
44
- !expected_attributes.include?(attribute_name) || (
45
- actual_attributes.include?(attribute_name) &&
46
- expected_attributes[attribute_name] == actual_attributes[attribute_name]
47
- )
46
+ !expected_attributes.include?(attribute_name) ||
47
+ (
48
+ actual_attributes.include?(attribute_name) &&
49
+ expected_attributes[attribute_name] ==
50
+ actual_attributes[attribute_name]
51
+ )
48
52
  end
49
53
 
50
54
  def should_add_insert_operation?(attribute_name)
51
55
  expected_attributes.include?(attribute_name) &&
52
56
  actual_attributes.include?(attribute_name) &&
53
- expected_attributes[attribute_name] != actual_attributes[attribute_name]
57
+ expected_attributes[attribute_name] !=
58
+ actual_attributes[attribute_name]
54
59
  end
55
60
  end
56
61
  end
@@ -3,19 +3,19 @@ module SuperDiff
3
3
  module OperationTreeBuilders
4
4
  autoload(
5
5
  :CollectionContainingExactly,
6
- "super_diff/rspec/operation_tree_builders/collection_containing_exactly",
6
+ "super_diff/rspec/operation_tree_builders/collection_containing_exactly"
7
7
  )
8
8
  autoload(
9
9
  :CollectionIncluding,
10
- "super_diff/rspec/operation_tree_builders/collection_including",
10
+ "super_diff/rspec/operation_tree_builders/collection_including"
11
11
  )
12
12
  autoload(
13
13
  :HashIncluding,
14
- "super_diff/rspec/operation_tree_builders/hash_including",
14
+ "super_diff/rspec/operation_tree_builders/hash_including"
15
15
  )
16
16
  autoload(
17
17
  :ObjectHavingAttributes,
18
- "super_diff/rspec/operation_tree_builders/object_having_attributes",
18
+ "super_diff/rspec/operation_tree_builders/object_having_attributes"
19
19
  )
20
20
  end
21
21
  end
@@ -20,10 +20,8 @@ module SuperDiff
20
20
  end
21
21
 
22
22
  def self.a_hash_including_something?(value)
23
- fuzzy_object?(value) &&
24
- value.respond_to?(:expecteds) &&
25
- value.expecteds.one? &&
26
- value.expecteds.first.is_a?(::Hash)
23
+ fuzzy_object?(value) && value.respond_to?(:expecteds) &&
24
+ value.expecteds.one? && value.expecteds.first.is_a?(::Hash)
27
25
  end
28
26
 
29
27
  # HINT: `a_hash_including` is an alias of `include` in the rspec-expectations gem.
@@ -33,8 +31,7 @@ module SuperDiff
33
31
  end
34
32
 
35
33
  def self.a_collection_including_something?(value)
36
- fuzzy_object?(value) &&
37
- value.respond_to?(:expecteds) &&
34
+ fuzzy_object?(value) && value.respond_to?(:expecteds) &&
38
35
  !(value.expecteds.one? && value.expecteds.first.is_a?(::Hash))
39
36
  end
40
37
 
@@ -84,10 +81,11 @@ module SuperDiff
84
81
  end
85
82
 
86
83
  def self.rspec_version
87
- @_rspec_version ||= begin
88
- require "rspec/core/version"
89
- GemVersion.new(::RSpec::Core::Version::STRING)
90
- end
84
+ @_rspec_version ||=
85
+ begin
86
+ require "rspec/core/version"
87
+ GemVersion.new(::RSpec::Core::Version::STRING)
88
+ end
91
89
  end
92
90
 
93
91
  SuperDiff.configuration.tap do |config|
@@ -95,14 +93,14 @@ module SuperDiff
95
93
  Differs::CollectionContainingExactly,
96
94
  Differs::CollectionIncluding,
97
95
  Differs::HashIncluding,
98
- Differs::ObjectHavingAttributes,
96
+ Differs::ObjectHavingAttributes
99
97
  )
100
98
 
101
99
  config.add_extra_operation_tree_builder_classes(
102
100
  OperationTreeBuilders::CollectionContainingExactly,
103
101
  OperationTreeBuilders::CollectionIncluding,
104
102
  OperationTreeBuilders::HashIncluding,
105
- OperationTreeBuilders::ObjectHavingAttributes,
103
+ OperationTreeBuilders::ObjectHavingAttributes
106
104
  )
107
105
 
108
106
  config.add_extra_inspection_tree_builder_classes(
@@ -114,7 +112,7 @@ module SuperDiff
114
112
  ObjectInspection::InspectionTreeBuilders::KindOf,
115
113
  ObjectInspection::InspectionTreeBuilders::ObjectHavingAttributes,
116
114
  # ObjectInspection::InspectionTreeBuilders::Primitive,
117
- ObjectInspection::InspectionTreeBuilders::ValueWithin,
115
+ ObjectInspection::InspectionTreeBuilders::ValueWithin
118
116
  )
119
117
  end
120
118
  end
@@ -8,11 +8,7 @@ module SuperDiff
8
8
  method_object :lines
9
9
 
10
10
  def call
11
- if all_lines_are_changed_or_unchanged?
12
- lines
13
- else
14
- elided_lines
15
- end
11
+ all_lines_are_changed_or_unchanged? ? lines : elided_lines
16
12
  end
17
13
 
18
14
  private
@@ -22,9 +18,11 @@ module SuperDiff
22
18
  end
23
19
 
24
20
  def elided_lines
25
- boxes_to_elide.reverse.reduce(lines) do |lines_with_elisions, box|
26
- with_box_elided(box, lines_with_elisions)
27
- end
21
+ boxes_to_elide
22
+ .reverse
23
+ .reduce(lines) do |lines_with_elisions, box|
24
+ with_box_elided(box, lines_with_elisions)
25
+ end
28
26
  end
29
27
 
30
28
  def boxes_to_elide
@@ -35,9 +33,7 @@ module SuperDiff
35
33
  end
36
34
 
37
35
  def panes_to_consider_for_eliding
38
- panes.select do |pane|
39
- pane.type == :clean && pane.range.size > maximum
40
- end
36
+ panes.select { |pane| pane.type == :clean && pane.range.size > maximum }
41
37
  end
42
38
 
43
39
  def panes
@@ -45,24 +41,26 @@ module SuperDiff
45
41
  end
46
42
 
47
43
  def padded_dirty_panes
48
- @_padded_dirty_panes ||= combine_congruent_panes(
49
- dirty_panes.
50
- map(&:padded).
51
- map { |pane| pane.capped_to(0, lines.size - 1) }
52
- )
44
+ @_padded_dirty_panes ||=
45
+ combine_congruent_panes(
46
+ dirty_panes
47
+ .map(&:padded)
48
+ .map { |pane| pane.capped_to(0, lines.size - 1) }
49
+ )
53
50
  end
54
51
 
55
52
  def dirty_panes
56
- @_dirty_panes ||= lines.
57
- each_with_index.
58
- select { |line, index| line.type != :noop }.
59
- reduce([]) do |panes, (_, index)|
60
- if !panes.empty? && panes.last.range.end == index - 1
61
- panes[0..-2] + [panes[-1].extended_to(index)]
62
- else
63
- panes + [Pane.new(type: :dirty, range: index..index)]
53
+ @_dirty_panes ||=
54
+ lines
55
+ .each_with_index
56
+ .select { |line, index| line.type != :noop }
57
+ .reduce([]) do |panes, (_, index)|
58
+ if !panes.empty? && panes.last.range.end == index - 1
59
+ panes[0..-2] + [panes[-1].extended_to(index)]
60
+ else
61
+ panes + [Pane.new(type: :dirty, range: index..index)]
62
+ end
64
63
  end
65
- end
66
64
  end
67
65
 
68
66
  def with_box_elided(box, lines)
@@ -92,7 +90,7 @@ module SuperDiff
92
90
  with_subset_of_lines_elided(
93
91
  lines,
94
92
  range: box.range,
95
- indentation_level: box.indentation_level,
93
+ indentation_level: box.indentation_level
96
94
  )
97
95
  end
98
96
  end
@@ -106,26 +104,25 @@ module SuperDiff
106
104
  end
107
105
 
108
106
  def all_indentation_levels
109
- lines.
110
- map(&:indentation_level).
111
- select { |indentation_level| indentation_level > 0 }.
112
- uniq
107
+ lines
108
+ .map(&:indentation_level)
109
+ .select { |indentation_level| indentation_level > 0 }
110
+ .uniq
113
111
  end
114
112
 
115
113
  def find_boxes_to_elide_within(pane)
116
114
  set_of_boxes =
117
115
  normalized_box_groups_at_decreasing_indentation_levels_within(pane)
118
116
 
119
- total_size_before_eliding = lines[pane.range].
120
- reject(&:complete_bookend?).
121
- size
117
+ total_size_before_eliding =
118
+ lines[pane.range].reject(&:complete_bookend?).size
122
119
 
123
120
  if total_size_before_eliding > maximum
124
121
  if maximum > 0
125
122
  set_of_boxes.find do |boxes|
126
123
  total_size_after_eliding =
127
124
  total_size_before_eliding -
128
- boxes.sum { |box| box.range.size - SIZE_OF_ELISION }
125
+ boxes.sum { |box| box.range.size - SIZE_OF_ELISION }
129
126
  total_size_after_eliding <= maximum
130
127
  end
131
128
  else
@@ -137,22 +134,21 @@ module SuperDiff
137
134
  end
138
135
 
139
136
  def normalized_box_groups_at_decreasing_indentation_levels_within(pane)
140
- box_groups_at_decreasing_indentation_levels_within(pane).
141
- map(&method(:filter_out_boxes_fully_contained_in_others)).
142
- map(&method(:combine_congruent_boxes))
137
+ box_groups_at_decreasing_indentation_levels_within(pane).map(
138
+ &method(:filter_out_boxes_fully_contained_in_others)
139
+ ).map(&method(:combine_congruent_boxes))
143
140
  end
144
141
 
145
142
  def box_groups_at_decreasing_indentation_levels_within(pane)
146
- boxes_within_pane = boxes.select do |box|
147
- box.fits_fully_within?(pane)
148
- end
143
+ boxes_within_pane = boxes.select { |box| box.fits_fully_within?(pane) }
149
144
 
150
- possible_indentation_levels = boxes_within_pane.
151
- map(&:indentation_level).
152
- select { |indentation_level| indentation_level > 0 }.
153
- uniq.
154
- sort.
155
- reverse
145
+ possible_indentation_levels =
146
+ boxes_within_pane
147
+ .map(&:indentation_level)
148
+ .select { |indentation_level| indentation_level > 0 }
149
+ .uniq
150
+ .sort
151
+ .reverse
156
152
 
157
153
  possible_indentation_levels.map do |indentation_level|
158
154
  boxes_within_pane.select do |box|
@@ -162,9 +158,10 @@ module SuperDiff
162
158
  end
163
159
 
164
160
  def filter_out_boxes_fully_contained_in_others(boxes)
165
- sorted_boxes = boxes.sort_by do |box|
166
- [box.indentation_level, box.range.begin, box.range.end]
167
- end
161
+ sorted_boxes =
162
+ boxes.sort_by do |box|
163
+ [box.indentation_level, box.range.begin, box.range.end]
164
+ end
168
165
 
169
166
  boxes.reject do |box2|
170
167
  sorted_boxes.any? do |box1|
@@ -185,14 +182,14 @@ module SuperDiff
185
182
  criterion = on
186
183
  spannables.reduce([]) do |combined_spannables, spannable|
187
184
  if (
188
- !combined_spannables.empty? &&
189
- spannable.range.begin <= combined_spannables.last.range.end + 1 &&
190
- spannable.public_send(criterion) ==
191
- combined_spannables.last.public_send(criterion)
192
- )
193
- combined_spannables[0..-2] + [
194
- combined_spannables[-1].extended_to(spannable.range.end),
195
- ]
185
+ !combined_spannables.empty? &&
186
+ spannable.range.begin <=
187
+ combined_spannables.last.range.end + 1 &&
188
+ spannable.public_send(criterion) ==
189
+ combined_spannables.last.public_send(criterion)
190
+ )
191
+ combined_spannables[0..-2] +
192
+ [combined_spannables[-1].extended_to(spannable.range.end)]
196
193
  else
197
194
  combined_spannables + [spannable]
198
195
  end
@@ -213,10 +210,8 @@ module SuperDiff
213
210
 
214
211
  with_subset_of_lines_elided(
215
212
  lines,
216
- range: Range.new(
217
- box.range.begin,
218
- box.range.begin + amount_to_elide - 1,
219
- ),
213
+ range:
214
+ Range.new(box.range.begin, box.range.begin + amount_to_elide - 1),
220
215
  indentation_level: box.indentation_level
221
216
  )
222
217
  end
@@ -252,14 +247,16 @@ module SuperDiff
252
247
  end
253
248
 
254
249
  opening_length, closing_length =
255
- half_of_maximum, half_of_maximum + remainder
250
+ half_of_maximum,
251
+ half_of_maximum + remainder
256
252
 
257
253
  with_subset_of_lines_elided(
258
254
  lines,
259
- range: Range.new(
260
- box.range.begin + opening_length,
261
- box.range.end - closing_length,
262
- ),
255
+ range:
256
+ Range.new(
257
+ box.range.begin + opening_length,
258
+ box.range.end - closing_length
259
+ ),
263
260
  indentation_level: box.indentation_level
264
261
  )
265
262
  end
@@ -270,8 +267,8 @@ module SuperDiff
270
267
  range,
271
268
  Elision.new(
272
269
  indentation_level: indentation_level,
273
- children: lines[range].map(&:as_elided),
274
- ),
270
+ children: lines[range].map(&:as_elided)
271
+ )
275
272
  )
276
273
  end
277
274
 
@@ -282,7 +279,7 @@ module SuperDiff
282
279
  class BuildPanes
283
280
  extend AttrExtras.mixin
284
281
 
285
- method_object [:dirty_panes!, :lines!]
282
+ method_object %i[dirty_panes! lines!]
286
283
 
287
284
  def call
288
285
  beginning + middle + ending
@@ -291,19 +288,13 @@ module SuperDiff
291
288
  private
292
289
 
293
290
  def beginning
294
- if (
295
- dirty_panes.empty? ||
296
- dirty_panes.first.range.begin == 0
297
- )
291
+ if (dirty_panes.empty? || dirty_panes.first.range.begin == 0)
298
292
  []
299
293
  else
300
294
  [
301
295
  Pane.new(
302
296
  type: :clean,
303
- range: Range.new(
304
- 0,
305
- dirty_panes.first.range.begin - 1
306
- )
297
+ range: Range.new(0, dirty_panes.first.range.begin - 1)
307
298
  )
308
299
  ]
309
300
  end
@@ -313,43 +304,30 @@ module SuperDiff
313
304
  if dirty_panes.size == 1
314
305
  dirty_panes
315
306
  else
316
- dirty_panes.
317
- each_with_index.
318
- each_cons(2).
319
- reduce([]) do |panes, ((pane1, _), (pane2, index2))|
307
+ dirty_panes
308
+ .each_with_index
309
+ .each_cons(2)
310
+ .reduce([]) do |panes, ((pane1, _), (pane2, index2))|
320
311
  panes +
321
- [
322
- pane1,
323
- Pane.new(
324
- type: :clean,
325
- range: Range.new(
326
- pane1.range.end + 1,
327
- pane2.range.begin - 1,
312
+ [
313
+ pane1,
314
+ Pane.new(
315
+ type: :clean,
316
+ range: Range.new(pane1.range.end + 1, pane2.range.begin - 1)
328
317
  )
329
- )
330
- ] + (
331
- index2 == dirty_panes.size - 1 ?
332
- [pane2] :
333
- []
334
- )
318
+ ] + (index2 == dirty_panes.size - 1 ? [pane2] : [])
335
319
  end
336
320
  end
337
321
  end
338
322
 
339
323
  def ending
340
- if (
341
- dirty_panes.empty? ||
342
- dirty_panes.last.range.end >= lines.size - 1
343
- )
324
+ if (dirty_panes.empty? || dirty_panes.last.range.end >= lines.size - 1)
344
325
  []
345
326
  else
346
327
  [
347
328
  Pane.new(
348
329
  type: :clean,
349
- range: Range.new(
350
- dirty_panes.last.range.end + 1,
351
- lines.size - 1
352
- )
330
+ range: Range.new(dirty_panes.last.range.end + 1, lines.size - 1)
353
331
  )
354
332
  ]
355
333
  end
@@ -359,26 +337,20 @@ module SuperDiff
359
337
  class Pane
360
338
  extend AttrExtras.mixin
361
339
 
362
- rattr_initialize [:type!, :range!]
340
+ rattr_initialize %i[type! range!]
363
341
 
364
342
  def extended_to(new_end)
365
343
  self.class.new(type: type, range: range.begin..new_end)
366
344
  end
367
345
 
368
346
  def padded
369
- self.class.new(
370
- type: type,
371
- range: Range.new(range.begin, range.end)
372
- )
347
+ self.class.new(type: type, range: Range.new(range.begin, range.end))
373
348
  end
374
349
 
375
350
  def capped_to(beginning, ending)
376
351
  new_beginning = range.begin < beginning ? beginning : range.begin
377
352
  new_ending = range.end > ending ? ending : range.end
378
- self.class.new(
379
- type: type,
380
- range: Range.new(new_beginning, new_ending),
381
- )
353
+ self.class.new(type: type, range: Range.new(new_beginning, new_ending))
382
354
  end
383
355
  end
384
356
 
@@ -427,14 +399,14 @@ module SuperDiff
427
399
  def open_new_collection_box(line, index)
428
400
  open_collection_boxes << Box.new(
429
401
  indentation_level: line.indentation_level,
430
- range: index..index,
402
+ range: index..index
431
403
  )
432
404
  end
433
405
 
434
406
  def record_item_box(line, index)
435
407
  final_boxes << Box.new(
436
408
  indentation_level: line.indentation_level,
437
- range: index..index,
409
+ range: index..index
438
410
  )
439
411
  end
440
412
  end
@@ -442,7 +414,7 @@ module SuperDiff
442
414
  class Box
443
415
  extend AttrExtras.mixin
444
416
 
445
- rattr_initialize [:indentation_level!, :range!]
417
+ rattr_initialize %i[indentation_level! range!]
446
418
 
447
419
  def fully_contains?(other)
448
420
  range.begin <= other.range.begin && range.end >= other.range.end
@@ -464,7 +436,7 @@ module SuperDiff
464
436
  class Elision
465
437
  extend AttrExtras.mixin
466
438
 
467
- rattr_initialize [:indentation_level!, :children!]
439
+ rattr_initialize %i[indentation_level! children!]
468
440
 
469
441
  def type
470
442
  :elision
@@ -15,7 +15,7 @@ module SuperDiff
15
15
  formattable_lines.each do |formattable_line|
16
16
  doc.public_send(
17
17
  "#{formattable_line.color}_line",
18
- formattable_line.content,
18
+ formattable_line.content
19
19
  )
20
20
  end
21
21
  end
@@ -34,7 +34,7 @@ module SuperDiff
34
34
  delete: :expected,
35
35
  insert: :actual,
36
36
  elision: :elision_marker,
37
- noop: :plain,
37
+ noop: :plain
38
38
  }.freeze
39
39
 
40
40
  pattr_initialize :line
@@ -47,7 +47,7 @@ module SuperDiff
47
47
  COLORS.fetch(line.type) do
48
48
  raise(
49
49
  KeyError,
50
- "Couldn't find color for line type #{line.type.inspect}!",
50
+ "Couldn't find color for line type #{line.type.inspect}!"
51
51
  )
52
52
  end
53
53
  end
@@ -58,7 +58,7 @@ module SuperDiff
58
58
  ICONS.fetch(line.type) do
59
59
  raise(
60
60
  KeyError,
61
- "Couldn't find icon for line type #{line.type.inspect}!",
61
+ "Couldn't find icon for line type #{line.type.inspect}!"
62
62
  )
63
63
  end
64
64
  end
@@ -68,11 +68,7 @@ module SuperDiff
68
68
  end
69
69
 
70
70
  def possible_comma
71
- if line.add_comma?
72
- ","
73
- else
74
- ""
75
- end
71
+ line.add_comma? ? "," : ""
76
72
  end
77
73
  end
78
74
  end
@@ -1,3 +1,3 @@
1
1
  module SuperDiff
2
- VERSION = "0.9.0".freeze
2
+ VERSION = "0.10.0".freeze
3
3
  end