Subject: | Bugs in :first-child and in implied universal selector |
Various valid selectors are translated incorrectly. The problems seem
to fall into two categories:
- The universal selector isn't assumed on some selectors (like an
unadorned `:lang(c)`, for example)
- Ordering matters for some types of selector; for example,
`E:first-child.c` works, but `E.c:first-child` doesn't
The attached patch adds several test cases (not all of which fail under
0.03); I regret that I don't have time to find a fix at the moment.
Subject: | tests.diff |
--- t/01_xpath.t.orig 2009-09-21 19:08:50.000000000 +0100
+++ t/01_xpath.t 2009-09-21 18:56:58.000000000 +0100
@@ -56,18 +56,120 @@
===
--- selector
+:first-child
+--- xpath
+//*[1]
+
+===
+--- selector
+E.c:first-child
+--- xpath
+//*[1]/self::E[contains(concat(' ', @class, ' '), ' c ')]
+
+===
+--- selector
+E:first-child.c
+--- xpath
+//*[1]/self::E[contains(concat(' ', @class, ' '), ' c ')]
+
+===
+--- selector
+E#i:first-child
+--- xpath
+//*[1]/self::E[@id='i']
+
+===
+--- selector
+E:first-child#i
+--- xpath
+//*[1]/self::E[@id='i']
+
+===
+--- selector
E:lang(c)
--- xpath
//E[@xml:lang='c' or starts-with(@xml:lang, 'c-')]
===
--- selector
+:lang(c)
+--- xpath
+//*[@xml:lang='c' or starts-with(@xml:lang, 'c-')]
+
+===
+--- selector
+:lang(c)#i
+--- xpath
+//*[@xml:lang='c' or starts-with(@xml:lang, 'c-')][@id='i']
+
+===
+--- selector
+#i:lang(c)
+--- xpath
+//*[@xml:lang='c' or starts-with(@xml:lang, 'c-')][@id='i']
+
+===
+--- selector
+*:lang(c)#i
+--- xpath
+//*[@xml:lang='c' or starts-with(@xml:lang, 'c-')][@id='i']
+
+===
+--- selector
+E:lang(c)#i
+--- xpath
+//E[@xml:lang='c' or starts-with(@xml:lang, 'c-')][@id='i']
+
+===
+--- selector
+E#i:lang(c)
+--- xpath
+//E[@xml:lang='c' or starts-with(@xml:lang, 'c-')][@id='i']
+
+===
+--- selector
+*:lang(c)#i.first-child
+--- xpath
+//*[@xml:lang='c' or starts-with(@xml:lang, 'c-')][@id='i']
+
+===
+--- selector
+E:lang(c)#i.first-child
+--- xpath
+//*[1]/self::E[@xml:lang='c' or starts-with(@xml:lang, 'c-')][@id='i']
+
+===
+--- selector
+E:lang(c).first-child#i
+--- xpath
+//*[1]/self::E[@xml:lang='c' or starts-with(@xml:lang, 'c-')][@id='i']
+
+===
+--- selector
+E#i:lang(c).first-child
+--- xpath
+//*[1]/self::E[@xml:lang='c' or starts-with(@xml:lang, 'c-')][@id='i']
+
+===
+--- selector
E + F
--- xpath
//E/following-sibling::*[1]/self::F
===
--- selector
+#bar
+--- xpath
+//*[@id='bar']
+
+===
+--- selector
+*#bar
+--- xpath
+//*[@id='bar']
+
+===
+--- selector
E + #bar
--- xpath
//E/following-sibling::*[1]/self::*[@id='bar']
@@ -80,6 +182,18 @@
===
--- selector
+*[foo]
+--- xpath
+//*[@foo]
+
+===
+--- selector
+[foo]
+--- xpath
+//*[@foo]
+
+===
+--- selector
E[foo]
--- xpath
//E[@foo]
@@ -104,6 +218,18 @@
===
--- selector
+.warning
+--- xpath
+//*[contains(concat(' ', @class, ' '), ' warning ')]
+
+===
+--- selector
+*.warning
+--- xpath
+//*[contains(concat(' ', @class, ' '), ' warning ')]
+
+===
+--- selector
DIV.warning
--- xpath
//DIV[contains(concat(' ', @class, ' '), ' warning ')]
@@ -122,6 +248,24 @@
===
--- selector
+:nth-child(1)
+--- xpath
+//*[count(preceding-sibling::*) = 0]
+
+===
+--- selector
+*:nth-child(1)
+--- xpath
+//*[count(preceding-sibling::*) = 0]
+
+===
+--- selector
E:nth-child(1)
--- xpath
//E[count(preceding-sibling::*) = 0]
+
+===
+--- selector
+E:nth-child(2)
+--- xpath
+//E[count(preceding-sibling::*) = 1]