summaryrefslogtreecommitdiffstats
path: root/test/json/test_json_generate.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/json/test_json_generate.rb')
-rw-r--r--test/json/test_json_generate.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/json/test_json_generate.rb b/test/json/test_json_generate.rb
index e720b2d86..b7e0bc22c 100644
--- a/test/json/test_json_generate.rb
+++ b/test/json/test_json_generate.rb
@@ -70,6 +70,7 @@ EOT
#assert s.check_circular
h = { 1=>2 }
h[3] = h
+ assert_raises(JSON::CircularDatastructure) { generate(h) }
assert_raises(JSON::CircularDatastructure) { generate(h, s) }
s = JSON.state.new(:check_circular => true)
#assert s.check_circular
@@ -77,4 +78,22 @@ EOT
a << a
assert_raises(JSON::CircularDatastructure) { generate(a, s) }
end
+
+ def test_allow_nan
+ assert_raises(GeneratorError) { generate([JSON::NaN]) }
+ assert_equal '[NaN]', generate([JSON::NaN], :allow_nan => true)
+ assert_equal '[NaN]', fast_generate([JSON::NaN])
+ assert_raises(GeneratorError) { pretty_generate([JSON::NaN]) }
+ assert_equal "[\n NaN\n]", pretty_generate([JSON::NaN], :allow_nan => true)
+ assert_raises(GeneratorError) { generate([JSON::Infinity]) }
+ assert_equal '[Infinity]', generate([JSON::Infinity], :allow_nan => true)
+ assert_equal '[Infinity]', fast_generate([JSON::Infinity])
+ assert_raises(GeneratorError) { pretty_generate([JSON::Infinity]) }
+ assert_equal "[\n Infinity\n]", pretty_generate([JSON::Infinity], :allow_nan => true)
+ assert_raises(GeneratorError) { generate([JSON::MinusInfinity]) }
+ assert_equal '[-Infinity]', generate([JSON::MinusInfinity], :allow_nan => true)
+ assert_equal '[-Infinity]', fast_generate([JSON::MinusInfinity])
+ assert_raises(GeneratorError) { pretty_generate([JSON::MinusInfinity]) }
+ assert_equal "[\n -Infinity\n]", pretty_generate([JSON::MinusInfinity], :allow_nan => true)
+ end
end