@@ -143,53 +143,61 @@ def visit_pseudo_class_aaron(node)
143
143
)
144
144
end
145
145
146
- it "# id" do
147
- assert_xpath ( "//*[@id='foo']" , "#foo" )
148
- assert_xpath ( "//*[@id='escape:needed,']" , "#escape\\ :needed\\ ," )
149
- assert_xpath ( "//*[@id='escape:needed,']" , '#escape\3Aneeded\,' )
150
- assert_xpath ( "//*[@id='escape:needed,']" , '#escape\3A needed\2C' )
151
- assert_xpath ( "//*[@id='escape:needed']" , '#escape\00003Aneeded' )
152
- end
153
-
154
- describe "attribute" do
155
- it "basic mechanics" do
156
- assert_xpath ( "//h1[@a='Tender Lovemaking']" , "h1[a='Tender Lovemaking']" )
157
- assert_xpath ( "//h1[@a]" , "h1[a]" )
158
- assert_xpath ( %q{//h1[@a='gnewline\n']} , "h1[a='\\ gnew\\ \n line\\ \\ n']" )
159
- assert_xpath ( "//h1[@a='test']" , %q{h1[a=\te\st]} )
160
- end
161
-
162
- it "parses leading @ (extended-syntax)" do
163
- assert_xpath ( "//a[@id='Boing']" , "a[@id='Boing']" )
164
- assert_xpath ( "//a[@id='Boing']" , "a[@id = 'Boing']" )
165
- assert_xpath ( "//a[@id='Boing']//div" , "a[@id='Boing'] div" )
146
+ describe "namespaces" do
147
+ let ( :ns ) do
148
+ {
149
+ "xmlns" => "http://default.example.com/" ,
150
+ "hoge" => "http://hoge.example.com/" ,
151
+ }
166
152
end
167
153
168
- it "namespacing " do
154
+ it "basic mechanics " do
169
155
assert_xpath ( "//a[@flavorjones:href]" , "a[flavorjones|href]" )
170
156
assert_xpath ( "//a[@href]" , "a[|href]" )
171
157
assert_xpath ( "//*[@flavorjones:href]" , "*[flavorjones|href]" )
158
+ end
172
159
173
- ns = {
174
- "xmlns" => "http://default.example.com/" ,
175
- "hoge" => "http://hoge.example.com/" ,
176
- }
177
-
178
- # An intentionally-empty namespace means "don't use the default xmlns"
179
- assert_equal ( [ "//a" ] , Nokogiri ::CSS . xpath_for ( "|a" , ns : ns , cache : false ) )
180
-
181
- # The default namespace is not applied to attributes (just elements)
160
+ it "default namespace is applied to elements but not attributes" do
182
161
assert_equal (
183
162
[ "//xmlns:a[@class='bar']" ] ,
184
163
Nokogiri ::CSS . xpath_for ( "a[class='bar']" , ns : ns , cache : false ) ,
185
164
)
165
+ end
166
+
167
+ it "intentionally-empty namespace omits the default xmlns" do
168
+ # An intentionally-empty namespace
169
+ assert_equal ( [ "//a" ] , Nokogiri ::CSS . xpath_for ( "|a" , ns : ns , cache : false ) )
170
+ end
186
171
187
- # We can explicitly apply a namespace to an attribue
172
+ it "explicit namespaces are applied to attributes" do
188
173
assert_equal (
189
174
[ "//xmlns:a[@hoge:class='bar']" ] ,
190
175
Nokogiri ::CSS . xpath_for ( "a[hoge|class='bar']" , ns : ns , cache : false ) ,
191
176
)
192
177
end
178
+ end
179
+
180
+ describe "attribute" do
181
+ it "basic mechanics" do
182
+ assert_xpath ( "//h1[@a='Tender Lovemaking']" , "h1[a='Tender Lovemaking']" )
183
+ assert_xpath ( "//h1[@a]" , "h1[a]" )
184
+ assert_xpath ( %q{//h1[@a='gnewline\n']} , "h1[a='\\ gnew\\ \n line\\ \\ n']" )
185
+ assert_xpath ( "//h1[@a='test']" , %q{h1[a=\te\st]} )
186
+ end
187
+
188
+ it "#id escaping" do
189
+ assert_xpath ( "//*[@id='foo']" , "#foo" )
190
+ assert_xpath ( "//*[@id='escape:needed,']" , "#escape\\ :needed\\ ," )
191
+ assert_xpath ( "//*[@id='escape:needed,']" , '#escape\3Aneeded\,' )
192
+ assert_xpath ( "//*[@id='escape:needed,']" , '#escape\3A needed\2C' )
193
+ assert_xpath ( "//*[@id='escape:needed']" , '#escape\00003Aneeded' )
194
+ end
195
+
196
+ it "parses leading @ (extended-syntax)" do
197
+ assert_xpath ( "//a[@id='Boing']" , "a[@id='Boing']" )
198
+ assert_xpath ( "//a[@id='Boing']" , "a[@id = 'Boing']" )
199
+ assert_xpath ( "//a[@id='Boing']//div" , "a[@id='Boing'] div" )
200
+ end
193
201
194
202
it "rhs with quotes" do
195
203
assert_xpath ( %q{//h1[@a="'"]} , %q{h1[a="'"]} )
0 commit comments