diff options
author | Jean Boussier <jean.boussier@gmail.com> | 2020-09-09 15:24:22 +0200 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2020-10-20 21:40:25 +0900 |
commit | 520e0916af0fe53a5ca57269a2bae50cc60e4241 (patch) | |
tree | 0e5b9d615852b0557cc6cd95ce851d59df9d6121 /test | |
parent | f6680c9ad1b334f094144d788887cd33f7043f41 (diff) | |
download | ruby-520e0916af0fe53a5ca57269a2bae50cc60e4241.tar.gz |
Implement a freeze: parser option
If set to true all parsed objects will be
immediately frozen, and strings will be
deduplicated if the Ruby implementation
allows it.
Diffstat (limited to 'test')
-rw-r--r-- | test/json/json_parser_test.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test/json/json_parser_test.rb b/test/json/json_parser_test.rb index 514441efce..e29f3f126f 100644 --- a/test/json/json_parser_test.rb +++ b/test/json/json_parser_test.rb @@ -218,6 +218,17 @@ class JSONParserTest < Test::Unit::TestCase end end + def test_freeze + assert_predicate parse('{}', :freeze => true), :frozen? + assert_predicate parse('[]', :freeze => true), :frozen? + assert_predicate parse('"foo"', :freeze => true), :frozen? + + if string_deduplication_available? + assert_same -'foo', parse('"foo"', :freeze => true) + assert_same -'foo', parse('{"foo": 1}', :freeze => true).keys.first + end + end + def test_parse_comments json = <<EOT { @@ -468,6 +479,16 @@ EOT private + def string_deduplication_available? + r1 = rand.to_s + r2 = r1.dup + begin + (-r1).equal?(-r2) + rescue NoMethodError + false # No String#-@ + end + end + def assert_equal_float(expected, actual, delta = 1e-2) Array === expected and expected = expected.first Array === actual and actual = actual.first |