2010-03-28 17:49:37 -04:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2013-03-26 10:55:04 -04:00
|
|
|
require_relative 'helper'
|
2010-03-28 17:49:37 -04:00
|
|
|
|
|
|
|
module Psych
|
|
|
|
class TestEmitter < TestCase
|
|
|
|
def setup
|
|
|
|
super
|
2010-03-31 02:33:45 -04:00
|
|
|
@out = StringIO.new('')
|
2010-03-28 17:49:37 -04:00
|
|
|
@emitter = Psych::Emitter.new @out
|
|
|
|
end
|
|
|
|
|
2010-07-08 12:02:26 -04:00
|
|
|
def test_line_width
|
2014-10-31 15:37:38 -04:00
|
|
|
@emitter.line_width = 10
|
2010-07-08 12:02:26 -04:00
|
|
|
assert_equal 10, @emitter.line_width
|
|
|
|
end
|
|
|
|
|
2010-03-28 17:49:37 -04:00
|
|
|
def test_set_canonical
|
|
|
|
@emitter.canonical = true
|
|
|
|
assert_equal true, @emitter.canonical
|
|
|
|
|
|
|
|
@emitter.canonical = false
|
|
|
|
assert_equal false, @emitter.canonical
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_indentation_set
|
|
|
|
assert_equal 2, @emitter.indentation
|
|
|
|
@emitter.indentation = 5
|
|
|
|
assert_equal 5, @emitter.indentation
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_emit_utf_8
|
|
|
|
@emitter.start_stream Psych::Nodes::Stream::UTF8
|
|
|
|
@emitter.start_document [], [], false
|
|
|
|
@emitter.scalar '日本語', nil, nil, false, true, 1
|
|
|
|
@emitter.end_document true
|
|
|
|
@emitter.end_stream
|
|
|
|
assert_match('日本語', @out.string)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_start_stream_arg_error
|
|
|
|
assert_raises(TypeError) do
|
|
|
|
@emitter.start_stream 'asdfasdf'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_start_doc_arg_error
|
|
|
|
@emitter.start_stream Psych::Nodes::Stream::UTF8
|
|
|
|
|
|
|
|
[
|
|
|
|
[nil, [], false],
|
|
|
|
[[nil, nil], [], false],
|
|
|
|
[[], 'foo', false],
|
|
|
|
[[], ['foo'], false],
|
|
|
|
[[], [nil,nil], false],
|
|
|
|
].each do |args|
|
|
|
|
assert_raises(TypeError) do
|
|
|
|
@emitter.start_document(*args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_scalar_arg_error
|
|
|
|
@emitter.start_stream Psych::Nodes::Stream::UTF8
|
|
|
|
@emitter.start_document [], [], false
|
|
|
|
|
|
|
|
[
|
|
|
|
[:foo, nil, nil, false, true, 1],
|
|
|
|
['foo', Object.new, nil, false, true, 1],
|
|
|
|
['foo', nil, Object.new, false, true, 1],
|
|
|
|
['foo', nil, nil, false, true, :foo],
|
2010-05-19 13:15:27 -04:00
|
|
|
[nil, nil, nil, false, true, 1],
|
2010-03-28 17:49:37 -04:00
|
|
|
].each do |args|
|
|
|
|
assert_raises(TypeError) do
|
|
|
|
@emitter.scalar(*args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_start_sequence_arg_error
|
|
|
|
@emitter.start_stream Psych::Nodes::Stream::UTF8
|
|
|
|
@emitter.start_document [], [], false
|
|
|
|
|
|
|
|
assert_raises(TypeError) do
|
|
|
|
@emitter.start_sequence(nil, Object.new, true, 1)
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_raises(TypeError) do
|
|
|
|
@emitter.start_sequence(nil, nil, true, :foo)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|