diff options
Diffstat (limited to 'test/json/json_ext_parser_test.rb')
-rw-r--r-- | test/json/json_ext_parser_test.rb | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/test/json/json_ext_parser_test.rb b/test/json/json_ext_parser_test.rb index c5a030ea8a..f49f88b596 100644 --- a/test/json/json_ext_parser_test.rb +++ b/test/json/json_ext_parser_test.rb @@ -1,8 +1,10 @@ #frozen_string_literal: false -require 'test_helper' +require_relative 'test_helper' class JSONExtParserTest < Test::Unit::TestCase if defined?(JSON::Ext::Parser) + include JSON + def test_allocate parser = JSON::Ext::Parser.new("{}") assert_raise(TypeError, '[ruby-core:35079]') do @@ -11,5 +13,22 @@ class JSONExtParserTest < Test::Unit::TestCase parser = JSON::Ext::Parser.allocate assert_raise(TypeError, '[ruby-core:35079]') { parser.source } end + + def test_error_messages + ex = assert_raise(ParserError) { parse('Infinity') } + assert_equal "unexpected token at 'Infinity'", ex.message + + unless RUBY_PLATFORM =~ /java/ + ex = assert_raise(ParserError) { parse('-Infinity') } + assert_equal "unexpected token at '-Infinity'", ex.message + end + + ex = assert_raise(ParserError) { parse('NaN') } + assert_equal "unexpected token at 'NaN'", ex.message + end + + def parse(json) + JSON::Ext::Parser.new(json).parse + end end end |