3 test("expressions - element", function() {
\r
5 ok( $("*").size() >= 30, "Select all" );
\r
6 t( "Element Selector", "div", ["main","foo"] );
\r
7 t( "Element Selector", "body", ["body"] );
\r
8 t( "Element Selector", "html", ["html"] );
\r
9 t( "Parent Element", "div div", ["foo"] );
\r
10 ok( $("param", "#object1").length == 2, "Object/param as context" );
\r
13 test("expressions - id", function() {
\r
15 t( "ID Selector", "#body", ["body"] );
\r
16 t( "ID Selector w/ Element", "body#body", ["body"] );
\r
17 t( "ID Selector w/ Element", "ul#first", [] );
\r
18 t( "ID selector with existing ID descendant", "#firstp #simon1", ["simon1"] );
\r
19 t( "ID selector with non-existing descendant", "#firstp #foobar", [] );
\r
21 t( "ID Selector, child ID present", "#form > #radio1", ["radio1"] ); // bug #267
\r
22 t( "ID Selector, not an ancestor ID", "#form #first", [] );
\r
23 t( "ID Selector, not a child ID", "#form > #option1a", [] );
\r
25 t( "All Children of ID", "#foo/*", ["sndp", "en", "sap"] );
\r
26 t( "All Children of ID with no children", "#firstUL/*", [] );
\r
31 test("expressions - class", function() {
\r
33 t( "Class Selector", ".blog", ["mark","simon"] );
\r
34 t( "Class Selector", ".blog.link", ["simon"] );
\r
35 t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
\r
36 t( "Parent Class Selector", "p .blog", ["mark","simon"] );
\r
39 test("expressions - multiple", function() {
\r
41 t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
\r
42 t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
\r
43 t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
\r
44 t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
\r
47 test("expressions - child and adjacent", function() {
\r
49 t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
\r
50 t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
\r
51 t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
\r
52 t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
\r
53 t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
\r
54 t( "All Children", "code > *", ["anchor1","anchor2"] );
\r
55 t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
\r
56 t( "Adjacent", "a + a", ["groups"] );
\r
57 t( "Adjacent", "a +a", ["groups"] );
\r
58 t( "Adjacent", "a+ a", ["groups"] );
\r
59 t( "Adjacent", "a+a", ["groups"] );
\r
60 t( "Adjacent", "p + p", ["ap","en","sap"] );
\r
61 t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
\r
62 t( "First Child", "p:first-child", ["firstp","sndp"] );
\r
65 test("expressions - attributes", function() {
\r
67 t( "Attribute Exists", "a[@title]", ["google"] );
\r
68 t( "Attribute Exists", "*[@title]", ["google"] );
\r
69 t( "Attribute Exists", "[@title]", ["google"] );
\r
71 t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
\r
72 t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
\r
73 t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
\r
74 t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
\r
75 t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
\r
76 t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
\r
78 t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
\r
79 t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
\r
80 t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
\r
82 t("Select options via [@selected]", "#select1 option[@selected]", ["option1a"] );
\r
83 t("Select options via [@selected]", "#select2 option[@selected]", ["option2d"] );
\r
84 t("Select options via [@selected]", "#select3 option[@selected]", ["option3b", "option3c"] );
\r
86 t( "Grouped Form Elements", "input[@name='foo[bar]']", ["hidden2"] );
\r
88 t( ":not() Existing attribute", "select:not([@multiple])", ["select1", "select2"]);
\r
89 t( ":not() Equals attribute", "select:not([@name=select1])", ["select2", "select3"]);
\r
90 t( ":not() Equals quoted attribute", "select:not([@name='select1'])", ["select2", "select3"]);
\r
93 test("expressions - pseudo (:) selctors", function() {
\r
95 t( "First Child", "p:first-child", ["firstp","sndp"] );
\r
96 t( "Last Child", "p:last-child", ["sap"] );
\r
97 t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
\r
98 t( "Empty", "ul:empty", ["firstUL"] );
\r
99 t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2","name"] );
\r
100 t( "Disabled UI Element", "input:disabled", ["text2"] );
\r
101 t( "Checked UI Element", "input:checked", ["radio2","check1"] );
\r
102 t( "Selected Option Element", "option:selected", ["option1a","option2d","option3b","option3c"] );
\r
103 t( "Text Contains", "a:contains('Google')", ["google","groups"] );
\r
104 t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
\r
105 t( "Element Preceded By", "p ~ div", ["foo"] );
\r
106 t( "Not", "a.blog:not(.link)", ["mark"] );
\r
108 t( "nth Element", "p:nth(1)", ["ap"] );
\r
109 t( "First Element", "p:first", ["firstp"] );
\r
110 t( "Last Element", "p:last", ["first"] );
\r
111 t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
\r
112 t( "Odd Elements", "p:odd", ["ap","en","first"] );
\r
113 t( "Position Equals", "p:eq(1)", ["ap"] );
\r
114 t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
\r
115 t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
\r
116 t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
\r
117 t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2","name"] );
\r
118 t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
\r
120 t( "Form element :input", ":input", ["text1", "text2", "radio1", "radio2", "check1", "check2", "hidden1", "hidden2", "name", "button", "area1", "select1", "select2", "select3"] );
\r
121 t( "Form element :radio", ":radio", ["radio1", "radio2"] );
\r
122 t( "Form element :checkbox", ":checkbox", ["check1", "check2"] );
\r
123 t( "Form element :text", ":text", ["text1", "text2", "hidden2", "name"] );
\r
124 t( "Form element :radio:checked", ":radio:checked", ["radio2"] );
\r
125 t( "Form element :checkbox:checked", ":checkbox:checked", ["check1"] );
\r
126 t( "Form element :checkbox:checked, :radio:checked", ":checkbox:checked, :radio:checked", ["check1", "radio2"] );
\r
129 test("expressions - basic xpath", function() {
\r
131 ok( jQuery.find("//*").length >= 30, "All Elements (//*)" );
\r
132 t( "All Div Elements", "//div", ["main","foo"] );
\r
133 t( "Absolute Path", "/html/body", ["body"] );
\r
134 t( "Absolute Path w/ *", "/* /body", ["body"] );
\r
135 t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
\r
136 t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
\r
137 t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
\r
138 t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
\r
139 t( "Attribute Exists", "//a[@title]", ["google"] );
\r
140 t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
\r
141 t( "Parent Axis", "//p/..", ["main","foo"] );
\r
142 t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","floatTest","sndp","en","sap"] );
\r
143 t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","floatTest","sndp","en","sap"] );
\r
144 t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
\r
146 $("#foo").each(function() {
\r
147 isSet( $("/p", this).get(), q("sndp", "en", "sap"), "Check XPath context" );
\r