summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-05-22 18:05:36 -0400
committerAaron Patterson <aaron.patterson@gmail.com>2010-05-22 18:05:36 -0400
commite232744e1ffcb2322a911140f508023c67866c2c (patch)
tree5ee3330be16fe640ba7af25f09ac2cc25a2c26de /test
parent01b3d734cd685516ae4cba5bd4dbb7daab4931ee (diff)
downloadpsych-e232744e1ffcb2322a911140f508023c67866c2c.zip
adding a json stream emitter
Diffstat (limited to 'test')
-rw-r--r--test/psych/json/test_stream.rb75
1 files changed, 75 insertions, 0 deletions
diff --git a/test/psych/json/test_stream.rb b/test/psych/json/test_stream.rb
new file mode 100644
index 0000000..712465d
--- /dev/null
+++ b/test/psych/json/test_stream.rb
@@ -0,0 +1,75 @@
+require_relative '../helper'
+
+module Psych
+ module JSON
+ class TestStream < TestCase
+ def setup
+ @io = StringIO.new
+ @stream = Psych::JSON::Stream.new(@io)
+ @stream.start
+ end
+
+ def test_explicit_documents
+ @io = StringIO.new
+ @stream = Psych::JSON::Stream.new(@io)
+ @stream.start
+
+ @stream.push({ 'foo' => 'bar' })
+
+ assert !@stream.finished?, 'stream not finished'
+ @stream.finish
+ assert @stream.finished?, 'stream finished'
+
+ assert_match(/^---/, @io.string)
+ assert_match(/\.\.\.$/, @io.string)
+ end
+
+ def test_null
+ @stream.push(nil)
+ assert_match(/^--- null/, @io.string)
+ end
+
+ def test_string
+ @stream.push "foo"
+ assert_match(/(['"])foo\1/, @io.string)
+ end
+
+ def test_symbol
+ @stream.push :foo
+ assert_match(/(['"])foo\1/, @io.string)
+ end
+
+ def test_int
+ @stream.push 10
+ assert_match(/^--- 10/, @io.string)
+ end
+
+ def test_float
+ @stream.push 1.2
+ assert_match(/^--- 1.2/, @io.string)
+ end
+
+ def test_hash
+ hash = { 'one' => 'two' }
+ @stream.push hash
+
+ json = @io.string
+ assert_match(/}$/, json)
+ assert_match(/^--- \{/, json)
+ assert_match(/['"]one['"]/, json)
+ assert_match(/['"]two['"]/, json)
+ end
+
+ def test_list_to_json
+ list = %w{ one two }
+ @stream.push list
+
+ json = @io.string
+ assert_match(/]$/, json)
+ assert_match(/^--- \[/, json)
+ assert_match(/['"]one['"]/, json)
+ assert_match(/['"]two['"]/, json)
+ end
+ end
+ end
+end