summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2019-04-26 19:38:43 +0200
committerJean Boussier <jean.boussier@gmail.com>2019-04-26 19:38:43 +0200
commit7d04834b79aa6677b1bff42161311cb79809ed7d (patch)
tree3b6c934a64f8660c0bbc5091c1cb58b342a23a26 /test
parenta28037330ff1507fe014b85a44b96034c24ba48d (diff)
downloadpsych-7d04834b79aa6677b1bff42161311cb79809ed7d.zip
Do not allocate a string to check if a scalar is an integer
Diffstat (limited to 'test')
-rw-r--r--test/psych/test_scalar_scanner.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/psych/test_scalar_scanner.rb b/test/psych/test_scalar_scanner.rb
index ebe8daf..d12a905 100644
--- a/test/psych/test_scalar_scanner.rb
+++ b/test/psych/test_scalar_scanner.rb
@@ -113,5 +113,22 @@ module Psych
def test_scan_strings_starting_with_underscores
assert_equal "_100", ss.tokenize('_100')
end
+
+ def test_scan_int_commas_and_underscores
+ # NB: This test is to ensure backward compatibility with prior Psych versions,
+ # not to test against any actual YAML specification.
+ 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 0b010101010, ss.tokenize('0b010101010')
+ assert_equal 0b010101010, ss.tokenize('0b0,1_0,1_,0,1_01,0')
+
+ assert_equal 01234567, ss.tokenize('01234567')
+ assert_equal 01234567, ss.tokenize('0_,,,1_2,_34567')
+
+ assert_equal 0x123456789abcdef, ss.tokenize('0x123456789abcdef')
+ assert_equal 0x123456789abcdef, ss.tokenize('0x12_,34,_56,_789abcdef')
+ end
end
end