Commit 62f7f7be authored by Scott González's avatar Scott González Committed by Timmy Willison

Build: Remove unused Sizzle test files

parent 5150442e
...@@ -50,11 +50,7 @@ module.exports = function( grunt ) { ...@@ -50,11 +50,7 @@ module.exports = function( grunt ) {
}, },
src: { src: {
files: { files: {
"src/sizzle/dist": "sizzle/dist", "src/sizzle/dist": "sizzle/dist"
"src/sizzle/test/data": "sizzle/test/data",
"src/sizzle/test/unit": "sizzle/test/unit",
"src/sizzle/test/index.html": "sizzle/test/index.html",
"src/sizzle/test/jquery.js": "sizzle/test/jquery.js"
} }
}, },
tests: { tests: {
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script>var QUnit = parent.QUnit</script>
<script src="testinit.js"></script>
<script src="../../dist/sizzle.js"></script>
</head>
<body>
<script>
var doc = parent.document,
unframed = [ doc.getElementById( "qunit-fixture" ), doc.body, doc.documentElement ],
framed = Sizzle( "*" );
window.parent.iframeCallback(
Sizzle.uniqueSort( unframed.concat( framed ) ),
framed.concat( unframed.reverse() ),
"Mixed array was sorted correctly"
);
</script>
</body>
</html>
var fireNative,
jQuery = this.jQuery || "jQuery", // For testing .noConflict()
$ = this.$ || "$",
originaljQuery = jQuery,
original$ = $;
(function() {
// Config parameter to force basic code paths
QUnit.config.urlConfig.push({
id: "basic",
label: "Bypass optimizations",
tooltip: "Force use of the most basic code by disabling native querySelectorAll; contains; compareDocumentPosition"
});
if ( QUnit.urlParams.basic ) {
document.querySelectorAll = null;
document.documentElement.contains = null;
document.documentElement.compareDocumentPosition = null;
// Return array of length two to pass assertion
// But support should be false as its not native
document.getElementsByClassName = function() { return [ 0, 1 ]; };
}
})();
/**
* Returns an array of elements with the given IDs
* @example q("main", "foo", "bar")
* @result [<div id="main">, <span id="foo">, <input id="bar">]
*/
function q() {
var r = [],
i = 0;
for ( ; i < arguments.length; i++ ) {
r.push( document.getElementById( arguments[i] ) );
}
return r;
}
/**
* Asserts that a select matches the given IDs
* @param {String} a - Assertion name
* @param {String} b - Sizzle selector
* @param {String} c - Array of ids to construct what is expected
* @example t("Check for something", "//[a]", ["foo", "baar"]);
* @result returns true if "//[a]" return two elements with the IDs 'foo' and 'baar'
*/
function t( a, b, c ) {
var f = Sizzle(b),
s = "",
i = 0;
for ( ; i < f.length; i++ ) {
s += ( s && "," ) + '"' + f[ i ].id + '"';
}
deepEqual(f, q.apply( q, c ), a + " (" + b + ")");
}
/**
* Add random number to url to stop caching
*
* @example url("data/test.html")
* @result "data/test.html?10538358428943"
*
* @example url("data/test.php?foo=bar")
* @result "data/test.php?foo=bar&10538358345554"
*/
function url( value ) {
return value + (/\?/.test(value) ? "&" : "?") + new Date().getTime() + "" + parseInt(Math.random()*100000);
}
var createWithFriesXML = function() {
var string = '<?xml version="1.0" encoding="UTF-8"?> \
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" \
xmlns:xsd="http://www.w3.org/2001/XMLSchema" \
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> \
<soap:Body> \
<jsconf xmlns="http://www.example.com/ns1"> \
<response xmlns:ab="http://www.example.com/ns2"> \
<meta> \
<component id="seite1" class="component"> \
<properties xmlns:cd="http://www.example.com/ns3"> \
<property name="prop1"> \
<thing /> \
<value>1</value> \
</property> \
<property name="prop2"> \
<thing att="something" /> \
</property> \
<foo_bar>foo</foo_bar> \
</properties> \
</component> \
</meta> \
</response> \
</jsconf> \
</soap:Body> \
</soap:Envelope>';
return jQuery.parseXML( string );
};
fireNative = document.createEvent ?
function( node, type ) {
var event = document.createEvent("HTMLEvents");
event.initEvent( type, true, true );
node.dispatchEvent( event );
} :
function( node, type ) {
var event = document.createEventObject();
node.fireEvent( "on" + type, event );
};
function testIframeWithCallback( title, fileName, func ) {
test( title, function() {
var iframe;
stop();
window.iframeCallback = function() {
var self = this,
args = arguments;
setTimeout(function() {
window.iframeCallback = undefined;
iframe.remove();
func.apply( self, args );
func = function() {};
start();
}, 0 );
};
iframe = jQuery( "<div/>" ).css({ position: "absolute", width: "500px", left: "-600px" })
.append( jQuery( "<iframe/>" ).attr( "src", url( "./data/" + fileName ) ) )
.appendTo( "#qunit-fixture" );
});
};
window.iframeCallback = undefined;
function moduleTeardown() {}
This diff is collapsed.
This diff is collapsed.
module("extending", { teardown: moduleTeardown });
test("custom pseudos", function() {
expect( 6 );
Sizzle.selectors.filters.foundation = Sizzle.selectors.filters.root;
deepEqual( Sizzle(":foundation"), [ document.documentElement ], "Copy element filter with new name" );
delete Sizzle.selectors.filters.foundation;
Sizzle.selectors.setFilters.primary = Sizzle.selectors.setFilters.first;
t( "Copy set filter with new name", "div:primary", ["qunit"] );
delete Sizzle.selectors.setFilters.primary;
Sizzle.selectors.filters.aristotlean = Sizzle.selectors.createPseudo(function() {
return function( elem ) {
return !!elem.id;
};
});
t( "Custom element filter", "#foo :aristotlean", [ "sndp", "en", "yahoo", "sap", "anchor2", "simon" ] );
delete Sizzle.selectors.filters.aristotlean;
Sizzle.selectors.filters.endswith = Sizzle.selectors.createPseudo(function( text ) {
return function( elem ) {
return Sizzle.getText( elem ).slice( -text.length ) === text;
};
});
t( "Custom element filter with argument", "a:endswith(ogle)", ["google"] );
delete Sizzle.selectors.filters.endswith;
Sizzle.selectors.setFilters.second = Sizzle.selectors.createPseudo(function() {
return Sizzle.selectors.createPseudo(function( seed, matches ) {
if ( seed[1] ) {
matches[1] = seed[1];
seed[1] = false;
}
});
});
t( "Custom set filter", "#qunit-fixture p:second", ["ap"] );
delete Sizzle.selectors.filters.second;
Sizzle.selectors.setFilters.slice = Sizzle.selectors.createPseudo(function( argument ) {
var bounds = argument.split(":");
return Sizzle.selectors.createPseudo(function( seed, matches ) {
var i = bounds[1];
// Match elements found at the specified indexes
while ( --i >= bounds[0] ) {
if ( seed[i] ) {
matches[i] = seed[i];
seed[i] = false;
}
}
});
});
t( "Custom set filter with argument", "#qunit-fixture p:slice(1:3)", [ "ap", "sndp" ] );
delete Sizzle.selectors.filters.slice;
});
test("backwards-compatible custom pseudos", function() {
expect( 3 );
Sizzle.selectors.filters.icontains = function( elem, i, match ) {
return Sizzle.getText( elem ).toLowerCase().indexOf( (match[3] || "").toLowerCase() ) > -1;
};
t( "Custom element filter with argument", "a:icontains(THIS BLOG ENTRY)", ["simon1"] );
delete Sizzle.selectors.filters.icontains;
Sizzle.selectors.setFilters.podium = function( elements, argument ) {
var count = argument == null || argument === "" ? 3 : +argument;
return elements.slice( 0, count );
};
// Using TAG as the first token here forces this setMatcher into a fail state
// Where the descendent combinator was lost
t( "Custom setFilter", "form#form :PODIUM", ["label-for", "text1", "text2"] );
t( "Custom setFilter with argument", "#form input:Podium(1)", ["text1"] );
delete Sizzle.selectors.setFilters.podium;
});
test("custom attribute getters", function() {
expect( 2 );
var original = Sizzle.selectors.attrHandle.hreflang,
selector = "a:contains('mark')[hreflang='http://diveintomark.org/en']";
Sizzle.selectors.attrHandle.hreflang = function( elem, name ) {
var href = elem.getAttribute("href"),
lang = elem.getAttribute( name );
return lang && ( href + lang );
};
deepEqual( Sizzle(selector, createWithFriesXML()), [], "Custom attrHandle (preferred document)" );
t( "Custom attrHandle (preferred document)", selector, ["mark"] );
Sizzle.selectors.attrHandle.hreflang = original;
});
This diff is collapsed.
module("utilities", { teardown: moduleTeardown });
function testAttr( doc ) {
expect( 9 );
var el;
if ( doc ) {
// XML
el = doc.createElement( "input" );
el.setAttribute( "type", "checkbox" );
} else {
// Set checked on creation by creating with a fragment
// See http://jsfiddle.net/8sVgA/1/show/light in oldIE
el = jQuery( "<input type='checkbox' checked='checked' />" )[0];
}
// Set it again for good measure
el.setAttribute( "checked", "checked" );
el.setAttribute( "id", "id" );
el.setAttribute( "value", "on" );
strictEqual( Sizzle.attr( el, "nonexistent" ), null, "nonexistent" );
strictEqual( Sizzle.attr( el, "id" ), "id", "existent" );
strictEqual( Sizzle.attr( el, "value" ), "on", "value" );
strictEqual( Sizzle.attr( el, "checked" ), "checked", "boolean" );
strictEqual( Sizzle.attr( el, "href" ), null, "interpolation risk" );
strictEqual( Sizzle.attr( el, "constructor" ), null,
"Object.prototype property \"constructor\" (negative)" );
strictEqual( Sizzle.attr( el, "watch" ), null,
"Gecko Object.prototype property \"watch\" (negative)" );
el.setAttribute( "constructor", "foo" );
el.setAttribute( "watch", "bar" );
strictEqual( Sizzle.attr( el, "constructor" ), "foo",
"Object.prototype property \"constructor\"" );
strictEqual( Sizzle.attr( el, "watch" ), "bar",
"Gecko Object.prototype property \"watch\"" );
}
test("Sizzle.attr (HTML)", function() {
testAttr();
});
test("Sizzle.attr (XML)", function() {
testAttr( jQuery.parseXML("<root/>") );
});
test("Sizzle.contains", function() {
expect( 16 );
var container = document.getElementById("nonnodes"),
element = container.firstChild,
text = element.nextSibling,
nonContained = container.nextSibling,
detached = document.createElement("a");
ok( element && element.nodeType === 1, "preliminary: found element" );
ok( text && text.nodeType === 3, "preliminary: found text" );
ok( nonContained, "preliminary: found non-descendant" );
ok( Sizzle.contains(container, element), "child" );
ok( Sizzle.contains(container.parentNode, element), "grandchild" );
ok( Sizzle.contains(container, text), "text child" );
ok( Sizzle.contains(container.parentNode, text), "text grandchild" );
ok( !Sizzle.contains(container, container), "self" );
ok( !Sizzle.contains(element, container), "parent" );
ok( !Sizzle.contains(container, nonContained), "non-descendant" );
ok( !Sizzle.contains(container, document), "document" );
ok( !Sizzle.contains(container, document.documentElement), "documentElement (negative)" );
ok( !Sizzle.contains(container, null), "Passing null does not throw an error" );
ok( Sizzle.contains(document, document.documentElement), "documentElement (positive)" );
ok( Sizzle.contains(document, element), "document container (positive)" );
ok( !Sizzle.contains(document, detached), "document container (negative)" );
});
if ( jQuery("<svg xmlns='http://www.w3.org/2000/svg' version='1.1' height='1' width='1'><g/></svg>")[0].firstChild ) {
test("Sizzle.contains in SVG (jQuery #10832)", function() {
expect( 4 );
var svg = jQuery(
"<svg xmlns='http://www.w3.org/2000/svg' version='1.1' height='1' width='1'>" +
"<g><circle cx='1' cy='1' r='1' /></g>" +
"</svg>"
).appendTo("#qunit-fixture")[0];
ok( Sizzle.contains( svg, svg.firstChild ), "root child" );
ok( Sizzle.contains( svg.firstChild, svg.firstChild.firstChild ), "element child" );
ok( Sizzle.contains( svg, svg.firstChild.firstChild ), "root granchild" );
ok( !Sizzle.contains( svg.firstChild.firstChild, svg.firstChild ), "parent (negative)" );
});
}
test("Sizzle.uniqueSort", function() {
expect( 14 );
function Arrayish( arr ) {
var i = this.length = arr.length;
while ( i-- ) {
this[ i ] = arr[ i ];
}
}
Arrayish.prototype = {
slice: [].slice,
sort: [].sort,
splice: [].splice
};
var i, tests,
detached = [],
body = document.body,
fixture = document.getElementById("qunit-fixture"),
detached1 = document.createElement("p"),
detached2 = document.createElement("ul"),
detachedChild = detached1.appendChild( document.createElement("a") ),
detachedGrandchild = detachedChild.appendChild( document.createElement("b") );
for ( i = 0; i < 12; i++ ) {
detached.push( document.createElement("li") );
detached[i].id = "detached" + i;
detached2.appendChild( document.createElement("li") ).id = "detachedChild" + i;
}
tests = {
"Empty": {
input: [],
expected: []
},
"Single-element": {
input: [ fixture ],
expected: [ fixture ]
},
"No duplicates": {
input: [ fixture, body ],
expected: [ body, fixture ]
},
"Duplicates": {
input: [ body, fixture, fixture, body ],
expected: [ body, fixture ]
},
"Detached": {
input: detached.slice( 0 ),
expected: detached.slice( 0 )
},
"Detached children": {
input: [
detached2.childNodes[0],
detached2.childNodes[1],
detached2.childNodes[2],
detached2.childNodes[3]
],
expected: [
detached2.childNodes[0],
detached2.childNodes[1],
detached2.childNodes[2],
detached2.childNodes[3]
]
},
"Attached/detached mixture": {
input: [ detached1, fixture, detached2, document, detachedChild, body, detachedGrandchild ],
expected: [ document, body, fixture ],
length: 3
}
};
jQuery.each( tests, function( label, test ) {
var length = test.length || test.input.length;
deepEqual( Sizzle.uniqueSort( test.input ).slice( 0, length ), test.expected, label + " (array)" );
deepEqual( Sizzle.uniqueSort( new Arrayish(test.input) ).slice( 0, length ), test.expected, label + " (quasi-array)" );
});
});
testIframeWithCallback( "Sizzle.uniqueSort works cross-window (jQuery #14381)", "mixed_sort.html", deepEqual );
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment