summaryrefslogtreecommitdiff
path: root/tests/json_parser_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'tests/json_parser_test.rb')
-rw-r--r--tests/json_parser_test.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/json_parser_test.rb b/tests/json_parser_test.rb
index 514441e..e29f3f1 100644
--- a/tests/json_parser_test.rb
+++ b/tests/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