summaryrefslogtreecommitdiff
path: root/test/json/json_ext_parser_test.rb
diff options
context:
space:
mode:
authorJean Boussier <[email protected]>2024-11-05 16:35:58 +0100
committerJean Boussier <[email protected]>2024-11-05 18:00:36 +0100
commitca8f21ace86e9c7ab184b3f0087ff458c06b178c (patch)
treee5a4c05ba4bff8d9dc19963936d2c81248200881 /test/json/json_ext_parser_test.rb
parente8522f06b51f86214d28259118c736ac8951d8cd (diff)
[ruby/json] Resync
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/12003
Diffstat (limited to 'test/json/json_ext_parser_test.rb')
-rw-r--r--test/json/json_ext_parser_test.rb74
1 files changed, 36 insertions, 38 deletions
diff --git a/test/json/json_ext_parser_test.rb b/test/json/json_ext_parser_test.rb
index 9db8ae772f..da61504989 100644
--- a/test/json/json_ext_parser_test.rb
+++ b/test/json/json_ext_parser_test.rb
@@ -2,53 +2,51 @@
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
- parser.__send__(:initialize, "{}")
- end
- parser = JSON::Ext::Parser.allocate
- assert_raise(TypeError, '[ruby-core:35079]') { parser.source }
- end
+ include JSON
- def test_error_messages
- ex = assert_raise(ParserError) { parse('Infinity') }
- assert_equal "unexpected token at 'Infinity'", ex.message
+ def test_allocate
+ parser = JSON::Ext::Parser.new("{}")
+ assert_raise(TypeError, '[ruby-core:35079]') do
+ parser.__send__(:initialize, "{}")
+ end
+ parser = JSON::Ext::Parser.allocate
+ assert_raise(TypeError, '[ruby-core:35079]') { parser.source }
+ end
- unless RUBY_PLATFORM =~ /java/
- ex = assert_raise(ParserError) { parse('-Infinity') }
- assert_equal "unexpected token at '-Infinity'", ex.message
- end
+ def test_error_messages
+ ex = assert_raise(ParserError) { parse('Infinity') }
+ assert_equal "unexpected token at 'Infinity'", ex.message
- ex = assert_raise(ParserError) { parse('NaN') }
- assert_equal "unexpected token at 'NaN'", ex.message
+ unless RUBY_PLATFORM =~ /java/
+ ex = assert_raise(ParserError) { parse('-Infinity') }
+ assert_equal "unexpected token at '-Infinity'", ex.message
end
- if GC.respond_to?(:stress=)
- def test_gc_stress_parser_new
- payload = JSON.dump([{ foo: 1, bar: 2, baz: 3, egg: { spam: 4 } }] * 10)
-
- previous_stress = GC.stress
- JSON::Parser.new(payload).parse
- ensure
- GC.stress = previous_stress
- end
+ ex = assert_raise(ParserError) { parse('NaN') }
+ assert_equal "unexpected token at 'NaN'", ex.message
+ end
- def test_gc_stress
- payload = JSON.dump([{ foo: 1, bar: 2, baz: 3, egg: { spam: 4 } }] * 10)
+ if GC.respond_to?(:stress=)
+ def test_gc_stress_parser_new
+ payload = JSON.dump([{ foo: 1, bar: 2, baz: 3, egg: { spam: 4 } }] * 10)
- previous_stress = GC.stress
- JSON.parse(payload)
- ensure
- GC.stress = previous_stress
- end
+ previous_stress = GC.stress
+ JSON::Parser.new(payload).parse
+ ensure
+ GC.stress = previous_stress
end
- def parse(json)
- JSON::Ext::Parser.new(json).parse
+ def test_gc_stress
+ payload = JSON.dump([{ foo: 1, bar: 2, baz: 3, egg: { spam: 4 } }] * 10)
+
+ previous_stress = GC.stress
+ JSON.parse(payload)
+ ensure
+ GC.stress = previous_stress
end
end
+
+ def parse(json)
+ JSON::Ext::Parser.new(json).parse
+ end
end