forked from maik/xml-simple
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtc_out.rb
executable file
·121 lines (110 loc) · 2.55 KB
/
tc_out.rb
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
$: << File.join(File.dirname(__FILE__), '../lib')
require 'test/unit'
require 'xmlsimple'
class TC_Out < Test::Unit::TestCase # :nodoc:
def test_simple_structure
hash = {
'opt' => [
{
'x' => [ { 'content'=> 'text1'} ],
'y' => [ { 'content'=> 'text2'} ]
}
]
}
expected = <<"END_OF_XML"
<opt>
<opt>
<x>text1</x>
<y>text2</y>
</opt>
</opt>
END_OF_XML
assert_equal(expected, XmlSimple.xml_out(hash))
end
def test_keep_root
hash = {
'opt' => [
{
'x' => [ { 'content'=> 'text1'} ],
'y' => [ { 'content'=> 'text2'} ]
}
]
}
expected = <<"END_OF_XML"
<opt>
<x>text1</x>
<y>text2</y>
</opt>
END_OF_XML
assert_equal(expected, XmlSimple.xml_out(hash, { 'keep_root' => true }))
end
def test_original
hash = {
'logdir' => '/var/log/foo/',
'debugfile' => '/tmp/foo.debug',
'server' => {
'sahara' => {
'osversion' => '2.6',
'osname' => 'solaris',
'address' => [ '10.0.0.101', '10.0.1.101' ]
},
'gobi' => {
'osversion' => '6.5',
'osname' => 'irix',
'address' => '10.0.0.102'
},
'kalahari' => {
'osversion' => '2.0.34',
'osname' => 'linux',
'address' => [ '10.0.0.103', '10.0.1.103' ]
}
}
}
#puts XmlSimple.xml_out(hash)
end
def test_xyz
hash = {
'abc' => [
{
'z' => ['ZZZ', {}, {}]
}
],
'b' => [
{
'c' => ['Eins', 'Eins', 'Zwei']
},
{
'c' => [
'Drei',
'Zwei',
{ 'd' => [ 'yo' ] }
]
}
],
'xyz' => [ 'Hallo' ],
'att' => [ { 'test' => '42' } ],
'att2' => [ { 'test' => '4711', 'content' => 'CONTENT' } ],
'element' => [
{
'att' => '1',
'content' => 'one'
},
{
'att' => '2',
'content' => 'two'
},
{
'att' => '3',
'content' => 'three'
},
],
}
#puts XmlSimple.xml_out(hash)
end
def test_output_with_symbols
test1 = { :foo => 'abc' }
expected = "<opt foo=\"abc\" />\n"
output = XmlSimple.xml_out(test1)
assert_equal(output, expected)
end
end