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.
- data/.gitignore +19 -0
- data/.gitignore~ +17 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +44 -0
- data/Gemfile~ +13 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/bin/dbg_x2o +8 -0
- data/bin/x2y +8 -0
- data/bin/y2x +17 -0
- data/ixyml.gemspec +23 -0
- data/lib/ixyml.rb +10 -0
- data/lib/ixyml/version.rb +3 -0
- data/lib/ixyml/xyml.rb +821 -0
- data/lib/ixyml/xyml_element.rb +778 -0
- data/test/dirTemp/ktest00.nml.j2j.json +1 -0
- data/test/dirTemp/ktest00.nml.nml.xml +53 -0
- data/test/dirTemp/ktest00.nml.nml.yaml +74 -0
- data/test/dirTemp/ktest00.nml.x2j.json +1 -0
- data/test/dirTemp/ktest00.nml.x2x.xml +53 -0
- data/test/dirTemp/ktest00.nml.xyj.yaml +134 -0
- data/test/dirTemp/ktest00.nml.xyx.xml +53 -0
- data/test/dirTemp/ktest00.nml.xyx.yaml +134 -0
- data/test/dirTemp/ktest00.nml.y2j.json +1 -0
- data/test/dirTemp/ktest00.nml.y2y.yaml +74 -0
- data/test/dirTemp/ktest00.nml.yxy.xml +2 -0
- data/test/dirTemp/ktest00.nml.yxy.yaml +74 -0
- data/test/dirTemp/ktest01.nml.yaml +74 -0
- data/test/dirTemp/ktest01.yxy.xml +2 -0
- data/test/dirTemp/ktest01.yxy.yaml +74 -0
- data/test/dirTemp/test01.nml.nml.xml +21 -0
- data/test/dirTemp/test01.nml.nml.yaml +5 -0
- data/test/dirTemp/test01.nml.x2j.json +1 -0
- data/test/dirTemp/test01.nml.x2x.xml +21 -0
- data/test/dirTemp/test01.nml.xyj.yaml +18 -0
- data/test/dirTemp/test01.nml.xyx.xml +21 -0
- data/test/dirTemp/test01.nml.xyx.yaml +18 -0
- data/test/dirTemp/test01.nml.y2j.json +1 -0
- data/test/dirTemp/test01.nml.y2y.yaml +5 -0
- data/test/dirTemp/test01.nml.yaml +74 -0
- data/test/dirTemp/test01.nml.yxy.xml +3 -0
- data/test/dirTemp/test01.nml.yxy.yaml +5 -0
- data/test/dirTemp/test01.yxy.xml +2 -0
- data/test/dirTemp/test01.yxy.yaml +74 -0
- data/test/dirTemp/testBreak.nml.yaml +7 -0
- data/test/dirTemp/testBreak.yxy.xml +5 -0
- data/test/dirTemp/testBreak.yxy.yaml +7 -0
- data/test/dirTemp/testCDATA.nml.nml.xml +26 -0
- data/test/dirTemp/testCDATA.nml.x2j.json +1 -0
- data/test/dirTemp/testCDATA.nml.x2x.xml +26 -0
- data/test/dirTemp/testCDATA.nml.xyj.yaml +18 -0
- data/test/dirTemp/testCDATA.nml.xyx.xml +26 -0
- data/test/dirTemp/testCDATA.nml.xyx.yaml +18 -0
- data/test/dirTemp/testCDATA.nml.y2j.json +1 -0
- data/test/dirTemp/testEscape.nml.nml.xml +77 -0
- data/test/dirTemp/testEscape.nml.nml.yaml +53 -0
- data/test/dirTemp/testEscape.nml.x2j.json +1 -0
- data/test/dirTemp/testEscape.nml.x2x.xml +77 -0
- data/test/dirTemp/testEscape.nml.xyj.yaml +213 -0
- data/test/dirTemp/testEscape.nml.xyx.xml +77 -0
- data/test/dirTemp/testEscape.nml.xyx.yaml +213 -0
- data/test/dirTemp/testEscape.nml.y2j.json +1 -0
- data/test/dirTemp/testEscape.nml.y2y.yaml +53 -0
- data/test/dirTemp/testEscape.nml.yxy.xml +2 -0
- data/test/dirTemp/testEscape.nml.yxy.yaml +53 -0
- data/test/dirTemp/testNS.nml.nml.xml +21 -0
- data/test/dirTemp/testNS.nml.x2j.json +1 -0
- data/test/dirTemp/testNS.nml.x2x.xml +21 -0
- data/test/dirTemp/testNS.nml.xyj.yaml +19 -0
- data/test/dirTemp/testNS.nml.xyx.xml +21 -0
- data/test/dirTemp/testNS.nml.xyx.yaml +19 -0
- data/test/dirTemp/testNS.nml.y2j.json +1 -0
- data/test/test_xyml.rb +167 -0
- data/test/test_xyml.rb~ +167 -0
- data/test/test_xyml_element.rb +241 -0
- data/test/test_xyml_element.rb~ +111 -0
- data/test/testfiles/ktest00.nml.ori.json +1 -0
- data/test/testfiles/ktest00.nml.ori.xml +53 -0
- data/test/testfiles/ktest00.nml.ori.yaml +74 -0
- data/test/testfiles/ktest00.nml.ori.yaml~ +75 -0
- data/test/testfiles/ktest01.ori.yaml +75 -0
- data/test/testfiles/test01.nml.ori.xml +21 -0
- data/test/testfiles/test01.nml.ori.yaml +5 -0
- data/test/testfiles/test01.ori.yaml +75 -0
- data/test/testfiles/testBreak.ori.yaml +10 -0
- data/test/testfiles/testCDATA.ng.ng.xml +26 -0
- data/test/testfiles/testEscape.nml.ori.xml +77 -0
- data/test/testfiles/testEscape.nml.ori.yaml +105 -0
- data/test/testfiles/testNS.nml.ori.xml +21 -0
- data/test/testfiles/xmlTemp.xml +2 -0
- data/test/testfiles/xymlTemp.xyml +6 -0
- metadata +230 -0
|
@@ -0,0 +1,241 @@
|
|
|
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
|
+
|
|
9
|
+
should ". Xyml_node has same values as correspoinding raw hash and array have." do
|
|
10
|
+
nodeQT=Xyml::Element.new(:questionText)
|
|
11
|
+
#pp nodeQT
|
|
12
|
+
nodeQT.st("textQT")
|
|
13
|
+
nodeQT.sa(:type,"instruction")
|
|
14
|
+
#print "#D#test_xyml_element.rb:nodeQT=";pp nodeQT
|
|
15
|
+
assert_equal(nodeQT[:questionText][1],"textQT")
|
|
16
|
+
assert_equal(nodeQT.gt,"textQT")
|
|
17
|
+
nodeQ=Xyml::Element.new(:question)
|
|
18
|
+
nodeQ.ac(nodeQT)
|
|
19
|
+
assert_equal(nodeQ.gcn(:questionText)[0].gt,"textQT")
|
|
20
|
+
nodeQ.sa(:type,'handWriting')
|
|
21
|
+
assert_equal(nodeQ.ga(:type),'handWriting')
|
|
22
|
+
xyml=Xyml::Document.new(:quizlist)
|
|
23
|
+
xyml.root.ac(nodeQ)
|
|
24
|
+
assert_equal(xyml.root.gcn(:question)[0].ga(:type),'handWriting')
|
|
25
|
+
nodeQ.sa(:type,'handWritingChanged')
|
|
26
|
+
assert_equal('handWritingChanged',nodeQ.ga(:type))
|
|
27
|
+
#print "#D#test_xyml_element.rb:Xyml_node:nodeQ=";pp nodeQ
|
|
28
|
+
nodeQT2=Xyml::Element.new(:questionText)
|
|
29
|
+
nodeQT2.st("textQT2")
|
|
30
|
+
nodeQT2.sa(:type,"choices");
|
|
31
|
+
nodeQ.ac(nodeQT2)
|
|
32
|
+
assert_equal("textQT2",nodeQ.gc[1].gt)
|
|
33
|
+
assert_equal("textQT",nodeQ.gcf.gt)
|
|
34
|
+
assert_equal("textQT",nodeQ.gcfn(:questionText).gt)
|
|
35
|
+
assert_equal("textQT2",nodeQ.gca(:type,"choices")[0].gt)
|
|
36
|
+
assert_equal("textQT2",nodeQ.gcna(:questionText,:type,"choices")[0].gt)
|
|
37
|
+
assert_equal("textQT2",nodeQ.gcfna(:questionText,:type,"choices").gt)
|
|
38
|
+
assert_equal(nodeQ,nodeQT2.gp)
|
|
39
|
+
assert_equal(nodeQT,nodeQT2.gsp)
|
|
40
|
+
assert_equal(nil,nodeQT.gsp)
|
|
41
|
+
assert_equal(nil,nodeQ.gsp)
|
|
42
|
+
assert_equal(nodeQT2,nodeQT.gss)
|
|
43
|
+
assert_equal(nil,nodeQT2.gss)
|
|
44
|
+
assert_equal(nil,nodeQ.gss)
|
|
45
|
+
nodeQT3=Xyml.extend_element({:questionText=>[
|
|
46
|
+
{:text_type=> "html"},
|
|
47
|
+
{:task_set => false},
|
|
48
|
+
{:title => nil},
|
|
49
|
+
{:instruction => nil},"textQT3"]})
|
|
50
|
+
#nodeQ.icb(nodeQT,nodeQT3)
|
|
51
|
+
nodeQT.isp(nodeQT3)
|
|
52
|
+
#p "#D#test_xyml_element.rb:nodeQ=";pp nodeQ
|
|
53
|
+
assert_equal(nodeQT3,nodeQT.gsp)
|
|
54
|
+
nodeQT4=Xyml.extend_element({:questionText=>[
|
|
55
|
+
{:text_type=> "text"},
|
|
56
|
+
{:task_set => false},
|
|
57
|
+
{:title => nil},
|
|
58
|
+
{:instruction => nil},"textQT4"]})
|
|
59
|
+
#nodeQ.ica(nodeQT2,nodeQT4)
|
|
60
|
+
nodeQT2.iss(nodeQT4)
|
|
61
|
+
assert_equal(nodeQT4,nodeQT2.gss)
|
|
62
|
+
#pp "#D#test_xyml_element.rb:xyml=";pp xyml
|
|
63
|
+
assert_equal(xyml.root,nodeQT4.gr)
|
|
64
|
+
nodeQT4.da(:task_set)
|
|
65
|
+
assert_equal(nil,nodeQT4.ga(:task_set))
|
|
66
|
+
nodeQT4.dsl
|
|
67
|
+
assert_equal(nil,nodeQT4.gr)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
should ". Created xyml_node can be saved as a xyml file." do
|
|
71
|
+
doc=Xyml::Document.new :quiz
|
|
72
|
+
doc.root.sa(:type,'handWriting')
|
|
73
|
+
elementQuestions=Xyml::Element.new(:questions)
|
|
74
|
+
elementQuestion=Xyml::Element.new(:question)
|
|
75
|
+
elementQuestion.st('who are your?');
|
|
76
|
+
doc.root.ac(elementQuestions)
|
|
77
|
+
elementQuestions.ac(elementQuestion)
|
|
78
|
+
doc.out_XYML(File.open(fileDir+'xymlTemp.xyml','w'))
|
|
79
|
+
docNew=Xyml::Document.new File.open(fileDir+'xymlTemp.xyml','r')
|
|
80
|
+
#docNew=Xyml::Document.new
|
|
81
|
+
#docNew.load_XYML File.open(fileDir+'xymlTemp.xyml','r')
|
|
82
|
+
#print "#D#test_xyml_element.rb:can be saved as xyml:(xyml 1)doc=";pp doc
|
|
83
|
+
#print "#D#test_xyml_element.rb:can be saved as xyml:(xyml 2)docNew=";pp docNew
|
|
84
|
+
assert_equal(doc.inspect,docNew.inspect)
|
|
85
|
+
#print doc.root.gcfn(:questions).to_s
|
|
86
|
+
#print "#D#test_xyml_element.rb:can be saved as xyml:docNew=#{docNew.root.gcfn(:questions).to_s}"
|
|
87
|
+
assert_equal(doc.root.gcfn(:questions).to_s,docNew.root.gcfn(:questions).to_s)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
should ". Created xyml_node can be saved as a xml file." do
|
|
91
|
+
doc=Xyml::Document.new :quiz
|
|
92
|
+
doc.root.sa(:type,'handWriting')
|
|
93
|
+
elementQuestions=Xyml::Element.new(:questions)
|
|
94
|
+
elementQuestion=Xyml::Element.new(:question)
|
|
95
|
+
elementQuestion.st('who are your?');
|
|
96
|
+
doc.root.ac(elementQuestions)
|
|
97
|
+
elementQuestions.ac(elementQuestion)
|
|
98
|
+
doc.out_XML(File.open(fileDir+'xmlTemp.xml','w'))
|
|
99
|
+
docNew=Xyml::Document.new
|
|
100
|
+
docNew.load_XML(File.open(fileDir+'xmlTemp.xml','r'))
|
|
101
|
+
#print "#D#test_xyml_element.rb:can be saved as xml:(1)doc=";pp doc
|
|
102
|
+
#print "#D#test_xyml_element.rb:can be saved as xml:(2)docNew=";pp docNew
|
|
103
|
+
#print open(fileDir+'xmlTemp.xml').read
|
|
104
|
+
assert_equal(doc.inspect,docNew.inspect)
|
|
105
|
+
#print doc.root.gcfn(:questions).to_s
|
|
106
|
+
#print "#D#test_xyml_element.rb:can be saved as xml:(3)docNew.root.gcfn(:questions)=#{docNew.root.gcfn(:questions).to_s}\n"
|
|
107
|
+
#print "#D#test_xyml_element.rb:can be saved as xml:(4)doc.root.gcfn(:questions)=#{doc.root.gcfn(:questions).to_s}\n"
|
|
108
|
+
assert_equal(doc.root.gcfn(:questions).to_s,docNew.root.gcfn(:questions).to_s)
|
|
109
|
+
#print "#D#test_xyml_element.rb:can be saved as xml:(5)docNew.root.gcfn(:questions).gcfn(:question)=#{docNew.root.gcfn(:questions).gcfn(:question).to_s}\n"
|
|
110
|
+
#print "#D#test_xyml_element.rb:can be saved as xml:(6)doc.root.gcfn(:questions).gcfn(:question)=#{doc.root.gcfn(:questions).gcfn(:question).to_s}\n"
|
|
111
|
+
assert_equal(doc.root.gcfn(:questions).gcfn(:question).to_s,docNew.root.gcfn(:questions).gcfn(:question).to_s)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
should ". program samples in the document work correctly." do
|
|
115
|
+
# gc(get children)
|
|
116
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
117
|
+
assert_equal(:d,xyml_tree.root.gc[0].name)
|
|
118
|
+
assert_equal('fff',xyml_tree.root.gc[0].ga(:e))
|
|
119
|
+
assert_equal(:d,xyml_tree.root.gc[1].name)
|
|
120
|
+
assert_equal('ggg',xyml_tree.root.gc[1].ga(:e))
|
|
121
|
+
assert_equal(:h,xyml_tree.root.gc[2].name)
|
|
122
|
+
assert_equal('fff',xyml_tree.root.gc[2].ga(:e))
|
|
123
|
+
# gcf(get first child)
|
|
124
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
125
|
+
assert_equal(:d,xyml_tree.root.gcf.name)
|
|
126
|
+
assert_equal('fff',xyml_tree.root.gcf.ga(:e))
|
|
127
|
+
# gcn(get child elements with the designated name)
|
|
128
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
129
|
+
assert_equal(:d,xyml_tree.root.gcn(:d)[0].name)
|
|
130
|
+
assert_equal('fff',xyml_tree.root.gcn(:d)[0].ga(:e))
|
|
131
|
+
assert_equal(:d,xyml_tree.root.gcn(:d)[1].name)
|
|
132
|
+
assert_equal('ggg',xyml_tree.root.gcn(:d)[1].ga(:e))
|
|
133
|
+
assert_equal(2,xyml_tree.root.gcn(:d).size)
|
|
134
|
+
# gcfn(get the first child element with the designated name)
|
|
135
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
136
|
+
assert_equal(:d,xyml_tree.root.gcfn(:d).name)
|
|
137
|
+
assert_equal('fff',xyml_tree.root.gcfn(:d).ga(:e))
|
|
138
|
+
# gcna(get child elements with the designated element name and atrribute)
|
|
139
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
140
|
+
assert_equal(:d,xyml_tree.root.gcna(:d,:e,'ggg')[0].name)
|
|
141
|
+
assert_equal('ggg',xyml_tree.root.gcna(:d,:e,'ggg')[0].ga(:e))
|
|
142
|
+
assert_equal(1,xyml_tree.root.gcna(:d,:e,'fff').size)
|
|
143
|
+
# gca(get child elements with the designated atrribute)
|
|
144
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
145
|
+
assert_equal(:d,xyml_tree.root.gca(:e,'fff')[0].name)
|
|
146
|
+
assert_equal('fff',xyml_tree.root.gca(:e,'fff')[0].ga(:e))
|
|
147
|
+
assert_equal(:h,xyml_tree.root.gca(:e,'fff')[1].name)
|
|
148
|
+
assert_equal('fff',xyml_tree.root.gca(:e,'fff')[1].ga(:e))
|
|
149
|
+
assert_equal(2,xyml_tree.root.gca(:e,'fff').size)
|
|
150
|
+
# gcfna(get the first child elements with the designated element name and atrribute)
|
|
151
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
152
|
+
assert_equal(:d,xyml_tree.root.gcfna(:d,:e,'ggg').name)
|
|
153
|
+
assert_equal('ggg',xyml_tree.root.gcfna(:d,:e,'ggg').ga(:e))
|
|
154
|
+
# gsp(get the previous sibling element)
|
|
155
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
156
|
+
my_element=xyml_tree.root.gcfna 'd','e','ggg'
|
|
157
|
+
assert_equal(:d,my_element.gsp.name)
|
|
158
|
+
assert_equal('fff',my_element.gsp.ga(:e))
|
|
159
|
+
# gss(get the immediately succeeding sibling element)
|
|
160
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
161
|
+
my_element=xyml_tree.root.gcfna 'd','e','ggg'
|
|
162
|
+
assert_equal(:h,my_element.gss.name)
|
|
163
|
+
assert_equal('fff',my_element.gss.ga(:e))
|
|
164
|
+
# ac(add a child)
|
|
165
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
166
|
+
my_element=xyml_tree.root.gcfna 'd','e','ggg'
|
|
167
|
+
my_element.ac({j:[{e:'kkk'}]})
|
|
168
|
+
assert_equal(:j,my_element.gcf.name)
|
|
169
|
+
assert_equal('kkk',my_element.gcf.ga(:e))
|
|
170
|
+
my_element.st(my_element.gt)
|
|
171
|
+
assert_equal('text',my_element[:d][2])
|
|
172
|
+
# isp(insert an element as a previous sibling element)
|
|
173
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
174
|
+
my_element=xyml_tree.root.gcfna 'd','e','ggg'
|
|
175
|
+
my_element.isp({j:[{e:'kkk'}]})
|
|
176
|
+
assert_equal(:j,my_element.gsp.name)
|
|
177
|
+
assert_equal('kkk',my_element.gsp.ga(:e))
|
|
178
|
+
# iss(insert an element as an immediately succeeding sibling element)
|
|
179
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
180
|
+
my_element=xyml_tree.root.gcfna 'd','e','ggg'
|
|
181
|
+
my_element.iss({j:[{e:'kkk'}]})
|
|
182
|
+
assert_equal(:j,my_element.gss.name)
|
|
183
|
+
assert_equal('kkk',my_element.gss.ga(:e))
|
|
184
|
+
# ga(get value of attribute with the designated attribute name)
|
|
185
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
186
|
+
assert_equal('ccc',xyml_tree.root.ga(:b))
|
|
187
|
+
# sa(set value to the attribute with the designated attribute name)
|
|
188
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
189
|
+
my_element=xyml_tree.root.gcfna 'd','e','ggg'
|
|
190
|
+
my_element.sa(:e,'lll').sa(:m,'nnn')
|
|
191
|
+
assert_equal('lll',my_element.ga(:e))
|
|
192
|
+
assert_equal('nnn',my_element.ga(:m))
|
|
193
|
+
# da(delete attribute)
|
|
194
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
195
|
+
xyml_tree.root.da(:b)
|
|
196
|
+
assert_equal(nil,xyml_tree.root.ga(:b))
|
|
197
|
+
# gt(get text)
|
|
198
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
199
|
+
my_element=xyml_tree.root.gcfna 'd','e','ggg'
|
|
200
|
+
assert_equal('text',my_element.gt)
|
|
201
|
+
my_element.at 'abc'
|
|
202
|
+
assert_equal('textabc',my_element.gt)
|
|
203
|
+
assert_equal(['text','abc'],my_element.gt(:raw))
|
|
204
|
+
# st(set text)
|
|
205
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
206
|
+
my_element=xyml_tree.root.gcfna 'd','e','ggg'
|
|
207
|
+
my_element.st('abc')
|
|
208
|
+
assert_equal('abc',my_element.gt)
|
|
209
|
+
my_element.st(nil)
|
|
210
|
+
assert_equal('',my_element.gt)
|
|
211
|
+
|
|
212
|
+
# at(add text)
|
|
213
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
214
|
+
my_element=xyml_tree.root.gcfna 'd','e','ggg'
|
|
215
|
+
my_element.at('abc')
|
|
216
|
+
assert_equal('textabc',my_element.gt)
|
|
217
|
+
# gp(get the parent element)
|
|
218
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
219
|
+
my_element=xyml_tree.root.gcfna 'd','e','ggg'
|
|
220
|
+
assert_equal(:a,my_element.gp.name)
|
|
221
|
+
assert_equal(nil,xyml_tree.root.gp)
|
|
222
|
+
# gr(get the root element)
|
|
223
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
224
|
+
new_element=Xyml::Element.new(:j)
|
|
225
|
+
xyml_tree.root.gcfna('d','e','ggg').ac new_element
|
|
226
|
+
assert_equal(:a,new_element.gr.name)
|
|
227
|
+
# is_root?
|
|
228
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
229
|
+
assert_equal(true,xyml_tree.root.is_root?)
|
|
230
|
+
assert_equal(false,xyml_tree.root.gcfna('d','e','ggg').is_root?)
|
|
231
|
+
# dsl(delete the self element from the child element array of its parent element)
|
|
232
|
+
xyml_tree=Xyml::Document.new({a:[{b:'ccc'},{d:[{e:'fff'}]},{d:[{e:'ggg'},'text']},{h:[{e:'fff'}]}]})
|
|
233
|
+
xyml_tree.root.gcfna('d','e','ggg').dsl
|
|
234
|
+
assert_equal(:d,xyml_tree.root.gc[0].name)
|
|
235
|
+
assert_equal('fff',xyml_tree.root.gc[0].ga(:e))
|
|
236
|
+
assert_equal(:h,xyml_tree.root.gc[1].name)
|
|
237
|
+
assert_equal('fff',xyml_tree.root.gc[1].ga(:e))
|
|
238
|
+
assert_equal(2,xyml_tree.root.gc.size)
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
end
|
|
@@ -0,0 +1,111 @@
|
|
|
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
|
+
|
|
9
|
+
should ". Xyml_node has same values as correspoinding raw hash and array have." do
|
|
10
|
+
nodeQT=Xyml.element_new(:questionText)
|
|
11
|
+
#pp nodeQT
|
|
12
|
+
nodeQT.st("textQT")
|
|
13
|
+
nodeQT.sa(:type,"instruction")
|
|
14
|
+
#print "#D#test_xyml_element.rb:nodeQT=";pp nodeQT
|
|
15
|
+
assert_equal(nodeQT[:questionText][1],"textQT")
|
|
16
|
+
assert_equal(nodeQT.gt,"textQT")
|
|
17
|
+
nodeQ=Xyml.element_new(:question)
|
|
18
|
+
nodeQ.ac(nodeQT)
|
|
19
|
+
assert_equal(nodeQ.gcn(:questionText)[0].gt,"textQT")
|
|
20
|
+
nodeQ.sa(:type,'handWriting')
|
|
21
|
+
assert_equal(nodeQ.ga(:type),'handWriting')
|
|
22
|
+
xyml=Xyml::Document.new(:quizlist)
|
|
23
|
+
xyml.root.ac(nodeQ)
|
|
24
|
+
assert_equal(xyml.root.gcn(:question)[0].ga(:type),'handWriting')
|
|
25
|
+
nodeQ.sa(:type,'handWritingChanged')
|
|
26
|
+
assert_equal('handWritingChanged',nodeQ.ga(:type))
|
|
27
|
+
#print "#D#test_xyml_element.rb:Xyml_node:nodeQ=";pp nodeQ
|
|
28
|
+
nodeQT2=Xyml.element_new(:questionText)
|
|
29
|
+
nodeQT2.st("textQT2")
|
|
30
|
+
nodeQT2.sa(:type,"choices");
|
|
31
|
+
nodeQ.ac(nodeQT2)
|
|
32
|
+
assert_equal("textQT2",nodeQ.gc[1].gt)
|
|
33
|
+
assert_equal("textQT",nodeQ.gcf.gt)
|
|
34
|
+
assert_equal("textQT",nodeQ.gcfn(:questionText).gt)
|
|
35
|
+
assert_equal("textQT2",nodeQ.gca(:type,"choices")[0].gt)
|
|
36
|
+
assert_equal("textQT2",nodeQ.gcna(:questionText,:type,"choices")[0].gt)
|
|
37
|
+
assert_equal("textQT2",nodeQ.gcfna(:questionText,:type,"choices").gt)
|
|
38
|
+
assert_equal(nodeQ,nodeQT2.gp)
|
|
39
|
+
assert_equal(nodeQT,nodeQT2.gsp)
|
|
40
|
+
assert_equal(nil,nodeQT.gsp)
|
|
41
|
+
assert_equal(nil,nodeQ.gsp)
|
|
42
|
+
assert_equal(nodeQT2,nodeQT.gsn)
|
|
43
|
+
assert_equal(nil,nodeQT2.gsn)
|
|
44
|
+
assert_equal(nil,nodeQ.gsn)
|
|
45
|
+
nodeQT3=Xyml.extend_element({:questionText=>[
|
|
46
|
+
{:text_type=> "html"},
|
|
47
|
+
{:task_set => false},
|
|
48
|
+
{:title => nil},
|
|
49
|
+
{:instruction => nil},"textQT3"]})
|
|
50
|
+
nodeQ.icb(nodeQT,nodeQT3)
|
|
51
|
+
assert_equal(nodeQT3,nodeQT.gsp)
|
|
52
|
+
nodeQT4=Xyml.extend_element({:questionText=>[
|
|
53
|
+
{:text_type=> "text"},
|
|
54
|
+
{:task_set => false},
|
|
55
|
+
{:title => nil},
|
|
56
|
+
{:instruction => nil},"textQT4"]})
|
|
57
|
+
nodeQ.ica(nodeQT2,nodeQT4)
|
|
58
|
+
assert_equal(nodeQT4,nodeQT2.gsn)
|
|
59
|
+
#pp "#D#test_xyml_element.rb:xyml=";pp xyml
|
|
60
|
+
assert_equal(xyml.root,nodeQT4.gr)
|
|
61
|
+
nodeQT4.da(:task_set)
|
|
62
|
+
assert_equal(nil,nodeQT4.ga(:task_set))
|
|
63
|
+
nodeQT4.dsl
|
|
64
|
+
assert_equal(nil,nodeQT4.gr)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
should ". Created xyml_node can be saved as a xyml file." do
|
|
68
|
+
doc=Xyml::Document.new :quiz
|
|
69
|
+
doc.root.sa(:type,'handWriting')
|
|
70
|
+
elementQuestions=Xyml.element_new(:questions)
|
|
71
|
+
elementQuestion=Xyml.element_new(:question)
|
|
72
|
+
elementQuestion.st('who are your?');
|
|
73
|
+
doc.root.ac(elementQuestions)
|
|
74
|
+
elementQuestions.ac(elementQuestion)
|
|
75
|
+
doc.out_XYML(File.open(fileDir+'xymlTemp.xyml','w'))
|
|
76
|
+
docNew=Xyml::Document.new File.open(fileDir+'xymlTemp.xyml','r')
|
|
77
|
+
#docNew=Xyml::Document.new
|
|
78
|
+
#docNew.load_XYML File.open(fileDir+'xymlTemp.xyml','r')
|
|
79
|
+
#print "#D#test_xyml_element.rb:can be saved as xyml:(xyml 1)doc=";pp doc
|
|
80
|
+
#print "#D#test_xyml_element.rb:can be saved as xyml:(xyml 2)docNew=";pp docNew
|
|
81
|
+
assert_equal(doc.inspect,docNew.inspect)
|
|
82
|
+
#print doc.root.gcfn(:questions).to_s
|
|
83
|
+
#print "#D#test_xyml_element.rb:can be saved as xyml:docNew=#{docNew.root.gcfn(:questions).to_s}"
|
|
84
|
+
assert_equal(doc.root.gcfn(:questions).to_s,docNew.root.gcfn(:questions).to_s)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
should ". Created xyml_node can be saved as a xml file." do
|
|
88
|
+
doc=Xyml::Document.new :quiz
|
|
89
|
+
doc.root.sa(:type,'handWriting')
|
|
90
|
+
elementQuestions=Xyml.element_new(:questions)
|
|
91
|
+
elementQuestion=Xyml.element_new(:question)
|
|
92
|
+
elementQuestion.st('who are your?');
|
|
93
|
+
doc.root.ac(elementQuestions)
|
|
94
|
+
elementQuestions.ac(elementQuestion)
|
|
95
|
+
doc.out_XML(File.open(fileDir+'xmlTemp.xml','w'))
|
|
96
|
+
docNew=Xyml::Document.new
|
|
97
|
+
docNew.load_XML(File.open(fileDir+'xmlTemp.xml','r'))
|
|
98
|
+
#print "#D#test_xyml_element.rb:can be saved as xml:(1)doc=";pp doc
|
|
99
|
+
#print "#D#test_xyml_element.rb:can be saved as xml:(2)docNew=";pp docNew
|
|
100
|
+
assert_equal(doc.inspect,docNew.inspect)
|
|
101
|
+
#print doc.root.gcfn(:questions).to_s
|
|
102
|
+
#print "#D#test_xyml_element.rb:can be saved as xml:(3)docNew.root.gcfn(:questions)=#{docNew.root.gcfn(:questions).to_s}\n"
|
|
103
|
+
#print "#D#test_xyml_element.rb:can be saved as xml:(4)doc.root.gcfn(:questions)=#{doc.root.gcfn(:questions).to_s}\n"
|
|
104
|
+
assert_equal(doc.root.gcfn(:questions).to_s,docNew.root.gcfn(:questions).to_s)
|
|
105
|
+
#print "#D#test_xyml_element.rb:can be saved as xml:(5)docNew.root.gcfn(:questions).gcfn(:question)=#{docNew.root.gcfn(:questions).gcfn(:question).to_s}\n"
|
|
106
|
+
#print "#D#test_xyml_element.rb:can be saved as xml:(6)doc.root.gcfn(:questions).gcfn(:question)=#{doc.root.gcfn(:questions).gcfn(:question).to_s}\n"
|
|
107
|
+
assert_equal(doc.root.gcfn(:questions).gcfn(:question).to_s,docNew.root.gcfn(:questions).gcfn(:question).to_s)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[{"quiz":["\n",{"quizUnit":["\n",{"unitText":[{"format":"html"},"次の",{"u":["下線部"]},"の読み仮名を漢字に直せ。"]},"\n",{"info2":[{"id":"info2a"},{"type":"defaultNumberOfLetters"},"3"]},"\n",{"info":[{"type":"defaultAllotment"},"\n",{"noChild":[]},"\n",{"noChild2":[]},"\n3"]},"\n",{"question":[{"type":"handWriting"},"\n",{"questionText":[{"format":"html"},"古く、",{"u":["ばいえん"]},"でまっ黒にすすけた煉瓦壁の陰に汽車が停まると、"]},"\n",{"info":[{"type":"numberOfLetters"},"2"]},"\n",{"answer":[{"fraction":"100"},"\n",{"text":["煤煙"]},"\n"]},"\n",{"answer":[{"fraction":"0"},"\n",{"text":["梅園"]},"\n",{"feedback":["\n",{"text":["これは”ばいえん”違いですね。"]},"\n"]},"\n"]},"\n",{"source":["\n",{"author":["有島武郎"]},"\n",{"title":["或る女(前編)"]},"\n",{"link":["\n",{"label":["青空文庫"]},"\n",{"url":["http://www.aozora.gr.jp/"]},"\n"]},"\n"]},"\n"]},"\n",{"question":[{"type":"handWriting"},"\n",{"questionText":[{"format":"html"},"2古く",{"u":["ばいえん"]},"でまっ黒にすすけた煉瓦壁の陰に汽車が停まると、"]},"\n",{"info":[{"type":"numberOfLetters"},"2"]},"\n",{"answer":[{"fraction":"100"},"\n",{"text":["2煤煙"]},"\n"]},"\n",{"answer":[{"fraction":"0"},"\n",{"text":["2梅園"]},"\n",{"feedback":["\n",{"text":["2これは”ばいえん”違いですね。"]},"\n"]},"\n"]},"\n",{"source":["\n",{"author":["2有島武郎"]},"\n",{"title":["2或る女(前編)"]},"\n",{"link":["\n",{"label":["2青空文庫"]},"\n",{"url":["2http://www.aozora.gr.jp/"]},"\n"]},"\n"]},"\n"]},"\n"]},"\n"]}]
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<?xml version='1.0' encoding='UTF-8'?>
|
|
2
|
+
<quiz>
|
|
3
|
+
<quizUnit>
|
|
4
|
+
<unitText format='html'>次の<u>下線部</u>の読み仮名を漢字に直せ。</unitText>
|
|
5
|
+
<info2 id='info2a' type='defaultNumberOfLetters'>3</info2>
|
|
6
|
+
<info type='defaultAllotment'>
|
|
7
|
+
<noChild/>
|
|
8
|
+
<noChild2/>
|
|
9
|
+
3</info>
|
|
10
|
+
<question type='handWriting'>
|
|
11
|
+
<questionText format='html'>古く、<u>ばいえん</u>でまっ黒にすすけた煉瓦壁の陰に汽車が停まると、</questionText>
|
|
12
|
+
<info type='numberOfLetters'>2</info>
|
|
13
|
+
<answer fraction='100'>
|
|
14
|
+
<text>煤煙</text>
|
|
15
|
+
</answer>
|
|
16
|
+
<answer fraction='0'>
|
|
17
|
+
<text>梅園</text>
|
|
18
|
+
<feedback>
|
|
19
|
+
<text>これは”ばいえん”違いですね。</text>
|
|
20
|
+
</feedback>
|
|
21
|
+
</answer>
|
|
22
|
+
<source>
|
|
23
|
+
<author>有島武郎</author>
|
|
24
|
+
<title>或る女(前編)</title>
|
|
25
|
+
<link>
|
|
26
|
+
<label>青空文庫</label>
|
|
27
|
+
<url>http://www.aozora.gr.jp/</url>
|
|
28
|
+
</link>
|
|
29
|
+
</source>
|
|
30
|
+
</question>
|
|
31
|
+
<question type='handWriting'>
|
|
32
|
+
<questionText format='html'>2古く<u>ばいえん</u>でまっ黒にすすけた煉瓦壁の陰に汽車が停まると、</questionText>
|
|
33
|
+
<info type='numberOfLetters'>2</info>
|
|
34
|
+
<answer fraction='100'>
|
|
35
|
+
<text>2煤煙</text>
|
|
36
|
+
</answer>
|
|
37
|
+
<answer fraction='0'>
|
|
38
|
+
<text>2梅園</text>
|
|
39
|
+
<feedback>
|
|
40
|
+
<text>2これは”ばいえん”違いですね。</text>
|
|
41
|
+
</feedback>
|
|
42
|
+
</answer>
|
|
43
|
+
<source>
|
|
44
|
+
<author>2有島武郎</author>
|
|
45
|
+
<title>2或る女(前編)</title>
|
|
46
|
+
<link>
|
|
47
|
+
<label>2青空文庫</label>
|
|
48
|
+
<url>2http://www.aozora.gr.jp/</url>
|
|
49
|
+
</link>
|
|
50
|
+
</source>
|
|
51
|
+
</question>
|
|
52
|
+
</quizUnit>
|
|
53
|
+
</quiz>
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
---
|
|
2
|
+
- quiz:
|
|
3
|
+
- quizUnit:
|
|
4
|
+
- unitText:
|
|
5
|
+
- format: html
|
|
6
|
+
- 次の
|
|
7
|
+
- u:
|
|
8
|
+
- 下線部
|
|
9
|
+
- の読み仮名を漢字に直せ。
|
|
10
|
+
- info2:
|
|
11
|
+
- type: defaultNumberOfLetters
|
|
12
|
+
- 3
|
|
13
|
+
- info:
|
|
14
|
+
- type: defaultAllotment
|
|
15
|
+
- 3
|
|
16
|
+
- question:
|
|
17
|
+
- type: handWriting
|
|
18
|
+
- questionText:
|
|
19
|
+
- format: html
|
|
20
|
+
- 古く、<u>ばいえん</u>でまっ黒にすすけた煉瓦壁の陰に汽車が停まると、
|
|
21
|
+
- info:
|
|
22
|
+
- type: numberOfLetters
|
|
23
|
+
- answer:
|
|
24
|
+
- fraction: 100
|
|
25
|
+
- text:
|
|
26
|
+
- 煤煙
|
|
27
|
+
- answer:
|
|
28
|
+
- fraction: 0
|
|
29
|
+
- text:
|
|
30
|
+
- 梅園
|
|
31
|
+
- feedback:
|
|
32
|
+
- text:
|
|
33
|
+
- これは”ばいえん”違いですね。
|
|
34
|
+
- source:
|
|
35
|
+
- author:
|
|
36
|
+
- 有島武郎
|
|
37
|
+
- title:
|
|
38
|
+
- 或る女(前編)
|
|
39
|
+
- link:
|
|
40
|
+
- label:
|
|
41
|
+
- 青空文庫
|
|
42
|
+
- url:
|
|
43
|
+
- http://www.aozora.gr.jp/
|
|
44
|
+
- question:
|
|
45
|
+
- type: handWriting
|
|
46
|
+
- questionText:
|
|
47
|
+
- format: html
|
|
48
|
+
- 2古く
|
|
49
|
+
- u:
|
|
50
|
+
- ばいえん
|
|
51
|
+
- でまっ黒にすすけた煉瓦壁の陰に汽車が停まると、
|
|
52
|
+
- info:
|
|
53
|
+
- type: numberOfLetters
|
|
54
|
+
- answer:
|
|
55
|
+
- fraction: 100
|
|
56
|
+
- text:
|
|
57
|
+
- 2煤煙
|
|
58
|
+
- answer:
|
|
59
|
+
- fraction: 0
|
|
60
|
+
- text:
|
|
61
|
+
- 2梅園
|
|
62
|
+
- feedback:
|
|
63
|
+
- text:
|
|
64
|
+
- 2これは”ばいえん”違いですね。
|
|
65
|
+
- source:
|
|
66
|
+
- author:
|
|
67
|
+
- 2有島武郎
|
|
68
|
+
- title:
|
|
69
|
+
- 2或る女(前編)
|
|
70
|
+
- link:
|
|
71
|
+
- label:
|
|
72
|
+
- 2青空文庫
|
|
73
|
+
- url:
|
|
74
|
+
- 2http://www.aozora.gr.jp/
|