Moved all the expressions tests over into selector area, out of the main suite.
[jquery.git] / src / selector / selectorTest.js
1 module("selector");\r
2 \r
3 test("expressions - element", function() {\r
4         expect(5);\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 });\r
11 \r
12 test("expressions - id", function() {\r
13         expect(8);\r
14         t( "ID Selector", "#body", ["body"] );\r
15         t( "ID Selector w/ Element", "body#body", ["body"] );\r
16         t( "ID Selector w/ Element", "ul#first", [] );\r
17         \r
18         t( "ID Selector, child ID present", "#form > #radio1", ["radio1"] );  // bug #267\r
19         t( "ID Selector, not an ancestor ID", "#form  #first", [] );\r
20         t( "ID Selector, not a child ID", "#form > #option1a", [] );\r
21         \r
22         t( "All Children of ID", "#foo/*", ["sndp", "en", "sap"]  );\r
23         t( "All Children of ID with no children", "#firstUL/*", []  );\r
24 });\r
25 \r
26 test("expressions - class", function() {\r
27         expect(4);\r
28         t( "Class Selector", ".blog", ["mark","simon"] );\r
29         t( "Class Selector", ".blog.link", ["simon"] );\r
30         t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );\r
31         t( "Parent Class Selector", "p .blog", ["mark","simon"] );\r
32 });\r
33 \r
34 test("expressions - multiple", function() {\r
35         expect(4);\r
36         t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );\r
37         t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );\r
38         t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );\r
39         t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );\r
40 });\r
41 \r
42 test("expressions - child and adjacent", function() {\r
43         expect(14);\r
44         t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );\r
45         t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );\r
46         t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );\r
47         t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );\r
48         t( "Child w/ Class", "p > a.blog", ["mark","simon"] );\r
49         t( "All Children", "code > *", ["anchor1","anchor2"] );\r
50         t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );\r
51         t( "Adjacent", "a + a", ["groups"] );\r
52         t( "Adjacent", "a +a", ["groups"] );\r
53         t( "Adjacent", "a+ a", ["groups"] );\r
54         t( "Adjacent", "a+a", ["groups"] );\r
55         t( "Adjacent", "p + p", ["ap","en","sap"] );\r
56         t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );\r
57         t( "First Child", "p:first-child", ["firstp","sndp"] );\r
58 });\r
59 \r
60 test("expressions - attributes", function() {\r
61         expect(19);\r
62         t( "Attribute Exists", "a[@title]", ["google"] );\r
63         t( "Attribute Exists", "*[@title]", ["google"] );\r
64         t( "Attribute Exists", "[@title]", ["google"] );\r
65         \r
66         t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );\r
67         t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );\r
68         t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );\r
69         t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );\r
70         t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );\r
71         t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );\r
72         \r
73         t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );\r
74         t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );\r
75         t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );\r
76         \r
77         t("Select options via [@selected]", "#select1 option[@selected]", ["option1a"] );\r
78         t("Select options via [@selected]", "#select2 option[@selected]", ["option2d"] );\r
79         t("Select options via [@selected]", "#select3 option[@selected]", ["option3b", "option3c"] );\r
80         \r
81         t( "Grouped Form Elements", "input[@name='foo[bar]']", ["hidden2"] );\r
82         \r
83         t( ":not() Existing attribute", "select:not([@multiple])", ["select1", "select2"]);\r
84         t( ":not() Equals attribute", "select:not([@name=select1])", ["select2", "select3"]);\r
85         t( ":not() Equals quoted attribute", "select:not([@name='select1'])", ["select2", "select3"]);\r
86 });\r
87 \r
88 test("expressions - pseudo (:) selctors", function() {\r
89         expect(30);\r
90         t( "First Child", "p:first-child", ["firstp","sndp"] );\r
91         t( "Last Child", "p:last-child", ["sap"] );\r
92         t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );\r
93         t( "Empty", "ul:empty", ["firstUL"] );\r
94         t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2","name"] );\r
95         t( "Disabled UI Element", "input:disabled", ["text2"] );\r
96         t( "Checked UI Element", "input:checked", ["radio2","check1"] );\r
97         t( "Selected Option Element", "option:selected", ["option1a","option2d","option3b","option3c"] );\r
98         t( "Text Contains", "a:contains('Google')", ["google","groups"] );\r
99         t( "Text Contains", "a:contains('Google Groups')", ["groups"] );\r
100         t( "Element Preceded By", "p ~ div", ["foo"] );\r
101         t( "Not", "a.blog:not(.link)", ["mark"] );\r
102         \r
103         t( "nth Element", "p:nth(1)", ["ap"] );\r
104         t( "First Element", "p:first", ["firstp"] );\r
105         t( "Last Element", "p:last", ["first"] );\r
106         t( "Even Elements", "p:even", ["firstp","sndp","sap"] );\r
107         t( "Odd Elements", "p:odd", ["ap","en","first"] );\r
108         t( "Position Equals", "p:eq(1)", ["ap"] );\r
109         t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );\r
110         t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );\r
111         t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );\r
112         t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2","name"] );\r
113         t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );\r
114         \r
115         t( "Form element :input", ":input", ["text1", "text2", "radio1", "radio2", "check1", "check2", "hidden1", "hidden2", "name", "button", "area1", "select1", "select2", "select3"] );\r
116         t( "Form element :radio", ":radio", ["radio1", "radio2"] );\r
117         t( "Form element :checkbox", ":checkbox", ["check1", "check2"] );\r
118         t( "Form element :text", ":text", ["text1", "text2", "hidden2", "name"] );\r
119         t( "Form element :radio:checked", ":radio:checked", ["radio2"] );\r
120         t( "Form element :checkbox:checked", ":checkbox:checked", ["check1"] );\r
121         t( "Form element :checkbox:checked, :radio:checked", ":checkbox:checked, :radio:checked", ["check1", "radio2"] );\r
122 });\r
123 \r
124 test("expressions - basic xpath", function() {\r
125         expect(14);\r
126         ok( jQuery.find("//*").length >= 30, "All Elements (//*)" );\r
127         t( "All Div Elements", "//div", ["main","foo"] );\r
128         t( "Absolute Path", "/html/body", ["body"] );\r
129         t( "Absolute Path w/ *", "/* /body", ["body"] );\r
130         t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );\r
131         t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );\r
132         t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );\r
133         t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );\r
134         t( "Attribute Exists", "//a[@title]", ["google"] );\r
135         t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );\r
136         t( "Parent Axis", "//p/..", ["main","foo"] );\r
137         t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","floatTest","sndp","en","sap"] );\r
138         t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","floatTest","sndp","en","sap"] );\r
139         t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );\r
140 });