X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=build%2Ftest%2Ftest.js;h=e76b795a2ca541c4cff6a732c956ad6ae3fba548;hb=6f510757ab47b4377c8af954418d216afda37949;hp=453eb5db79744bf8c15ed741f7547d82949734f5;hpb=76ac10ed1f53d5166e18461e0d1bb98ceabe1e84;p=jquery.git diff --git a/build/test/test.js b/build/test/test.js index 453eb5d..e76b795 100644 --- a/build/test/test.js +++ b/build/test/test.js @@ -1,38 +1,41 @@ load( "build/js/writeFile.js", "build/js/parse.js" ); +function addParams(name, params) { + if(params.length > 0) { + name += "("; + for ( var i = 0; i < params.length; i++) { + name += params[i].type + ", "; + } + return name.substring(0, name.length - 2) + ")"; + } else { + return name + "()"; + } +} +function addTestWrapper(name, test) { + return 'test("' + name + '", function() {\n' + test + '\n});'; +} + var dir = arguments[1]; +var jq = parse( read(arguments[0]) ); -var indexFile = readFile( "build/test/index.html" ); -var testFile = readFile( "build/test/test.html" ); -var files = {}; +var testFile = []; -var jq = parse( readFile( arguments[0] ) ); +String.prototype.decode = function() { + return this.replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&"); +}; for ( var i = 0; i < jq.length; i++ ) { if ( jq[i].tests.length > 0 ) { - - var count = 1; - while ( files[ jq[i].name + count ] ) { count++; } - var name = jq[i].name + count; - - var myFile = testFile - .replace( /{TITLE}/g, jq[i].name ) - .replace( /{NUM}/g, jq[i].tests.length ) - .replace( /{TESTS}/g, jq[i].tests.join("\n") ); - - var fileName = "tests/" + name + ".js"; - - //writeFile( dir + "/" + fileName, myFile ); - writeFile( dir + "/" + fileName, jq[i].tests.join("\n") ); - - files[ fileName ] = 1; + var method = jq[i]; + var name = addParams(method.name, method.params); + for(var j = 0; j < method.tests.length; j++) { + if(j > 0) { + name += "x"; + } + testFile[testFile.length] = addTestWrapper(name, method.tests[j].decode()) + "\n"; + } } } -var fileString = ""; -for ( var i in files ) { - if ( fileString ) fileString += ", "; - fileString += "'" + i + "'"; -} - -writeFile( dir + "/index.html", indexFile.replace( /{FILES}/g, fileString ) ); +var indexFile = readFile( "build/test/index.html" ); +writeFile( dir + "/index.html", indexFile.replace( /{TESTS}/g, testFile.join("\n") ) );