Skip to content

Commit

Permalink
Test String#blank? with every non-dummy encoding
Browse files Browse the repository at this point in the history
This adds test coverage for `String#blank?` with every non-dummy
encoding that is bundled with Ruby.
  • Loading branch information
jonathanhefner committed May 8, 2023
1 parent 114e974 commit a126949
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions activesupport/test/core_ext/object/blank_test.rb
Expand Up @@ -16,14 +16,21 @@ def empty?
end
end

BLANK = [ EmptyTrue.new, nil, false, "", " ", " \n\t \r ", " ", "\u00a0", [], {}, " ".encode("UTF-16LE") ]
NOT = [ EmptyFalse.new, Object.new, true, 0, 1, "a", [nil], { nil => 0 }, Time.now, "my value".encode("UTF-16LE") ]
BLANK = [ EmptyTrue.new, nil, false, "", " ", " \n\t \r ", " ", "\u00a0", [], {} ]
NOT = [ EmptyFalse.new, Object.new, true, 0, 1, "a", [nil], { nil => 0 }, Time.now ]

def test_blank
BLANK.each { |v| assert_equal true, v.blank?, "#{v.inspect} should be blank" }
NOT.each { |v| assert_equal false, v.blank?, "#{v.inspect} should not be blank" }
end

def test_blank_with_bundled_string_encodings
Encoding.list.reject(&:dummy?).each do |encoding|
assert_predicate " ".encode(encoding), :blank?
assert_not_predicate "a".encode(encoding), :blank?
end
end

def test_present
BLANK.each { |v| assert_equal false, v.present?, "#{v.inspect} should not be present" }
NOT.each { |v| assert_equal true, v.present?, "#{v.inspect} should be present" }
Expand Down

0 comments on commit a126949

Please sign in to comment.