ixyml 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. data/.gitignore +19 -0
  2. data/.gitignore~ +17 -0
  3. data/Gemfile +12 -0
  4. data/Gemfile.lock +44 -0
  5. data/Gemfile~ +13 -0
  6. data/LICENSE +22 -0
  7. data/README.md +29 -0
  8. data/Rakefile +2 -0
  9. data/bin/dbg_x2o +8 -0
  10. data/bin/x2y +8 -0
  11. data/bin/y2x +17 -0
  12. data/ixyml.gemspec +23 -0
  13. data/lib/ixyml.rb +10 -0
  14. data/lib/ixyml/version.rb +3 -0
  15. data/lib/ixyml/xyml.rb +821 -0
  16. data/lib/ixyml/xyml_element.rb +778 -0
  17. data/test/dirTemp/ktest00.nml.j2j.json +1 -0
  18. data/test/dirTemp/ktest00.nml.nml.xml +53 -0
  19. data/test/dirTemp/ktest00.nml.nml.yaml +74 -0
  20. data/test/dirTemp/ktest00.nml.x2j.json +1 -0
  21. data/test/dirTemp/ktest00.nml.x2x.xml +53 -0
  22. data/test/dirTemp/ktest00.nml.xyj.yaml +134 -0
  23. data/test/dirTemp/ktest00.nml.xyx.xml +53 -0
  24. data/test/dirTemp/ktest00.nml.xyx.yaml +134 -0
  25. data/test/dirTemp/ktest00.nml.y2j.json +1 -0
  26. data/test/dirTemp/ktest00.nml.y2y.yaml +74 -0
  27. data/test/dirTemp/ktest00.nml.yxy.xml +2 -0
  28. data/test/dirTemp/ktest00.nml.yxy.yaml +74 -0
  29. data/test/dirTemp/ktest01.nml.yaml +74 -0
  30. data/test/dirTemp/ktest01.yxy.xml +2 -0
  31. data/test/dirTemp/ktest01.yxy.yaml +74 -0
  32. data/test/dirTemp/test01.nml.nml.xml +21 -0
  33. data/test/dirTemp/test01.nml.nml.yaml +5 -0
  34. data/test/dirTemp/test01.nml.x2j.json +1 -0
  35. data/test/dirTemp/test01.nml.x2x.xml +21 -0
  36. data/test/dirTemp/test01.nml.xyj.yaml +18 -0
  37. data/test/dirTemp/test01.nml.xyx.xml +21 -0
  38. data/test/dirTemp/test01.nml.xyx.yaml +18 -0
  39. data/test/dirTemp/test01.nml.y2j.json +1 -0
  40. data/test/dirTemp/test01.nml.y2y.yaml +5 -0
  41. data/test/dirTemp/test01.nml.yaml +74 -0
  42. data/test/dirTemp/test01.nml.yxy.xml +3 -0
  43. data/test/dirTemp/test01.nml.yxy.yaml +5 -0
  44. data/test/dirTemp/test01.yxy.xml +2 -0
  45. data/test/dirTemp/test01.yxy.yaml +74 -0
  46. data/test/dirTemp/testBreak.nml.yaml +7 -0
  47. data/test/dirTemp/testBreak.yxy.xml +5 -0
  48. data/test/dirTemp/testBreak.yxy.yaml +7 -0
  49. data/test/dirTemp/testCDATA.nml.nml.xml +26 -0
  50. data/test/dirTemp/testCDATA.nml.x2j.json +1 -0
  51. data/test/dirTemp/testCDATA.nml.x2x.xml +26 -0
  52. data/test/dirTemp/testCDATA.nml.xyj.yaml +18 -0
  53. data/test/dirTemp/testCDATA.nml.xyx.xml +26 -0
  54. data/test/dirTemp/testCDATA.nml.xyx.yaml +18 -0
  55. data/test/dirTemp/testCDATA.nml.y2j.json +1 -0
  56. data/test/dirTemp/testEscape.nml.nml.xml +77 -0
  57. data/test/dirTemp/testEscape.nml.nml.yaml +53 -0
  58. data/test/dirTemp/testEscape.nml.x2j.json +1 -0
  59. data/test/dirTemp/testEscape.nml.x2x.xml +77 -0
  60. data/test/dirTemp/testEscape.nml.xyj.yaml +213 -0
  61. data/test/dirTemp/testEscape.nml.xyx.xml +77 -0
  62. data/test/dirTemp/testEscape.nml.xyx.yaml +213 -0
  63. data/test/dirTemp/testEscape.nml.y2j.json +1 -0
  64. data/test/dirTemp/testEscape.nml.y2y.yaml +53 -0
  65. data/test/dirTemp/testEscape.nml.yxy.xml +2 -0
  66. data/test/dirTemp/testEscape.nml.yxy.yaml +53 -0
  67. data/test/dirTemp/testNS.nml.nml.xml +21 -0
  68. data/test/dirTemp/testNS.nml.x2j.json +1 -0
  69. data/test/dirTemp/testNS.nml.x2x.xml +21 -0
  70. data/test/dirTemp/testNS.nml.xyj.yaml +19 -0
  71. data/test/dirTemp/testNS.nml.xyx.xml +21 -0
  72. data/test/dirTemp/testNS.nml.xyx.yaml +19 -0
  73. data/test/dirTemp/testNS.nml.y2j.json +1 -0
  74. data/test/test_xyml.rb +167 -0
  75. data/test/test_xyml.rb~ +167 -0
  76. data/test/test_xyml_element.rb +241 -0
  77. data/test/test_xyml_element.rb~ +111 -0
  78. data/test/testfiles/ktest00.nml.ori.json +1 -0
  79. data/test/testfiles/ktest00.nml.ori.xml +53 -0
  80. data/test/testfiles/ktest00.nml.ori.yaml +74 -0
  81. data/test/testfiles/ktest00.nml.ori.yaml~ +75 -0
  82. data/test/testfiles/ktest01.ori.yaml +75 -0
  83. data/test/testfiles/test01.nml.ori.xml +21 -0
  84. data/test/testfiles/test01.nml.ori.yaml +5 -0
  85. data/test/testfiles/test01.ori.yaml +75 -0
  86. data/test/testfiles/testBreak.ori.yaml +10 -0
  87. data/test/testfiles/testCDATA.ng.ng.xml +26 -0
  88. data/test/testfiles/testEscape.nml.ori.xml +77 -0
  89. data/test/testfiles/testEscape.nml.ori.yaml +105 -0
  90. data/test/testfiles/testNS.nml.ori.xml +21 -0
  91. data/test/testfiles/xmlTemp.xml +2 -0
  92. data/test/testfiles/xymlTemp.xyml +6 -0
  93. metadata +230 -0
