diff options
author | Jari Vetoniemi <jari.vetoniemi@indooratlas.com> | 2020-03-16 18:49:26 +0900 |
---|---|---|
committer | Jari Vetoniemi <jari.vetoniemi@indooratlas.com> | 2020-03-30 00:39:06 +0900 |
commit | fcbf63e62c627deae76c1b8cb8c0876c536ed811 (patch) | |
tree | 64cb17de3f41a2b6fef2368028fbd00349946994 /jni/ruby/test/psych/test_stream.rb |
Fresh start
Diffstat (limited to 'jni/ruby/test/psych/test_stream.rb')
-rw-r--r-- | jni/ruby/test/psych/test_stream.rb | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/jni/ruby/test/psych/test_stream.rb b/jni/ruby/test/psych/test_stream.rb new file mode 100644 index 0000000..7e41178 --- /dev/null +++ b/jni/ruby/test/psych/test_stream.rb @@ -0,0 +1,93 @@ +require_relative 'helper' + +module Psych + class TestStream < TestCase + def test_parse_partial + rb = Psych.parse("--- foo\n...\n--- `").to_ruby + assert_equal 'foo', rb + end + + def test_load_partial + rb = Psych.load("--- foo\n...\n--- `") + assert_equal 'foo', rb + end + + def test_parse_stream_yields_documents + list = [] + Psych.parse_stream("--- foo\n...\n--- bar") do |doc| + list << doc.to_ruby + end + assert_equal %w{ foo bar }, list + end + + def test_parse_stream_break + list = [] + Psych.parse_stream("--- foo\n...\n--- `") do |doc| + list << doc.to_ruby + break + end + assert_equal %w{ foo }, list + end + + def test_load_stream_yields_documents + list = [] + Psych.load_stream("--- foo\n...\n--- bar") do |ruby| + list << ruby + end + assert_equal %w{ foo bar }, list + end + + def test_load_stream_break + list = [] + Psych.load_stream("--- foo\n...\n--- `") do |ruby| + list << ruby + break + end + assert_equal %w{ foo }, list + end + + def test_explicit_documents + io = StringIO.new + stream = Psych::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_start_takes_block + io = StringIO.new + stream = Psych::Stream.new(io) + stream.start do |emitter| + emitter.push({ 'foo' => 'bar' }) + end + + assert stream.finished?, 'stream finished' + assert_match(/^---/, io.string) + assert_match(/\.\.\.$/, io.string) + end + + def test_no_backreferences + io = StringIO.new + stream = Psych::Stream.new(io) + stream.start do |emitter| + x = { 'foo' => 'bar' } + emitter.push x + emitter.push x + end + + assert stream.finished?, 'stream finished' + assert_match(/^---/, io.string) + assert_match(/\.\.\.$/, io.string) + assert_equal 2, io.string.scan('---').length + assert_equal 2, io.string.scan('...').length + assert_equal 2, io.string.scan('foo').length + assert_equal 2, io.string.scan('bar').length + end + end +end |