[前][次][番号順一覧][スレッド一覧]

ruby-changes:18903

From: tenderlove <ko1@a...>
Date: Mon, 21 Feb 2011 10:02:50 +0900 (JST)
Subject: [ruby-changes:18903] Ruby:r30928 (trunk): * ext/psych/lib/psych/json/stream.rb: fix JSON stream emits to use

tenderlove	2011-02-21 10:02:41 +0900 (Mon, 21 Feb 2011)

  New Revision: 30928

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=30928

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/ext/psych/lib/psych/json/stream.rb
    trunk/test/psych/json/test_stream.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 30927)
+++ ChangeLog	(revision 30928)
@@ -1,3 +1,9 @@
+Mon Feb 21 10:01:01 2011  Aaron Patterson <aaron@t...>
+
+	* 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@g...>
 
 	* test/ruby/test_system.rb (TestSystem#test_system_at):
Index: ext/psych/lib/psych/json/stream.rb
===================================================================
--- ext/psych/lib/psych/json/stream.rb	(revision 30927)
+++ ext/psych/lib/psych/json/stream.rb	(revision 30928)
@@ -23,8 +23,17 @@
         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
Index: test/psych/json/test_stream.rb
===================================================================
--- test/psych/json/test_stream.rb	(revision 30927)
+++ test/psych/json/test_stream.rb	(revision 30928)
@@ -31,12 +31,12 @@
 
       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 @@
         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,9 +67,23 @@
         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
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]