Commit e7a29e42 authored by John Resig's avatar John Resig

Moved the tests into jQuery proper.

parent 139a9cd7
<html>
<head>
<script type="text/javascript" src="lib/Test/Harness.js"></script>
<script type="text/javascript" src="lib/Test/Harness/Browser.js"></script>
</head>
<body>
<h1>jQuery - Test Suite</h1>
<script type="text/javascript">
new Test.Harness.Browser().runTests(
"tests/prereq.html",
"tests/css1.html",
"tests/css2.html",
"tests/css3.html",
"tests/xpath.html",
"tests/custom.html",
"tests/basic.html"
);
</script>
</body>
</html>
This diff is collapsed.
// # $Id: Kinetic.pm 1493 2005-04-07 19:20:18Z theory $
// Set up namespace.
if (typeof self != 'undefined') {
//Browser
if (typeof Test == 'undefined') Test = {PLATFORM: 'browser'};
else Test.PLATFORM = 'browser';
} else if (typeof _player != 'undefined'){
//Director
if (typeof _global.Test != "object") _global.Test = {PLATFORM: 'director'};
else _global.Test.PLATFORM = 'director';
} else {
throw new Error("Test.Harness does not support your platform");
}
Test.Harness = function () {};
Test.Harness.VERSION = '0.11';
Test.Harness.Done = 0;
// Stoopid IE.
Test.Harness.LF = typeof document != "undefined"
&& typeof document.all != "undefined"
? "\r"
: "\n";
Test.Harness.prototype.isDone = Test.Harness.isDone;
/*
bonus Number of individual todo tests unexpectedly passed
ran Number of individual tests ran
ok Number of individual tests passed
subSkipped Number of individual tests skipped
todo Number of individual todo tests
files Number of test files ran
good Number of test files passed
bad Number of test files failed
tests Number of test files originally given
skipped Number of test files skipped
*/
Test.Harness.prototype.bonus = 0;
Test.Harness.prototype.ran = 0;
Test.Harness.prototype.ok = 0;
Test.Harness.prototype.subSkipped = 0;
Test.Harness.prototype.todo = 0;
Test.Harness.prototype.files = 0;
Test.Harness.prototype.good = 0;
Test.Harness.prototype.bad = 0;
Test.Harness.prototype.tests = 0;
Test.Harness.prototype.skipped = 0;
Test.Harness.prototype.failures = [];
Test.Harness.runTests = function () {
// XXX Can't handle inheritance, right? Or can we?
var harness = new Test.Harness();
harness.runTests.apply(harness, arguments);
};
Test.Harness.prototype.outFileNames = function (files) {
var len = 0;
for (var i = 0; i < files.length; i++) {
if (files[i].length > len) len = files[i].length;
}
len += 3;
var ret = [];
for (var i = 0; i < files.length; i++) {
var outName = files[i];
var add = len - files[i].length;
// Where is Perl's x operator when I need it??
for (var j = 0; j < add; j++) {
outName += '.';
}
ret.push(outName);
}
return ret;
};
Test.Harness.prototype.outputResults = function (test, file, fn, attrs) {
this.tests++;
this.ran += test.TestResults.length;
var fails = [];
var track = {
fn: file,
total: test.expectedTests,
ok: 0,
failList: []
};
if (test.TestResults.length) {
this.files++;
var pass = true;
for (var i = 0; i < test.TestResults.length; i++) {
var ok = "ok";
if (test.TestResults[i].ok) {
this.ok++;
track.ok++
if (test.TestResults[i].type == 'todo') {
// Handle unexpected pass.
if (test.TestResults[i].actualOK) this.bonus++;
this.todo ++;
} else if (test.TestResults[i].type == 'skip') this.subSkipped++;
} else {
if (test.TestResults[i].type == 'todo') {
// Expected failure.
this.todo++;
} else {
pass = false;
track.failList.push(i + 1);
}
ok = "not ok"; // XXX Need to handle TODO and TODO Skipped.
}
if (!pass || attrs.verbose) fn(test.TestResults[i].output);
}
if (pass) {
this.good++;
fn("ok" + Test.Harness.LF);
} else {
this.bad++;
var err = "NOK # Failed ";
if (track.failList.length == 1) {
err += "test " + track.failList[0];
} else {
err += "tests " + this._failList(track.failList);
}
fn(err + " in " + file + Test.Harness.LF);
}
} else if (test.SkipAll){
// All tests skipped.
this.skipped++;
this.good++;
fn("1..0 # Skip 1" + Test.Harness.LF);
} else {
// Wha happened? Tests ran, but no results!
this.files++;
this.bad++;
fn("FAILED before any test output arrived" + Test.Harness.LF);
}
if (track.failList.length) this.failures.push(track);
};
Test.Harness.prototype._allOK = function () {
return this.bad == 0 && (this.ran || this.skipped) ? true : false;
};
Test.Harness.prototype.outputSummary = function (fn, time) {
var bonusmsg = this._bonusmsg();
var pct;
if (this._allOK()) {
fn("All tests successful" + bonusmsg + '.' + Test.Harness.LF);
} else if (!this.tests) {
fn("FAILED—no tests were run for some reason." + Test.Harness.LF);
} else if (!this.ran) {
var blurb = this.tests == 1 ? "file" : "files";
fn("FAILED—" + this.tests + " test " + blurb + " could be run, "
+ "alas—no output ever seen." + Test.Harness.LF);
} else {
pct = this.good / this.tests * 100;
var pctOK = 100 * this.ok / this.ran;
var subpct = (this.ran - this.ok) + "/" + this.ran
+ " subtests failed, " + pctOK.toPrecision(4) + "% okay.";
if (this.bad) {
bonusmsg = bonusmsg.replace(/^,?\s*/, '');
if (bonusmsg) fn(bonusmsg + '.' + Test.Harness.LF);
fn("Failed " + this.bad + "/" + this.tests + " test scripts, "
+ pct.toPrecision(4) + "% okay. " + subpct + Test.Harness.LF);
}
this.formatFailures(fn);
}
fn("Files=" + this.tests + ", Tests=" + this.ran + ", " + (time / 1000)
+ " seconds" + Test.Harness.LF);
};
Test.Harness.prototype.formatFailures = function () {
var table = '';
var failedStr = "Failed Test";
var middleStr = " Total Fail Failed ";
var listStr = "List of Failed";
var cols = 80;
// Figure out our longest name string for formatting purposes.
var maxNamelen = failedStr.length;
for (var i = 0; i < this.failures.length; i++) {
var len = this.failures[i].length;
if (len > maxNamelen) maxNamelen = len;
}
var listLen = cols - middleStr.length - maxNamelen.length;
if (listLen < listStr.length) {
listLen = listStr.length;
maxNamelen = cols - middleStr.length - listLen;
if (maxNamelen < failedStr.length) {
maxNamelen = failedStr.length;
cols = maxNamelen + middleStr.length + listLen;
}
}
var out = failedStr;
if (out.length < maxNamelen) {
for (var j = out.length; j < maxNameLength; j++) {
out += ' ';
}
}
out += ' ' + middleStr;
// XXX Need to finish implementing the text-only version of the failures
// table.
};
Test.Harness.prototype._bonusmsg = function () {
var bonusmsg = '';
if (this.bonus) {
bonusmsg = (" (" + this.bonus + " subtest" + (this.bonus > 1 ? 's' : '')
+ " UNEXPECTEDLY SUCCEEDED)");
}
if (this.skipped) {
bonusmsg += ", " + this.skipped + " test"
+ (this.skipped != 1 ? 's' : '');
if (this.subSkipped) {
bonusmsg += " and " + this.subSkipped + " subtest"
+ (this.subSkipped != 1 ? 's' : '');
}
bonusmsg += ' skipped';
} else if (this.subSkipped) {
bonusmsg += ", " + this.subSkipped + " subtest"
+ (this.subSkipped != 1 ? 's' : '') + " skipped";
}
return bonusmsg;
}
Test.Harness.prototype._failList = function (fails) {
var last = -1;
var dash = '';
var list = [];
for (var i = 0; i < fails.length; i++) {
if (dash) {
// We're in a series of numbers.
if (fails[i] - 1 == last) {
// We're still in it.
last = fails[i];
} else {
// End of the line.
list[list.length-1] += dash + last;
last = -1;
list.push(fails[i]);
dash = '';
}
} else if (fails[i] - 1 == last) {
// We're in a new series.
last = fails[i];
dash = '-';
} else {
// Not in a sequence.
list.push(fails[i]);
last = fails[i];
}
}
if (dash) list[list.length-1] += dash + last;
return list.join(' ');
}
// # $Id: Kinetic.pm 1493 2005-04-07 19:20:18Z theory $
if (typeof JSAN != 'undefined') new JSAN().use('Test.Harness');
Test.Harness.Browser = function () {};
Test.Harness.Browser.VERSION = '0.11';
Test.Harness.Browser.runTests = function () {
var harness = new Test.Harness.Browser();
harness.runTests.apply(harness, arguments);
};
Test.Harness.Browser.prototype = new Test.Harness();
Test.Harness.Browser.prototype.interval = 100;
Test.Harness.Browser.prototype._setupFrame = function (a) {
// Setup the iFrame to run the tests.
var node = document.getElementById('buffer');
if (node) return node.contentWindow;
node = document.createElement("iframe");
node.setAttribute("id", "buffer");
node.setAttribute("name", "buffer");
node.style.visibility = "hidden";
node.style.height = 0;
node.style.width = 0;
document.body.appendChild(node);
var self = this;
setTimeout( function(){
self.buffer = node.contentWindow;
self._runTests.apply(self,a);
}, 200 );
};
Test.Harness.Browser.prototype._setupOutput = function () {
// Setup the pre element for test output.
var node = document.createElement("pre");
node.setAttribute("id", "output");
document.body.appendChild(node);
return function (msg) {
node.appendChild(document.createTextNode(msg));
window.scrollTo(0, document.body.offsetHeight
|| document.body.scrollHeight);
};
};
Test.Harness.Browser.prototype._setupSummary = function () {
// Setup the div for the summary.
var node = document.createElement("div");
node.setAttribute("id", "summary");
//node.setAttribute("style", "white-space:pre; font-family: Verdana,Arial,serif;");
document.body.appendChild(node);
return function (msg) {
node.appendChild(document.createTextNode(msg));
window.scrollTo(0, document.body.offsetHeight
|| document.body.scrollHeight);
};
};
Test.Harness.Browser.prototype.runTests = function () {
this._setupFrame(arguments);
}
Test.Harness.Browser.prototype._runTests = function () {
var files = this.args.file
? typeof this.args.file == 'string' ? [this.args.file] : this.args.file
: arguments;
if (!files.length) return;
var outfiles = this.outFileNames(files);
var buffer = this.buffer;
var harness = this;
var ti = 0;
var start;
var node = document.getElementById('output');
var output = this._setupOutput();
var summaryOutput = this._setupSummary();
// These depend on how we're watching for a test to finish.
var finish = function () {}, runNext = function () {};
// This function handles most of the work of outputting results and
// running the next test, if there is one.
var runner = function () {
harness.outputResults(
buffer.Test.Builder.Test,
files[ti],
output,
harness.args
);
if (files[++ti]) {
output(outfiles[ti] + (harness.args.verbose ? Test.Harness.LF : ''));
buffer.location.href = files[ti] + "?" + start.getTime();
runNext();
} else {
harness.outputSummary(
summaryOutput,
new Date() - start
);
finish();
}
};
if (Object.watch) {
// We can use the cool watch method, and avoid setting timeouts!
// We just need to unwatch() when all tests are finished.
finish = function () { Test.Harness.unwatch('Done') };
Test.Harness.watch('Done', function (attr, prev, next) {
if (next < buffer.Test.Builder.Instances.length) return next;
runner();
return 0;
});
} else {
// Damn. We have to set timeouts. :-(
var wait = function () {
// Check Test.Harness.Done. If it's non-zero, then we know that
// the buffer is fully loaded, because it has incremented
// Test.Harness.Done.
if (Test.Harness.Done > 0
&& Test.Harness.Done >= buffer.Test.Builder.Instances.length)
{
Test.Harness.Done = 0;
runner();
} else {
window.setTimeout(wait, harness.interval);
}
};
// We'll just have to set a timeout for the next test.
runNext = function () { window.setTimeout(wait, harness.interval); };
window.setTimeout(wait, this.interval);
}
// Now start the first test.
output(outfiles[ti] + (this.args.verbose ? Test.Harness.LF : ''));
start = new Date();
buffer.location.href = files[ti] + "?" + start.getTime(); // replace() doesn't seem to work.
};
// From "JavaScript: The Difinitive Guide 4ed", p 214.
Test.Harness.Browser.prototype.args = {};
var pairs = location.search.substring(1).split(",");
for (var i = 0; i < pairs.length; i++) {
var pos = pairs[i].indexOf('=');
if (pos == -1) continue;
var key = pairs[i].substring(0, pos);
var val = pairs[i].substring(pos + 1);
if (Test.Harness.Browser.prototype.args[key]) {
if (typeof Test.Harness.Browser.prototype.args[key] == 'string') {
Test.Harness.Browser.prototype.args[key] =
[Test.Harness.Browser.prototype.args[key]];
}
Test.Harness.Browser.prototype.args[key].push(unescape(val));
} else {
Test.Harness.Browser.prototype.args[key] = unescape(val);
}
}
delete pairs;
Test.Harness.Browser.prototype.formatFailures = function (fn) {
// XXX append new element for table and then populate it.
var failedStr = "Failed Test";
var middleStr = " Total Fail Failed ";
var listStr = "List of Failed";
var table = '<table style=""><tr><th>Failed Test</th><th>Total</th>'
+ '<th>Fail</th><th>Failed</th></tr>';
for (var i = 0; i < this.failures.length; i++) {
var track = this.failures[i];
table += '<tr><td>' + track.fn + '</td>'
+ '<td>' + track.total + '</td>'
+ '<td>' + track.total - track.ok + '</td>'
+ '<td>' + this._failList(track.failList) + '</td></tr>'
};
table += '</table>' + Test.Harness.LF;
var node = document.getElementById('summary');
node.innerHTML += table;
window.scrollTo(0, document.body.offsetHeight || document.body.scrollHeight);
};
// # $Id: Kinetic.pm 1493 2005-04-07 19:20:18Z theory $
Test.Harness.Director = function () {};
Test.Harness.Director.VERSION = '0.11';
Test.Harness.Director.runTests = function () {
var harness = new Test.Harness.Director();
harness.runTests.apply(harness, arguments);
};
Test.Harness.Director.prototype = new Test.Harness();
Test.Harness.Director.prototype.verbose = true;
Test.Harness.Director.prototype.args = {};
Test.Harness.Director.prototype.runTests = function (x_aFunctionNames) {
// Allow for an array or a simple list in arguments.
// XXX args.file isn't quite right since it's more function names, but
// that is still to be ironed out.
var functionNames = this.args.file
? typeof this.args.file == 'string' ? [this.args.file] : this.args.file
: arguments;
if (!x_aFunctionNames.length) return;
var outfunctions = this.outFileNames(x_aFunctionNames);
var harness = this;
var start = new Date();
var newLineRx = /(?:\r?\n|\r)+$/;
var output = function (msg) { trace(msg.replace(newLineRx, '')) };
for (var x = 0; x < x_aFunctionNames.length; x++){
output(outfunctions[x]);
eval(x_aFunctionNames[x] + "()");
harness.outputResults(
Test.Builder.Test,
x_aFunctionNames[x],
output,
harness.args
);
}
harness.outputSummary(
output,
new Date() - start
);
};
Test.Harness.Director.prototype.formatFailures = function (fn) {
// XXX Delete once the all-text version is implemented in Test.Harness.
var failedStr = "Failed Test";
var middleStr = " Total Fail Failed ";
var listStr = "List of Failed";
var table = '<table style=""><tr><th>Failed Test</th><th>Total</th>'
+ '<th>Fail</th><th>Failed</th></tr>';
for (var i = 0; i < this.failures.length; i++) {
var track = this.failures[i];
table += '<tr><td>' + track.fn + '</td>'
+ '<td>' + track.total + '</td>'
+ '<td>' + track.total - track.ok + '</td>'
+ '<td>' + this._failList(track.failList) + '</td></tr>'
};
table += '</table>';
output(table);
};
\ No newline at end of file
This diff is collapsed.
// # $Id: Kinetic.pm 1493 2005-04-07 19:20:18Z theory $
// Set up package.
if (typeof JSAN != 'undefined') new JSAN().use('Test.Builder');
else {
if (typeof Test == 'undefined' || typeof Test.Builder == 'undefined')
throw new Error(
"You must load either JSAN or Test.Builder "
+ "before loading Test.Simple"
);
}
Test.Simple = {};
Test.Simple.EXPORT = ['plan', 'ok'];
Test.Simple.EXPORT_TAGS = { ':all': Test.Simple.EXPORT };
Test.Simple.VERSION = '0.11';
Test.Simple.plan = function (cmds) {
return Test.Simple.Test.plan(cmds);
};
Test.Simple.ok = function (val, desc) {
return Test.Simple.Test.ok(val, desc);
};
// Handle exporting.
if (typeof JSAN == 'undefined') Test.Builder.exporter(Test.Simple);
Test.Simple.Test = new Test.Builder();
This diff is collapsed.
This diff is collapsed.
function q() {
var r = new Array();
for ( var i = 0; i < arguments.length; i++ ) {
r.push( document.getElementById( arguments[i] ) );
}
return r;
}
function t(a,b,c) {
var f = jQuery.find(b);
var s = "";
for ( var i = 0; i < f.length; i++ )
s += (s?",":"") + '"' + f[i].id + '"';
isSet(f,q.apply(q,c),a + " (" + b + ")") ||
diag( s );
}
function o(a) {
var li = document.createElement("li");
li.innerHTML = a;
if ( a.indexOf("#") == 0 )
li.className = "comment";
else if ( a.indexOf("TODO") >= 0 )
li.className = "todo";
else if ( a.indexOf("not ok") == 0 )
li.classname = "fail";
else
li.className = "pass";
document.getElementById("test").appendChild(li);
}
plan({noPlan: true});
<html id="html">
<head>
<script type="text/javascript" src="../lib/Test/Builder.js"></script>
<script type="text/javascript" src="../lib/Test/More.js"></script>
<script type="text/javascript" src="../lib/test.js"></script>
<script type="text/javascript" src="../../jquery/jquery-svn.js"></script>
</head>
<body id="body">
<h1>Basic Usage</h1>
<!-- Test HTML -->
<div id="main" style="display: none;"></div>
<div id="foo" style="display: none;"></div>
<pre id="test"><script>
plan({tests: 11});
var div = $("div");
diag( "Getters" );
cmpOK( div.size(), "==", 2, "Get Number of Elements Found" );
isSet( div.get(), q("main","foo"), "Get All Elements" );
cmpOK( div.get(0), "==", document.getElementById("main"),
"Get A Single Element" );
diag( "Setters" );
div.each(function(){this.foo = 'zoo';});
var pass = true;
for ( var i = 0; i < div.size(); i++ ) {
if ( div.get(i).foo != "zoo" ) pass = false;
}
ok( pass, "Execute, Relative" );
div.addClass("test");
var pass = true;
for ( var i = 0; i < div.size(); i++ ) {
if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
}
ok( pass, "Add Class" );
div.removeClass("test");
var pass = true;
for ( var i = 0; i < div.size(); i++ ) {
if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
}
ok( pass, "Remove Class" );
div.html("<b>test</b>");
var pass = true;
for ( var i = 0; i < div.size(); i++ ) {
if ( div.get(i).childNodes.length == 0 ) pass = false;
}
ok( pass, "Set HTML" );
div.attr("foo", "bar");
var pass = true;
for ( var i = 0; i < div.size(); i++ ) {
if ( div.get(i).foo != "bar" ) pass = false;
}
ok( pass, "Set Attribute" );
div.attr({foo: 'baz', zoo: 'ping'});
var pass = true;
for ( var i = 0; i < div.size(); i++ ) {
if ( div.get(i).foo != "baz" && div.get(i).zoo != "ping" ) pass = false;
}
ok( pass, "Set Multiple Attributes" );
diag( "Effects" );
var pass = true;
div.show().each(function(){
if ( this.style.display == "none" ) pass = false;
});
ok( pass, "Show" );
var pass = true;
div.hide().each(function(){
if ( this.style.display != "none" ) pass = false;
});
ok( pass, "Hide" );
</script></pre>
</body>
</html>
<html id="html">
<head>
<script type="text/javascript" src="../lib/Test/Builder.js"></script>
<script type="text/javascript" src="../lib/Test/More.js"></script>
<script type="text/javascript" src="../lib/test.js"></script>
<script type="text/javascript" src="../../jquery/jquery-svn.js"></script>
</head>
<body id="body">
<h1>CSS 1 Selectors</h1>
<!-- Test HTML -->
<div id="main" style="display: none;">
<p id="first">See <a id="simon1" href="http://simon.incutio.com/archive/2003/03/25/#getElementsBySelector" rel="bookmark">this blog entry</a>
for more information.</p><p>Here are some links in a normal paragraph:
<a id="google" href="http://www.google.com/" title="Google!">Google</a>,
<a id="groups" href="http://groups.google.com/">Google Groups</a>.
This link has <code><a href="#" id="anchor1">class="blog"</a></code>:
<a href="http://diveintomark.org/" class="blog" hreflang="en" id="mark">diveintomark</a></p>
<div id="foo"><p>Everything inside the red border is inside a div with
<code>id="foo"</code>.</p><p lang="en">This is a normal link:
<a id="yahoo"href="http://www.yahoo.com/">Yahoo</a></p>
<p>This link has <code><a href="#2" id="anchor2">class="blog"</a></code>:
<a href="http://simon.incutio.com/" class="blog link" id="simon">Simon Willison's Weblog</a></p></div>
<p>Try them out: </p>
<ul id="first"></ul>
</div>
<pre id="test"><script>
plan({tests: 16});
t( "Element Selector", "div", ["main","foo"] );
t( "Element Selector", "body", ["body"] );
t( "Element Selector", "html", ["html"] );
cmpOK( $("*").size(), ">=", 30, "Element Selector" );
t( "Parent Element", "div div", ["foo"] );
t( "ID Selector", "#body", ["body"] );
t( "ID Selector w/ Element", "body#body", ["body"] );
cmpOK($("ul#first").get(0), "==", document.getElementsByTagName("ul")[0],
"ID Selector w/ Element");
t( "Class Selector", ".blog", ["simon","mark"] );
t( "Class Selector", ".blog.link", ["simon"] );
t( "Class Selector w/ Element", "a.blog", ["simon","mark"] );
t( "Parent Class Selector", "p .blog", ["simon","mark"] );
t( "Comma Support", "a.blog, div",
["main","foo","simon","mark"] );
t( "Comma Support", "a.blog , div",
["main","foo","simon","mark"] );
t( "Comma Support", "a.blog ,div",
["main","foo","simon","mark"] );
t( "Comma Support", "a.blog,div",
["main","foo","simon","mark"] );
</script></pre>
</body>
</html>
<html id="html">
<head>
<script type="text/javascript" src="../lib/Test/Builder.js"></script>
<script type="text/javascript" src="../lib/Test/More.js"></script>
<script type="text/javascript" src="../lib/test.js"></script>
<script type="text/javascript" src="../../jquery/jquery-svn.js"></script>
</head>
<body id="body">
<h1>CSS 2 Selectors</h1>
<!-- Test HTML -->
<div id="main" style="display: none;">
<p id="firstp">See <a id="simon1" href="http://simon.incutio.com/archive/2003/03/25/#getElementsBySelector" rel="bookmark">this blog entry</a>
for more information.</p>
<p id="ap">Here are some links in a normal paragraph:
<a id="google" href="http://www.google.com/" title="Google!">Google</a>,
<a id="groups" href="http://groups.google.com/">Google Groups</a>.
This link has <code><a href="#" id="anchor1">class="blog"</a></code>:
<a href="http://diveintomark.org/" class="blog" hreflang="en" id="mark">diveintomark</a></p>
<div id="foo"><p id="sndp">Everything inside the red border is inside a div with
<code>id="foo"</code>.</p><p lang="en" id="en">This is a normal link:
<a id="yahoo" href="http://www.yahoo.com/" class="blogTest">Yahoo</a></p>
<p id="sap">This link has <code><a href="#2" id="anchor2">class="blog"</a></code>:
<a href="http://simon.incutio.com/" class="blog link" id="simon" rel="bookmark link">Simon Willison's Weblog</a></p></div>
<p id="first">Try them out: </p>
<ul id="first"></ul>
</div>
<pre id="test"><script>
plan({tests: 20});
t( "Child", "p > a",
["simon1","google","groups","mark","yahoo","simon"] );
t( "Child", "p> a",
["simon1","google","groups","mark","yahoo","simon"] );
t( "Child", "p >a",
["simon1","google","groups","mark","yahoo","simon"] );
t( "Child", "p>a",
["simon1","google","groups","mark","yahoo","simon"] );
t( "Child w/ Class", "p > a.blog",
["mark","simon"] );
t( "All Children", "code > *",
["anchor1","anchor2"] );
t( "All Grandchildren", "p > * > *",
["anchor1","anchor2"] );
t( "Adjacent", "a + a", ["groups"] );
t( "Adjacent", "a +a", ["groups"] );
t( "Adjacent", "a+ a", ["groups"] );
t( "Adjacent", "a+a", ["groups"] );
t( "Adjacent", "p + p", ["ap","en","sap"] );
t( "Comma, Child, and Adjacent", "a + a, code > a",
["anchor1","anchor2","groups"] );
t( "First Child", "p:first-child", ["firstp","sndp"] );
diag( "Note: @ is used for XPath compatability" );
t( "Attribute Exists", "a[@title]", ["google"] );
t( "Attribute Exists", "*[@title]", ["google"] );
t( "Attribute Exists", "[@title]", ["google"] );
t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
</script></pre>
</body>
</html>
<html id="html">
<head>
<script type="text/javascript" src="../lib/Test/Builder.js"></script>
<script type="text/javascript" src="../lib/Test/More.js"></script>
<script type="text/javascript" src="../lib/test.js"></script>
<script type="text/javascript" src="../../jquery/jquery-svn.js"></script>
</head>
<body id="body">
<h1>CSS 3 Selectors</h1>
<!-- Test HTML -->
<div id="main" style="display: none;">
<p id="firstp">See <a id="simon1" href="http://simon.incutio.com/archive/2003/03/25/#getElementsBySelector" rel="bookmark">this blog entry</a> for more information.</p>
<p id="ap">
Here are some links in a normal paragraph: <a id="google" href="http://www.google.com/" title="Google!">Google</a>,
<a id="groups" href="http://groups.google.com/">Google Groups</a>.
This link has <code><a href="#" id="anchor1">class="blog"</a></code>:
<a href="http://diveintomark.org/" class="blog" hreflang="en" id="mark">diveintomark</a>
</p>
<div id="foo">
<p id="sndp">Everything inside the red border is inside a div with
<code>id="foo"</code>.</p>
<p lang="en" id="en">This is a normal link:
<a id="yahoo" href="http://www.yahoo.com/" class="blogTest">Yahoo</a></p>
<p id="sap">This link has <code><a href="#2" id="anchor2">class="blog"</a></code>:
<a href="http://simon.incutio.com/" class="blog link" id="simon">Simon Willison's Weblog</a></p>
</div>
<p id="first">Try them out: </p>
<ul id="first"></ul>
<ol id="empty"></ol>
<form>
<input type="text" value="Test" id="text1"/>
<input type="text" value="Test" id="text2" disabled="disabled"/>
<input type="radio" name="radio1" id="radio1"/>
<input type="radio" name="radio2" id="radio2" checked/>
<input type="checkbox" name="check" id="check1" checked/>
<input type="checkbox" name="check" id="check2"/>
</form>
</div>
<pre id="test"><script>
plan({tests: 14});
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( "First Child", "p:first-child",
["firstp","sndp"] );
t( "Last Child", "p:last-child",
["sap"] );
t( "Only Child", "a:only-child",
["simon1","anchor1","anchor2","yahoo"] );
t( "Empty", "ol:empty", ["empty"] );
t( "Enabled UI Element", "input:enabled",
["text1","radio1","radio2","check1","check2"] );
t( "Disabled UI Element", "input:disabled",
["text2"] );
t( "Checked UI Element", "input:checked",
["radio2","check1"] );
t( "Text Contains", "a:contains('Google')",
["google","groups"] );
t( "Text Contains", "a:contains('Google Groups')",
["groups"] );
t( "Element Preceded By", "p ~ div", ["foo"] );
t( "Not", "a.blog:not(.link)", ["mark"] );
</script></pre>
</body>
</html>
<html id="html">
<head>
<script type="text/javascript" src="../lib/Test/Builder.js"></script>
<script type="text/javascript" src="../lib/Test/More.js"></script>
<script type="text/javascript" src="../lib/test.js"></script>
<script type="text/javascript" src="../../jquery/jquery-svn.js"></script>
</head>
<body id="body">
<h1>Custom Expressions</h1>
<!-- Test HTML -->
<div id="main" style="display: none;">
<p id="firstp">See <a id="simon1" href="http://simon.incutio.com/archive/2003/03/25/#getElementsBySelector" rel="bookmark">this blog entry</a>
for more information.</p>
<p id="ap">Here are some links in a normal paragraph:
<a id="google" href="http://www.google.com/" title="Google!">Google</a>,
<a id="groups" href="http://groups.google.com/">Google Groups</a>.
This link has <code><a href="#" id="anchor1">class="blog"</a></code>:
<a href="http://diveintomark.org/" class="blog" hreflang="en" id="mark">diveintomark</a>
</p>
<div id="foo">
<p id="sndp">Everything inside the red border is inside a div with
<code>id="foo"</code>.</p>
<p lang="en" id="en">This is a normal link:
<a id="yahoo" href="http://www.yahoo.com/" class="blogTest">Yahoo</a></p>
<p id="sap">This link has <code><a href="#2" id="anchor2">class="blog"</a></code>:
<a href="http://simon.incutio.com/" class="blog link" id="simon">Simon Willison's Weblog</a></p>
</div>
<p id="first">Try them out: </p>
<ol id="empty"></ol>
<form id="form">
<input type="hidden" value="Test" id="hidden"/>
<input type="text" value="Test" id="text1" style="display:none;"/>
<input type="text" value="Test" id="text2" disabled="disabled"/>
<input type="radio" name="radio1" id="radio1"/>
<input type="radio" name="radio2" id="radio2" checked/>
<input type="checkbox" name="check" id="check1" checked/>
<input type="checkbox" name="check" id="check2" style="visibility:hidden;"/>
</form>
</div>
<pre id="test"><script>
plan({tests: 11});
t( "nth Element", "p:nth(1)", ["ap"] );
t( "First Element", "p:first", ["firstp"] );
t( "Last Element", "p:last", ["first"] );
t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
t( "Odd Elements", "p:odd", ["ap","en","first"] );
t( "Position Equals", "p:eq(1)", ["ap"] );
t( "Position Greater Than", "p:gt(0)",
["ap","sndp","en","sap","first"] );
t( "Position Less Than", "p:lt(3)",
["firstp","ap","sndp"] );
t( "Is A Parent", "p:parent",
["firstp","ap","sndp","en","sap","first"] );
t( "Is Visible", "input:visible",
["text2","radio1","radio2","check1"] );
t( "Is Hidden", "input:hidden",
["hidden","text1","check2"] );
</script></pre>
</body>
</html>
<html id="html">
<head>
<script type="text/javascript" src="../lib/Test/Builder.js"></script>
<script type="text/javascript" src="../lib/Test/More.js"></script>
<script type="text/javascript" src="../lib/test.js"></script>
<script type="text/javascript" src="../../jquery/jquery-svn.js"></script>
</head>
<body id="body">
<h1>Test for Prerequisites</h1>
<pre id="test"><script>
plan({tests: 11});
ok( Array.prototype.push, "Array.push()" );
ok( Function.prototype.apply, "Function.apply()" );
ok( document.getElementById, "getElementById" );
ok( document.getElementsByTagName, "getElementsByTagName" );
ok( RegExp, "RegExp" );
ok( jQuery, "jQuery" );
ok( $, "$()" );
ok( $.find, "Select" );
ok( $.filter, "filter()" );
ok( $.event.add, "addEvent" );
ok( $.event.remove, "removeEvent" );
</script></pre>
</body>
</html>
<html id="html">
<head>
<script type="text/javascript" src="../lib/Test/Builder.js"></script>
<script type="text/javascript" src="../lib/Test/More.js"></script>
<script type="text/javascript" src="../lib/test.js"></script>
<script type="text/javascript" src="../../jquery/jquery-svn.js"></script>
</head>
<body id="body">
<h1>XPath Expressions</h1>
<!-- Test HTML -->
<div id="main" style="display: none;">
<p id="firstp">See <a id="simon1" href="http://simon.incutio.com/archive/2003/03/25/#getElementsBySelector" rel="bookmark">this blog entry</a>
for more information.</p>
<p id="ap">Here are some links in a normal paragraph:
<a id="google" href="http://www.google.com/" title="Google!">Google</a>,
<a id="groups" href="http://groups.google.com/">Google Groups</a>.
This link has <code><a href="#" id="anchor1">class="blog"</a></code>:
<a href="http://diveintomark.org/" class="blog" hreflang="en" id="mark">diveintomark</a>
</p>
<div id="foo">
<p id="sndp">Everything inside the red border is inside a div with
<code>id="foo"</code>.</p>
<p lang="en" id="en">This is a normal link:
<a id="yahoo" href="http://www.yahoo.com/" class="blogTest">Yahoo</a>
</p>
<p id="sap">This link has <code><a href="#2" id="anchor2">class="blog"</a></code>:
<a href="http://simon.incutio.com/" class="blog link" id="simon">Simon Willison's Weblog</a>
</p>
</div>
<p id="first">Try them out: </p>
<ol id="empty"></ol>
<form id="form">
<input type="text" value="Test" id="text1"/>
<input type="text" value="Test" id="text2" disabled="disabled"/>
<input type="radio" name="radio1" id="radio1"/>
<input type="radio" name="radio2" id="radio2" checked/>
<input type="checkbox" name="check" id="check1" checked/>
<input type="checkbox" name="check" id="check2"/>
</form>
</div>
<pre id="test"><script>
plan({tests: 14});
cmpOK( $.find("//*").length, ">=", 30, "All Elements (//*)" );
t( "All Div Elements", "//div", ["main","foo"] );
t( "Absolute Path", "/html/body", ["body"] );
t( "Absolute Path w/ *", "/*/body", ["body"] );
t( "Long Absolute Path", "/html/body/div/div/p", ["sndp","en","sap"] );
t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
t( "Attribute Exists", "//a[@title]", ["google"] );
t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
t( "Parent Axis", "//p/..", ["main","foo"] );
t( "Sibling Axis", "//p/../",
["firstp","ap","foo","first","empty","form","sndp","en","sap"] );
t( "Sibling Axis", "//p/../*",
["firstp","ap","foo","first","empty","form","sndp","en","sap"] );
t( "Has Children", "//p[a]",
["firstp","ap","en","sap"] );
</script></pre>
</body>
</html>
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