From a4e83764f44d524d385bb8a04cff6e5a7556cc8e Mon Sep 17 00:00:00 2001 From: Oleg Gaidarenko Date: Thu, 27 Feb 2014 03:23:10 +0400 Subject: [PATCH] Tests: Add more tests for Sizzle attributes --- test/unit/selector.js | 92 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 89 insertions(+), 3 deletions(-) diff --git a/test/unit/selector.js b/test/unit/selector.js index 6236b5d6d..3293ea1db 100644 --- a/test/unit/selector.js +++ b/test/unit/selector.js @@ -89,7 +89,7 @@ test("name", function() { form.remove(); }); -test( "comma selectors", function() { +test( "selectors with comma", function() { expect( 4 ); var fixture = jQuery( "

" ); @@ -100,12 +100,98 @@ test( "comma selectors", function() { equal( fixture.find( "h2 , div p" ).filter( "h2" ).length, 1, "has to find one

" ); }); +test("attributes", function() { + expect( 54 ); -test("attributes - jQuery only", function() { - expect( 5 ); + var opt, input, attrbad, div, withScript; t( "Find elements with a tabindex attribute", "[tabindex]", ["listWithTabIndex", "foodWithNegativeTabIndex", "linkWithTabIndex", "linkWithNegativeTabIndex", "linkWithNoHrefWithTabIndex", "linkWithNoHrefWithNegativeTabIndex"] ); + t( "Attribute Exists", "#qunit-fixture a[title]", ["google"] ); + t( "Attribute Exists (case-insensitive)", "#qunit-fixture a[TITLE]", ["google"] ); + t( "Attribute Exists", "#qunit-fixture *[title]", ["google"] ); + t( "Attribute Exists", "#qunit-fixture [title]", ["google"] ); + t( "Attribute Exists", "#qunit-fixture a[ title ]", ["google"] ); + + t( "Boolean attribute exists", "#select2 option[selected]", ["option2d"]); + t( "Boolean attribute equals", "#select2 option[selected='selected']", ["option2d"]); + + t( "Attribute Equals", "#qunit-fixture a[rel='bookmark']", ["simon1"] ); + t( "Attribute Equals", "#qunit-fixture a[rel='bookmark']", ["simon1"] ); + t( "Attribute Equals", "#qunit-fixture a[rel=bookmark]", ["simon1"] ); + t( "Attribute Equals", "#qunit-fixture a[href='http://www.google.com/']", ["google"] ); + t( "Attribute Equals", "#qunit-fixture a[ rel = 'bookmark' ]", ["simon1"] ); + t( "Attribute Equals Number", "#qunit-fixture option[value=1]", ["option1b","option2b","option3b","option4b","option5c"] ); + t( "Attribute Equals Number", "#qunit-fixture li[tabIndex=-1]", ["foodWithNegativeTabIndex"] ); + + document.getElementById("anchor2").href = "#2"; + t( "href Attribute", "p a[href^=#]", ["anchor2"] ); + t( "href Attribute", "p a[href*=#]", ["simon1", "anchor2"] ); + + t( "for Attribute", "form label[for]", ["label-for"] ); + t( "for Attribute in form", "#form [for=action]", ["label-for"] ); + + t( "Attribute containing []", "input[name^='foo[']", ["hidden2"] ); + t( "Attribute containing []", "input[name^='foo[bar]']", ["hidden2"] ); + t( "Attribute containing []", "input[name*='[bar]']", ["hidden2"] ); + t( "Attribute containing []", "input[name$='bar]']", ["hidden2"] ); + t( "Attribute containing []", "input[name$='[bar]']", ["hidden2"] ); + t( "Attribute containing []", "input[name$='foo[bar]']", ["hidden2"] ); + t( "Attribute containing []", "input[name*='foo[bar]']", ["hidden2"] ); + + t( "Multiple Attribute Equals", "#form input[type='radio'], #form input[type='hidden']", ["radio1", "radio2", "hidden1"] ); + t( "Multiple Attribute Equals", "#form input[type='radio'], #form input[type=\"hidden\"]", ["radio1", "radio2", "hidden1"] ); + t( "Multiple Attribute Equals", "#form input[type='radio'], #form input[type=hidden]", ["radio1", "radio2", "hidden1"] ); + + t( "Attribute selector using UTF8", "span[lang=中文]", ["台北"] ); + + t( "Attribute Begins With", "a[href ^= 'http://www']", ["google","yahoo"] ); + t( "Attribute Ends With", "a[href $= 'org/']", ["mark"] ); + t( "Attribute Contains", "a[href *= 'google']", ["google","groups"] ); + t( "Attribute Is Not Equal", "#ap a[hreflang!='en']", ["google","groups","anchor1"] ); + + t( "Empty values", "#select1 option[value='']", ["option1a"] ); + t( "Empty values", "#select1 option[value!='']", ["option1b","option1c","option1d"] ); + + t( "Select options via :selected", "#select1 option:selected", ["option1a"] ); + t( "Select options via :selected", "#select2 option:selected", ["option2d"] ); + t( "Select options via :selected", "#select3 option:selected", ["option3b", "option3c"] ); + t( "Select options via :selected", "select[name='select2'] option:selected", ["option2d"] ); + + t( "Grouped Form Elements", "input[name='foo[bar]']", ["hidden2"] ); + + // Make sure attribute value quoting works correctly. See jQuery #6093; #6428; #13894 + // Use seeded results to bypass querySelectorAll optimizations + attrbad = jQuery( + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + ).appendTo("#qunit-fixture").get(); + + t( "Underscores don't need escaping", "input[id=types_all]", ["types_all"] ); + + t( "input[type=text]", "#form input[type=text]", ["text1", "text2", "hidden2", "name"] ); + t( "input[type=search]", "#form input[type=search]", ["search"] ); + + withScript = supportjQuery( "