From 2087329bda3cdc81df4545be68c9450b7ebb5c6f Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 25 Feb 2011 14:07:59 -0800 Subject: merging from ruby trunk --- test/psych/json/test_stream.rb | 46 ++++++++++++++++++++++++++++++++++++------ test/psych/test_json_tree.rb | 11 ++++++++++ 2 files changed, 51 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/psych/json/test_stream.rb b/test/psych/json/test_stream.rb index 712465d..45d0219 100644 --- a/test/psych/json/test_stream.rb +++ b/test/psych/json/test_stream.rb @@ -31,12 +31,12 @@ module Psych def test_string @stream.push "foo" - assert_match(/(['"])foo\1/, @io.string) + assert_match(/(["])foo\1/, @io.string) end def test_symbol @stream.push :foo - assert_match(/(['"])foo\1/, @io.string) + assert_match(/(["])foo\1/, @io.string) end def test_int @@ -56,8 +56,8 @@ module Psych json = @io.string assert_match(/}$/, json) assert_match(/^--- \{/, json) - assert_match(/['"]one['"]/, json) - assert_match(/['"]two['"]/, json) + assert_match(/["]one['"]/, json) + assert_match(/["]two['"]/, json) end def test_list_to_json @@ -67,8 +67,42 @@ module Psych json = @io.string assert_match(/]$/, json) assert_match(/^--- \[/, json) - assert_match(/['"]one['"]/, json) - assert_match(/['"]two['"]/, json) + assert_match(/["]one["]/, json) + assert_match(/["]two["]/, json) + end + + class Foo; end + + def test_json_dump_exclude_tag + @stream << Foo.new + json = @io.string + refute_match('Foo', json) + end + + class Bar + def encode_with coder + coder.represent_seq 'omg', %w{ a b c } + end + end + + def test_json_list_dump_exclude_tag + @stream << Bar.new + json = @io.string + refute_match('omg', json) + end + + def test_time + time = Time.utc(2010, 10, 10) + @stream.push({'a' => time }) + json = @io.string + assert_match "{\"a\": \"2010-10-10 00:00:00.000000000Z\"}\n", json + end + + def test_datetime + time = Time.new(2010, 10, 10).to_datetime + @stream.push({'a' => time }) + json = @io.string + assert_match "{\"a\": \"#{time.strftime("%Y-%m-%d %H:%M:%S.%9N %:z")}\"}\n", json end end end diff --git a/test/psych/test_json_tree.rb b/test/psych/test_json_tree.rb index 423a528..b694560 100644 --- a/test/psych/test_json_tree.rb +++ b/test/psych/test_json_tree.rb @@ -31,6 +31,17 @@ module Psych assert_match(/['"]two['"]/, json) end + class Bar + def encode_with coder + coder.represent_seq 'omg', %w{ a b c } + end + end + + def test_json_list_dump_exclude_tag + json = Psych.to_json Bar.new + refute_match('omg', json) + end + def test_list_to_json list = %w{ one two } json = Psych.to_json(list) -- cgit v1.2.3