ox 1.5.4 → 1.5.5
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of ox might be problematic. Click here for more details.
- data/README.md +21 -3
- data/ext/ox/dump.c +64 -42
- data/ext/ox/extconf.rb +34 -2
- data/ext/ox/gen_load.c +13 -13
- data/ext/ox/obj_load.c +31 -28
- data/ext/ox/ox.c +41 -31
- data/ext/ox/ox.h +20 -13
- data/ext/ox/parse.c +1 -0
- data/ext/ox/sax.c +323 -26
- data/lib/ox.rb +1 -2
- data/lib/ox/element.rb +1 -1
- data/lib/ox/sax.rb +24 -11
- data/lib/ox/version.rb +1 -1
- metadata +4 -50
- data/test/Sample.graffle +0 -2318
- data/test/bench.rb +0 -53
- data/test/bug1.rb +0 -24
- data/test/bug2.rb +0 -38
- data/test/bug3.rb +0 -21
- data/test/cache16_test.rb +0 -17
- data/test/cache8_test.rb +0 -17
- data/test/cache_test.rb +0 -17
- data/test/files.rb +0 -29
- data/test/func.rb +0 -652
- data/test/gen_sample.rb +0 -22
- data/test/obj_sample.rb +0 -19
- data/test/ox/change.rb +0 -16
- data/test/ox/dir.rb +0 -21
- data/test/ox/doc.rb +0 -39
- data/test/ox/file.rb +0 -33
- data/test/ox/group.rb +0 -18
- data/test/ox/hasprops.rb +0 -18
- data/test/ox/layer.rb +0 -14
- data/test/ox/line.rb +0 -22
- data/test/ox/oval.rb +0 -12
- data/test/ox/rect.rb +0 -12
- data/test/ox/shape.rb +0 -37
- data/test/ox/text.rb +0 -23
- data/test/parse_cmp.rb +0 -261
- data/test/perf.rb +0 -91
- data/test/perf_gen.rb +0 -237
- data/test/perf_mars.rb +0 -114
- data/test/perf_obj.rb +0 -124
- data/test/perf_pod.rb +0 -88
- data/test/perf_sax.rb +0 -233
- data/test/perf_write.rb +0 -80
- data/test/sample.rb +0 -55
- data/test/sample/change.rb +0 -14
- data/test/sample/dir.rb +0 -19
- data/test/sample/doc.rb +0 -36
- data/test/sample/file.rb +0 -48
- data/test/sample/group.rb +0 -16
- data/test/sample/hasprops.rb +0 -16
- data/test/sample/layer.rb +0 -12
- data/test/sample/line.rb +0 -20
- data/test/sample/oval.rb +0 -10
- data/test/sample/rect.rb +0 -10
- data/test/sample/shape.rb +0 -35
- data/test/sample/text.rb +0 -20
- data/test/sax_test.rb +0 -468
- data/test/test.rb +0 -70
data/test/sample/change.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
|
2
|
-
module Sample
|
3
|
-
class Change
|
4
|
-
attr_accessor :time
|
5
|
-
attr_accessor :user
|
6
|
-
attr_accessor :comment
|
7
|
-
|
8
|
-
def initialize(comment=nil, time=nil, user=nil)
|
9
|
-
@user = user || ENV['USER']
|
10
|
-
@time = time || Time.now
|
11
|
-
@comment = comment
|
12
|
-
end
|
13
|
-
end # Change
|
14
|
-
end # Sample
|
data/test/sample/dir.rb
DELETED
data/test/sample/doc.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'sample/hasprops'
|
3
|
-
require 'sample/group'
|
4
|
-
require 'sample/layer'
|
5
|
-
require 'sample/line'
|
6
|
-
require 'sample/shape'
|
7
|
-
require 'sample/oval'
|
8
|
-
require 'sample/rect'
|
9
|
-
require 'sample/text'
|
10
|
-
require 'sample/change'
|
11
|
-
|
12
|
-
module Sample
|
13
|
-
class Doc
|
14
|
-
include HasProps
|
15
|
-
|
16
|
-
attr_accessor :title
|
17
|
-
attr_accessor :create_time
|
18
|
-
attr_accessor :user
|
19
|
-
# Hash of layers in the document indexed by layer name.
|
20
|
-
attr_reader :layers
|
21
|
-
attr_reader :change_history
|
22
|
-
|
23
|
-
def initialize(title)
|
24
|
-
@title = title
|
25
|
-
@user = ENV['USER']
|
26
|
-
@create_time = Time.now
|
27
|
-
@layers = { }
|
28
|
-
@change_history = []
|
29
|
-
end
|
30
|
-
|
31
|
-
def add_change(comment, time=nil, user=nil)
|
32
|
-
@change_history << Change.new(comment, time, user)
|
33
|
-
end
|
34
|
-
|
35
|
-
end # Doc
|
36
|
-
end # Sample
|
data/test/sample/file.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'etc'
|
3
|
-
|
4
|
-
module Sample
|
5
|
-
|
6
|
-
class File
|
7
|
-
attr_accessor :name, :ctime, :mtime, :size, :owner, :group, :permissions
|
8
|
-
|
9
|
-
def initialize(filename)
|
10
|
-
@name = ::File.basename(filename)
|
11
|
-
stat = ::File.stat(filename)
|
12
|
-
@ctime = stat.ctime
|
13
|
-
@mtime = stat.mtime
|
14
|
-
@size = stat.size
|
15
|
-
@owner = Etc.getpwuid(stat.uid).name
|
16
|
-
@group = Etc.getgrgid(stat.gid).name
|
17
|
-
if false
|
18
|
-
@permissions = {
|
19
|
-
'user' => {
|
20
|
-
'read' => (0 != (stat.mode & 0x0100)),
|
21
|
-
'write' => (0 != (stat.mode & 0x0080)),
|
22
|
-
'execute' => (0 != (stat.mode & 0x0040))},
|
23
|
-
'group' => {
|
24
|
-
'read' => (0 != (stat.mode & 0x0020)),
|
25
|
-
'write' => (0 != (stat.mode & 0x0010)),
|
26
|
-
'execute' => (0 != (stat.mode & 0x0008))},
|
27
|
-
'other' => {
|
28
|
-
'read' => (0 != (stat.mode & 0x0004)),
|
29
|
-
'write' => (0 != (stat.mode & 0x0002)),
|
30
|
-
'execute' => (0 != (stat.mode & 0x0001))}
|
31
|
-
}
|
32
|
-
else
|
33
|
-
@permissions = {
|
34
|
-
'user' => [(0 != (stat.mode & 0x0100)) ? 'r' : '-',
|
35
|
-
(0 != (stat.mode & 0x0080)) ? 'w' : '-',
|
36
|
-
(0 != (stat.mode & 0x0040)) ? 'x' : '-'].join(''),
|
37
|
-
'group' => [(0 != (stat.mode & 0x0020)) ? 'r' : '-',
|
38
|
-
(0 != (stat.mode & 0x0010)) ? 'w' : '-',
|
39
|
-
(0 != (stat.mode & 0x0008)) ? 'x' : '-'].join(''),
|
40
|
-
'other' => [(0 != (stat.mode & 0x0004)) ? 'r' : '-',
|
41
|
-
(0 != (stat.mode & 0x0002)) ? 'w' : '-',
|
42
|
-
(0 != (stat.mode & 0x0001)) ? 'x' : '-'].join('')
|
43
|
-
}
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
end # File
|
48
|
-
end # Sample
|
data/test/sample/group.rb
DELETED
data/test/sample/hasprops.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
|
2
|
-
module Sample
|
3
|
-
module HasProps
|
4
|
-
|
5
|
-
def add_prop(key, value)
|
6
|
-
@props = { } unless self.instance_variable_defined?(:@props)
|
7
|
-
@props[key] = value
|
8
|
-
end
|
9
|
-
|
10
|
-
def props
|
11
|
-
@props = { } unless self.instance_variable_defined?(:@props)
|
12
|
-
@props
|
13
|
-
end
|
14
|
-
|
15
|
-
end # HasProps
|
16
|
-
end # Sample
|
data/test/sample/layer.rb
DELETED
data/test/sample/line.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
module Sample
|
2
|
-
|
3
|
-
class Line
|
4
|
-
include HasProps
|
5
|
-
|
6
|
-
attr_accessor :x, :y, :dx, :dy
|
7
|
-
attr_accessor :color
|
8
|
-
attr_accessor :thick
|
9
|
-
|
10
|
-
def initialize(x, y, dx, dy, thick, color)
|
11
|
-
@x = x
|
12
|
-
@y = y
|
13
|
-
@dx = dx
|
14
|
-
@dy = dy
|
15
|
-
@thick = thick
|
16
|
-
@color = color
|
17
|
-
end
|
18
|
-
|
19
|
-
end # Line
|
20
|
-
end # Sample
|
data/test/sample/oval.rb
DELETED
data/test/sample/rect.rb
DELETED
data/test/sample/shape.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
|
2
|
-
module Sample
|
3
|
-
class Shape
|
4
|
-
include HasProps
|
5
|
-
|
6
|
-
attr_accessor :bounds
|
7
|
-
attr_accessor :color
|
8
|
-
attr_accessor :border, :border_color
|
9
|
-
|
10
|
-
def initialize(left, top, wide, high, color=nil)
|
11
|
-
@bounds = [[left, top], [left + wide, top + high]]
|
12
|
-
@color = color
|
13
|
-
@border = 1
|
14
|
-
@border_color = :black
|
15
|
-
end
|
16
|
-
|
17
|
-
def left
|
18
|
-
@bounds[0][0]
|
19
|
-
end
|
20
|
-
|
21
|
-
def top
|
22
|
-
@bounds[0][1]
|
23
|
-
end
|
24
|
-
|
25
|
-
def width
|
26
|
-
@bounds[1][0] - @bounds[0][0]
|
27
|
-
end
|
28
|
-
|
29
|
-
def height
|
30
|
-
@bounds[1][1] - @bounds[0][1]
|
31
|
-
end
|
32
|
-
|
33
|
-
end # Shape
|
34
|
-
end # Sample
|
35
|
-
|
data/test/sample/text.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
|
2
|
-
module Sample
|
3
|
-
class Text < Shape
|
4
|
-
attr_accessor :text
|
5
|
-
attr_accessor :font
|
6
|
-
attr_accessor :font_size
|
7
|
-
attr_accessor :just
|
8
|
-
attr_accessor :text_color
|
9
|
-
|
10
|
-
def initialize(text, left, top, wide, high, color=nil)
|
11
|
-
super(left, top, wide, high, color)
|
12
|
-
@text = text
|
13
|
-
@font = 'helvetica'
|
14
|
-
@font_size = 14
|
15
|
-
@just = 'left'
|
16
|
-
@text_color = 'black'
|
17
|
-
end
|
18
|
-
|
19
|
-
end # Text
|
20
|
-
end # Sample
|
data/test/sax_test.rb
DELETED
@@ -1,468 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby -wW1
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
$: << File.join(File.dirname(__FILE__), "../lib")
|
5
|
-
$: << File.join(File.dirname(__FILE__), "../ext")
|
6
|
-
|
7
|
-
require 'stringio'
|
8
|
-
require 'test/unit'
|
9
|
-
require 'optparse'
|
10
|
-
require 'ox'
|
11
|
-
|
12
|
-
opts = OptionParser.new
|
13
|
-
opts.on("-h", "--help", "Show this display") { puts opts; Process.exit!(0) }
|
14
|
-
files = opts.parse(ARGV)
|
15
|
-
|
16
|
-
class StartSax < ::Ox::Sax
|
17
|
-
attr_accessor :calls
|
18
|
-
|
19
|
-
def initialize()
|
20
|
-
@calls = []
|
21
|
-
end
|
22
|
-
|
23
|
-
def start_element(name)
|
24
|
-
@calls << [:start_element, name]
|
25
|
-
end
|
26
|
-
|
27
|
-
def attr(name, value)
|
28
|
-
@calls << [:attr, name, value]
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
class AllSax < StartSax
|
33
|
-
def initialize()
|
34
|
-
super
|
35
|
-
end
|
36
|
-
|
37
|
-
def instruct(target)
|
38
|
-
@calls << [:instruct, target]
|
39
|
-
end
|
40
|
-
|
41
|
-
def doctype(value)
|
42
|
-
@calls << [:doctype, value]
|
43
|
-
end
|
44
|
-
|
45
|
-
def comment(value)
|
46
|
-
@calls << [:comment, value]
|
47
|
-
end
|
48
|
-
|
49
|
-
def cdata(value)
|
50
|
-
@calls << [:cdata, value]
|
51
|
-
end
|
52
|
-
|
53
|
-
def text(value)
|
54
|
-
@calls << [:text, value]
|
55
|
-
end
|
56
|
-
|
57
|
-
def end_element(name)
|
58
|
-
@calls << [:end_element, name]
|
59
|
-
end
|
60
|
-
|
61
|
-
def error(message, line, column)
|
62
|
-
@calls << [:error, message, line, column]
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
class Func < ::Test::Unit::TestCase
|
67
|
-
|
68
|
-
def test_sax_io_pipe
|
69
|
-
handler = AllSax.new()
|
70
|
-
input,w = IO.pipe
|
71
|
-
w << %{<top/>}
|
72
|
-
w.close
|
73
|
-
Ox.sax_parse(handler, input)
|
74
|
-
assert_equal(handler.calls,
|
75
|
-
[[:start_element, :top],
|
76
|
-
[:end_element, :top]])
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_sax_io_file
|
80
|
-
handler = AllSax.new()
|
81
|
-
input = IO.open(IO.sysopen(File.join(File.dirname(__FILE__), 'basic.xml')))
|
82
|
-
Ox.sax_parse(handler, input)
|
83
|
-
assert_equal(handler.calls,
|
84
|
-
[[:start_element, :top],
|
85
|
-
[:end_element, :top]])
|
86
|
-
end
|
87
|
-
|
88
|
-
def parse_compare(xml, expected, handler_class=AllSax, special=false)
|
89
|
-
handler = handler_class.new()
|
90
|
-
input = StringIO.new(xml)
|
91
|
-
if special
|
92
|
-
Ox.sax_parse(handler, input, :convert_special => true)
|
93
|
-
else
|
94
|
-
Ox.sax_parse(handler, input)
|
95
|
-
end
|
96
|
-
assert_equal(expected, handler.calls)
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_sax_instruct_simple
|
100
|
-
parse_compare(%{<?xml?>}, [[:instruct, 'xml']])
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_sax_instruct_blank
|
104
|
-
parse_compare(%{<?xml?>}, [], StartSax)
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_sax_instruct_attrs
|
108
|
-
parse_compare(%{<?xml version="1.0" encoding="UTF-8"?>},
|
109
|
-
[[:instruct, 'xml'],
|
110
|
-
[:attr, :version, "1.0"],
|
111
|
-
[:attr, :encoding, "UTF-8"]])
|
112
|
-
end
|
113
|
-
|
114
|
-
def test_sax_instruct_loose
|
115
|
-
parse_compare(%{<? xml
|
116
|
-
version = "1.0"
|
117
|
-
encoding = "UTF-8" ?>},
|
118
|
-
[[:instruct, 'xml'],
|
119
|
-
[:attr, :version, "1.0"],
|
120
|
-
[:attr, :encoding, "UTF-8"]])
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_sax_element_simple
|
124
|
-
parse_compare(%{<top/>},
|
125
|
-
[[:start_element, :top],
|
126
|
-
[:end_element, :top]])
|
127
|
-
end
|
128
|
-
|
129
|
-
def test_sax_element_attrs
|
130
|
-
parse_compare(%{<top x="57" y='42' z=33 />},
|
131
|
-
[[:start_element, :top],
|
132
|
-
[:attr, :x, "57"],
|
133
|
-
[:attr, :y, "42"],
|
134
|
-
[:attr, :z, "33"],
|
135
|
-
[:end_element, :top]])
|
136
|
-
end
|
137
|
-
|
138
|
-
def test_sax_two_top
|
139
|
-
parse_compare(%{<top/><top/>},
|
140
|
-
[[:start_element, :top],
|
141
|
-
[:end_element, :top],
|
142
|
-
[:error, "invalid format, multiple top level elements", 1, 9],
|
143
|
-
[:start_element, :top],
|
144
|
-
[:end_element, :top]])
|
145
|
-
|
146
|
-
|
147
|
-
end
|
148
|
-
|
149
|
-
def test_sax_nested1
|
150
|
-
parse_compare(%{<?xml version="1.0"?>
|
151
|
-
<top>
|
152
|
-
<child>
|
153
|
-
<grandchild/>
|
154
|
-
</child>
|
155
|
-
</top>
|
156
|
-
},
|
157
|
-
[[:instruct, 'xml'],
|
158
|
-
[:attr, :version, "1.0"],
|
159
|
-
[:start_element, :top],
|
160
|
-
[:start_element, :child],
|
161
|
-
[:start_element, :grandchild],
|
162
|
-
[:end_element, :grandchild],
|
163
|
-
[:end_element, :child],
|
164
|
-
[:end_element, :top],
|
165
|
-
])
|
166
|
-
end
|
167
|
-
|
168
|
-
def test_sax_nested1_tight
|
169
|
-
parse_compare(%{<?xml version="1.0"?><top><child><grandchild/></child></top>},
|
170
|
-
[[:instruct, 'xml'],
|
171
|
-
[:attr, :version, "1.0"],
|
172
|
-
[:start_element, :top],
|
173
|
-
[:start_element, :child],
|
174
|
-
[:start_element, :grandchild],
|
175
|
-
[:end_element, :grandchild],
|
176
|
-
[:end_element, :child],
|
177
|
-
[:end_element, :top],
|
178
|
-
])
|
179
|
-
end
|
180
|
-
|
181
|
-
def test_sax_element_name_mismatch
|
182
|
-
parse_compare(%{<?xml version="1.0"?>
|
183
|
-
<top>
|
184
|
-
<child>
|
185
|
-
<grandchild/>
|
186
|
-
</parent>
|
187
|
-
</top>},
|
188
|
-
[[:instruct, 'xml'],
|
189
|
-
[:attr, :version, "1.0"],
|
190
|
-
[:start_element, :top],
|
191
|
-
[:start_element, :child],
|
192
|
-
[:start_element, :grandchild],
|
193
|
-
[:end_element, :grandchild],
|
194
|
-
[:error, "invalid format, element start and end names do not match", 5, 12]
|
195
|
-
])
|
196
|
-
end
|
197
|
-
|
198
|
-
def test_sax_nested
|
199
|
-
parse_compare(%{<?xml version="1.0"?>
|
200
|
-
<top>
|
201
|
-
<child>
|
202
|
-
<grandchild/>
|
203
|
-
</child>
|
204
|
-
<child>
|
205
|
-
<grandchild/>
|
206
|
-
<grandchild/>
|
207
|
-
</child>
|
208
|
-
</top>
|
209
|
-
},
|
210
|
-
[[:instruct, 'xml'],
|
211
|
-
[:attr, :version, "1.0"],
|
212
|
-
[:start_element, :top],
|
213
|
-
[:start_element, :child],
|
214
|
-
[:start_element, :grandchild],
|
215
|
-
[:end_element, :grandchild],
|
216
|
-
[:end_element, :child],
|
217
|
-
[:start_element, :child],
|
218
|
-
[:start_element, :grandchild],
|
219
|
-
[:end_element, :grandchild],
|
220
|
-
[:start_element, :grandchild],
|
221
|
-
[:end_element, :grandchild],
|
222
|
-
[:end_element, :child],
|
223
|
-
[:end_element, :top],
|
224
|
-
])
|
225
|
-
end
|
226
|
-
def test_sax_element_no_term
|
227
|
-
parse_compare(%{
|
228
|
-
<top>
|
229
|
-
<child/>
|
230
|
-
},
|
231
|
-
[[:start_element, :top],
|
232
|
-
[:start_element, :child],
|
233
|
-
[:end_element, :child],
|
234
|
-
[:error, "invalid format, element not terminated", 4, 1]
|
235
|
-
])
|
236
|
-
end
|
237
|
-
|
238
|
-
def test_sax_text
|
239
|
-
parse_compare(%{<top>This is some text.</top>},
|
240
|
-
[[:start_element, :top],
|
241
|
-
[:text, "This is some text."],
|
242
|
-
[:end_element, :top]
|
243
|
-
])
|
244
|
-
end
|
245
|
-
|
246
|
-
def test_sax_special
|
247
|
-
parse_compare(%{<top name="A&Z">This is <some> text.</top>},
|
248
|
-
[[:start_element, :top],
|
249
|
-
[:attr, :name, 'A&Z'],
|
250
|
-
[:text, "This is <some> text."],
|
251
|
-
[:end_element, :top]
|
252
|
-
], AllSax, true)
|
253
|
-
end
|
254
|
-
|
255
|
-
def test_sax_text_no_term
|
256
|
-
parse_compare(%{<top>This is some text.},
|
257
|
-
[[:start_element, :top],
|
258
|
-
[:error, "invalid format, text terminated unexpectedly", 1, 24],
|
259
|
-
])
|
260
|
-
end
|
261
|
-
# TBD invalid chacters in text
|
262
|
-
|
263
|
-
def test_sax_doctype
|
264
|
-
parse_compare(%{<?xml version="1.0"?>
|
265
|
-
<!DOCTYPE top PUBLIC "top.dtd">
|
266
|
-
<top/>
|
267
|
-
},
|
268
|
-
[[:instruct, 'xml'],
|
269
|
-
[:attr, :version, "1.0"],
|
270
|
-
[:doctype, ' top PUBLIC "top.dtd"'],
|
271
|
-
[:start_element, :top],
|
272
|
-
[:end_element, :top]])
|
273
|
-
end
|
274
|
-
|
275
|
-
def test_sax_doctype_bad_order
|
276
|
-
parse_compare(%{<?xml version="1.0"?>
|
277
|
-
<top/>
|
278
|
-
<!DOCTYPE top PUBLIC "top.dtd">
|
279
|
-
},
|
280
|
-
[[:instruct, 'xml'],
|
281
|
-
[:attr, :version, "1.0"],
|
282
|
-
[:start_element, :top],
|
283
|
-
[:end_element, :top],
|
284
|
-
[:error, "invalid format, DOCTYPE can not come after an element", 3, 11],
|
285
|
-
[:doctype, ' top PUBLIC "top.dtd"']])
|
286
|
-
end
|
287
|
-
|
288
|
-
def test_sax_instruct_bad_order
|
289
|
-
parse_compare(%{
|
290
|
-
<!DOCTYPE top PUBLIC "top.dtd">
|
291
|
-
<?xml version="1.0"?>
|
292
|
-
<top/>
|
293
|
-
},
|
294
|
-
[[:doctype, " top PUBLIC \"top.dtd\""],
|
295
|
-
[:error, "invalid format, instruction must come before elements", 3, 3],
|
296
|
-
[:instruct, "xml"],
|
297
|
-
[:attr, :version, "1.0"],
|
298
|
-
[:start_element, :top],
|
299
|
-
[:end_element, :top]])
|
300
|
-
end
|
301
|
-
|
302
|
-
def test_sax_comment
|
303
|
-
parse_compare(%{<?xml version="1.0"?>
|
304
|
-
<!--First comment.-->
|
305
|
-
<top>Before<!--Nested comment.-->After</top>
|
306
|
-
},
|
307
|
-
[[:instruct, 'xml'],
|
308
|
-
[:attr, :version, "1.0"],
|
309
|
-
[:comment, 'First comment.'],
|
310
|
-
[:start_element, :top],
|
311
|
-
[:text, 'Before'],
|
312
|
-
[:comment, 'Nested comment.'],
|
313
|
-
[:text, 'After'],
|
314
|
-
[:end_element, :top]])
|
315
|
-
end
|
316
|
-
|
317
|
-
def test_sax_comment_no_term
|
318
|
-
parse_compare(%{<?xml version="1.0"?>
|
319
|
-
<!--First comment.--
|
320
|
-
<top/>
|
321
|
-
},
|
322
|
-
[[:instruct, 'xml'],
|
323
|
-
[:attr, :version, "1.0"],
|
324
|
-
[:error, "invalid format, comment terminated unexpectedly", 3, 1], # continue on
|
325
|
-
[:comment, 'First comment.'],
|
326
|
-
[:start_element, :top],
|
327
|
-
[:end_element, :top]])
|
328
|
-
end
|
329
|
-
|
330
|
-
def test_sax_cdata
|
331
|
-
parse_compare(%{<?xml version="1.0"?>
|
332
|
-
<top>
|
333
|
-
<![CDATA[This is CDATA.]]>
|
334
|
-
</top>
|
335
|
-
},
|
336
|
-
[[:instruct, 'xml'],
|
337
|
-
[:attr, :version, "1.0"],
|
338
|
-
[:start_element, :top],
|
339
|
-
[:cdata, 'This is CDATA.'],
|
340
|
-
[:end_element, :top]])
|
341
|
-
end
|
342
|
-
|
343
|
-
def test_sax_cdata_no_term
|
344
|
-
parse_compare(%{<?xml version="1.0"?>
|
345
|
-
<top>
|
346
|
-
<![CDATA[This is CDATA.]]
|
347
|
-
</top>
|
348
|
-
},
|
349
|
-
[[:instruct, 'xml'],
|
350
|
-
[:attr, :version, "1.0"],
|
351
|
-
[:start_element, :top],
|
352
|
-
[:error, "invalid format, cdata terminated unexpectedly", 5, 1]])
|
353
|
-
end
|
354
|
-
|
355
|
-
def test_sax_cdata_empty
|
356
|
-
parse_compare(%{<?xml version="1.0"?>
|
357
|
-
<top>
|
358
|
-
<child><![CDATA[]]></child>
|
359
|
-
<child><![CDATA[This is CDATA.]]></child>
|
360
|
-
</top>
|
361
|
-
},
|
362
|
-
[[:instruct, 'xml'],
|
363
|
-
[:attr, :version, '1.0'],
|
364
|
-
[:start_element, :top],
|
365
|
-
[:start_element, :child],
|
366
|
-
[:cdata, ''],
|
367
|
-
[:end_element, :child],
|
368
|
-
[:start_element, :child],
|
369
|
-
[:cdata, 'This is CDATA.'],
|
370
|
-
[:end_element, :child],
|
371
|
-
[:end_element, :top]])
|
372
|
-
end
|
373
|
-
|
374
|
-
def test_sax_mixed
|
375
|
-
parse_compare(%{<?xml version="1.0"?>
|
376
|
-
<?ox version="1.0" mode="object" circular="no" xsd_date="no"?>
|
377
|
-
<!DOCTYPE table PUBLIC "-//ox//DTD TABLE 1.0//EN" "http://www.ohler.com/DTDs/TestTable-1.0.dtd">
|
378
|
-
<table>
|
379
|
-
<row id="00004">
|
380
|
-
<cell id="A" type="Fixnum">1234</cell>
|
381
|
-
<cell id="B" type="String">A string.</cell>
|
382
|
-
<cell id="C" type="String">This is a longer string that stretches over a larger number of characters.</cell>
|
383
|
-
<cell id="D" type="Float">-12.345</cell>
|
384
|
-
<cell id="E" type="Date">2011-09-18 23:07:26 +0900</cell>
|
385
|
-
<cell id="F" type="Image"><![CDATA[xx00xx00xx00xx00xx00xx00xx00xx00xx00xx00xx00xx00xx00xx00xx00xx00xx00xx00xx00]]></cell>
|
386
|
-
</row>
|
387
|
-
</table>
|
388
|
-
},
|
389
|
-
[[:instruct, "xml"],
|
390
|
-
[:attr, :version, "1.0"],
|
391
|
-
[:instruct, "ox"],
|
392
|
-
[:attr, :version, "1.0"],
|
393
|
-
[:attr, :mode, "object"],
|
394
|
-
[:attr, :circular, "no"],
|
395
|
-
[:attr, :xsd_date, "no"],
|
396
|
-
[:doctype, " table PUBLIC \"-//ox//DTD TABLE 1.0//EN\" \"http://www.ohler.com/DTDs/TestTable-1.0.dtd\""],
|
397
|
-
[:start_element, :table],
|
398
|
-
[:start_element, :row],
|
399
|
-
[:attr, :id, "00004"],
|
400
|
-
[:start_element, :cell],
|
401
|
-
[:attr, :id, "A"],
|
402
|
-
[:attr, :type, "Fixnum"],
|
403
|
-
[:text, "1234"],
|
404
|
-
[:end_element, :cell],
|
405
|
-
[:start_element, :cell],
|
406
|
-
[:attr, :id, "B"],
|
407
|
-
[:attr, :type, "String"],
|
408
|
-
[:text, "A string."],
|
409
|
-
[:end_element, :cell],
|
410
|
-
[:start_element, :cell],
|
411
|
-
[:attr, :id, "C"],
|
412
|
-
[:attr, :type, "String"],
|
413
|
-
[:text, "This is a longer string that stretches over a larger number of characters."],
|
414
|
-
[:end_element, :cell],
|
415
|
-
[:start_element, :cell],
|
416
|
-
[:attr, :id, "D"],
|
417
|
-
[:attr, :type, "Float"],
|
418
|
-
[:text, "-12.345"],
|
419
|
-
[:end_element, :cell],
|
420
|
-
[:start_element, :cell],
|
421
|
-
[:attr, :id, "E"],
|
422
|
-
[:attr, :type, "Date"],
|
423
|
-
[:text, "2011-09-18 23:07:26 +0900"],
|
424
|
-
[:end_element, :cell],
|
425
|
-
[:start_element, :cell],
|
426
|
-
[:attr, :id, "F"],
|
427
|
-
[:attr, :type, "Image"],
|
428
|
-
[:cdata, "xx00xx00xx00xx00xx00xx00xx00xx00xx00xx00xx00xx00xx00xx00xx00xx00xx00xx00xx00"],
|
429
|
-
[:end_element, :cell],
|
430
|
-
[:end_element, :row],
|
431
|
-
[:end_element, :table]])
|
432
|
-
end
|
433
|
-
|
434
|
-
def test_sax_encoding
|
435
|
-
if RUBY_VERSION.start_with?('1.8')
|
436
|
-
assert(true)
|
437
|
-
else
|
438
|
-
parse_compare(%{<?xml version="1.0" encoding="UTF-8"?>
|
439
|
-
<top>ピーター</top>
|
440
|
-
},
|
441
|
-
[[:instruct, "xml"],
|
442
|
-
[:attr, :version, "1.0"],
|
443
|
-
[:attr, :encoding, "UTF-8"],
|
444
|
-
[:start_element, :top],
|
445
|
-
[:text, 'ピーター'],
|
446
|
-
[:end_element, :top]])
|
447
|
-
end
|
448
|
-
end
|
449
|
-
|
450
|
-
def test_sax_full_encoding
|
451
|
-
if RUBY_VERSION.start_with?('1.8')
|
452
|
-
assert(true)
|
453
|
-
else
|
454
|
-
parse_compare(%{<?xml version="1.0" encoding="UTF-8"?>
|
455
|
-
<いち name="ピーター" つま="まきえ">ピーター</いち>
|
456
|
-
},
|
457
|
-
[[:instruct, "xml"],
|
458
|
-
[:attr, :version, "1.0"],
|
459
|
-
[:attr, :encoding, "UTF-8"],
|
460
|
-
[:start_element, :いち],
|
461
|
-
[:attr, :name, 'ピーター'],
|
462
|
-
[:attr, :つま, 'まきえ'],
|
463
|
-
[:text, 'ピーター'],
|
464
|
-
[:end_element, :いち]])
|
465
|
-
end
|
466
|
-
end
|
467
|
-
|
468
|
-
end
|