mirror of
https://github.com/ruby/ruby.git
synced 2025-08-16 05:59:00 +02:00
[ruby/json] Resync
This commit is contained in:
parent
e8522f06b5
commit
ca8f21ace8
Notes:
git
2024-11-05 17:00:58 +00:00
18 changed files with 2167 additions and 866 deletions
|
@ -2,53 +2,51 @@
|
|||
require_relative 'test_helper'
|
||||
|
||||
class JSONExtParserTest < Test::Unit::TestCase
|
||||
if defined?(JSON::Ext::Parser)
|
||||
include JSON
|
||||
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 }
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
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)
|
||||
|
||||
ex = assert_raise(ParserError) { parse('NaN') }
|
||||
assert_equal "unexpected token at 'NaN'", ex.message
|
||||
previous_stress = GC.stress
|
||||
JSON::Parser.new(payload).parse
|
||||
ensure
|
||||
GC.stress = previous_stress
|
||||
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)
|
||||
def test_gc_stress
|
||||
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
|
||||
|
||||
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
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue