Skip to content

Commit

Permalink
Add String to primitive list (#262)
Browse files Browse the repository at this point in the history
`String` is considered a primitive for the purposes of inspection, but
was excluded from the `SuperDiff.primitive?` helper in order to support
custom multiline and single-line strings in that area of the codebase.

A simpler way of achieving the same result is to consider `String` to be
a primitive everywhere, and give the custom string equality matchers
higher precedence than the primitive equality matcher.
  • Loading branch information
jas14 authored Sep 22, 2024
1 parent f17507a commit f864fb5
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/super_diff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def self.date_like?(value)

def self.primitive?(value)
case value
when true, false, nil, Symbol, Numeric, Regexp, Class
when true, false, nil, Symbol, Numeric, Regexp, Class, String
true
else
false
Expand Down
2 changes: 1 addition & 1 deletion lib/super_diff/basic/inspection_tree_builders/primitive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Basic
module InspectionTreeBuilders
class Primitive < Core::AbstractInspectionTreeBuilder
def self.applies_to?(value)
SuperDiff.primitive?(value) || value.is_a?(::String)
SuperDiff.primitive?(value)
end

def call
Expand Down
2 changes: 1 addition & 1 deletion lib/super_diff/equality_matchers/defaults.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module SuperDiff
module EqualityMatchers
DEFAULTS = [
Primitive,
Array,
Hash,
MultilineString,
SinglelineString,
Primitive,
Default
].freeze
end
Expand Down

0 comments on commit f864fb5

Please sign in to comment.