0
|
1 |
"{ Package: 'stx:goodies/xmlsuite/xpath' }"
|
|
2 |
|
|
3 |
"{ NameSpace: XMLv2 }"
|
|
4 |
|
|
5 |
TestCase subclass:#XPathTests
|
|
6 |
instanceVariableNames:''
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'XML Suite-XPath-Tests'
|
|
10 |
!
|
|
11 |
|
|
12 |
|
|
13 |
!XPathTests class methodsFor:'defaults'!
|
|
14 |
|
|
15 |
defaultTestDirectory
|
|
16 |
|
|
17 |
^(Smalltalk getPackageDirectoryForPackage:self package) construct: 'resources/tests/'.
|
|
18 |
|
|
19 |
"Modified: / 28-09-2006 / 18:10:10 / janfrog"
|
|
20 |
! !
|
|
21 |
|
|
22 |
!XPathTests methodsFor:'private'!
|
|
23 |
|
|
24 |
loadExprTrees
|
|
25 |
|
|
26 |
| col tree |
|
|
27 |
col := Set new.
|
|
28 |
|
|
29 |
"child::*"
|
|
30 |
|
|
31 |
tree := XPathExprTreeNode new id:#rule_1_1.
|
|
32 |
tree subnodes add:(XPathExprTreeNode new id:#rule_3_1).
|
|
33 |
(tree subnodes at:1) subnodes add:(XPathExprTreeNode new id:#rule_4_1).
|
|
34 |
((tree subnodes at:1) subnodes at:1) subnodes
|
|
35 |
add:(XPathExprTreeNode new id:#rule_5_1);
|
|
36 |
add:(XPathExprTreeNode new id:#rule_7_1).
|
|
37 |
(((tree subnodes at:1) subnodes at:1) subnodes at:1) subnodes
|
|
38 |
add:(XPathExprTreeNode new id:#rule_6_x; synthetizedValue:'child');
|
|
39 |
add:(XPathExprTreeNode new).
|
|
40 |
(((tree subnodes at:1) subnodes at:1) subnodes at:2) subnodes
|
|
41 |
add:(XPathExprTreeNode new id:#rule_37_1).
|
|
42 |
col add: tree.
|
|
43 |
|
|
44 |
^ col.
|
|
45 |
!
|
|
46 |
|
|
47 |
validateExpression:anExpressionString withResult:aString
|
|
48 |
|doc filename nodeSet nodeSetString|
|
|
49 |
|
|
50 |
"an example of complete usage"
|
|
51 |
filename := self class defaultTestDirectory construct:'sample_001.xml'.
|
|
52 |
doc := XPathDocumentAdaptorFactory
|
|
53 |
documentAdaptorFor:(XMLv2::Parser forDOM3 processDocumentInFilename:filename
|
|
54 |
beforeScanDo:[:parser | parser validate:false ]).
|
|
55 |
nodeSet := (XPathProcessor new)
|
|
56 |
documentAdaptor:doc;
|
|
57 |
processExpression:anExpressionString.
|
|
58 |
nodeSetString := (nodeSet asString).
|
|
59 |
self assert:(nodeSetString = aString).
|
|
60 |
|
|
61 |
"Modified: / 24-10-2006 / 12:00:27 / janfrog"
|
|
62 |
! !
|
|
63 |
|
|
64 |
!XPathTests methodsFor:'testing'!
|
|
65 |
|
|
66 |
testExpression_001
|
|
67 |
self validateExpression:'child::*' withResult:'root1 '
|
|
68 |
!
|
|
69 |
|
|
70 |
testExpression_002
|
|
71 |
self validateExpression:'descendant::*' withResult:'root1 tag2 tag3 subtag4 subtag5 emp6 subtag7 b8 tag9 '
|
|
72 |
!
|
|
73 |
|
|
74 |
testExpression_003
|
|
75 |
self validateExpression:'child::*/child::*/descendant::*' withResult:'subtag1 subtag2 emp3 subtag4 b5 '
|
|
76 |
!
|
|
77 |
|
|
78 |
testExpression_004
|
|
79 |
self validateExpression:'descendant::tag' withResult:'tag1 tag2 tag3 '
|
|
80 |
!
|
|
81 |
|
|
82 |
testExpression_005
|
|
83 |
|doc filename node_set|
|
|
84 |
|
|
85 |
"an example of complete usage"
|
|
86 |
filename := self class defaultTestDirectory construct:'sample_001.xml'.
|
|
87 |
doc := XPathDocumentAdaptorFactory
|
|
88 |
documentAdaptorFor:(XML::XMLParser processDocumentInFilename:filename
|
|
89 |
beforeScanDo:[:parser | parser validate:false ]).
|
|
90 |
node_set := (XPathProcessor new documentAdaptor:doc) processExpression:'/'.
|
|
91 |
self assert:((node_set nodesInDocumentOrder at:1) isDocument).
|
|
92 |
|
|
93 |
"Modified: / 13-10-2006 / 20:54:33 / janfrog"
|
|
94 |
!
|
|
95 |
|
|
96 |
testExpression_006
|
|
97 |
self validateExpression:'/child::*' withResult:'root1 '
|
|
98 |
!
|
|
99 |
|
|
100 |
testExpression_007
|
|
101 |
self validateExpression:'//child::subtag' withResult:'subtag1 subtag2 subtag3 '
|
|
102 |
!
|
|
103 |
|
|
104 |
testExpression_008
|
|
105 |
self validateExpression:'child::root/child::tag//self::*' withResult:'tag1 tag2 subtag3 subtag4 emp5 subtag6 b7 tag8 '
|
|
106 |
!
|
|
107 |
|
|
108 |
testExpression_009
|
|
109 |
self validateExpression:'child::root/child::tag//child::*' withResult:'subtag1 subtag2 emp3 subtag4 b5 '
|
|
110 |
!
|
|
111 |
|
|
112 |
testExpression_010
|
|
113 |
self validateExpression:'child::root//.' withResult:'root1 tag2 tag3 subtag4 subtag5 emp7 subtag9 b11 tag13 '.
|
|
114 |
!
|
|
115 |
|
|
116 |
testExpression_011
|
|
117 |
self validateExpression:'/root/tag' withResult:'tag1 tag2 tag3 '.
|
|
118 |
!
|
|
119 |
|
|
120 |
testExpression_012
|
|
121 |
self validateExpression:'/root//@*' withResult:'1234somethingyes'.
|
|
122 |
! !
|
|
123 |
|
|
124 |
!XPathTests class methodsFor:'documentation'!
|
|
125 |
|
|
126 |
version
|
|
127 |
^ '$Header: /opt/data/cvs/stx/goodies/xmlsuite/xpath/XMLv2__XPathTests.st,v 1.4 2006-12-15 11:06:35 vranyj1 Exp $'
|
|
128 |
! !
|