blob: c7caf47c8758695acdd865ca3fa55f64437c24a4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
require 'minitest/autorun'
require 'psych'
module Psych
module Visitors
class TestToRuby < MiniTest::Unit::TestCase
def setup
@visitor = ToRuby.new
end
def test_scalar
scalar = Nodes::Scalar.new('foo')
assert_equal 'foo', @visitor.accept(scalar)
assert_equal 'foo', scalar.to_ruby
end
def test_sequence
seq = Nodes::Sequence.new
seq.children << Nodes::Scalar.new('foo')
seq.children << Nodes::Scalar.new('bar')
assert_equal %w{ foo bar }, seq.to_ruby
end
def test_mapping
mapping = Nodes::Mapping.new
mapping.children << Nodes::Scalar.new('foo')
mapping.children << Nodes::Scalar.new('bar')
assert_equal({'foo' => 'bar'}, mapping.to_ruby)
end
def test_document
doc = Nodes::Document.new
doc.children << Nodes::Scalar.new('foo')
assert_equal 'foo', doc.to_ruby
end
def test_stream
a = Nodes::Document.new
a.children << Nodes::Scalar.new('foo')
b = Nodes::Document.new
b.children << Nodes::Scalar.new('bar')
stream = Nodes::Stream.new
stream.children << a
stream.children << b
assert_equal %w{ foo bar }, stream.to_ruby
end
end
end
end
|