aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-02-21 01:02:41 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-02-21 01:02:41 +0000
commit6673f4e8afb9d468849bcc7d87c82c46c799f119 (patch)
tree18cc40375e35f132894992ca6f2c99e38aafe8b0
parent39160bd46dfc3207429b256c6fa41838668259d6 (diff)
downloadruby-6673f4e8afb9d468849bcc7d87c82c46c799f119.tar.gz
* ext/psych/lib/psych/json/stream.rb: fix JSON stream emits to use
double quotes during stream. * test/psych/json/test_stream.rb: tests to reflect changes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30928 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--ext/psych/lib/psych/json/stream.rb11
-rw-r--r--test/psych/json/test_stream.rb26
3 files changed, 36 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 44c12001a6..b4d13db4c0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Mon Feb 21 10:01:01 2011 Aaron Patterson <aaron@tenderlovemaking.com>
+
+ * ext/psych/lib/psych/json/stream.rb: fix JSON stream emits to use
+ double quotes during stream.
+ * test/psych/json/test_stream.rb: tests to reflect changes.
+
Mon Feb 21 00:38:56 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
* test/ruby/test_system.rb (TestSystem#test_system_at):
diff --git a/ext/psych/lib/psych/json/stream.rb b/ext/psych/lib/psych/json/stream.rb
index a6da584cbf..b240b6cbdb 100644
--- a/ext/psych/lib/psych/json/stream.rb
+++ b/ext/psych/lib/psych/json/stream.rb
@@ -23,8 +23,17 @@ module Psych
end
end
+ def visit_Time o
+ formatted = format_time o
+ @emitter.scalar formatted, nil, nil, false, true, Nodes::Scalar::DOUBLE_QUOTED
+ end
+
+ def visit_DateTime o
+ visit_Time o.to_time
+ end
+
def visit_String o
- @emitter.scalar o.to_s, nil, nil, false, true, Nodes::Scalar::ANY
+ @emitter.scalar o.to_s, nil, nil, false, true, Nodes::Scalar::DOUBLE_QUOTED
end
alias :visit_Symbol :visit_String
end
diff --git a/test/psych/json/test_stream.rb b/test/psych/json/test_stream.rb
index 712465d4c0..252535abaa 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,22 @@ 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_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