summaryrefslogtreecommitdiff
path: root/test/psych/test_scalar_scanner.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/psych/test_scalar_scanner.rb')
-rw-r--r--test/psych/test_scalar_scanner.rb74
1 files changed, 72 insertions, 2 deletions
diff --git a/test/psych/test_scalar_scanner.rb b/test/psych/test_scalar_scanner.rb
index 1bd6488e75..02b923afe2 100644
--- a/test/psych/test_scalar_scanner.rb
+++ b/test/psych/test_scalar_scanner.rb
@@ -66,6 +66,10 @@ module Psych
assert_equal(1 / 0.0, ss.tokenize('.inf'))
end
+ def test_scan_plus_inf
+ assert_equal(1 / 0.0, ss.tokenize('+.inf'))
+ end
+
def test_scan_minus_inf
assert_equal(-1 / 0.0, ss.tokenize('-.inf'))
end
@@ -111,7 +115,15 @@ module Psych
end
def test_scan_strings_starting_with_underscores
- assert_equal "_100", ss.tokenize('_100')
+ assert_equal '_100', ss.tokenize('_100')
+ end
+
+ def test_scan_strings_starting_with_number
+ assert_equal '450D', ss.tokenize('450D')
+ end
+
+ def test_scan_strings_ending_with_underscores
+ assert_equal '100_', ss.tokenize('100_')
end
def test_scan_int_commas_and_underscores
@@ -120,7 +132,10 @@ module Psych
assert_equal 123_456_789, ss.tokenize('123_456_789')
assert_equal 123_456_789, ss.tokenize('123,456,789')
assert_equal 123_456_789, ss.tokenize('1_2,3,4_5,6_789')
- assert_equal 123_456_789, ss.tokenize('1_2,3,4_5,6_789_')
+
+ assert_equal 1, ss.tokenize('1')
+ assert_equal 1, ss.tokenize('+1')
+ assert_equal(-1, ss.tokenize('-1'))
assert_equal 0b010101010, ss.tokenize('0b010101010')
assert_equal 0b010101010, ss.tokenize('0b0,1_0,1_,0,1_01,0')
@@ -133,5 +148,60 @@ module Psych
assert_equal 0x123456789abcdef, ss.tokenize('0x_12_,34,_56,_789abcdef')
assert_equal 0x123456789abcdef, ss.tokenize('0x12_,34,_56,_789abcdef__')
end
+
+ def test_scan_strict_int_commas_and_underscores
+ # this test is to ensure adherence to YML spec using the 'strict_integer' option
+ scanner = Psych::ScalarScanner.new ClassLoader.new, strict_integer: true
+ assert_equal 123_456_789, scanner.tokenize('123_456_789')
+ assert_equal '123,456,789', scanner.tokenize('123,456,789')
+ assert_equal '1_2,3,4_5,6_789', scanner.tokenize('1_2,3,4_5,6_789')
+
+ assert_equal 1, scanner.tokenize('1')
+ assert_equal 1, scanner.tokenize('+1')
+ assert_equal(-1, scanner.tokenize('-1'))
+
+ assert_equal 0b010101010, scanner.tokenize('0b010101010')
+ assert_equal 0b010101010, scanner.tokenize('0b01_01_01_010')
+ assert_equal '0b0,1_0,1_,0,1_01,0', scanner.tokenize('0b0,1_0,1_,0,1_01,0')
+
+ assert_equal 01234567, scanner.tokenize('01234567')
+ assert_equal '0_,,,1_2,_34567', scanner.tokenize('0_,,,1_2,_34567')
+
+ assert_equal 0x123456789abcdef, scanner.tokenize('0x123456789abcdef')
+ assert_equal 0x123456789abcdef, scanner.tokenize('0x12_34_56_789abcdef')
+ assert_equal '0x12_,34,_56,_789abcdef', scanner.tokenize('0x12_,34,_56,_789abcdef')
+ assert_equal '0x_12_,34,_56,_789abcdef', scanner.tokenize('0x_12_,34,_56,_789abcdef')
+ assert_equal '0x12_,34,_56,_789abcdef__', scanner.tokenize('0x12_,34,_56,_789abcdef__')
+ end
+
+ def test_scan_dot
+ assert_equal '.', ss.tokenize('.')
+ end
+
+ def test_scan_plus_dot
+ assert_equal '+.', ss.tokenize('+.')
+ end
+
+ class MatchCallCounter < String
+ attr_reader :match_call_count
+
+ def match?(pat)
+ @match_call_count ||= 0
+ @match_call_count += 1
+ super
+ end
+ end
+
+ def test_scan_ascii_matches_quickly
+ ascii = MatchCallCounter.new('abcdefghijklmnopqrstuvwxyz')
+ ss.tokenize(ascii)
+ assert_equal 1, ascii.match_call_count
+ end
+
+ def test_scan_unicode_matches_quickly
+ unicode = MatchCallCounter.new('鳥かご関連用品')
+ ss.tokenize(unicode)
+ assert_equal 1, unicode.match_call_count
+ end
end
end