Commit 97ea4749 authored by Jörn Zaefferer's avatar Jörn Zaefferer

Improved test suite to reset fixture after each test, added selects to test...

Improved test suite to reset fixture after each test, added selects to test ':selected'; Added docs for index(obj); Modified is(expr) to return false for an invalid expression, changed docs, too; Added lots of testcases; Changed filename of testfiles: adding leading zeros
parent 519b7d33
...@@ -24,15 +24,12 @@ ...@@ -24,15 +24,12 @@
</p> </p>
<div id="foo"> <div id="foo">
<p id="sndp">Everything inside the red border is inside a div with <p id="sndp">Everything inside the red border is inside a div with <code>id="foo"</code>.</p>
<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 lang="en" id="en">This is a normal link: <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>
<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> </div>
<p id="first">Try them out: </p> <p id="first">Try them out:</p>
<ul id="firstUL"></ul> <ul id="firstUL"></ul>
<ol id="empty"></ol> <ol id="empty"></ol>
<form id="form"> <form id="form">
...@@ -46,6 +43,25 @@ ...@@ -46,6 +43,25 @@
<input type="hidden" name="hidden" id="hidden1"/> <input type="hidden" name="hidden" id="hidden1"/>
<input type="text" style="display:none;" id="hidden2"/> <input type="text" style="display:none;" id="hidden2"/>
<select name="select1" id="select1">
<option id="option1a" value="">Nothing</option>
<option id="option1b" value="1">1</option>
<option id="option1c" value="2">2</option>
<option id="option1d" value="3">3</option>
</select>
<select name="select1" id="select2">
<option id="option2a" value="">Nothing</option>
<option id="option2b" value="1">1</option>
<option id="option2c" value="2">2</option>
<option id="option2d" selected value="3">3</option>
</select>
<select name="select3" id="select3" multiple="multiple">
<option id="option3a" value="">Nothing</option>
<option id="option3b" selected="selected" value="1">1</option>
<option id="option3c" selected value="2">2</option>
<option id="option3d" value="3">3</option>
</select>
</form> </form>
</div> </div>
</dl> </dl>
......
var queue = [];
var blocking = false;
function reset() {
synchronize(function() {
blocking = true;
$.get('index.html', function(content) {
var div = $(document.createElement('div')).html(content)
// search for main div
.find('[@id=main]').html();
$('#main').html(div);
blocking = false;
process();
});
});
}
function synchronize(callback) {
queue[queue.length] = callback;
if(!blocking) {
process();
}
}
function process() {
while(queue.length && !blocking) {
var call = queue[0];
queue = queue.slice(1);
call();
}
}
function runTests(files) { function runTests(files) {
runTest( files, 0 ); var startTime = new Date();
for( var i=0; i < files.length; i++) {
runTest( files, i );
reset();
}
synchronize(function() {
var runTime = new Date() - startTime;
$('body').append('<br/>Tests completed in ' + runTime + ' milliseconds.');
});
} }
function runTest( files, num ) { function runTest( files, num ) {
synchronize(function() {
blocking = true;
$.get(files[num],function(js){ $.get(files[num],function(js){
js = js.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&"); js = js.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&");
try { try {
eval(js); eval(js);
} catch(e) { } catch(e) {
Test.push( [ false, "Died on test #" + Test.length + ": " + e ] ); Test.push( [ false, "Died on test #" + (Test.length+1) + ": " + e ] );
} }
var good = 0, bad = 0; var good = 0, bad = 0;
...@@ -47,7 +89,9 @@ function runTest( files, num ) { ...@@ -47,7 +89,9 @@ function runTest( files, num ) {
document.getElementById("tests").appendChild( li ); document.getElementById("tests").appendChild( li );
Test = []; Test = [];
if ( ++num < files.length ) runTest( files, num ); blocking = false;
process();
});
}); });
} }
......
...@@ -13,11 +13,12 @@ var count = 1; ...@@ -13,11 +13,12 @@ var count = 1;
for ( var i = 0; i < jq.length; i++ ) { for ( var i = 0; i < jq.length; i++ ) {
if ( jq[i].tests.length > 0 ) { if ( jq[i].tests.length > 0 ) {
var name = count + "-" + jq[i].name; var name = count + "-" + jq[i].name;
if(count < 100) {
var myFile = testFile name = "0" + name;
.replace( /{TITLE}/g, jq[i].name ) }
.replace( /{NUM}/g, jq[i].tests.length ) if(count < 10) {
.replace( /{TESTS}/g, jq[i].tests.join("\n") ); name = "0" + name;
}
var fileName = "tests/" + name + ".js"; var fileName = "tests/" + name + ".js";
......
This diff is collapsed.
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