3 test("element", function() {
5 ok( $("*").size() >= 30, "Select all" );
6 t( "Element Selector", "div", ["main","foo"] );
7 t( "Element Selector", "body", ["body"] );
8 t( "Element Selector", "html", ["html"] );
9 t( "Parent Element", "div div", ["foo"] );
10 ok( $("param", "#object1").length == 2, "Object/param as context" );
12 ok( $("#length").length, '<input name="length"> cannot be found under IE, see #945' );
13 ok( $("#lengthtest input").length, '<input name="length"> cannot be found under IE, see #945' );
15 t( "Element Selector with underscore", "foo_bar", ["foobar"] );
18 test("broken", function() {
20 t( "Broken Selector", "[", [] );
21 t( "Broken Selector", "(", [] );
22 t( "Broken Selector", "{", [] );
23 t( "Broken Selector", "<", [] );
24 t( "Broken Selector", "()", [] );
25 t( "Broken Selector", "<>", [] );
26 t( "Broken Selector", "{}", [] );
29 test("id", function() {
31 t( "ID Selector", "#body", ["body"] );
32 t( "ID Selector w/ Element", "body#body", ["body"] );
33 t( "ID Selector w/ Element", "ul#first", [] );
34 t( "ID selector with existing ID descendant", "#firstp #simon1", ["simon1"] );
35 t( "ID selector with non-existant descendant", "#firstp #foobar", [] );
36 t( "ID selector using UTF8", "#台北Táiběi", ["台北Táiběi"] );
37 t( "Multiple ID selectors using UTF8", "#台北Táiběi, #台北", ["台北Táiběi","台北"] );
38 t( "Descendant ID selector using UTF8", "div #台北", ["台北"] );
39 t( "Child ID selector using UTF8", "form > #台北", ["台北"] );
41 t( "Escaped ID", "#foo\\:bar", ["foo:bar"] );
42 t( "Escaped ID", "#test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
43 t( "Descendant escaped ID", "div #foo\\:bar", ["foo:bar"] );
44 t( "Descendant escaped ID", "div #test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
45 t( "Child escaped ID", "form > #foo\\:bar", ["foo:bar"] );
46 t( "Child escaped ID", "form > #test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
48 t( "ID Selector, child ID present", "#form > #radio1", ["radio1"] ); // bug #267
49 t( "ID Selector, not an ancestor ID", "#form #first", [] );
50 t( "ID Selector, not a child ID", "#form > #option1a", [] );
52 t( "All Children of ID", "#foo/*", ["sndp", "en", "sap"] );
53 t( "All Children of ID with no children", "#firstUL/*", [] );
55 $('<a name="tName1">tName1 A</a><a name="tName2">tName2 A</a><div id="tName1">tName1 Div</div>').appendTo('#main');
56 ok( $("#tName1")[0].id == 'tName1', "ID selector with same value for a name attribute" );
57 ok( $("#tName2").length == 0, "ID selector non-existing but name attribute on an A tag" );
58 t( "ID Selector on Form with an input that has a name of 'id'", "#lengthtest", ["lengthtest"] );
60 t( "ID selector with non-existant ancestor", "#asdfasdf #foobar", [] ); // bug #986
63 test("class", function() {
65 t( "Class Selector", ".blog", ["mark","simon"] );
66 t( "Class Selector", ".blog.link", ["simon"] );
67 t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
68 t( "Parent Class Selector", "p .blog", ["mark","simon"] );
70 t( "Class selector using UTF8", ".台北Táiběi", ["utf8class1"] );
71 t( "Class selector using UTF8", ".台北", ["utf8class1","utf8class2"] );
72 t( "Class selector using UTF8", ".台北Táiběi.台北", ["utf8class1"] );
73 t( "Class selector using UTF8", ".台北Táiběi, .台北", ["utf8class1","utf8class2"] );
74 t( "Descendant class selector using UTF8", "div .台北Táiběi", ["utf8class1"] );
75 t( "Child class selector using UTF8", "form > .台北Táiběi", ["utf8class1"] );
77 t( "Escaped Class", ".foo\\:bar", ["foo:bar"] );
78 t( "Escaped Class", ".test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
79 t( "Descendant scaped Class", "div .foo\\:bar", ["foo:bar"] );
80 t( "Descendant scaped Class", "div .test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
81 t( "Child escaped Class", "form > .foo\\:bar", ["foo:bar"] );
82 t( "Child escaped Class", "form > .test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
85 test("multiple", function() {
87 t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
88 t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
89 t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
90 t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
93 test("child and adjacent", function() {
95 t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
96 t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
97 t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
98 t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
99 t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
100 t( "All Children", "code > *", ["anchor1","anchor2"] );
101 t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
102 t( "Adjacent", "a + a", ["groups"] );
103 t( "Adjacent", "a +a", ["groups"] );
104 t( "Adjacent", "a+ a", ["groups"] );
105 t( "Adjacent", "a+a", ["groups"] );
106 t( "Adjacent", "p + p", ["ap","en","sap"] );
107 t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
109 t( "First Child", "p:first-child", ["firstp","sndp"] );
110 t( "Nth Child", "p:nth-child(1)", ["firstp","sndp"] );
112 t( "Last Child", "p:last-child", ["sap"] );
114 t( "Nth-child", "#main form > *:nth-child(2)", ["text2","idTest"] );
115 t( "Nth-child", "#main form > :nth-child(2)", ["text2","idTest"] );
118 test("attributes", function() {
120 t( "Attribute Exists", "a[@title]", ["google"] );
121 t( "Attribute Exists", "*[@title]", ["google"] );
122 t( "Attribute Exists", "[@title]", ["google"] );
124 t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
125 t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
126 t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
127 t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
128 t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
129 t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
131 t( "Attribute selector using UTF8", "span[@lang=中文]", ["台北"] );
133 t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
134 t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
135 t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
137 t("Select options via [@selected]", "#select1 option[@selected]", ["option1a"] );
138 t("Select options via [@selected]", "#select2 option[@selected]", ["option2d"] );
139 t("Select options via [@selected]", "#select3 option[@selected]", ["option3b", "option3c"] );
141 t( "Grouped Form Elements", "input[@name='foo[bar]']", ["hidden2"] );
143 t( ":not() Existing attribute", "select:not([@multiple])", ["select1", "select2"]);
144 t( ":not() Equals attribute", "select:not([@name=select1])", ["select2", "select3"]);
145 t( ":not() Equals quoted attribute", "select:not([@name='select1'])", ["select2", "select3"]);
148 test("pseudo (:) selectors", function() {
150 t( "First Child", "p:first-child", ["firstp","sndp"] );
151 t( "Last Child", "p:last-child", ["sap"] );
152 t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
153 t( "Empty", "ul:empty", ["firstUL"] );
154 t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2","name","length","idTest"] );
155 t( "Disabled UI Element", "input:disabled", ["text2"] );
156 t( "Checked UI Element", "input:checked", ["radio2","check1"] );
157 t( "Selected Option Element", "option:selected", ["option1a","option2d","option3b","option3c"] );
158 t( "Text Contains", "a:contains('Google')", ["google","groups"] );
159 t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
160 t( "Element Preceded By", "p ~ div", ["foo"] );
161 t( "Not", "a.blog:not(.link)", ["mark"] );
163 t( "nth Element", "p:nth(1)", ["ap"] );
164 t( "First Element", "p:first", ["firstp"] );
165 t( "Last Element", "p:last", ["first"] );
166 t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
167 t( "Odd Elements", "p:odd", ["ap","en","first"] );
168 t( "Position Equals", "p:eq(1)", ["ap"] );
169 t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
170 t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
171 t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
172 t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2","name","length","idTest"] );
173 t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
175 t( "Form element :input", ":input", ["text1", "text2", "radio1", "radio2", "check1", "check2", "hidden1", "hidden2", "name", "button", "area1", "select1", "select2", "select3", "length", "idTest"] );
176 t( "Form element :radio", ":radio", ["radio1", "radio2"] );
177 t( "Form element :checkbox", ":checkbox", ["check1", "check2"] );
178 t( "Form element :text", ":text", ["text1", "text2", "hidden2", "name", "length", "idTest"] );
179 t( "Form element :radio:checked", ":radio:checked", ["radio2"] );
180 t( "Form element :checkbox:checked", ":checkbox:checked", ["check1"] );
181 t( "Form element :checkbox:checked, :radio:checked", ":checkbox:checked, :radio:checked", ["check1", "radio2"] );
184 test("basic xpath", function() {
186 ok( jQuery.find("//*").length >= 30, "All Elements (//*)" );
187 t( "All Div Elements", "//div", ["main","foo"] );
188 t( "Absolute Path", "/html/body", ["body"] );
189 t( "Absolute Path w/ *", "/* /body", ["body"] );
190 t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
191 t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
192 t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
193 t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
194 t( "Attribute Exists", "//a[@title]", ["google"] );
195 t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
196 t( "Parent Axis", "//p/..", ["main","foo"] );
197 t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","floatTest","iframe","lengthtest","table","sndp","en","sap"] );
198 t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","floatTest","iframe","lengthtest","table","sndp","en","sap"] );
199 t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
201 $("#foo").each(function() {
202 isSet( $("/p", this).get(), q("sndp", "en", "sap"), "Check XPath context" );