@@ -0,0 +1 @@
1
+ [{"quiz":["\n",{"group1":["\n",{"e":["-"]},"\n",{"e":["?a"]},"\n",{"e":["aa?"]},"\n",{"e":["?"]},"\n",{"e":["a:"]},"\n",{"e":[":a"]},"\n",{"e":[":"]},"\n",{"e":["a:a"]},"\n",{"e":["a:a:"]},"\n",{"e":["a,"]},"\n",{"e":["a["]},"\n",{"e":["a]"]},"\n",{"e":["[]"]},"\n",{"e":["["]},"\n",{"e":["]"]},"\n",{"e":["a{"]},"\n",{"e":["a}"]},"\n",{"e":["{}"]},"\n",{"e":["{"]},"\n",{"e":["}"]},"\n",{"e":["@"]},"\n",{"e":["#"]},"\n",{"e":["a &"]},"\n",{"e":["!"]},"\n",{"e":["<"]},"\n",{"e":[">"]},"\n",{"e":["'"]},"\n",{"e":["\"'\""]},"\n",{"e":["\"\""]},"\n",{"e":["'\"'"]},"\n",{"e":["\\"]},"\n",{"e":["\\:"]},"\n",{"e":["\"aa\\\"aa\""]},"\n",{"e":["\"\\\"\""]},"\n",{"e":["%"]},"\n",{"e":["`"]},"\n",{"e":["&"]},"\n"]},"\n",{"group2":["\n",{"e":[{"a00":""}]},"\n",{"e":[{"a01":"-"}]},"\n",{"e":[{"a02":"?"}]},"\n",{"e":[{"a03":","}]},"\n",{"e":[{"a04":"["}]},"\n",{"e":[{"a05":"]"}]},"\n",{"e":[{"a06":"{"}]},"\n",{"e":[{"a07":"}"}]},"\n",{"e":[{"a08":"@"}]},"\n",{"e":[{"a09":"before#after"}]},"\n",{"e":[{"a10":"&"}]},"\n",{"e":[{"a11":"!"}]},"\n",{"e":[{"a12":"<"}]},"\n",{"e":[{"a13":">"}]},"\n",{"e":[{"a14":"\""}]},"\n",{"e":[{"a15":"'"}]},"\n",{"e":[{"a16":"\"'\""}]},"\n",{"e":[{"a17":"\"\""}]},"\n",{"e":[{"a18":"'\"'"}]},"\n",{"e":[{"a19":"\\"}]},"\n",{"e":[{"a20":"\\:"}]},"\n",{"e":[{"a21":"\"aa\\\"aa\""}]},"\n",{"e":[{"a22":"\"\\\"\""}]},"\n",{"e":[{"a23":"%"}]},"\n",{"e":[{"a24":"`"}]},"\n",{"e":[{"a25":"\n"}]},"\n",{"e":[{"a26":"\n\ta"}]},"\n",{"e":[{"a27":"\t"}]},"\n",{"e":[{"a28":"\ta\t"}]},"\n",{"e":[{"a29":"\\t"}]},"\n",{"e":[{"a30":"\\n"}]},"\n"]},"\n"]}]
@@ -0,0 +1,53 @@
1
+ ---
2
+ - quiz:
3
+ - group1:
4
+ - text:
5
+ - "abc: deedfadsfads"
6
+ - text:
7
+ - -a
8
+ - text:
9
+ - ?a
10
+ - text:
11
+ - aa?
12
+ - text:
13
+ - a,
14
+ - text:
15
+ - a[
16
+ - text:
17
+ - a]
18
+ - text:
19
+ - a}
20
+ - text:
21
+ - a@
22
+ - text:
23
+ - before1#after1
24
+ - test:
25
+ - a &
26
+ - text:
27
+ - a !
28
+ - text:
29
+ - a <
30
+ - text:
31
+ - a >
32
+ - test:
33
+ - a '
34
+ - test:
35
+ - "'"
36
+ - test:
37
+ - "aa\"aa"
38
+ - test:
39
+ - "\""
40
+ - text:
41
+ - a%
42
+ - text:
43
+ - a`
44
+ - text3:
45
+ - a00: attribute
46
+ - a01:
47
+ - a02: a-
48
+ - a03: ?a
49
+ - a04: aa?
50
+ - a10: a,
51
+ - a11: a[
52
+ - a13: a]
53
+ - a15: a}
@@ -0,0 +1,2 @@
1
+ <?xml version='1.0' encoding='UTF-8'?>
2
+ <quiz><group1><text>abc: deedfadsfads</text><text>-a</text><text>?a</text><text>aa?</text><text>a,</text><text>a[</text><text>a]</text><text>a}</text><text>a@</text><text>before1#after1</text><test>a &amp;</test><text>a !</text><text>a &lt;</text><text>a &gt;</text><test>a &apos;</test><test>&apos;</test><test>aa&quot;aa</test><test>&quot;</test><text>a%</text><text>a`</text><text3 a00='attribute' a01='' a02='a-' a03='?a' a04='aa?' a10='a,' a11='a[' a13='a]' a15='a}'/></group1></quiz>
@@ -0,0 +1,53 @@
1
+ ---
2
+ - quiz:
3
+ - group1:
4
+ - text:
5
+ - "abc: deedfadsfads"
6
+ - text:
7
+ - -a
8
+ - text:
9
+ - ?a
10
+ - text:
11
+ - aa?
12
+ - text:
13
+ - a,
14
+ - text:
15
+ - a[
16
+ - text:
17
+ - a]
18
+ - text:
19
+ - a}
20
+ - text:
21
+ - a@
22
+ - text:
23
+ - before1#after1
24
+ - test:
25
+ - a &
26
+ - text:
27
+ - a !
28
+ - text:
29
+ - a <
30
+ - text:
31
+ - a >
32
+ - test:
33
+ - a '
34
+ - test:
35
+ - "'"
36
+ - test:
37
+ - "aa\"aa"
38
+ - test:
39
+ - "\""
40
+ - text:
41
+ - a%
42
+ - text:
43
+ - a`
44
+ - text3:
45
+ - a00: attribute
46
+ - a01:
47
+ - a02: a-
48
+ - a03: ?a
49
+ - a04: aa?
50
+ - a10: a,
51
+ - a11: a[
52
+ - a13: a]
53
+ - a15: a}
@@ -0,0 +1,21 @@
1
+ <?xml version='1.0' encoding='UTF-8'?>
2
+ <quiz xmlns:hnd=''>
3
+ <hnd:group1>
4
+ <hnd:text1>
5
+ abcdefg
6
+ hijklmnopq
7
+ rstuvwxyz
8
+ </hnd:text1>
9
+ <hnd:text2>
10
+ abcdefg
11
+ hijklmnopq
12
+ rstuvwxyz
13
+ </hnd:text2>
14
+ </hnd:group1>
15
+ <hnd:group2>
16
+ <hnd:text1>
17
+ abcdefg
18
+ hijklmnopq
19
+ </hnd:text1>
20
+ </hnd:group2>
21
+ </quiz>
@@ -0,0 +1 @@
1
+ [{"quiz":[{"xmlns:hnd":""},"\n ",{"hnd:group1":["\n ",{"hnd:text1":["\n abcdefg\n hijklmnopq\n rstuvwxyz\n "]},"\n ",{"hnd:text2":["\nabcdefg\nhijklmnopq\nrstuvwxyz\n "]},"\n "]},"\n ",{"hnd:group2":["\n ",{"hnd:text1":["\n abcdefg\n hijklmnopq\n "]},"\n "]},"\n"]}]
@@ -0,0 +1,21 @@
1
+ <?xml version='1.0' encoding='UTF-8'?>
2
+ <quiz xmlns:hnd=''>
3
+ <hnd:group1>
4
+ <hnd:text1>
5
+ abcdefg
6
+ hijklmnopq
7
+ rstuvwxyz
8
+ </hnd:text1>
9
+ <hnd:text2>
10
+ abcdefg
11
+ hijklmnopq
12
+ rstuvwxyz
13
+ </hnd:text2>
14
+ </hnd:group1>
15
+ <hnd:group2>
16
+ <hnd:text1>
17
+ abcdefg
18
+ hijklmnopq
19
+ </hnd:text1>
20
+ </hnd:group2>
21
+ </quiz>
@@ -0,0 +1,19 @@
1
+ ---
2
+ - quiz:
3
+ - xmlns:hnd:
4
+ - "\n "
5
+ - hnd:group1:
6
+ - "\n "
7
+ - hnd:text1:
8
+ - "\n abcdefg\n hijklmnopq\n rstuvwxyz\n "
9
+ - "\n "
10
+ - hnd:text2:
11
+ - "\nabcdefg\nhijklmnopq\nrstuvwxyz\n "
12
+ - "\n "
13
+ - "\n "
14
+ - hnd:group2:
15
+ - "\n "
16
+ - hnd:text1:
17
+ - "\n abcdefg\n hijklmnopq\n "
18
+ - "\n "
19
+ - "\n"
@@ -0,0 +1,21 @@
1
+ <?xml version='1.0' encoding='UTF-8'?>
2
+ <quiz xmlns:hnd=''>
3
+ <hnd:group1>
4
+ <hnd:text1>
5
+ abcdefg
6
+ hijklmnopq
7
+ rstuvwxyz
8
+ </hnd:text1>
9
+ <hnd:text2>
10
+ abcdefg
11
+ hijklmnopq
12
+ rstuvwxyz
13
+ </hnd:text2>
14
+ </hnd:group1>
15
+ <hnd:group2>
16
+ <hnd:text1>
17
+ abcdefg
18
+ hijklmnopq
19
+ </hnd:text1>
20
+ </hnd:group2>
21
+ </quiz>
@@ -0,0 +1,19 @@
1
+ ---
2
+ - quiz:
3
+ - xmlns:hnd:
4
+ - "\n "
5
+ - hnd:group1:
6
+ - "\n "
7
+ - hnd:text1:
8
+ - "\n abcdefg\n hijklmnopq\n rstuvwxyz\n "
9
+ - "\n "
10
+ - hnd:text2:
11
+ - "\nabcdefg\nhijklmnopq\nrstuvwxyz\n "
12
+ - "\n "
13
+ - "\n "
14
+ - hnd:group2:
15
+ - "\n "
16
+ - hnd:text1:
17
+ - "\n abcdefg\n hijklmnopq\n "
18
+ - "\n "
19
+ - "\n"
@@ -0,0 +1 @@
1
+ [{"quiz":[{"xmlns:hnd":""},"\n ",{"hnd:group1":["\n ",{"hnd:text1":["\n abcdefg\n hijklmnopq\n rstuvwxyz\n "]},"\n ",{"hnd:text2":["\nabcdefg\nhijklmnopq\nrstuvwxyz\n "]},"\n "]},"\n ",{"hnd:group2":["\n ",{"hnd:text1":["\n abcdefg\n hijklmnopq\n "]},"\n "]},"\n"]}]
@@ -0,0 +1,167 @@
1
+ require 'test/unit'
2
+ require 'shoulda'
3
+ require_relative '../lib/ixyml/xyml'
4
+
5
+ class TestDocument < Test::Unit::TestCase
6
+
7
+ fileDir="test/testfiles/"
8
+ tempDir="test/dirTemp/"
9
+
10
+ should ". No differences between loaded xml file and saved xml file" do
11
+ Dir.glob(fileDir+"*.nml.ori.xml") do |fn|
12
+ print "###xml->xml### fn="+fn+"\n"
13
+ xyml=Xyml::Document.new
14
+ fnout=fn.sub(/ori.xml/,'x2x.xml').sub(fileDir,tempDir)
15
+ #p "fn=#{fn},fnout=#{fnout}"
16
+ xyml.load_XML(File.open(fn))
17
+ #p "#D#test_xyml.rb:x2x:loaded dom=";dom_print_rcsv(xyml.get_DOM,0)
18
+ #p "#D#test_xml.rb:xml->xml:xyml=";pp xyml
19
+ xyml.out_XML(File.open(fnout,'w'))
20
+ #p "fnout=#{fnout}"
21
+ #pp open(fnout).readlines
22
+ diff = open(fn).readlines - open(fnout).readlines
23
+ assert_equal([],diff)
24
+ diff = open(fnout).readlines - open(fn).readlines
25
+ assert_equal([],diff)
26
+ end
27
+ end
28
+
29
+ should ". No differences between loaded yaml file and saved yaml file" do
30
+ Dir.glob(fileDir+"*.nml.ori.yaml") do |fn|
31
+ print "###yaml->yaml### fn="+fn+"\n"
32
+ xyml=Xyml::Document.new
33
+ fnout=fn.sub(/ori.yaml/,'y2y.yaml').sub(fileDir,tempDir)
34
+ xyml.load_XYML(File.open(fn))
35
+ #p "#D#test_xyml.rb:yaml->yaml:xyml=";pp xyml
36
+ xyml.out_XYML(File.open(fnout,'w'))
37
+ diff = open(fn).readlines - open(fnout).readlines
38
+ diff = diff.find_all {|str| !str.start_with?('#')}
39
+ assert_equal([],diff)
40
+ diff = open(fnout).readlines - open(fn).readlines
41
+ assert_equal([],diff)
42
+ end
43
+ end
44
+
45
+ should ". No differences between loaded yaml file and saved yaml -> xml -> yaml file" do
46
+ Dir.glob(fileDir+"*.ori.yaml") do |fn|
47
+ print "###yaml->xml->yaml### fn="+fn+"\n"
48
+ xyml=Xyml::Document.new
49
+ fnoutT=fn.sub(/ori.yaml/,'nml.yaml').sub(fileDir,tempDir)
50
+ fnoutX=fn.sub(/ori.yaml/,'yxy.xml').sub(fileDir,tempDir)
51
+ fnoutY=fn.sub(/ori.yaml/,'yxy.yaml').sub(fileDir,tempDir)
52
+ xyml.load_XYML(File.open(fn))
53
+ #p "#D#tst_xml.rb:yaml->xml->yaml: yaml loaded.";pp xyml
54
+ xyml.out_XYML_standard(File.open(fnoutT,'w'))
55
+ xyml.load_XYML(File.open(fnoutT))
56
+ #p "#D#tst_xml.rb:yaml->xml->yaml: yaml loaded.";pp xyml
57
+ xyml.out_XML(File.open(fnoutX,'w'))
58
+ xyml.load_XML(File.open(fnoutX))
59
+ #p "#D#tst_xml.rb:yaml->xml->yaml: xml loaded.";pp xyml
60
+ xyml.out_XYML(File.open(fnoutY,'w'))
61
+ diff = open(fnoutT).readlines - open(fnoutY).readlines
62
+ assert_equal([],diff)
63
+ diff = open(fnoutY).readlines - open(fnoutT).readlines
64
+ assert_equal([],diff)
65
+ end
66
+ end
67
+
68
+ should ". No differences between loaded xml file and saved xml -> yaml -> xml file" do
69
+ Dir.glob(fileDir+"*.ori.xml") do |fn|
70
+ print "###xml->yaml->xml### fn="+fn+"\n"
71
+ xyml=Xyml::Document.new
72
+ fnoutT=fn.sub(/ori.xml/,'nml.xml').sub(fileDir,tempDir)
73
+ fnoutX=fn.sub(/ori.xml/,'xyx.xml').sub(fileDir,tempDir)
74
+ fnoutY=fn.sub(/ori.xml/,'xyx.yaml').sub(fileDir,tempDir)
75
+ xyml.load_XML(File.open(fn))
76
+ #pp xyml
77
+ xyml.out_XML(File.open(fnoutT,'w'))
78
+ xyml.load_XML(File.open(fnoutT))
79
+ #p "#D#test_xyml.rb:xml->yaml->xml: xml loaded.fn=#{fnoutT}";pp xyml
80
+ xyml.out_XYML(File.open(fnoutY,'w'))
81
+ xyml.load_XYML(File.open(fnoutY))
82
+ #p "#D#test_xyml.rb:xml->yaml->xml: yaml loaded.fn=#{fnoutY}";pp xyml
83
+ xyml.out_XML(File.open(fnoutX,'w'))
84
+ diff = open(fnoutT).readlines - open(fnoutX).readlines
85
+ assert_equal([],diff)
86
+ diff = open(fnoutX).readlines - open(fnoutT).readlines
87
+ assert_equal([],diff)
88
+ end
89
+ end
90
+
91
+ should ". No differences between json file transfered from xml file and json file transfered from yaml file." do
92
+ Dir.glob(fileDir+"*.ori.xml") do |fn|
93
+ print "###xml->json,xml->yaml->json### fn="+fn+"\n"
94
+ xyml=Xyml::Document.new
95
+ fnoutT=fn.sub(/ori.xml/,'nml.xml').sub(fileDir,tempDir)
96
+ fnoutY=fn.sub(/ori.xml/,'xyj.yaml').sub(fileDir,tempDir)
97
+ fnoutXJ=fn.sub(/ori.xml/,'x2j.json').sub(fileDir,tempDir)
98
+ fnoutYJ=fn.sub(/ori.xml/,'y2j.json').sub(fileDir,tempDir)
99
+ xyml.load_XML(File.open(fn))
100
+ #pp xyml
101
+ xyml.out_XML(File.open(fnoutT,'w'))
102
+ xyml.load_XML(File.open(fnoutT))
103
+ #p "#D#test_xyml.rb:xml->yaml->json: xml loaded.fn=#{fnoutY}";pp xyml
104
+ xyml.out_JSON(File.open(fnoutXJ,'w'))
105
+ xyml.out_XYML(File.open(fnoutY,'w'))
106
+ xyml.load_XYML(File.open(fnoutY))
107
+ #p "#D#test_xyml.rb:xml->yaml->json: yaml loaded.fn=#{fnoutY}";pp xyml
108
+ # order of array elements in ruby objects changed from order in yaml. ????
109
+ xyml.out_JSON(File.open(fnoutYJ,'w'))
110
+ diff = open(fnoutXJ).readlines - open(fnoutYJ).readlines
111
+ assert_equal([],diff)
112
+ diff = open(fnoutYJ).readlines - open(fnoutXJ).readlines
113
+ assert_equal([],diff)
114
+ end
115
+ end
116
+
117
+ should ". No differences between loaded json file and saved json file" do
118
+ Dir.glob(fileDir+"*.nml.ori.json") do |fn|
119
+ print "###json->json### fn="+fn+"\n"
120
+ xyml=Xyml::Document.new
121
+ fnout=fn.sub(/ori.json/,'j2j.json').sub(fileDir,tempDir)
122
+ #p "fn=#{fn},fnout=#{fnout}"
123
+ xyml.load_XYML(File.open(fn))
124
+ #p "#D#test_xyml.rb:x2x:loaded dom=";dom_print_rcsv(xyml.get_DOM,0)
125
+ #p "#D#test_xml.rb:xml->xml:xyml=";pp xyml
126
+ xyml.out_JSON(File.open(fnout,'w'))
127
+ #p "fnout=#{fnout}"
128
+ #pp open(fnout).readlines
129
+ diff = open(fn).readlines - open(fnout).readlines
130
+ assert_equal([],diff)
131
+ diff = open(fnout).readlines - open(fn).readlines
132
+ assert_equal([],diff)
133
+ end
134
+ end
135
+
136
+
137
+ private
138
+
139
+ Indent="||"
140
+
141
+ def dom_print_rcsv elem,nest
142
+ print "================================\n"
143
+ print Indent*nest + "name : #{elem.name}\n"
144
+ attrs = elem.attributes
145
+ attrs.each{|a,e|
146
+ print Indent*nest + "attr :#{a}=#{e}\n"
147
+ }
148
+ print Indent*nest + "text : \n-->#{elem.text.to_s.gsub("\s",'_').gsub("\t",'\t')}<--\n"
149
+
150
+ elem.each do |node|
151
+ if node.is_a?(REXML::Element)
152
+ dom_print_rcsv node,nest+1
153
+ elsif node.is_a?(REXML::Text)
154
+ text=node.to_s
155
+ print Indent*nest + "textnode : \n-->#{text.gsub("\s",'_').gsub("\t",'\t')}<--\n"
156
+ end
157
+ end
158
+
159
+
160
+ #if elem.has_elements? then
161
+ # elem.each_element{|e|
162
+ # dom_print_rcsv e,nest+1
163
+ # }
164
+ #end
165
+ end
166
+
167
+ end
@@ -0,0 +1,167 @@
1
+ require 'test/unit'
2
+ require 'shoulda'
3
+ require_relative '../lib/xyml/xyml'
4
+
5
+ class TestDocument < Test::Unit::TestCase
6
+
7
+ fileDir="test/testfiles/"
8
+ tempDir="test/dirTemp/"
9
+
10
+ should ". No differences between loaded xml file and saved xml file" do
11
+ Dir.glob(fileDir+"*.nml.ori.xml") do |fn|
12
+ print "###xml->xml### fn="+fn+"\n"
13
+ xyml=Xyml::Document.new
14
+ fnout=fn.sub(/ori.xml/,'x2x.xml').sub(fileDir,tempDir)
15
+ #p "fn=#{fn},fnout=#{fnout}"
16
+ xyml.load_XML(File.open(fn))
17
+ #p "#D#test_xyml.rb:x2x:loaded dom=";dom_print_rcsv(xyml.get_DOM,0)
18
+ #p "#D#test_xml.rb:xml->xml:xyml=";pp xyml
19
+ xyml.out_XML(File.open(fnout,'w'))
20
+ #p "fnout=#{fnout}"
21
+ #pp open(fnout).readlines
22
+ diff = open(fn).readlines - open(fnout).readlines
23
+ assert_equal([],diff)
24
+ diff = open(fnout).readlines - open(fn).readlines
25
+ assert_equal([],diff)
26
+ end
27
+ end
28
+
29
+ should ". No differences between loaded yaml file and saved yaml file" do
30
+ Dir.glob(fileDir+"*.nml.ori.yaml") do |fn|
31
+ print "###yaml->yaml### fn="+fn+"\n"
32
+ xyml=Xyml::Document.new
33
+ fnout=fn.sub(/ori.yaml/,'y2y.yaml').sub(fileDir,tempDir)
34
+ xyml.load_XYML(File.open(fn))
35
+ #p "#D#test_xyml.rb:yaml->yaml:xyml=";pp xyml
36
+ xyml.out_XYML(File.open(fnout,'w'))
37
+ diff = open(fn).readlines - open(fnout).readlines
38
+ diff = diff.find_all {|str| !str.start_with?('#')}
39
+ assert_equal([],diff)
40
+ diff = open(fnout).readlines - open(fn).readlines
41
+ assert_equal([],diff)
42
+ end
43
+ end
44
+
45
+ should ". No differences between loaded yaml file and saved yaml -> xml -> yaml file" do
46
+ Dir.glob(fileDir+"*.ori.yaml") do |fn|
47
+ print "###yaml->xml->yaml### fn="+fn+"\n"
48
+ xyml=Xyml::Document.new
49
+ fnoutT=fn.sub(/ori.yaml/,'nml.yaml').sub(fileDir,tempDir)
50
+ fnoutX=fn.sub(/ori.yaml/,'yxy.xml').sub(fileDir,tempDir)
51
+ fnoutY=fn.sub(/ori.yaml/,'yxy.yaml').sub(fileDir,tempDir)
52
+ xyml.load_XYML(File.open(fn))
53
+ #p "#D#tst_xml.rb:yaml->xml->yaml: yaml loaded.";pp xyml
54
+ xyml.out_XYML_standard(File.open(fnoutT,'w'))
55
+ xyml.load_XYML(File.open(fnoutT))
56
+ #p "#D#tst_xml.rb:yaml->xml->yaml: yaml loaded.";pp xyml
57
+ xyml.out_XML(File.open(fnoutX,'w'))
58
+ xyml.load_XML(File.open(fnoutX))
59
+ #p "#D#tst_xml.rb:yaml->xml->yaml: xml loaded.";pp xyml
60
+ xyml.out_XYML(File.open(fnoutY,'w'))
61
+ diff = open(fnoutT).readlines - open(fnoutY).readlines
62
+ assert_equal([],diff)
63
+ diff = open(fnoutY).readlines - open(fnoutT).readlines
64
+ assert_equal([],diff)
65
+ end
66
+ end
67
+
68
+ should ". No differences between loaded xml file and saved xml -> yaml -> xml file" do
69
+ Dir.glob(fileDir+"*.ori.xml") do |fn|
70
+ print "###xml->yaml->xml### fn="+fn+"\n"
71
+ xyml=Xyml::Document.new
72
+ fnoutT=fn.sub(/ori.xml/,'nml.xml').sub(fileDir,tempDir)
73
+ fnoutX=fn.sub(/ori.xml/,'xyx.xml').sub(fileDir,tempDir)
74
+ fnoutY=fn.sub(/ori.xml/,'xyx.yaml').sub(fileDir,tempDir)
75
+ xyml.load_XML(File.open(fn))
76
+ #pp xyml
77
+ xyml.out_XML(File.open(fnoutT,'w'))
78
+ xyml.load_XML(File.open(fnoutT))
79
+ #p "#D#test_xyml.rb:xml->yaml->xml: xml loaded.fn=#{fnoutT}";pp xyml
80
+ xyml.out_XYML(File.open(fnoutY,'w'))
81
+ xyml.load_XYML(File.open(fnoutY))
82
+ #p "#D#test_xyml.rb:xml->yaml->xml: yaml loaded.fn=#{fnoutY}";pp xyml
83
+ xyml.out_XML(File.open(fnoutX,'w'))
84
+ diff = open(fnoutT).readlines - open(fnoutX).readlines
85
+ assert_equal([],diff)
86
+ diff = open(fnoutX).readlines - open(fnoutT).readlines
87
+ assert_equal([],diff)
88
+ end
89
+ end
90
+
91
+ should ". No differences between json file transfered from xml file and json file transfered from yaml file." do
92
+ Dir.glob(fileDir+"*.ori.xml") do |fn|
93
+ print "###xml->json,xml->yaml->json### fn="+fn+"\n"
94
+ xyml=Xyml::Document.new
95
+ fnoutT=fn.sub(/ori.xml/,'nml.xml').sub(fileDir,tempDir)
96
+ fnoutY=fn.sub(/ori.xml/,'xyj.yaml').sub(fileDir,tempDir)
97
+ fnoutXJ=fn.sub(/ori.xml/,'x2j.json').sub(fileDir,tempDir)
98
+ fnoutYJ=fn.sub(/ori.xml/,'y2j.json').sub(fileDir,tempDir)
99
+ xyml.load_XML(File.open(fn))
100
+ #pp xyml
101
+ xyml.out_XML(File.open(fnoutT,'w'))
102
+ xyml.load_XML(File.open(fnoutT))
103
+ #p "#D#test_xyml.rb:xml->yaml->json: xml loaded.fn=#{fnoutY}";pp xyml
104
+ xyml.out_JSON(File.open(fnoutXJ,'w'))
105
+ xyml.out_XYML(File.open(fnoutY,'w'))
106
+ xyml.load_XYML(File.open(fnoutY))
107
+ #p "#D#test_xyml.rb:xml->yaml->json: yaml loaded.fn=#{fnoutY}";pp xyml
108
+ # order of array elements in ruby objects changed from order in yaml. ????
109
+ xyml.out_JSON(File.open(fnoutYJ,'w'))
110
+ diff = open(fnoutXJ).readlines - open(fnoutYJ).readlines
111
+ assert_equal([],diff)
112
+ diff = open(fnoutYJ).readlines - open(fnoutXJ).readlines
113
+ assert_equal([],diff)
114
+ end
115
+ end
116
+
117
+ should ". No differences between loaded json file and saved json file" do
118
+ Dir.glob(fileDir+"*.nml.ori.json") do |fn|
119
+ print "###json->json### fn="+fn+"\n"
120
+ xyml=Xyml::Document.new
121
+ fnout=fn.sub(/ori.json/,'j2j.json').sub(fileDir,tempDir)
122
+ #p "fn=#{fn},fnout=#{fnout}"
123
+ xyml.load_XYML(File.open(fn))
124
+ #p "#D#test_xyml.rb:x2x:loaded dom=";dom_print_rcsv(xyml.get_DOM,0)
125
+ #p "#D#test_xml.rb:xml->xml:xyml=";pp xyml
126
+ xyml.out_JSON(File.open(fnout,'w'))
127
+ #p "fnout=#{fnout}"
128
+ #pp open(fnout).readlines
129
+ diff = open(fn).readlines - open(fnout).readlines
130
+ assert_equal([],diff)
131
+ diff = open(fnout).readlines - open(fn).readlines
132
+ assert_equal([],diff)
133
+ end
134
+ end
135
+
136
+
137
+ private
138
+
139
+ Indent="||"
140
+
141
+ def dom_print_rcsv elem,nest
142
+ print "================================\n"
143
+ print Indent*nest + "name : #{elem.name}\n"
144
+ attrs = elem.attributes
145
+ attrs.each{|a,e|
146
+ print Indent*nest + "attr :#{a}=#{e}\n"
147
+ }
148
+ print Indent*nest + "text : \n-->#{elem.text.to_s.gsub("\s",'_').gsub("\t",'\t')}<--\n"
149
+
150
+ elem.each do |node|
151
+ if node.is_a?(REXML::Element)
152
+ dom_print_rcsv node,nest+1
153
+ elsif node.is_a?(REXML::Text)
154
+ text=node.to_s
155
+ print Indent*nest + "textnode : \n-->#{text.gsub("\s",'_').gsub("\t",'\t')}<--\n"
156
+ end
157
+ end
158
+
159
+
160
+ #if elem.has_elements? then
161
+ # elem.each_element{|e|
162
+ # dom_print_rcsv e,nest+1
163
+ # }
164
+ #end
165
+ end
166
+
167
+ end