Subversion Repositories Applications.papyrus

Compare Revisions

Ignore whitespace Rev 2149 → Rev 2150

/trunk/api/js/dojo1.0/dojox/lang/utils.js
New file
0,0 → 1,54
if(!dojo._hasResource["dojox.lang.utils"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.lang.utils"] = true;
dojo.provide("dojox.lang.utils");
 
(function(){
var empty = {}, du = dojox.lang.utils;
dojo.mixin(dojox.lang.utils, {
coerceType: function(target, source){
switch(typeof target){
case "number": return Number(eval("(" + source + ")"));
case "string": return String(source);
case "boolean": return Boolean(eval("(" + source + ")"));
}
return eval("(" + source + ")");
},
updateWithObject: function(target, source, conv){
// summary: updates an existing object in place with properties from an "source" object.
// target: Object: the "target" object to be updated
// source: Object: the "source" object, whose properties will be used to source the existed object.
// conv: Boolean?: force conversion to the original type
if(!source){ return target; }
for(var x in target){
if(x in source && !(x in empty)){
var t = target[x];
if(t && typeof t == "object"){
du.updateObject(t, source[x]);
}else{
target[x] = conv ? du.coerceType(t, source[x]) : dojo.clone(source[x]);
}
}
}
return target; // Object
},
updateWithPattern: function(target, source, pattern, conv){
// summary: updates an existing object in place with properties from an "source" object.
// target: Object: the "target" object to be updated
// source: Object: the "source" object, whose properties will be used to source the existed object.
// pattern: Array: an array of properties to be copied
// conv: Boolean?: force conversion to the original type
if(!source || !pattern){ return target; }
for(var x in pattern){
if(x in source && !(x in empty)){
target[x] = conv ? du.coerceType(pattern[x], source[x]) : dojo.clone(source[x]);
}
}
return target; // Object
}
});
})();
 
}
/trunk/api/js/dojo1.0/dojox/lang/README
New file
0,0 → 1,37
-------------------------------------------------------------------------------
dojox.lang
-------------------------------------------------------------------------------
Version 0.990
Release date: 07/30/2007
-------------------------------------------------------------------------------
Project state:
[beta]
-------------------------------------------------------------------------------
Credits
Eugene Lazutkin (eugene.lazutkin@gmail.com)
-------------------------------------------------------------------------------
Project description
 
Implementation of common functional operations, and provisions.
Later we can add other JS language-related helpers.
-------------------------------------------------------------------------------
Dependencies:
 
None.
-------------------------------------------------------------------------------
Documentation
 
-------------------------------------------------------------------------------
Installation instructions
 
Grab the following from the Dojo SVN Repository:
http://svn.dojotoolkit.org/var/src/dojo/dojox/trunk/lang/*
 
Install into the following directory structure:
/dojox/lang/
 
...which should be at the same level as your Dojo checkout.
-------------------------------------------------------------------------------
Additional Notes
 
See tests and the source for more details.
/trunk/api/js/dojo1.0/dojox/lang/functional.js
New file
0,0 → 1,462
if(!dojo._hasResource["dojox.lang.functional"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.lang.functional"] = true;
dojo.provide("dojox.lang.functional");
 
// This module adds high-level functions and related constructs:
// - list comprehensions similar to JavaScript 1.7
// - anonymous functions built from the string
// - zip combiners
// - "reduce" family of functions
// - currying and partial functions
// - argument pre-processing: mixer and flip
// - miscellaneous useful functions
 
// Acknoledgements:
// - parts of this module (most notably lambda, constFun, invoke, pluck, and partial)
// are based on work by Oliver Steele (http://osteele.com/sources/javascript/functional/functional.js)
// which was published under MIT License
// - Simple "maybe" monad was donated by Alex Russell.
 
// Notes:
// - Dojo provides following high-level functions in dojo/_base/array.js:
// forEach, map, filter, every, some
// - These functions implemented with optional lambda expression as a parameter.
// - missing high-level functions are provided with the compatible API:
// foldl, foldl1, scanl, scanl1, foldr, foldr1, scanr, scanr1,
// reduce, reduceRight
// - lambda() and listcomp() produce functions, which after the compilation step are
// as fast as regular JS functions (at least theoretically).
 
(function(){
var d = dojo, df = dojox.lang.functional, g_re = /\bfor\b|\bif\b/gm, empty = {};
// split() is augmented on IE6 to ensure the uniform behavior
var split = "ab".split(/a*/).length > 1 ? String.prototype.split :
function(sep){
var r = this.split.call(this, sep),
m = sep.exec(this);
if(m && m.index == 0){ r.unshift(""); }
return r;
};
var lambda = function(/*String*/ s){
var args = [], sects = split.call(s, /\s*->\s*/m);
if(sects.length > 1){
while(sects.length){
s = sects.pop();
args = sects.pop().split(/\s*,\s*|\s+/m);
if(sects.length){ sects.push("(function(" + args + "){return (" + s + ")})"); }
}
} else if(s.match(/\b_\b/)) {
args = ["_"];
} else {
var l = s.match(/^\s*(?:[+*\/%&|\^\.=<>]|!=)/m),
r = s.match(/[+\-*\/%&|\^\.=<>!]\s*$/m);
if(l || r){
if(l){
args.push("$1");
s = "$1" + s;
}
if(r){
args.push("$2");
s = s + "$2";
}
} else {
var vars = s.
replace(/(?:\b[A-Z]|\.[a-zA-Z_$])[a-zA-Z_$\d]*|[a-zA-Z_$][a-zA-Z_$\d]*:|this|true|false|null|undefined|typeof|instanceof|in|delete|new|void|arguments|decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|escape|eval|isFinite|isNaN|parseFloat|parseInt|unescape|dojo|dijit|dojox|'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"/g, "").
match(/([a-z_$][a-z_$\d]*)/gi) || [];
var t = {};
d.forEach(vars, function(v){
if(!(v in t)){
args.push(v);
t[v] = 1;
}
});
}
}
return {args: args, body: "return (" + s + ");"}; // Object
};
var listcomp = function(/*String*/ s){
var frag = s.split(g_re), act = s.match(g_re),
head = ["var r = [];"], tail = [];
for(var i = 0; i < act.length;){
var a = act[i], f = frag[++i];
if(a == "for" && !/^\s*\(\s*(;|var)/.test(f)){
f = f.replace(/^\s*\(/, "(var ");
}
head.push(a, f, "{");
tail.push("}");
}
return head.join("") + "r.push(" + frag[0] + ");" + tail.join("") + "return r;"; // String
};
var currying = function(/*Object*/ info){
return function(){ // Function
if(arguments.length + info.args.length < info.arity){
return currying({func: info.func, arity: info.arity,
args: Array.prototype.concat.apply(info.args, arguments)});
}
return info.func.apply(this, Array.prototype.concat.apply(info.args, arguments));
};
};
var identity = function(x){ return x; };
var compose = function(/*Array*/ a){
return a.length ? function(){
var i = a.length - 1, x = df.lambda(a[i]).apply(this, arguments);
for(--i; i >= 0; --i){ x = df.lambda(a[i]).call(this, x); }
return x;
} : identity;
};
d.mixin(df, {
// lambda
buildLambda: function(/*String*/ s){
// summary: builds a function from a snippet, returns a string,
// which represents the function.
// description: This method returns a textual representation of a function
// built from the snippet. It is meant to be evaled in the proper context,
// so local variables can be pulled from the environment.
s = lambda(s);
return "function(" + s.args.join(",") + "){" + s.body + "}"; // String
},
lambda: function(/*Function|String|Array*/ s){
// summary: builds a function from a snippet, or array (composing), returns
// a function object; functions are passed through unmodified.
// description: This method is used to normalize a functional representation
// (a text snippet, an array, or a function) to a function object.
if(typeof s == "function"){ return s; }
if(s instanceof Array){ return compose(s); }
s = lambda(s);
return new Function(s.args, s.body); // Function
},
// sequence generators
repeat: function(/*Number*/ n, /*Function|String|Array*/ f, /*Object*/ z, /*Object?*/ o){
// summary: builds an array by repeatedly applying a unary function N times
// with a seed value Z.
o = o || d.global; f = df.lambda(f);
var t = new Array(n);
t[0] = z;
for(var i = 1; i < n; t[i] = z = f.call(o, z), ++i);
return t; // Array
},
until: function(/*Function|String|Array*/ pr, /*Function|String|Array*/ f, /*Object*/ z, /*Object?*/ o){
// summary: builds an array by repeatedly applying a unary function with
// a seed value Z until the predicate is satisfied.
o = o || d.global; f = df.lambda(f); pr = df.lambda(pr);
var t = [];
for(; !pr.call(o, z); t.push(z), z = f.call(o, z));
return t; // Array
},
buildListcomp: function(/*String*/ s){
// summary: builds a function from a text snippet, which represents a valid
// JS 1.7 list comprehension, returns a string, which represents the function.
// description: This method returns a textual representation of a function
// built from the list comprehension text snippet (conformant to JS 1.7).
// It is meant to be evaled in the proper context, so local variable can be
// pulled from the environment.
return "function(){" + listcomp(s) + "}"; // String
},
compileListcomp: function(/*String*/ s){
// summary: builds a function from a text snippet, which represents a valid
// JS 1.7 list comprehension, returns a function object.
// description: This method returns a function built from the list
// comprehension text snippet (conformant to JS 1.7). It is meant to be
// reused several times.
return new Function([], listcomp(s)); // Function
},
listcomp: function(/*String*/ s){
// summary: executes the list comprehension building an array.
return (new Function([], listcomp(s)))(); // Array
},
// classic reduce-class functions
foldl: function(/*Array*/ a, /*Function*/ f, /*Object*/ z, /*Object?*/ o){
// summary: repeatedly applies a binary function to an array from left
// to right using a seed value as a starting point; returns the final
// value.
a = typeof a == "string" ? a.split("") : a; o = o || d.global; f = df.lambda(f);
for(var i = 0; i < a.length; z = f.call(o, z, a[i], i, a), ++i);
return z; // Object
},
foldl1: function(/*Array*/ a, /*Function|String|Array*/ f, /*Object?*/ o){
// summary: repeatedly applies a binary function to an array from left
// to right; returns the final value.
a = typeof a == "string" ? a.split("") : a; o = o || d.global; f = df.lambda(f);
var z = a[0];
for(var i = 1; i < a.length; z = f.call(o, z, a[i], i, a), ++i);
return z; // Object
},
scanl: function(/*Array*/ a, /*Function|String|Array*/ f, /*Object*/ z, /*Object?*/ o){
// summary: repeatedly applies a binary function to an array from left
// to right using a seed value as a starting point; returns an array
// of values produced by foldl() at that point.
a = typeof a == "string" ? a.split("") : a; o = o || d.global; f = df.lambda(f);
var n = a.length, t = new Array(n + 1);
t[0] = z;
for(var i = 0; i < n; z = f.call(o, z, a[i], i, a), t[++i] = z);
return t; // Array
},
scanl1: function(/*Array*/ a, /*Function|String|Array*/ f, /*Object*/ z, /*Object?*/ o){
// summary: repeatedly applies a binary function to an array from left
// to right; returns an array of values produced by foldl1() at that
// point.
a = typeof a == "string" ? a.split("") : a; o = o || d.global; f = df.lambda(f);
var n = a.length, t = new Array(n), z = a[0];
t[0] = z;
for(var i = 1; i < n; z = f.call(o, z, a[i], i, a), t[i++] = z);
return t; // Array
},
foldr: function(/*Array*/ a, /*Function|String|Array*/ f, /*Object*/ z, /*Object?*/ o){
// summary: repeatedly applies a binary function to an array from right
// to left using a seed value as a starting point; returns the final
// value.
a = typeof a == "string" ? a.split("") : a; o = o || d.global; f = df.lambda(f);
for(var i = a.length; i > 0; --i, z = f.call(o, z, a[i], i, a));
return z; // Object
},
foldr1: function(/*Array*/ a, /*Function|String|Array*/ f, /*Object?*/ o){
// summary: repeatedly applies a binary function to an array from right
// to left; returns the final value.
a = typeof a == "string" ? a.split("") : a; o = o || d.global; f = df.lambda(f);
var n = a.length, z = a[n - 1];
for(var i = n - 1; i > 0; --i, z = f.call(o, z, a[i], i, a));
return z; // Object
},
scanr: function(/*Array*/ a, /*Function|String|Array*/ f, /*Object*/ z, /*Object?*/ o){
// summary: repeatedly applies a binary function to an array from right
// to left using a seed value as a starting point; returns an array
// of values produced by foldr() at that point.
a = typeof a == "string" ? a.split("") : a; o = o || d.global; f = df.lambda(f);
var n = a.length, t = new Array(n + 1);
t[n] = z;
for(var i = n; i > 0; --i, z = f.call(o, z, a[i], i, a), t[i] = z);
return t; // Array
},
scanr1: function(/*Array*/ a, /*Function|String|Array*/ f, /*Object*/ z, /*Object?*/ o){
// summary: repeatedly applies a binary function to an array from right
// to left; returns an array of values produced by foldr1() at that
// point.
a = typeof a == "string" ? a.split("") : a; o = o || d.global; f = df.lambda(f);
var n = a.length, t = new Array(n), z = a[n - 1];
t[n - 1] = z;
for(var i = n - 1; i > 0; --i, z = f.call(o, z, a[i], i, a), t[i] = z);
return t; // Array
},
// JS 1.6 standard array functions, which can take a lambda as a parameter.
// Consider using dojo._base.array functions, if you don't need the lambda support.
filter: function(/*Array*/ a, /*Function|String|Array*/ f, /*Object?*/ o){
// summary: creates a new array with all elements that pass the test
// implemented by the provided function.
a = typeof a == "string" ? a.split("") : a; o = o || d.global; f = df.lambda(f);
var n = a.length, t = [], v;
for(var i = 0; i < n; ++i){
v = a[i];
if(f.call(o, v, i, a)){ t.push(v); }
}
return t; // Array
},
forEach: function(/*Array*/ a, /*Function|String|Array*/ f, /*Object?*/ o){
// summary: executes a provided function once per array element.
a = typeof a == "string" ? a.split("") : a; o = o || d.global; f = df.lambda(f);
var n = a.length;
for(var i = 0; i < n; f.call(o, a[i], i, a), ++i);
},
map: function(/*Array*/ a, /*Function|String|Array*/ f, /*Object?*/ o){
// summary: creates a new array with the results of calling
// a provided function on every element in this array.
a = typeof a == "string" ? a.split("") : a; o = o || d.global; f = df.lambda(f);
var n = a.length, t = new Array(n);
for(var i = 0; i < n; t[i] = f.call(o, a[i], i, a), ++i);
return t; // Array
},
every: function(/*Array*/ a, /*Function|String|Array*/ f, /*Object?*/ o){
// summary: tests whether all elements in the array pass the test
// implemented by the provided function.
a = typeof a == "string" ? a.split("") : a; o = o || d.global; f = df.lambda(f);
var n = a.length;
for(var i = 0; i < n; ++i){
if(!f.call(o, a[i], i, a)){
return false; // Boolean
}
}
return true; // Boolean
},
some: function(/*Array*/ a, /*Function|String|Array*/ f, /*Object?*/ o){
// summary: tests whether some element in the array passes the test
// implemented by the provided function.
a = typeof a == "string" ? a.split("") : a; o = o || d.global; f = df.lambda(f);
var n = a.length;
for(var i = 0; i < n; ++i){
if(f.call(o, a[i], i, a)){
return true; // Boolean
}
}
return false; // Boolean
},
// JS 1.8 standard array functions, which can take a lambda as a parameter.
reduce: function(/*Array*/ a, /*Function*/ f, /*Object?*/ z){
// summary: apply a function simultaneously against two values of the array
// (from left-to-right) as to reduce it to a single value.
return arguments.length < 3 ? df.foldl1(a, f) : df.foldl(a, f, z); // Object
},
reduceRight: function(/*Array*/ a, /*Function*/ f, /*Object?*/ z){
// summary: apply a function simultaneously against two values of the array
// (from right-to-left) as to reduce it to a single value.
return arguments.length < 3 ? df.foldr1(a, f) : df.foldr(a, f, z); // Object
},
// currying and partial functions
curry: function(/*Function|String|Array*/ f, /*Number?*/ arity){
// summary: curries a function until the arity is satisfied, at
// which point it returns the calculated value.
f = df.lambda(f);
arity = typeof arity == "number" ? arity : f.length;
return currying({func: f, arity: arity, args: []}); // Function
},
arg: {}, // marker for missing arguments
partial: function(/*Function|String|Array*/ f){
// summary: creates a function where some arguments are bound, and
// some arguments (marked as dojox.lang.functional.arg) are will be
// accepted by the final function in the order they are encountered.
// description: This method is used to produce partially bound
// functions. If you want to change the order of arguments, use
// dojox.lang.functional.mixer() or dojox.lang.functional.flip().
var a = arguments, args = new Array(a.length - 1), p = [];
f = df.lambda(f);
for(var i = 1; i < a.length; ++i){
var t = a[i];
args[i - 1] = t;
if(t == df.arg){
p.push(i - 1);
}
}
return function(){ // Function
var t = Array.prototype.slice.call(args, 0); // clone the array
for(var i = 0; i < p.length; ++i){
t[p[i]] = arguments[i];
}
return f.apply(this, t);
};
},
// argument pre-processing
mixer: function(/*Function|String|Array*/ f, /*Array*/ mix){
// summary: changes the order of arguments using an array of
// numbers mix --- i-th argument comes from mix[i]-th place
// of supplied arguments.
f = df.lambda(f);
return function(){ // Function
var t = new Array(mix.length);
for(var i = 0; i < mix.length; ++i){
t[i] = arguments[mix[i]];
}
return f.apply(this, t);
};
},
flip: function(/*Function|String|Array*/ f){
// summary: changes the order of arguments by reversing their
// order.
f = df.lambda(f);
return function(){ // Function
// reverse arguments
var a = arguments, l = a.length - 1, t = new Array(l + 1), i;
for(i = 0; i <= l; ++i){
t[l - i] = a[i];
}
return f.apply(this, t);
};
},
// combiners
zip: function(){
// summary: returns an array of arrays, where the i-th array
// contains the i-th element from each of the argument arrays.
// description: This is the venerable zip combiner (for example,
// see Python documentation for general details). The returned
// array is truncated to match the length of the shortest input
// array.
var n = arguments[0].length, m = arguments.length, i;
for(i = 1; i < m; n = Math.min(n, arguments[i++].length));
var t = new Array(n), j;
for(i = 0; i < n; ++i){
var p = new Array(m);
for(j = 0; j < m; p[j] = arguments[j][i], ++j);
t[i] = p;
}
return t; // Array
},
unzip: function(/*Array*/ a){
// summary: similar to dojox.lang.functional.zip(), but takes
// a single array of arrays as the input.
// description: This function is similar to dojox.lang.functional.zip()
// and can be used to unzip objects packed by
// dojox.lang.functional.zip(). It is here mostly to provide
// a short-cut for the different method signature.
return df.zip.apply(null, a); // Array
},
// miscelaneous functional adapters
constFun: function(/*Object*/ x){
// summary: returns a function, which produces a constant value
// regardless of supplied parameters.
return function(){ return x; }; // Function
},
invoke: function(/*String*/ m){
// summary: returns a function, which invokes a method on supplied
// object using optional parameters.
return function(/*Object*/ o){ // Function
return o[m].apply(o, Array.prototype.slice.call(arguments, 1));
};
},
pluck: function(/*String*/ m){
// summary: returns a function, which returns a named object member.
return function(/*Object*/ o){ // Function
return o[m];
};
},
// object helpers
forIn: function(/*Object*/ obj, /*Function|String|Array*/ f, /*Object?*/ o){
// summary: iterates over all object members skipping members, which
// are present in the empty object (IE and/or 3rd-party libraries).
o = o || d.global; f = df.lambda(f);
for(var i in obj){
if(i in empty){ continue; }
f.call(o, obj[i], i, obj);
}
},
forEachReversed: function(/*Array*/ a, /*Function|String|Array*/ f, /*Object?*/ o){
// summary: executes a provided function once per array element.
a = typeof a == "string" ? a.split("") : a; o = o || d.global; f = df.lambda(f);
for(var i = a.length - 1; i >= 0; f.call(o, a[i], i, a), --i);
}
});
 
// monads
dojo.declare("dojox.lang.functional.MaybeMonad", null, {
constructor: function(/*Object*/ value){
// summary: constructs a monad optionally initializing all additional members
if(arguments.length){
this.value = value;
}
},
bind: function(/*dojox.lang.functional.Monad*/ monad, /*Function|String|Array*/ f, /*Object?*/ o){
// summary: this is the classic bind method, which applies a function to a monad,
// and returns a result as a monad; it is meant to be overwritten to incorporate
// side effects
if(!("value" in monad)){
return new this.constructor(); // dojox.lang.functional.MaybeMonad
}
// => possible side-effects go here
o = o || d.global; f = df.lambda(f);
return f.call(o, monad.value); // dojox.lang.functional.Monad
},
// class-specific methods
isNothing: function(){
// summary: check if there is no bound value.
return !("value" in this); // Boolean
}
});
df.MaybeMonad.returnMonad = function(/*Object*/ value){
// summary: puts a valye in the Maybe monad.
return new df.MaybeMonad(value); // dojox.lang.functional.MaybeMonad
};
df.MaybeMonad.zero = new df.MaybeMonad();
})();
 
}
/trunk/api/js/dojo1.0/dojox/lang/LICENSE
New file
0,0 → 1,21
The MIT License
 
Copyright (c) 2007 Oliver Steele
 
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
 
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
/trunk/api/js/dojo1.0/dojox/lang/tests/lambda.js
New file
0,0 → 1,22
if(!dojo._hasResource["dojox.lang.tests.lambda"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.lang.tests.lambda"] = true;
dojo.provide("dojox.lang.tests.lambda");
dojo.require("dojox.lang.functional");
 
(function(){
var df = dojox.lang.functional;
tests.register("dojox.lang.tests.lambda", [
function testLambda1(t){ t.assertEqual(df.repeat(3, "3*", 1), [1, 3, 9]); },
function testLambda2(t){ t.assertEqual(df.repeat(3, "*3", 1), [1, 3, 9]); },
function testLambda3(t){ t.assertEqual(df.repeat(3, "_*3", 1), [1, 3, 9]); },
function testLambda4(t){ t.assertEqual(df.repeat(3, "3*_", 1), [1, 3, 9]); },
function testLambda5(t){ t.assertEqual(df.repeat(3, "n->n*3", 1), [1, 3, 9]); },
function testLambda6(t){ t.assertEqual(df.repeat(3, "n*3", 1), [1, 3, 9]); },
function testLambda7(t){ t.assertEqual(df.repeat(3, "3*m", 1), [1, 3, 9]); },
function testLambda8(t){ t.assertEqual(df.repeat(3, "->1", 1), [1, 1, 1]); },
function testLambda9(t){ t.assertEqual(df.repeat(3, function(n){ return n * 3; }, 1), [1, 3, 9]); },
function testLambda10(t){ t.assertEqual(df.repeat(3, ["_-1", ["*3"]], 1), [1, 2, 5]); }
]);
})();
 
}
/trunk/api/js/dojo1.0/dojox/lang/tests/curry.js
New file
0,0 → 1,30
if(!dojo._hasResource["dojox.lang.tests.curry"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.lang.tests.curry"] = true;
dojo.provide("dojox.lang.tests.curry");
dojo.require("dojox.lang.functional");
 
(function(){
var df = dojox.lang.functional, add5 = df.curry("+")(5), sub3 = df.curry("_-3"), fun = df.lambda("100*a + 10*b + c");
tests.register("dojox.lang.tests.curry", [
function testCurry1(t){ t.assertEqual(df.curry("+")(1, 2), 3); },
function testCurry2(t){ t.assertEqual(df.curry("+")(1)(2), 3); },
function testCurry3(t){ t.assertEqual(df.curry("+")(1, 2, 3), 3); },
function testCurry4(t){ t.assertEqual(add5(1), 6); },
function testCurry5(t){ t.assertEqual(add5(3), 8); },
function testCurry6(t){ t.assertEqual(add5(5), 10); },
function testCurry7(t){ t.assertEqual(sub3(1), -2); },
function testCurry8(t){ t.assertEqual(sub3(3), 0); },
function testCurry9(t){ t.assertEqual(sub3(5), 2); },
function testPartial1(t){ t.assertEqual(df.partial(fun, 1, 2, 3)(), 123); },
function testPartial2(t){ t.assertEqual(df.partial(fun, 1, 2, df.arg)(3), 123); },
function testPartial3(t){ t.assertEqual(df.partial(fun, 1, df.arg, 3)(2), 123); },
function testPartial4(t){ t.assertEqual(df.partial(fun, 1, df.arg, df.arg)(2, 3), 123); },
function testPartial5(t){ t.assertEqual(df.partial(fun, df.arg, 2, 3)(1), 123); },
function testPartial6(t){ t.assertEqual(df.partial(fun, df.arg, 2, df.arg)(1, 3), 123); },
function testPartial7(t){ t.assertEqual(df.partial(fun, df.arg, df.arg, 3)(1, 2), 123); },
function testPartial8(t){ t.assertEqual(df.partial(fun, df.arg, df.arg, df.arg)(1, 2, 3), 123); }
]);
})();
 
}
/trunk/api/js/dojo1.0/dojox/lang/tests/fold.js
New file
0,0 → 1,33
if(!dojo._hasResource["dojox.lang.tests.fold"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.lang.tests.fold"] = true;
dojo.provide("dojox.lang.tests.fold");
dojo.require("dojox.lang.functional");
 
(function(){
var df = dojox.lang.functional, a = df.arg;
tests.register("dojox.lang.tests.fold", [
function testFoldl1(t){ t.assertEqual(df.foldl([1, 2, 3], "+", 0), 6); },
function testFoldl2(t){ t.assertEqual(df.foldl1([1, 2, 3], "*"), 6); },
function testFoldl3(t){ t.assertEqual(df.foldl1([1, 2, 3], "/"), 1/6); },
function testFoldl4(t){ t.assertEqual(df.foldl1([1, 2, 3], df.partial(Math.max, a, a)), 3); },
function testFoldl5(t){ t.assertEqual(df.foldl1([1, 2, 3], df.partial(Math.min, a, a)), 1); },
function testFoldr1(t){ t.assertEqual(df.foldr([1, 2, 3], "+", 0), 6); },
function testFoldr2(t){ t.assertEqual(df.foldr1([1, 2, 3], "*"), 6); },
function testFoldr3(t){ t.assertEqual(df.foldr1([1, 2, 3], "/"), 3/2); },
function testFoldr4(t){ t.assertEqual(df.foldr1([1, 2, 3], df.partial(Math.max, a, a)), 3); },
function testFoldr5(t){ t.assertEqual(df.foldr1([1, 2, 3], df.partial(Math.min, a, a)), 1); },
function testScanl1(t){ t.assertEqual(df.scanl([1, 2, 3], "+", 0), [0, 1, 3, 6]); },
function testScanl2(t){ t.assertEqual(df.scanl1([1, 2, 3], "*"), [1, 2, 6]); },
function testScanl3(t){ t.assertEqual(df.scanl1([1, 2, 3], df.partial(Math.max, a, a)), [1, 2, 3]); },
function testScanl4(t){ t.assertEqual(df.scanl1([1, 2, 3], df.partial(Math.min, a, a)), [1, 1, 1]); },
function testScanr1(t){ t.assertEqual(df.scanr([1, 2, 3], "+", 0), [6, 5, 3, 0]); },
function testScanr2(t){ t.assertEqual(df.scanr1([1, 2, 3], "*"), [6, 6, 3]); },
function testScanr3(t){ t.assertEqual(df.scanr1([1, 2, 3], df.partial(Math.max, a, a)), [3, 3, 3]); },
function testScanr4(t){ t.assertEqual(df.scanr1([1, 2, 3], df.partial(Math.min, a, a)), [1, 2, 3]); }
]);
})();
 
}
/trunk/api/js/dojo1.0/dojox/lang/tests/main.js
New file
0,0 → 1,16
if(!dojo._hasResource["dojox.lang.tests.test_fun"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.lang.tests.test_fun"] = true;
dojo.provide("dojox.lang.tests.test_fun");
 
try{
dojo.require("dojox.lang.tests.listcomp");
dojo.require("dojox.lang.tests.lambda");
dojo.require("dojox.lang.tests.fold");
dojo.require("dojox.lang.tests.curry");
dojo.require("dojox.lang.tests.misc");
dojo.require("dojox.lang.tests.std");
}catch(e){
doh.debug(e);
}
 
}
/trunk/api/js/dojo1.0/dojox/lang/tests/listcomp.js
New file
0,0 → 1,26
if(!dojo._hasResource["dojox.lang.tests.listcomp"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.lang.tests.listcomp"] = true;
dojo.provide("dojox.lang.tests.listcomp");
dojo.require("dojox.lang.functional");
 
(function(){
var df = dojox.lang.functional;
tests.register("dojox.lang.tests.listcomp", [
function testIterator1(t){ t.assertEqual(df.repeat(3, function(n){ return n + 1; }, 0), [0, 1, 2]); },
function testIterator2(t){ t.assertEqual(df.repeat(3, function(n){ return n * 3; }, 1), [1, 3, 9]); },
function testIterator3(t){ t.assertEqual(df.until(function(n){ return n > 10; }, function(n){ return n * 3; }, 1), [1, 3, 9]); },
function testListcomp1(t){ t.assertEqual(df.listcomp("i for(var i=0; i<3; ++i)"), [0, 1, 2]); },
function testListcomp2(t){ t.assertEqual(df.listcomp("i*j for(var i=0; i<3; ++i) for(var j=0; j<3; ++j)"), [0, 0, 0, 0, 1, 2, 0, 2, 4]); },
function testListcomp3(t){ t.assertEqual(df.listcomp("i*j for(var i=0; i<3; ++i) if(i%2==1) for(var j=0; j<3; ++j)"), [0, 1, 2]); },
function testListcomp4(t){ t.assertEqual(df.listcomp("i+j for(var i=0; i<3; ++i) for(var j=0; j<3; ++j)"), [0, 1, 2, 1, 2, 3, 2, 3, 4]); },
function testListcomp5(t){ t.assertEqual(df.listcomp("i+j for(var i=0; i<3; ++i) if(i%2==1) for(var j=0; j<3; ++j)"), [1, 2, 3]); },
function testListcomp6(t){ t.assertEqual(df.listcomp("i for(i=0; i<3; ++i)"), [0, 1, 2]); },
function testListcomp7(t){ t.assertEqual(df.listcomp("i*j for(i=0; i<3; ++i) for(j=0; j<3; ++j)"), [0, 0, 0, 0, 1, 2, 0, 2, 4]); },
function testListcomp8(t){ t.assertEqual(df.listcomp("i*j for(i=0; i<3; ++i) if(i%2==1) for(j=0; j<3; ++j)"), [0, 1, 2]); },
function testListcomp9(t){ t.assertEqual(df.listcomp("i+j for(i=0; i<3; ++i) for(j=0; j<3; ++j)"), [0, 1, 2, 1, 2, 3, 2, 3, 4]); },
function testListcomp10(t){ t.assertEqual(df.listcomp("i+j for(i=0; i<3; ++i) if(i%2==1) for(j=0; j<3; ++j)"), [1, 2, 3]); }
]);
})();
 
}
/trunk/api/js/dojo1.0/dojox/lang/tests/std.js
New file
0,0 → 1,31
if(!dojo._hasResource["dojox.lang.tests.std"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.lang.tests.std"] = true;
dojo.provide("dojox.lang.tests.std");
dojo.require("dojox.lang.functional");
 
(function(){
var df = dojox.lang.functional, v, isOdd = "%2";
tests.register("dojox.lang.tests.std", [
function testFilter1(t){ t.assertEqual(df.filter([1, 2, 3], isOdd), [1, 3]); },
function testFilter2(t){ t.assertEqual(df.filter([1, 2, 3], "%2==0"), [2]); },
function testForEach(t){ t.assertEqual(
(v = [], df.forEach([1, 2, 3], function(x){ v.push(x); }), v), [1, 2, 3]); },
function testMap(t){ t.assertEqual(df.map([1, 2, 3], "+3"), [4, 5, 6]); },
function testEvery1(t){ t.assertFalse(df.every([1, 2, 3], isOdd)); },
function testEvery2(t){ t.assertTrue(df.every([1, 3, 5], isOdd)); },
 
function testSome1(t){ t.assertFalse(df.some([2, 4, 6], isOdd)); },
function testSome2(t){ t.assertTrue(df.some([1, 2, 3], isOdd)); },
 
function testReduce1(t){ t.assertEqual(df.reduce([4, 2, 1], "x-y"), 1); },
function testReduce2(t){ t.assertEqual(df.reduce([4, 2, 1], "x-y", 8), 1); },
function testReduceRight1(t){ t.assertEqual(df.reduceRight([4, 2, 1], "x-y"), -5); },
function testReduceRight2(t){ t.assertEqual(df.reduceRight([4, 2, 1], "x-y", 8), 1); }
]);
})();
 
}
/trunk/api/js/dojo1.0/dojox/lang/tests/misc.js
New file
0,0 → 1,36
if(!dojo._hasResource["dojox.lang.tests.misc"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.lang.tests.misc"] = true;
dojo.provide("dojox.lang.tests.misc");
dojo.require("dojox.lang.functional");
 
(function(){
var df = dojox.lang.functional, fun = df.lambda("100*a + 10*b + c"), result = [];
df.forIn({a: 1, b: 2}, function(v, i){ result.push("[" + i + "] = " + v); });
tests.register("dojox.lang.tests.misc", [
function testZip1(t){ t.assertEqual(df.zip([1, 2, 3], [4, 5, 6]), [[1, 4], [2, 5], [3, 6]]); },
function testZip2(t){ t.assertEqual(df.zip([1, 2], [3, 4], [5, 6]), [[1, 3, 5], [2, 4, 6]]); },
function testUnzip1(t){ t.assertEqual(df.unzip([[1, 4], [2, 5], [3, 6]]), [[1, 2, 3], [4, 5, 6]]); },
function testUnzip2(t){ t.assertEqual(df.unzip([[1, 3, 5], [2, 4, 6]]), [[1, 2], [3, 4], [5, 6]]); },
function testConst1(t){ t.assertEqual(df.constFun(5)(), 5); },
function testConst2(t){ t.assertEqual(df.constFun(8)(), 8); },
function testInvoke1(t){ t.assertEqual(df.invoke("max")(Math, 1, 2), 2); },
function testInvoke2(t){ t.assertEqual(df.invoke("min")(Math, 1, 2), 1); },
function testPluck1(t){ t.assertEqual(df.pluck("PI")(Math), Math.PI); },
function testPluck2(t){ t.assertEqual(df.pluck("E")(Math), Math.E); },
function testMixer(t){ t.assertEqual(df.mixer(fun, [1, 2, 0])(3, 1, 2), 123); },
function testFlip(t){ t.assertEqual(df.flip(fun)(3, 2, 1), 123); },
function testCompose1(t){ t.assertEqual(df.lambda(["+5", "*3"])(8), 8 * 3 + 5); },
function testCompose2(t){ t.assertEqual(df.lambda(["+5", "*3"].reverse())(8), (8 + 5) * 3); },
function testForIn(t){ t.assertEqual(result.sort().join(", "), "[a] = 1, [b] = 2"); }
]);
})();
 
}
/trunk/api/js/dojo1.0/dojox/lang/tests/fun_perf.html
New file
0,0 → 1,61
<html>
<head>
<title>clocking fun</title>
<style type="text/css">
@import "../resources/dojo.css";
</style>
<script type="text/javascript" src="../../../dojo/dojo.js" djConfig="isDebug:true"></script>
<script type="text/javascript" src="../functional.js"></script>
<script type="text/javascript">
dojo.addOnLoad(function(){
var LEN = 1000, ITER = 100, SUM = (LEN - 1) * LEN / 2;
var foldl_1 = function(/*Array*/ a, /*Function*/ f, /*Object*/ z){
for(var i = 0; i < a.length; z = f.call(dojo.global, z, a[i++]));
return z;
};
var foldl_2 = function(/*Array*/ a, /*Function*/ f, /*Object*/ z){
dojo.forEach(a, function(x){ z = f.call(dojo.global, z, x); });
return z;
};
var foldl_3 = function(/*Array*/ a, /*Function*/ f, /*Object*/ z){
a.forEach(function(x){ z = f.call(dojo.global, z, x); });
return z;
};
var sample = dojox.lang.functional.repeat(LEN, function(x){ return x + 1; }, 0);
console.profile("dojox.lang.functional.foldl");
for(var i = 0; i < ITER; ++i){
var t = dojox.lang.functional.foldl(sample, function(a, b){ return a + b; }, 0);
console.assert(t == SUM);
}
console.profileEnd("dojox.lang.functional.foldl");
console.profile("dojox.lang.functional.reduce");
for(var i = 0; i < ITER; ++i){
var t = dojox.lang.functional.reduce(sample, function(a, b){ return a + b; });
console.assert(t == SUM);
}
console.profileEnd("dojox.lang.functional.reduce");
console.profile("raw loop");
for(var i = 0; i < ITER; ++i){
var t = foldl_1(sample, function(a, b){ return a + b; }, 0);
console.assert(t == SUM);
}
console.profileEnd("raw loop");
console.profile("dojo.forEach");
for(var i = 0; i < ITER; ++i){
var t = foldl_2(sample, function(a, b){ return a + b; }, 0);
console.assert(t == SUM);
}
console.profileEnd("dojo.forEach");
console.profile("Array.forEach");
for(var i = 0; i < ITER; ++i){
var t = foldl_3(sample, function(a, b){ return a + b; }, 0);
console.assert(t == SUM);
}
console.profileEnd("Array.forEach");
});
</script>
</head>
<body>
<p>This test is meant to run on Firefox with Firebug installed.</p>
</body>
</html>
/trunk/api/js/dojo1.0/dojox/lang/tests/runTests.html
New file
0,0 → 1,9
<html>
<head>
<title>DojoX Functional Unit Test Runner</title>
<meta http-equiv="REFRESH" content="0;url=../../../util/doh/runner.html?testModule=dojox.lang.tests.main" />
</head>
<body>
<p>Redirecting to D.O.H runner.</p>
</body>
</html>