summaryrefslogtreecommitdiff
path: root/test/json/json_ext_parser_test.rb
diff options
context:
space:
mode:
authorJean Boussier <[email protected]>2025-05-12 15:41:12 +0200
committerHiroshi SHIBATA <[email protected]>2025-05-13 14:12:22 +0900
commitcd7495a1d0e003360c96bb9746c1a8e6b3c6901c (patch)
tree9a898c4c544a71f2cc8031ea7f4fbe2c3ecbfde1 /test/json/json_ext_parser_test.rb
parent8cc1aa82f1a14b9d1822562eb943e7ffb41b426e (diff)
[ruby/json] Further improve parsing errors
Report EOF when applicable instead of an empty fragment. Also stop fragment extraction on first whitespace. https://github.com/ruby/json/commit/cc1daba860
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/13310
Diffstat (limited to 'test/json/json_ext_parser_test.rb')
-rw-r--r--test/json/json_ext_parser_test.rb21
1 files changed, 18 insertions, 3 deletions
diff --git a/test/json/json_ext_parser_test.rb b/test/json/json_ext_parser_test.rb
index 739798d05b..e610f642f1 100644
--- a/test/json/json_ext_parser_test.rb
+++ b/test/json/json_ext_parser_test.rb
@@ -14,20 +14,35 @@ class JSONExtParserTest < Test::Unit::TestCase
end
def test_error_messages
- ex = assert_raise(ParserError) { parse('Infinity') }
+ ex = assert_raise(ParserError) { parse('Infinity something') }
unless RUBY_PLATFORM =~ /java/
assert_equal "unexpected token 'Infinity' at line 1 column 1", ex.message
end
- ex = assert_raise(ParserError) { parse('-Infinity') }
+ ex = assert_raise(ParserError) { parse('foo bar') }
+ unless RUBY_PLATFORM =~ /java/
+ assert_equal "unexpected token 'foo' at line 1 column 1", ex.message
+ end
+
+ ex = assert_raise(ParserError) { parse('-Infinity something') }
unless RUBY_PLATFORM =~ /java/
assert_equal "unexpected token '-Infinity' at line 1 column 1", ex.message
end
- ex = assert_raise(ParserError) { parse('NaN') }
+ ex = assert_raise(ParserError) { parse('NaN something') }
unless RUBY_PLATFORM =~ /java/
assert_equal "unexpected token 'NaN' at line 1 column 1", ex.message
end
+
+ ex = assert_raise(ParserError) { parse(' ') }
+ unless RUBY_PLATFORM =~ /java/
+ assert_equal "unexpected end of input at line 1 column 4", ex.message
+ end
+
+ ex = assert_raise(ParserError) { parse('{ ') }
+ unless RUBY_PLATFORM =~ /java/
+ assert_equal "expected object key, got EOF at line 1 column 5", ex.message
+ end
end
if GC.respond_to?(:stress=)