xamplr-pp 1.0.0 → 1.1.4

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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ junk*
2
+ tmp
3
+ *.sw?
4
+ .DS_Store
5
+ coverage
6
+ rdoc
7
+ pkg
data/Makefile ADDED
@@ -0,0 +1,12 @@
1
+
2
+ check:
3
+ git clean -dx --dry-run
4
+
5
+ clean:
6
+ git clean -fdx
7
+
8
+ release:
9
+ rake version:bump:patch release
10
+
11
+ stalk:
12
+ gemstalk hutch xamplr-pp
data/VERSION.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  ---
2
- :minor: 0
3
- :patch: 0
4
2
  :major: 1
3
+ :minor: 1
4
+ :patch: 4
5
+ :build:
@@ -0,0 +1,212 @@
1
+ # xampl-pp : XML pull parser
2
+ # Copyright (C) 2002-2009 Bob Hutchison
3
+ #
4
+ # This library is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU Lesser General Public
6
+ # License as published by the Free Software Foundation; either
7
+ # version 2.1 of the License, or (at your option) any later version.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # #Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+ #
18
+
19
+
20
+ require "Lapidary/TestCase"
21
+ require "xampl-pp"
22
+
23
+ class XppTestEventTypes < Xampl_PP
24
+ def setType(v)
25
+ @type = v
26
+ end
27
+ end
28
+
29
+ class TC_EventTypes < Lapidary::TestCase
30
+ def setup
31
+ @xpp = XppTestEventTypes.new
32
+ end
33
+ #def tearDown
34
+ #end
35
+
36
+ def testSTART_DOCUMENT
37
+
38
+ @xpp.setType Xampl_PP::START_DOCUMENT
39
+ assert @xpp.startDocument?
40
+ assert !@xpp.endDocument?
41
+ assert !@xpp.startElement?
42
+ assert !@xpp.endElement?
43
+ assert !@xpp.text?
44
+ assert !@xpp.cdata?
45
+ assert !@xpp.entityRef?
46
+ assert !@xpp.ignorableWhitespace?
47
+ assert !@xpp.processingInstruction?
48
+ assert !@xpp.comment?
49
+ assert !@xpp.doctype?
50
+ end
51
+
52
+ def testEND_DOCUMENT
53
+
54
+ @xpp.setType Xampl_PP::END_DOCUMENT
55
+ assert !@xpp.startDocument?
56
+ assert @xpp.endDocument?
57
+ assert !@xpp.startElement?
58
+ assert !@xpp.endElement?
59
+ assert !@xpp.text?
60
+ assert !@xpp.cdata?
61
+ assert !@xpp.entityRef?
62
+ assert !@xpp.ignorableWhitespace?
63
+ assert !@xpp.processingInstruction?
64
+ assert !@xpp.comment?
65
+ assert !@xpp.doctype?
66
+ end
67
+
68
+ def testSTART_ELEMENT
69
+
70
+ @xpp.setType Xampl_PP::START_ELEMENT
71
+ assert !@xpp.startDocument?
72
+ assert !@xpp.endDocument?
73
+ assert @xpp.startElement?
74
+ assert !@xpp.endElement?
75
+ assert !@xpp.text?
76
+ assert !@xpp.cdata?
77
+ assert !@xpp.entityRef?
78
+ assert !@xpp.ignorableWhitespace?
79
+ assert !@xpp.processingInstruction?
80
+ assert !@xpp.comment?
81
+ assert !@xpp.doctype?
82
+ end
83
+
84
+ def testEND_ELEMENT
85
+
86
+ @xpp.setType Xampl_PP::END_ELEMENT
87
+ assert !@xpp.startDocument?
88
+ assert !@xpp.endDocument?
89
+ assert !@xpp.startElement?
90
+ assert @xpp.endElement?
91
+ assert !@xpp.text?
92
+ assert !@xpp.cdata?
93
+ assert !@xpp.entityRef?
94
+ assert !@xpp.ignorableWhitespace?
95
+ assert !@xpp.processingInstruction?
96
+ assert !@xpp.comment?
97
+ assert !@xpp.doctype?
98
+ end
99
+
100
+ def testTEXT
101
+
102
+ @xpp.setType Xampl_PP::TEXT
103
+ assert !@xpp.startDocument?
104
+ assert !@xpp.endDocument?
105
+ assert !@xpp.startElement?
106
+ assert !@xpp.endElement?
107
+ assert @xpp.text?
108
+ assert !@xpp.cdata?
109
+ assert !@xpp.entityRef?
110
+ assert !@xpp.ignorableWhitespace?
111
+ assert !@xpp.processingInstruction?
112
+ assert !@xpp.comment?
113
+ assert !@xpp.doctype?
114
+ end
115
+
116
+ def testCDATA_SECTION
117
+
118
+ @xpp.setType Xampl_PP::CDATA_SECTION
119
+ assert !@xpp.startDocument?
120
+ assert !@xpp.endDocument?
121
+ assert !@xpp.startElement?
122
+ assert !@xpp.endElement?
123
+ assert !@xpp.text?
124
+ assert @xpp.cdata?
125
+ assert !@xpp.entityRef?
126
+ assert !@xpp.ignorableWhitespace?
127
+ assert !@xpp.processingInstruction?
128
+ assert !@xpp.comment?
129
+ assert !@xpp.doctype?
130
+ end
131
+
132
+ def testENTITY_REF
133
+
134
+ @xpp.setType Xampl_PP::ENTITY_REF
135
+ assert !@xpp.startDocument?
136
+ assert !@xpp.endDocument?
137
+ assert !@xpp.startElement?
138
+ assert !@xpp.endElement?
139
+ assert !@xpp.text?
140
+ assert !@xpp.cdata?
141
+ assert @xpp.entityRef?
142
+ assert !@xpp.ignorableWhitespace?
143
+ assert !@xpp.processingInstruction?
144
+ assert !@xpp.comment?
145
+ assert !@xpp.doctype?
146
+ end
147
+
148
+ def testIGNORABLE_WHITESPACE
149
+
150
+ @xpp.setType Xampl_PP::IGNORABLE_WHITESPACE
151
+ assert !@xpp.startDocument?
152
+ assert !@xpp.endDocument?
153
+ assert !@xpp.startElement?
154
+ assert !@xpp.endElement?
155
+ assert !@xpp.text?
156
+ assert !@xpp.cdata?
157
+ assert !@xpp.entityRef?
158
+ assert @xpp.ignorableWhitespace?
159
+ assert !@xpp.processingInstruction?
160
+ assert !@xpp.comment?
161
+ assert !@xpp.doctype?
162
+ end
163
+
164
+ def testPROCESSING_INSTRUCTION
165
+
166
+ @xpp.setType Xampl_PP::PROCESSING_INSTRUCTION
167
+ assert !@xpp.startDocument?
168
+ assert !@xpp.endDocument?
169
+ assert !@xpp.startElement?
170
+ assert !@xpp.endElement?
171
+ assert !@xpp.text?
172
+ assert !@xpp.cdata?
173
+ assert !@xpp.entityRef?
174
+ assert !@xpp.ignorableWhitespace?
175
+ assert @xpp.processingInstruction?
176
+ assert !@xpp.comment?
177
+ assert !@xpp.doctype?
178
+ end
179
+
180
+ def testCOMMENT
181
+
182
+ @xpp.setType Xampl_PP::COMMENT
183
+ assert !@xpp.startDocument?
184
+ assert !@xpp.endDocument?
185
+ assert !@xpp.startElement?
186
+ assert !@xpp.endElement?
187
+ assert !@xpp.text?
188
+ assert !@xpp.cdata?
189
+ assert !@xpp.entityRef?
190
+ assert !@xpp.ignorableWhitespace?
191
+ assert !@xpp.processingInstruction?
192
+ assert @xpp.comment?
193
+ assert !@xpp.doctype?
194
+ end
195
+
196
+ def testDOCUMENT_DECLARATION
197
+
198
+ @xpp.setType Xampl_PP::DOCTYPE
199
+ assert !@xpp.startDocument?
200
+ assert !@xpp.endDocument?
201
+ assert !@xpp.startElement?
202
+ assert !@xpp.endElement?
203
+ assert !@xpp.text?
204
+ assert !@xpp.cdata?
205
+ assert !@xpp.entityRef?
206
+ assert !@xpp.ignorableWhitespace?
207
+ assert !@xpp.processingInstruction?
208
+ assert !@xpp.comment?
209
+ assert @xpp.doctype?
210
+ end
211
+ end
212
+
@@ -0,0 +1,56 @@
1
+ # xampl-pp : XML pull parser
2
+ # Copyright (C) 2002-2009 Bob Hutchison
3
+ #
4
+ # This library is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU Lesser General Public
6
+ # License as published by the Free Software Foundation; either
7
+ # version 2.1 of the License, or (at your option) any later version.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # #Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+ #
18
+
19
+ require "Lapidary/TestCase"
20
+ require "xampl-pp"
21
+
22
+ class TC_Features < Lapidary::TestCase
23
+ def setup
24
+ @xpp = Xampl_PP.new
25
+ end
26
+ #def tearDown
27
+ #end
28
+
29
+ def testInitialState
30
+ # the xpp parser will initialise to the following state
31
+ assert @xpp.processNamespace
32
+ assert !@xpp.reportNamespaceAttributes
33
+ end
34
+
35
+ def testProcessNamespace
36
+ @xpp.processNamespace = false
37
+ assert !@xpp.processNamespace
38
+ assert !@xpp.reportNamespaceAttributes
39
+
40
+ @xpp.processNamespace = true
41
+ assert @xpp.processNamespace
42
+ assert !@xpp.reportNamespaceAttributes
43
+ end
44
+
45
+ def testReportNamespaceAttributes
46
+ @xpp.reportNamespaceAttributes = true
47
+ assert @xpp.processNamespace
48
+ assert @xpp.reportNamespaceAttributes
49
+
50
+ @xpp.reportNamespaceAttributes = false
51
+ assert @xpp.processNamespace
52
+ assert !@xpp.reportNamespaceAttributes
53
+ end
54
+ end
55
+
56
+
@@ -0,0 +1,240 @@
1
+ # xampl-pp : XML pull parser
2
+ # Copyright (C) 2002-2009 Bob Hutchison
3
+ #
4
+ # This library is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU Lesser General Public
6
+ # License as published by the Free Software Foundation; either
7
+ # version 2.1 of the License, or (at your option) any later version.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # #Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+ #
18
+ require "Lapidary/TestCase"
19
+ require "xampl-pp"
20
+
21
+ class XppTestInput < Xampl_PP
22
+ def input
23
+ @input
24
+ end
25
+
26
+ def inputBuffer
27
+ @inputBuffer
28
+ end
29
+
30
+ def doSkipWhitespace
31
+ skipWhitespace
32
+ end
33
+
34
+ def doRead
35
+ read
36
+ end
37
+
38
+ def doExpect(c)
39
+ expect(c)
40
+ end
41
+
42
+ def doPeekAt0
43
+ peekAt0
44
+ end
45
+
46
+ def doPeekAt1
47
+ peekAt1
48
+ end
49
+
50
+ #def peek
51
+ #@peek
52
+ #end
53
+ end
54
+
55
+ class TC_Input < Lapidary::TestCase
56
+ def setup
57
+ @xpp = XppTestInput.new
58
+ end
59
+ #def tearDown
60
+ #end
61
+
62
+ def testInitialStateWithStringSource
63
+ @xpp.input = "hello"
64
+
65
+ assert @xpp.input == nil
66
+ assert @xpp.inputBuffer == "hello"
67
+ assert @xpp.column == 0
68
+
69
+ assert @xpp.startDocument?
70
+
71
+ assert @xpp.line == 1
72
+ assert @xpp.column == 0
73
+ assert @xpp.elementName.length == 0
74
+
75
+ assert @xpp.name == nil
76
+ assert @xpp.namespace == nil
77
+ assert @xpp.prefix == nil
78
+
79
+ assert @xpp.attributeName.length == 0
80
+ assert @xpp.attributeNamespace.length == 0
81
+ assert @xpp.attributePrefix.length == 0
82
+ assert @xpp.attributeValue.length == 0
83
+ end
84
+
85
+ def testInitialStateWithIOSource
86
+ @xpp.input = STDIN
87
+
88
+ assert @xpp.input == STDIN
89
+ assert @xpp.inputBuffer == nil
90
+ assert @xpp.column == 0
91
+
92
+ assert @xpp.startDocument?
93
+
94
+ assert @xpp.line == 0
95
+ assert @xpp.column == 0
96
+ assert @xpp.elementName.length == 0
97
+
98
+ assert @xpp.name == nil
99
+ assert @xpp.namespace == nil
100
+ assert @xpp.prefix == nil
101
+
102
+ assert @xpp.attributeName.length == 0
103
+ assert @xpp.attributeNamespace.length == 0
104
+ assert @xpp.attributePrefix.length == 0
105
+ assert @xpp.attributeValue.length == 0
106
+ end
107
+
108
+ def testPeekAtStringSource
109
+ @xpp.input = "1_2"
110
+ assert ?1 == @xpp.doPeekAt0
111
+ @xpp.doRead
112
+ assert ?2 == @xpp.doPeekAt1
113
+ @xpp.doRead
114
+ @xpp.doRead
115
+ assert nil == @xpp.doPeekAt0
116
+ end
117
+
118
+ def testPeekAtIOSource000
119
+ @xpp.input = File.new("TC_Input000.data")
120
+ assert ?1 == @xpp.doPeekAt0
121
+ @xpp.doRead
122
+ assert ?2 == @xpp.doPeekAt1
123
+ @xpp.doRead
124
+ @xpp.doRead
125
+ assert nil == @xpp.doPeekAt1 # have to get by the end of line
126
+ end
127
+
128
+ def testReadStringSource
129
+ @xpp.input = "12345"
130
+ assert ?1 == @xpp.doRead
131
+ assert 1 == @xpp.column
132
+ assert ?2 == @xpp.doRead
133
+ assert 2 == @xpp.column
134
+ assert ?3 == @xpp.doRead
135
+ assert 3 == @xpp.column
136
+ assert ?4 == @xpp.doRead
137
+ assert 4 == @xpp.column
138
+ assert ?5 == @xpp.doRead
139
+ assert 5 == @xpp.column
140
+ assert nil == @xpp.doRead
141
+ assert 0 == @xpp.column
142
+
143
+ assert 2 == @xpp.line
144
+ assert 0 == @xpp.elementName.length
145
+ end
146
+
147
+ def testReadIOSource
148
+ @xpp.input = File.new("TC_Input001.data")
149
+ assert ?1 == @xpp.doRead
150
+ assert 1 == @xpp.column
151
+ assert ?_ == @xpp.doRead
152
+ assert 2 == @xpp.column
153
+ assert ?2 == @xpp.doRead
154
+ assert 3 == @xpp.column
155
+ assert ?_ == @xpp.doRead
156
+ assert 4 == @xpp.column
157
+ assert ?_ == @xpp.doRead
158
+ assert 5 == @xpp.column
159
+ assert ?3 == @xpp.doRead
160
+ assert 6 == @xpp.column
161
+ assert ?_ == @xpp.doRead
162
+ assert 7 == @xpp.column
163
+ assert ?_ == @xpp.doRead
164
+ assert 8 == @xpp.column
165
+ assert ?_ == @xpp.doRead
166
+ assert 9 == @xpp.column
167
+ assert ?4 == @xpp.doRead
168
+ assert 10 == @xpp.column
169
+ assert ?_ == @xpp.doRead
170
+ assert 11 == @xpp.column
171
+ assert ?_ == @xpp.doRead
172
+ assert 12 == @xpp.column
173
+ assert ?_ == @xpp.doRead
174
+ assert 13 == @xpp.column
175
+ assert ?_ == @xpp.doRead
176
+ assert 14 == @xpp.column
177
+ assert ?5 == @xpp.doRead
178
+ assert 15 == @xpp.column
179
+
180
+ assert 1 == @xpp.line
181
+ assert ?\n == @xpp.doRead
182
+ assert 16 == @xpp.column
183
+ assert 1 == @xpp.line
184
+ assert nil == @xpp.doRead
185
+ assert 0 == @xpp.column
186
+
187
+ assert 0 == @xpp.elementName.length
188
+ end
189
+
190
+ def testMulipleInputRead000
191
+ # read the input until complete
192
+ for i in 1..3 do
193
+ @xpp.input = "12345"
194
+ s = ""
195
+ c = @xpp.doRead
196
+ while nil != c do
197
+ s = s << c
198
+ c = @xpp.doRead
199
+ end
200
+ assert "12345" == s
201
+ end
202
+ end
203
+
204
+ def testMulipleInputRead
205
+ # read part of the input only
206
+ for i in 1..3 do
207
+ @xpp.input = "12345"
208
+ s = ""
209
+ s = s << @xpp.doRead
210
+ s = s << @xpp.doRead
211
+ s = s << @xpp.doRead
212
+ assert "123" == s
213
+ end
214
+ end
215
+
216
+ def testExpectRead
217
+ @xpp.input = "12345"
218
+ assertNothingThrown { @xpp.doExpect(?1) }
219
+ assertRaises( RuntimeError ) { @xpp.doExpect(?1) }
220
+ end
221
+
222
+ def testSkipWhitespace
223
+ @xpp.input = "12345"
224
+ @xpp.doSkipWhitespace
225
+ assertNothingThrown { @xpp.doExpect(?1) }
226
+
227
+ @xpp.input = " 12345"
228
+ @xpp.doSkipWhitespace
229
+ assertNothingThrown { @xpp.doExpect(?1) }
230
+
231
+ @xpp.input = " \n \r\n 12345"
232
+ @xpp.doSkipWhitespace
233
+ assertNothingThrown { @xpp.doExpect(?1) }
234
+
235
+ @xpp.input = " \00012345"
236
+ @xpp.doSkipWhitespace
237
+ assertNothingThrown { @xpp.doExpect(0) }
238
+ end
239
+
240
+ end
@@ -0,0 +1 @@
1
+ 1_2
@@ -0,0 +1 @@
1
+ 1_2__3___4____5
@@ -0,0 +1,36 @@
1
+ # xampl-pp : XML pull parser
2
+ # Copyright (C) 2002-2009 Bob Hutchison
3
+ #
4
+ # This library is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU Lesser General Public
6
+ # License as published by the Free Software Foundation; either
7
+ # version 2.1 of the License, or (at your option) any later version.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # #Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+ #
18
+ require "Lapidary/TestCase"
19
+ require "xampl-pp"
20
+
21
+ class TC_Misc < Lapidary::TestCase
22
+ def setup
23
+ @xpp = Xampl_PP.new
24
+ end
25
+ #def tearDown
26
+ #end
27
+
28
+ def testEntityMap
29
+ assert @xpp.entityMap["amp"] == "&"
30
+ assert @xpp.entityMap["apos"] == "'"
31
+ assert @xpp.entityMap["gt"] == ">"
32
+ assert @xpp.entityMap["lt"] == "<"
33
+ assert @xpp.entityMap["quot"] == '"'
34
+ end
35
+ end
36
+