// ======================================================================== // CoreQuery Tests // ======================================================================== /* This test file incorporates most of the changes that come bundled with the SC.$-selector suite of tests, modified to fit CoreQuery's reduced API. You should be able to update most of these tests with updated versons of the same tests in SC.$. Be sure to replace all occurrences of jQuery with SC.$. */ htmlbody('\ \ \
\
\
\ \ \ ') ; module("selector"); test("element", function() { expect(7); ok( SC.$("*").size() >= 30, "Select all" ); var all = SC.$("*"), good = true; for ( var i = 0; i < all.length; i++ ) if ( all[i].nodeType == 8 ) good = false; ok( good, "Select all elements, no comment nodes" ); t( "Element Selector", "p", ["firstp","ap","sndp","en","sap","first"] ); //t( "Element Selector", "body", ["body"] ); //t( "Element Selector", "html", ["html"] ); t( "Parent Element", "div p", ["firstp","ap","sndp","en","sap","first"] ); equals( SC.$("param", "#object1").length, 2, "Object/param as context" ); ok( SC.$("#length").length, '<input name="length"> cannot be found under IE, see #945' ); ok( SC.$("#lengthtest input").length, '<input name="length"> cannot be found under IE, see #945' ); }); test("broken", function() { expect(7); t( "Broken Selector", "[", [] ); t( "Broken Selector", "(", [] ); t( "Broken Selector", "{", [] ); t( "Broken Selector", "<", [] ); t( "Broken Selector", "()", [] ); t( "Broken Selector", "<>", [] ); t( "Broken Selector", "{}", [] ); }); test("id", function() { expect(13); //t( "ID Selector", "#body", ["body"] ); //t( "ID Selector w/ Element", "body#body", ["body"] ); t( "ID Selector w/ Element", "ul#first", [] ); t( "ID selector with existing ID descendant", "#firstp #simon1", ["simon1"] ); t( "ID selector with non-existant descendant", "#firstp #foobar", [] ); t( "ID selector using UTF8", "#台北Táiběi", ["台北Táiběi"] ); t( "Multiple ID selectors using UTF8", "#台北Táiběi, #台北", ["台北Táiběi","台北"] ); t( "Descendant ID selector using UTF8", "div #台北", ["台北"] ); t( "Child ID selector using UTF8", "form > #台北", ["台北"] ); // These kinds of complex edge cases are not supported for now //t( "Escaped ID", "#foo\\:bar", ["foo:bar"] ); //t( "Escaped ID", "#test\\.foo\\[5\\]bar", ["test.foo[5]bar"] ); //t( "Descendant escaped ID", "div #foo\\:bar", ["foo:bar"] ); //t( "Descendant escaped ID", "div #test\\.foo\\[5\\]bar", ["test.foo[5]bar"] ); // Child selectors are not supported //t( "Child escaped ID", "form > #foo\\:bar", ["foo:bar"] ); //t( "Child escaped ID", "form > #test\\.foo\\[5\\]bar", ["test.foo[5]bar"] ); //t( "ID Selector, child ID present", "#form > #radio1", ["radio1"] ); // bug #267 t( "ID Selector, not an ancestor ID", "#form #first", [] ); //t( "ID Selector, not a child ID", "#form > #option1a", [] ); //t( "All Children of ID", "#foo > *", ["sndp", "en", "sap"] ); //t( "All Children of ID with no children", "#firstUL > *", [] ); SC.$('tName1 AtName2 A
tName1 Div
').appendTo('#main'); equals( SC.$("#tName1")[0].id, 'tName1', "ID selector with same value for a name attribute" ); equals( SC.$("#tName2").length, 0, "ID selector non-existing but name attribute on an A tag" ); t( "ID Selector on Form with an input that has a name of 'id'", "#lengthtest", ["lengthtest"] ); t( "ID selector with non-existant ancestor", "#asdfasdf #foobar", [] ); // bug #986 isSet( SC.$("body").find("div#form"), [], "ID selector within the context of another element" ); }); test("class", function() { expect(9); t( "Class Selector", ".blog", ["mark","simon"] ); t( "Class Selector", ".blog.link", ["simon"] ); t( "Class Selector w/ Element", "a.blog", ["mark","simon"] ); t( "Parent Class Selector", "p .blog", ["mark","simon"] ); t( "Class selector using UTF8", ".台北Táiběi", ["utf8class1"] ); t( "Class selector using UTF8", ".台北", ["utf8class1","utf8class2"] ); t( "Class selector using UTF8", ".台北Táiběi.台北", ["utf8class1"] ); t( "Class selector using UTF8", ".台北Táiběi, .台北", ["utf8class1","utf8class2"] ); t( "Descendant class selector using UTF8", "div .台北Táiběi", ["utf8class1"] ); //t( "Child class selector using UTF8", "form > .台北Táiběi", ["utf8class1"] ); //t( "Escaped Class", ".foo\\:bar", ["foo:bar"] ); //t( "Escaped Class", ".test\\.foo\\[5\\]bar", ["test.foo[5]bar"] ); //t( "Descendant scaped Class", "div .foo\\:bar", ["foo:bar"] ); //t( "Descendant scaped Class", "div .test\\.foo\\[5\\]bar", ["test.foo[5]bar"] ); //t( "Child escaped Class", "form > .foo\\:bar", ["foo:bar"] ); //t( "Child escaped Class", "form > .test\\.foo\\[5\\]bar", ["test.foo[5]bar"] ); }); test("multiple", function() { expect(4); t( "Comma Support", "a.blog, p", ["mark","simon","firstp","ap","sndp","en","sap","first"] ); t( "Comma Support", "a.blog , p", ["mark","simon","firstp","ap","sndp","en","sap","first"] ); t( "Comma Support", "a.blog ,p", ["mark","simon","firstp","ap","sndp","en","sap","first"] ); t( "Comma Support", "a.blog,p", ["mark","simon","firstp","ap","sndp","en","sap","first"] ); }); // none of these types of selectors are supported in CoreQuery. Sorry. //test("child and adjacent", function() { //test("attributes", function() { //test("pseudo (:) selectors", function() {