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