From 310c96b4134f8c0f5d63822a25ccdbc83c30e86e Mon Sep 17 00:00:00 2001 From: Florian Frank Date: Sat, 7 Aug 2010 01:18:56 +0200 Subject: added missing methods to State + tests --- tests/test_json_generate.rb | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'tests') diff --git a/tests/test_json_generate.rb b/tests/test_json_generate.rb index 26ca1ad..8dc804b 100755 --- a/tests/test_json_generate.rb +++ b/tests/test_json_generate.rb @@ -102,6 +102,51 @@ EOT assert s[:check_circular?] end + def test_pretty_state + state = PRETTY_STATE_PROTOTYPE.dup + assert_equal({ + :allow_nan => false, + :array_nl => "\n", + :ascii_only => false, + :depth => 0, + :indent => " ", + :max_nesting => 19, + :object_nl => "\n", + :space => " ", + :space_before => "", + }.sort_by { |n,| n.to_s }, state.to_h.sort_by { |n,| n.to_s }) + end + + def test_safe_state + state = SAFE_STATE_PROTOTYPE.dup + assert_equal({ + :allow_nan => false, + :array_nl => "", + :ascii_only => false, + :depth => 0, + :indent => "", + :max_nesting => 19, + :object_nl => "", + :space => "", + :space_before => "", + }.sort_by { |n,| n.to_s }, state.to_h.sort_by { |n,| n.to_s }) + end + + def test_fast_state + state = FAST_STATE_PROTOTYPE.dup + assert_equal({ + :allow_nan => false, + :array_nl => "", + :ascii_only => false, + :depth => 0, + :indent => "", + :max_nesting => 0, + :object_nl => "", + :space => "", + :space_before => "", + }.sort_by { |n,| n.to_s }, state.to_h.sort_by { |n,| n.to_s }) + end + def test_allow_nan assert_raises(GeneratorError) { generate([JSON::NaN]) } assert_equal '[NaN]', generate([JSON::NaN], :allow_nan => true) -- cgit v1.2.1