Mercurial > js4py
diff core-javascript/core-javascript-work/tutorial.js @ 139:de308579ea0d core-javascript
From tutorial.js remove duplicate testools.js code.
| author | Jonathan Fine <jfine@pytex.org> |
|---|---|
| date | Mon, 31 Oct 2011 20:09:50 +0000 |
| parents | 20d76c716c9d |
| children | abfb176c7346 |
line wrap: on
line diff
--- a/core-javascript/core-javascript-work/tutorial.js Mon Oct 31 19:58:29 2011 +0000 +++ b/core-javascript/core-javascript-work/tutorial.js Mon Oct 31 20:09:50 2011 +0000 @@ -1,20 +1,18 @@ -var telltail = 'global'; - -var TEST = function(title, code){ - print( 'Testing: ' + title ); - code(); -}; +// [Rhino] $ js -f testtools.js -f tutorial.js +// [JSDB] $ jsdb -load testtools.js -load tutorial.js -var assert = function(arg){ - if(!arg){ - ddt(); - } -}; +// start warm-up +TEST('warm-up', function() +{ + assert( '0' == 0 ); + assert ( 0 == '' ); + assert( '0' != '' ); -'0' == 0 || ddt; -0 == '' || ddt; -'0' != '' || ddt; -NaN != NaN || ddt; + var a = NaN; + assert( a != a ); + +}); +// end warm-up // start closures @@ -28,13 +26,13 @@ return value; }; var set = function(new_value){ - value = new_value; + value = new_value; }; return { get: get, set: set - }; + }; }; // Create and unpack two get-set pairs. @@ -70,14 +68,14 @@ var default_this = return_this(); assert( default_this.telltail === 'global' ); - + var obj = {}; obj.return_this = return_this; assert( obj.return_this === return_this ); - + assert( obj.return_this() === obj ); assert( obj['return_this']() === obj ); - + assert( return_this.call(obj) === obj ); assert( return_this.apply(obj) === obj ); @@ -121,7 +119,7 @@ assert( typeof array === 'object' ); assert( '' + obj === '[object Object]' ); - + assert( obj.toString() === '[object Object]' ); var object_toString = obj.toString; @@ -139,17 +137,17 @@ var return_arguments = function(){ return arguments; }; - + var my_arguments = return_arguments(0, 1); - + assert( my_arguments.length === 2 ); - + assert( my_arguments[0] === 0 ); assert( my_arguments[1] === 1 ); - + assert( '' + my_arguments === '[object Object]' ); assert( '' + [0, 1] === '0,1' ); - + var array_slice = [].slice; var my_arguments_fixed = array_slice.call( my_arguments );
