Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

publish tests for browsers with lowkick

  • Loading branch information...
commit 8217e025ea688cf0d33a1f9d8248d0168d6ca769 1 parent ae75f6a
@azer authored
View
11 Makefile
@@ -1,11 +1,6 @@
-install:
- cp -rf ../functools ~/.node_modules/foo
+do=publish
-docs:
- cd man; \
- ronn functools.1.ron -r -5 --markdown
+test:
+ ./node_modules/lowkick/bin/lowkick $(do) test/config.json
.PHONY: test
-test:
- cd test; \
- node node.js
View
120 README.md
@@ -57,7 +57,7 @@ pickEvens([1,5,9,2,6,5]) // returns [2,6]
$ npm install functools
```
-or
+or
```bash
$ wget https://raw.github.com/azer/functools/master/lib/functools.js
@@ -135,48 +135,7 @@ args: 3,14,1,5,9
Call *function* once for element in *iterable*.
```javascript
-each(function(el,ind,list){ console.assert( el == list[ind] ); }, [3,1,4]);
-```
-
-## map(*function*,*iterable*)
-
-Invoke *function* once for each element of *iterable*. Creates a new iterable
-containing the values returned by the function.
-
-```javascript
-
-function square(n){
- return n*n;
-}
-
-map(square,[3,1,4,1,5,9]); // returns [9,1,16,1,25,81]
-```
-
-Objects can be passed as well;
-
-```javascript
-var dict = { 'en':'hello', 'tr': 'merhaba', 'fr':'bonjour' };
-
-function capitalize(){
- return string.charAt(0).toUpperCase() + string.slice(1);
-}
-
-map(capitalize, dict); // returns { 'en':'Hello', 'tr':'Merhaba', 'fr':'Bonjour' }
-```
-
-## map.async(*function*,*iterable*, *callback*)
-
-Apply async *function* to every item of *iterable*, receiving a callback
-function which takes error (if there is) and replacement parameters.
-
-```javascript
-function readFile(id, callback){ ... callback(undefined, data); }
-
-map.async(readFile, ['./foo/bar', './foo/qux', './corge'], function(error, files){
- if(error) throw error;
-
- console.log(files[0]); // will put the content of ./foo/bar
-});
+each([3,1,4], function(el,ind,list){ console.assert( el == list[ind] ); });
```
## filter(*function*,*iterable*)
@@ -184,7 +143,7 @@ map.async(readFile, ['./foo/bar', './foo/qux', './corge'], function(error, files
Construct a new array from those elements of *iterable* for which *function* returns true.
```javascript
-filter(function(el,ind,list){ return el%2==0 },[3,1,4]); // returns [4]
+filter([3,1,4], function(el,ind,list){ return el%2==0 }); // returns [4]
```
## filter.async(*function*,*iterable*, *callback*)
@@ -199,14 +158,12 @@ var users = [ 3, 5, 8, 13, 21 ]; // only user#3 and user#8 have permission in th
function hasPermission(userId, callback){ ... callback(/* true or false */); }
-filter.async(hasPermission, users, function(permittedUsers){
+filter.async(users, hasPermission, function(permittedUsers){
assert.equal(permittedUsers.length, 4);
});
```
-
-
## juxt(*functions ...*)
Take a set of functions, return a function that is the juxtaposition of those
@@ -237,13 +194,54 @@ juxt.async(turkish, french, polish)("hello", function(error, results){
});
```
+## map(*function*,*iterable*)
+
+Invoke *function* once for each element of *iterable*. Creates a new iterable
+containing the values returned by the function.
+
+```javascript
+
+function square(n){
+ return n*n;
+}
+
+map([3,1,4,1,5,9], square); // returns [9,1,16,1,25,81]
+```
+
+Objects can be passed as well;
+
+```javascript
+var dict = { 'en':'hello', 'tr': 'merhaba', 'fr':'bonjour' };
+
+function capitalize(){
+ return string.charAt(0).toUpperCase() + string.slice(1);
+}
+
+map(dict, capitalize); // returns { 'en':'Hello', 'tr':'Merhaba', 'fr':'Bonjour' }
+```
+
+## map.async(*function*,*iterable*, *callback*)
+
+Apply async *function* to every item of *iterable*, receiving a callback
+function which takes error (if there is) and replacement parameters.
+
+```javascript
+function readFile(id, callback){ ... callback(undefined, data); }
+
+map.async(['./foo/bar', './foo/qux', './corge'], readFile, function(error, files){
+ if(error) throw error;
+
+ console.log(files[0]); // will put the content of ./foo/bar
+});
+```
+
## reduce(*function*,*iterable*)
Apply *function* cumulatively to the items of *iterable*, as to reduce the
*iterable* to a single value
```javascript
-reduce(function(x,y){ return x*y }, [3,1,4]); // returns 12
+reduce([3,1,4], function(x,y){ return x*y }); // returns 12
```
## reduce.async(*function*,*iterable*, *callback*)
@@ -256,7 +254,7 @@ var users = [2, 3, 5, 8, 13];
function usernames(accum, userId){ ... callback(undefined, accum + ', ' + username); }
-reduce.async(usernames, users, function(error, result){
+reduce.async(users, usernames, function(error, result){
if(error) throw error;
console.log(result); // foo, bar, qux ...
@@ -264,5 +262,29 @@ reduce.async(usernames, users, function(error, result){
```
+# Testing
+
+## On NodeJS:
+
+```
+$ npm test
+```
+
+## On Browsers
+
+Run `make test` command to publish the tests on `localhost:1314`. Visit the URL using the browser on which you want to run the tests. Stop the server (Ctrl+C) when you're done with testing.
+
+To see the summary of results;
+
+```
+$ make test do=verify
+Not Tested: firefox, ie8, ie7
+Passed: ie6, webkit
+
+Revision: 1.3.0
+Results Source: test/results.json
+Config: test/config.json
+```
+
# SEE ALSO
- [Functional Programming - Eloquent JavaScript](http://eloquentjavascript.net/chapter6.html)
View
36 test/browser.js
@@ -0,0 +1,36 @@
+var module = {},
+ assert = {
+ 'equal': function(a, b){
+ if( a !== b ){
+ throw new Error('Assertion Error: '+ a +' != ' + b);
+ }
+ },
+ 'ok': function(value){
+ assert.equal(value, true);
+ }
+ };
+
+function run(){
+ lowkick.signal('begin');
+
+ var tests = Object.keys(module.exports);
+
+ (function iter(i){
+
+ if(i >= tests.length){
+ lowkick.signal('end');
+ lowkick.ok();
+ return;
+ }
+
+ var name = tests[i];
+
+ lowkick.message('Running "'+name+'"');
+
+ module.exports[name](iter.bind(undefined, i+1));
+
+ }(0));
+
+}
+
+$(document).ready(run);
View
27 test/config.json
@@ -0,0 +1,27 @@
+{
+ "name": "functools test server",
+ "target": "results.json",
+ "logs": "logs",
+
+ "environ": [
+ "ie6",
+ "ie7",
+ "ie8",
+ "firefox",
+ "webkit"
+ ],
+
+ "server": {
+ "host": "localhost",
+ "port": "1314"
+ },
+
+ "scripts":[
+ "ext/es5-shim.min.js",
+ "../lib/functools.js",
+ "browser.js",
+ "main.js"
+ ]
+
+
+}
View
16 test/ext/es5-shim.min.js
@@ -0,0 +1,16 @@
+(function(n){"function"==typeof define?define(n):n()})(function(){function n(a){try{return Object.defineProperty(a,"sentinel",{}),"sentinel"in a}catch(d){}}if(!Function.prototype.bind)Function.prototype.bind=function(a){var d=this;if("function"!=typeof d)throw new TypeError;var b=p.call(arguments,1),c=function(){if(this instanceof c){var e=function(){};e.prototype=d.prototype;var e=new e,g=d.apply(e,b.concat(p.call(arguments)));return null!==g&&Object(g)===g?g:e}return d.apply(a,b.concat(p.call(arguments)))};
+return c};var l=Function.prototype.call,f=Object.prototype,p=Array.prototype.slice,m=l.bind(f.toString),h=l.bind(f.hasOwnProperty),t,u,q,r,o;if(o=h(f,"__defineGetter__"))t=l.bind(f.__defineGetter__),u=l.bind(f.__defineSetter__),q=l.bind(f.__lookupGetter__),r=l.bind(f.__lookupSetter__);if(!Array.isArray)Array.isArray=function(a){return"[object Array]"==m(a)};if(!Array.prototype.forEach)Array.prototype.forEach=function(a,d){var b=i(this),c=0,e=b.length>>>0;if("[object Function]"!=m(a))throw new TypeError;
+for(;c<e;)c in b&&a.call(d,b[c],c,b),c++};if(!Array.prototype.map)Array.prototype.map=function(a,d){var b=i(this),c=b.length>>>0,e=Array(c);if("[object Function]"!=m(a))throw new TypeError;for(var g=0;g<c;g++)g in b&&(e[g]=a.call(d,b[g],g,b));return e};if(!Array.prototype.filter)Array.prototype.filter=function(a,d){var b=i(this),c=b.length>>>0,e=[];if("[object Function]"!=m(a))throw new TypeError;for(var g=0;g<c;g++)g in b&&a.call(d,b[g],g,b)&&e.push(b[g]);return e};if(!Array.prototype.every)Array.prototype.every=
+function(a,d){var b=i(this),c=b.length>>>0;if("[object Function]"!=m(a))throw new TypeError;for(var e=0;e<c;e++)if(e in b&&!a.call(d,b[e],e,b))return!1;return!0};if(!Array.prototype.some)Array.prototype.some=function(a,d){var b=i(this),c=b.length>>>0;if("[object Function]"!=m(a))throw new TypeError;for(var e=0;e<c;e++)if(e in b&&a.call(d,b[e],e,b))return!0;return!1};if(!Array.prototype.reduce)Array.prototype.reduce=function(a){var d=i(this),b=d.length>>>0;if("[object Function]"!=m(a))throw new TypeError;
+if(!b&&1==arguments.length)throw new TypeError;var c=0,e;if(2<=arguments.length)e=arguments[1];else{do{if(c in d){e=d[c++];break}if(++c>=b)throw new TypeError;}while(1)}for(;c<b;c++)c in d&&(e=a.call(void 0,e,d[c],c,d));return e};if(!Array.prototype.reduceRight)Array.prototype.reduceRight=function(a){var d=i(this),b=d.length>>>0;if("[object Function]"!=m(a))throw new TypeError;if(!b&&1==arguments.length)throw new TypeError;var c,b=b-1;if(2<=arguments.length)c=arguments[1];else{do{if(b in d){c=d[b--];
+break}if(0>--b)throw new TypeError;}while(1)}do b in this&&(c=a.call(void 0,c,d[b],b,d));while(b--);return c};if(!Array.prototype.indexOf)Array.prototype.indexOf=function(a){var d=i(this),b=d.length>>>0;if(!b)return-1;var c=0;1<arguments.length&&(c=v(arguments[1]));for(c=0<=c?c:Math.max(0,b+c);c<b;c++)if(c in d&&d[c]===a)return c;return-1};if(!Array.prototype.lastIndexOf)Array.prototype.lastIndexOf=function(a){var d=i(this),b=d.length>>>0;if(!b)return-1;var c=b-1;1<arguments.length&&(c=Math.min(c,
+v(arguments[1])));for(c=0<=c?c:b-Math.abs(c);0<=c;c--)if(c in d&&a===d[c])return c;return-1};if(!Object.getPrototypeOf)Object.getPrototypeOf=function(a){return a.__proto__||(a.constructor?a.constructor.prototype:f)};if(!Object.getOwnPropertyDescriptor)Object.getOwnPropertyDescriptor=function(a,d){if("object"!=typeof a&&"function"!=typeof a||null===a)throw new TypeError("Object.getOwnPropertyDescriptor called on a non-object: "+a);if(h(a,d)){var b,c,e;b={enumerable:!0,configurable:!0};if(o){var g=
+a.__proto__;a.__proto__=f;c=q(a,d);e=r(a,d);a.__proto__=g;if(c||e){if(c)b.get=c;if(e)b.set=e;return b}}b.value=a[d];return b}};if(!Object.getOwnPropertyNames)Object.getOwnPropertyNames=function(a){return Object.keys(a)};if(!Object.create)Object.create=function(a,d){var b;if(null===a)b={__proto__:null};else{if("object"!=typeof a)throw new TypeError("typeof prototype["+typeof a+"] != 'object'");b=function(){};b.prototype=a;b=new b;b.__proto__=a}void 0!==d&&Object.defineProperties(b,d);return b};if(Object.defineProperty){var l=
+n({}),y="undefined"==typeof document||n(document.createElement("div"));if(!l||!y)var s=Object.defineProperty}if(!Object.defineProperty||s)Object.defineProperty=function(a,d,b){if("object"!=typeof a&&"function"!=typeof a||null===a)throw new TypeError("Object.defineProperty called on non-object: "+a);if("object"!=typeof b&&"function"!=typeof b||null===b)throw new TypeError("Property description must be an object: "+b);if(s)try{return s.call(Object,a,d,b)}catch(c){}if(h(b,"value"))if(o&&(q(a,d)||r(a,
+d))){var e=a.__proto__;a.__proto__=f;delete a[d];a[d]=b.value;a.__proto__=e}else a[d]=b.value;else{if(!o)throw new TypeError("getters & setters can not be defined on this javascript engine");h(b,"get")&&t(a,d,b.get);h(b,"set")&&u(a,d,b.set)}return a};if(!Object.defineProperties)Object.defineProperties=function(a,d){for(var b in d)h(d,b)&&Object.defineProperty(a,b,d[b]);return a};if(!Object.seal)Object.seal=function(a){return a};if(!Object.freeze)Object.freeze=function(a){return a};try{Object.freeze(function(){})}catch(D){Object.freeze=
+function(a){return function(d){return"function"==typeof d?d:a(d)}}(Object.freeze)}if(!Object.preventExtensions)Object.preventExtensions=function(a){return a};if(!Object.isSealed)Object.isSealed=function(){return!1};if(!Object.isFrozen)Object.isFrozen=function(){return!1};if(!Object.isExtensible)Object.isExtensible=function(a){if(Object(a)!==a)throw new TypeError;for(var d="";h(a,d);)d+="?";a[d]=!0;var b=h(a,d);delete a[d];return b};if(!Object.keys){var w=!0,x="toString,toLocaleString,valueOf,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,constructor".split(","),
+z=x.length,j;for(j in{toString:null})w=!1;Object.keys=function(a){if("object"!=typeof a&&"function"!=typeof a||null===a)throw new TypeError("Object.keys called on a non-object");var d=[],b;for(b in a)h(a,b)&&d.push(b);if(w)for(b=0;b<z;b++){var c=x[b];h(a,c)&&d.push(c)}return d}}if(!Date.prototype.toISOString||-1===(new Date(-621987552E5)).toISOString().indexOf("-000001"))Date.prototype.toISOString=function(){var a,d,b,c;if(!isFinite(this))throw new RangeError;a=[this.getUTCMonth()+1,this.getUTCDate(),
+this.getUTCHours(),this.getUTCMinutes(),this.getUTCSeconds()];c=this.getUTCFullYear();c=(0>c?"-":9999<c?"+":"")+("00000"+Math.abs(c)).slice(0<=c&&9999>=c?-4:-6);for(d=a.length;d--;)b=a[d],10>b&&(a[d]="0"+b);return c+"-"+a.slice(0,2).join("-")+"T"+a.slice(2).join(":")+"."+("000"+this.getUTCMilliseconds()).slice(-3)+"Z"};if(!Date.now)Date.now=function(){return(new Date).getTime()};if(!Date.prototype.toJSON)Date.prototype.toJSON=function(){if("function"!=typeof this.toISOString)throw new TypeError;return this.toISOString()};
+if(!Date.parse||864E13!==Date.parse("+275760-09-13T00:00:00.000Z"))Date=function(a){var d=function g(b,d,c,f,h,i,j){var k=arguments.length;return this instanceof a?(k=1==k&&""+b===b?new a(g.parse(b)):7<=k?new a(b,d,c,f,h,i,j):6<=k?new a(b,d,c,f,h,i):5<=k?new a(b,d,c,f,h):4<=k?new a(b,d,c,f):3<=k?new a(b,d,c):2<=k?new a(b,d):1<=k?new a(b):new a,k.constructor=g,k):a.apply(this,arguments)},b=RegExp("^(\\d{4}|[+-]\\d{6})(?:-(\\d{2})(?:-(\\d{2})(?:T(\\d{2}):(\\d{2})(?::(\\d{2})(?:\\.(\\d{3}))?)?(?:Z|(?:([-+])(\\d{2}):(\\d{2})))?)?)?)?$"),
+c;for(c in a)d[c]=a[c];d.now=a.now;d.UTC=a.UTC;d.prototype=a.prototype;d.prototype.constructor=d;d.parse=function(d){var c=b.exec(d);if(c){c.shift();for(var f=1;7>f;f++)c[f]=+(c[f]||(3>f?1:0)),1==f&&c[f]--;var h=+c.pop(),i=+c.pop(),j=c.pop(),f=0;if(j){if(23<i||59<h)return NaN;f=6E4*(60*i+h)*("+"==j?-1:1)}h=+c[0];return 0<=h&&99>=h?(c[0]=h+400,a.UTC.apply(this,c)+f-126227808E5):a.UTC.apply(this,c)+f}return a.parse.apply(this,arguments)};return d}(Date);j="\t\n\u000b\u000c\r \u00a0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029\ufeff";
+if(!String.prototype.trim||j.trim()){j="["+j+"]";var A=RegExp("^"+j+j+"*"),B=RegExp(j+j+"*$");String.prototype.trim=function(){return(""+this).replace(A,"").replace(B,"")}}var v=function(a){a=+a;a!==a?a=0:0!==a&&a!==1/0&&a!==-(1/0)&&(a=(0<a||-1)*Math.floor(Math.abs(a)));return a},C="a"!="a"[0],i=function(a){if(null==a)throw new TypeError;return C&&"string"==typeof a&&a?a.split(""):Object(a)}});
View
46 test/main.js
@@ -1,20 +1,10 @@
var node = typeof process != 'undefined' && process.versions && process.versions.node != undefined;
if(node){
- assert = require('assert');
functools = require("../lib/functools");
-} else {
- module = {};
- assert = {
- 'equal': function(a, b){
- if( a !== b ){
- throw new Error('Assertion Error: '+ a +' != ' + b);
- }
- }
- };
+ assert = require('assert');
}
-
function cube(x){ return x*x*x; };
function sum(x){ return x+x; };
function div(x){ return x/2; };
@@ -98,13 +88,13 @@ function test_each(callback){
var range = [3,1,4,1,5,9],
serial = 0;
- assert.equal(functools.each(function(el,ind,seq){
+ assert.equal(functools.each(range, function(el,ind,seq){
assert.equal(seq,range);
assert.equal(ind,serial++);
assert.ok(ind<seq.length);
- },range),range);
+ }),range);
callback();
@@ -115,7 +105,7 @@ function test_filter(callback){
rangeClone = Array.prototype.slice.call(range),
serial = 0;
- var evensInRange = functools.filter(function(el,ind,seq){
+ var evensInRange = functools.filter(range, function(el,ind,seq){
assert.equal(range.length, rangeClone.length);
@@ -129,7 +119,7 @@ function test_filter(callback){
assert.equal(seq[ind],el);
return el%2==0;
- },range);
+ });
assert.equal(evensInRange.length, 1);
assert.equal(evensInRange[0], 4);
@@ -142,9 +132,9 @@ function test_filter_async(callback){
rangeClone = Array.prototype.slice.call(range),
serial = 0;
- functools.filter.async(function(el,callback){
+ functools.filter.async(range, function(el,callback){
callback(el%2==0);
- },range, function(evensInRange){
+ }, function(evensInRange){
assert.equal(evensInRange.length, 1);
assert.equal(evensInRange[0], 4);
@@ -176,7 +166,6 @@ function test_juxt(callback){
assert.equal(result.mul, 6);
callback();
-
}
function test_juxt_async(callback){
@@ -199,8 +188,6 @@ function test_juxt_async(callback){
assert.equal(result[1], unaltered+2);
assert.equal(result[2], unaltered+3);
- console.log(2);
-
functools.juxt.async(cubeAsync, sumAsync, divAsync, mulAsync)(2,function(error, result){
if(error){
@@ -213,6 +200,7 @@ function test_juxt_async(callback){
assert.equal(result[2], 1);
assert.equal(result[3], 6);
+
functools.juxt.async({ 'cube':cubeAsync, 'sum':sumAsync, 'div':divAsync, 'mul':mulAsync })(2,function(error, result){
if(error){
@@ -242,7 +230,7 @@ function test_map(callback){
var range = [3,1,4],
serial = 0;
- var seq = functools.map(function(el,ind,seq){
+ var seq = functools.map(range, function(el,ind,seq){
assert.equal(range.length,seq.length);
for(var i = ind-1, len=range.length; ++i < len; ){
@@ -253,7 +241,7 @@ function test_map(callback){
assert.equal(el,seq[ind]);
return el*el;
- },range);
+ });
assert.equal(range[0], 3);
assert.equal(range[1], 1);
@@ -265,10 +253,10 @@ function test_map(callback){
range = { 'a': 3, 'b': 1, 'c': 4 };
- seq = functools.map(function(el, key, self){
+ seq = functools.map(range, function(el, key, self){
assert.equal(el, range[key]);
return el * el;
- }, range);
+ });
assert.equal(range.a, 3);
assert.equal(range.b, 1);
@@ -286,9 +274,9 @@ function test_map_async(callback){
var range = [3,1,4];
- functools.map.async(function(el,callback){
+ functools.map.async(range, function(el,callback){
callback(undefined, el*el);
- },range,function(error, seq){
+ },function(error, seq){
if(error){
throw error;
@@ -304,7 +292,7 @@ function test_map_async(callback){
range = { 'a': 3, 'b': 1, 'c': 4 };
- functools.map.async(function(el,callback){ callback(undefined, el*el); }, range, function(error, seq){
+ functools.map.async(range, function(el,callback){ callback(undefined, el*el); }, function(error, seq){
if(error){
throw error;
@@ -327,7 +315,7 @@ function test_map_async(callback){
};
function test_map_async_error(callback){
- functools.map.async(function(_,callback){ callback(new Error('foobar'),9); },[3,1,4],function(error, list){
+ functools.map.async([3,1,4],function(_,callback){ callback(new Error('foobar'),9); },function(error, list){
assert.equal(list[0], 9);
assert.equal(list[1], 1);
assert.equal(list[2], 4);
@@ -339,7 +327,7 @@ function test_map_async_error(callback){
function test_partial(callback){
- var sum = function(){
+ function sum(){
return functools.reduce(function(x,y){ return x+y },arguments);
};
View
18 test/results.json
@@ -0,0 +1,18 @@
+{
+ "environ": {
+ "navigator": true,
+ "modules": true,
+ "ie6": true,
+ "ie": true,
+ "dom": true,
+ "bind": true,
+ "v8": true,
+ "webkit": true,
+ "safari": true,
+ "gecko": true,
+ "chrome": true
+ },
+ "revision": "1.3.0",
+ "ok": true,
+ "serverTime": 1339206544529
+}
Please sign in to comment.
Something went wrong with that request. Please try again.