зеркало из https://github.com/mozilla/pjs.git
Bug 427500 - Upgrade the copy of MochiKit used in Mochitest, to v1.4.2; (Dv2) Remove MochiKit r1174 tests.
r=ctalbert.
This commit is contained in:
Родитель
a1c21c98d2
Коммит
50b2d22dee
|
@ -1,40 +0,0 @@
|
|||
var JSAN = {
|
||||
global: this,
|
||||
use: function (module, symbols) {
|
||||
var components = module.split(/\./);
|
||||
var fn = components.join('/') + '.js';
|
||||
var o = JSAN.global;
|
||||
var i, c;
|
||||
for (i = 0; i < components.length; i++) {
|
||||
o = o[components[i]];
|
||||
if (typeof(o) == 'undefined') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (typeof(o) != 'undefined') {
|
||||
return o;
|
||||
}
|
||||
|
||||
load(fn);
|
||||
o = JSAN.global;
|
||||
for (i = 0; i < components.length; i++) {
|
||||
o = o[components[i]];
|
||||
if (typeof(o) == 'undefined') {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
if (!symbols) {
|
||||
var tags = o.EXPORT_TAGS;
|
||||
if (tags) {
|
||||
symbols = tags[':common'] || tags[':all'];
|
||||
}
|
||||
}
|
||||
if (symbols) {
|
||||
for (i = 0; i < symbols.length; i++) {
|
||||
c = symbols[i];
|
||||
JSAN.global[c] = o[c];
|
||||
}
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
|
@ -52,34 +52,11 @@ PARALLEL_DIRS = \
|
|||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
_TEST_FILES = test_MochiKit-Async.html \
|
||||
test_MochiKit-Base.html \
|
||||
test_MochiKit-DateTime.html \
|
||||
test_MochiKit-DOM.html \
|
||||
test_MochiKit-Style.html \
|
||||
test_MochiKit-Format.html \
|
||||
test_MochiKit-Iter.html \
|
||||
test_MochiKit-Logging.html \
|
||||
test_MochiKit-MochiKit.html \
|
||||
test_MochiKit-Color.html \
|
||||
test_MochiKit-Signal.html \
|
||||
test_Base.js \
|
||||
test_Color.js \
|
||||
test_DateTime.js \
|
||||
test_DragAndDrop.js \
|
||||
test_Format.js \
|
||||
test_Iter.js \
|
||||
test_Logging.js \
|
||||
test_Signal.js \
|
||||
cli.js \
|
||||
FakeJSAN.js \
|
||||
standalone.js \
|
||||
test_MochiKit-Async.json \
|
||||
test_sanity.html \
|
||||
$(NULL)
|
||||
_TEST_FILES = \
|
||||
test_sanity.html \
|
||||
$(NULL)
|
||||
|
||||
# Copy the MochiKit tests into subdirectory, so the top level is all dirs
|
||||
# in the test screen. We leave them in tests/ in the src tree to mirror
|
||||
# the upstream MochiKit repository
|
||||
# Copy the sanity tests into a subdirectory, so the top level is all dirs
|
||||
# in the test screen.
|
||||
libs:: $(_TEST_FILES)
|
||||
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/$(relativesrcdir)/MochiKit_Unit_Tests
|
||||
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/$(relativesrcdir)/Harness_sanity
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
MochiKit = {__export__: true};
|
||||
load('tests/FakeJSAN.js')
|
||||
JSAN.use('MochiKit.MockDOM');
|
||||
var window = this;
|
||||
var document = MochiKit.MockDOM.document;
|
||||
JSAN.use('MochiKit.MochiKit');
|
|
@ -1,16 +0,0 @@
|
|||
load('tests/cli.js');
|
||||
|
||||
JSAN.use('MochiKit.Test');
|
||||
|
||||
print("[[ MochiKit.Base ]]");
|
||||
runTests('tests.test_Base');
|
||||
print("[[ MochiKit.Color ]]");
|
||||
runTests('tests.test_Color');
|
||||
print("[[ MochiKit.DateTime ]]");
|
||||
runTests('tests.test_DateTime');
|
||||
print("[[ MochiKit.Format ]]");
|
||||
runTests('tests.test_Format');
|
||||
print("[[ MochiKit.Iter ]]");
|
||||
runTests('tests.test_Iter');
|
||||
print("[[ MochiKit.Logging ]]");
|
||||
runTests('tests.test_Logging');
|
|
@ -1,500 +0,0 @@
|
|||
if (typeof(dojo) != 'undefined') { dojo.require('MochiKit.Base'); }
|
||||
if (typeof(JSAN) != 'undefined') { JSAN.use('MochiKit.Base'); }
|
||||
if (typeof(tests) == 'undefined') { tests = {}; }
|
||||
|
||||
tests.test_Base = function (t) {
|
||||
// test bind
|
||||
var not_self = {"toString": function () { return "not self"; } };
|
||||
var self = {"toString": function () { return "self"; } };
|
||||
var func = function (arg) { return this.toString() + " " + arg; };
|
||||
var boundFunc = bind(func, self);
|
||||
not_self.boundFunc = boundFunc;
|
||||
|
||||
t.is( isEmpty([], [], ""), true, "isEmpty true" )
|
||||
t.is( isEmpty([], [1], ""), true, "isEmpty true" )
|
||||
t.is( isNotEmpty([], [], ""), false, "isNotEmpty false" )
|
||||
t.is( isNotEmpty([], [1], ""), false, "isNotEmpty false" )
|
||||
|
||||
t.is( isEmpty([1], [1], "1"), false, "isEmpty false" )
|
||||
t.is( isEmpty([1], [1], "1"), false, "isEmpty false" )
|
||||
t.is( isNotEmpty([1], [1], "1"), true, "isNotEmpty true" )
|
||||
t.is( isNotEmpty([1], [1], "1"), true, "isNotEmpty true" )
|
||||
|
||||
t.is( boundFunc("foo"), "self foo", "boundFunc bound to self properly" );
|
||||
t.is( not_self.boundFunc("foo"), "self foo", "boundFunc bound to self on another obj" );
|
||||
t.is( bind(boundFunc, not_self)("foo"), "not self foo", "boundFunc successfully rebound!" );
|
||||
t.is( bind(boundFunc, undefined, "foo")(), "self foo", "boundFunc partial no self change" );
|
||||
t.is( bind(boundFunc, not_self, "foo")(), "not self foo", "boundFunc partial self change" );
|
||||
|
||||
// test method
|
||||
not_self = {"toString": function () { return "not self"; } };
|
||||
self = {"toString": function () { return "self"; } };
|
||||
func = function (arg) { return this.toString() + " " + arg; };
|
||||
var boundMethod = method(self, func);
|
||||
not_self.boundMethod = boundMethod;
|
||||
|
||||
t.is( boundMethod("foo"), "self foo", "boundMethod bound to self properly" );
|
||||
t.is( not_self.boundMethod("foo"), "self foo", "boundMethod bound to self on another obj" );
|
||||
t.is( method(not_self, boundMethod)("foo"), "not self foo", "boundMethod successfully rebound!" );
|
||||
t.is( method(undefined, boundMethod, "foo")(), "self foo", "boundMethod partial no self change" );
|
||||
t.is( method(not_self, boundMethod, "foo")(), "not self foo", "boundMethod partial self change" );
|
||||
|
||||
|
||||
|
||||
|
||||
// test bindMethods
|
||||
|
||||
var O = function (value) {
|
||||
bindMethods(this);
|
||||
this.value = value;
|
||||
};
|
||||
O.prototype.func = function () {
|
||||
return this.value;
|
||||
};
|
||||
|
||||
var o = new O("boring");
|
||||
var p = {};
|
||||
p.func = o.func;
|
||||
var func = o.func;
|
||||
t.is( o.func(), "boring", "bindMethods doesn't break shit" );
|
||||
t.is( p.func(), "boring", "bindMethods works on other objects" );
|
||||
t.is( func(), "boring", "bindMethods works on functions" );
|
||||
|
||||
var p = clone(o);
|
||||
t.ok( p instanceof O, "cloned correct inheritance" );
|
||||
var q = clone(p);
|
||||
t.ok( q instanceof O, "clone-cloned correct inheritance" );
|
||||
q.foo = "bar";
|
||||
t.is( p.foo, undefined, "clone-clone is copy-on-write" );
|
||||
p.bar = "foo";
|
||||
t.is( o.bar, undefined, "clone is copy-on-write" );
|
||||
t.is( q.bar, "foo", "clone-clone has proper delegation" );
|
||||
// unbind
|
||||
p.func = bind(p.func, null);
|
||||
t.is( p.func(), "boring", "clone function calls correct" );
|
||||
q.value = "awesome";
|
||||
t.is( q.func(), "awesome", "clone really does work" );
|
||||
|
||||
// test boring boolean funcs
|
||||
|
||||
t.is( isCallable(isCallable), true, "isCallable returns true on itself" );
|
||||
t.is( isCallable(1), false, "isCallable returns false on numbers" );
|
||||
|
||||
t.is( isUndefined(null), false, "null is not undefined" );
|
||||
t.is( isUndefined(""), false, "empty string is not undefined" );
|
||||
t.is( isUndefined(undefined), true, "undefined is undefined" );
|
||||
t.is( isUndefined({}.foo), true, "missing property is undefined" );
|
||||
|
||||
t.is( isUndefinedOrNull(null), true, "null is undefined or null" );
|
||||
t.is( isUndefinedOrNull(""), false, "empty string is not undefined or null" );
|
||||
t.is( isUndefinedOrNull(undefined), true, "undefined is undefined or null" );
|
||||
t.is( isUndefinedOrNull({}.foo), true, "missing property is undefined or null" );
|
||||
|
||||
// test extension of arrays
|
||||
var a = [];
|
||||
var b = [];
|
||||
var three = [1, 2, 3];
|
||||
|
||||
extend(a, three, 1);
|
||||
t.ok( objEqual(a, [2, 3]), "extend to an empty array" );
|
||||
extend(a, three, 1)
|
||||
t.ok( objEqual(a, [2, 3, 2, 3]), "extend to a non-empty array" );
|
||||
|
||||
extend(b, three);
|
||||
t.ok( objEqual(b, three), "extend of an empty array" );
|
||||
|
||||
t.is( compare(1, 2), -1, "numbers compare lt" );
|
||||
t.is( compare(2, 1), 1, "numbers compare gt" );
|
||||
t.is( compare(1, 1), 0, "numbers compare eq" );
|
||||
t.is( compare([1], [1]), 0, "arrays compare eq" );
|
||||
t.is( compare([1], [1, 2]), -1, "arrays compare lt (length)" );
|
||||
t.is( compare([1, 2], [2, 1]), -1, "arrays compare lt (contents)" );
|
||||
t.is( compare([1, 2], [1]), 1, "arrays compare gt (length)" );
|
||||
t.is( compare([2, 1], [1, 1]), 1, "arrays compare gt (contents)" );
|
||||
|
||||
// test partial application
|
||||
var a = [];
|
||||
var func = function (a, b) {
|
||||
if (arguments.length != 2) {
|
||||
return "bad args";
|
||||
} else {
|
||||
return this.value + a + b;
|
||||
}
|
||||
};
|
||||
var self = {"value": 1, "func": func};
|
||||
var self2 = {"value": 2};
|
||||
t.is( self.func(2, 3), 6, "setup for test is correct" );
|
||||
self.funcTwo = partial(self.func, 2);
|
||||
t.is( self.funcTwo(3), 6, "partial application works" );
|
||||
t.is( self.funcTwo(3), 6, "partial application works still" );
|
||||
t.is( bind(self.funcTwo, self2)(3), 7, "rebinding partial works" );
|
||||
self.funcTwo = bind(bind(self.funcTwo, self2), null);
|
||||
t.is( self.funcTwo(3), 6, "re-unbinding partial application works" );
|
||||
|
||||
|
||||
// nodeWalk test
|
||||
// ... looks a lot like a DOM tree on purpose
|
||||
var tree = {
|
||||
"id": "nodeWalkTestTree",
|
||||
"test:int": "1",
|
||||
"childNodes": [
|
||||
{
|
||||
"test:int": "2",
|
||||
"childNodes": [
|
||||
{"test:int": "5"},
|
||||
"ignored string",
|
||||
{"ignored": "object"},
|
||||
["ignored", "list"],
|
||||
{
|
||||
"test:skipchildren": "1",
|
||||
"childNodes": [{"test:int": 6}]
|
||||
}
|
||||
]
|
||||
},
|
||||
{"test:int": "3"},
|
||||
{"test:int": "4"}
|
||||
]
|
||||
}
|
||||
|
||||
var visitedNodes = [];
|
||||
nodeWalk(tree, function (node) {
|
||||
var attr = node["test:int"];
|
||||
if (attr) {
|
||||
visitedNodes.push(attr);
|
||||
}
|
||||
if (node["test:skipchildren"]) {
|
||||
return;
|
||||
}
|
||||
return node.childNodes;
|
||||
});
|
||||
|
||||
t.ok( objEqual(visitedNodes, ["1", "2", "3", "4", "5"]), "nodeWalk looks like it works");
|
||||
|
||||
// test map
|
||||
var minusOne = function (x) { return x - 1; };
|
||||
var res = map(minusOne, [1, 2, 3]);
|
||||
t.ok( objEqual(res, [0, 1, 2]), "map works" );
|
||||
|
||||
var res2 = xmap(minusOne, 1, 2, 3);
|
||||
t.ok( objEqual(res2, res), "xmap works" );
|
||||
|
||||
res = map(operator.add, [1, 2, 3], [2, 4, 6]);
|
||||
t.ok( objEqual(res, [3, 6, 9]), "map(fn, p, q) works" );
|
||||
|
||||
res = map(operator.add, [1, 2, 3], [2, 4, 6, 8]);
|
||||
t.ok( objEqual(res, [3, 6, 9]), "map(fn, p, q) works (q long)" );
|
||||
|
||||
res = map(operator.add, [1, 2, 3, 4], [2, 4, 6]);
|
||||
t.ok( objEqual(res, [3, 6, 9]), "map(fn, p, q) works (p long)" );
|
||||
|
||||
res = map(null, [1, 2, 3], [2, 4, 6]);
|
||||
t.ok( objEqual(res, [[1, 2], [2, 4], [3, 6]]), "map(null, p, q) works" );
|
||||
|
||||
res = zip([1, 2, 3], [2, 4, 6]);
|
||||
t.ok( objEqual(res, [[1, 2], [2, 4], [3, 6]]), "zip(p, q) works" );
|
||||
|
||||
res = map(null, [1, 2, 3]);
|
||||
t.ok( objEqual(res, [1, 2, 3]), "map(null, lst) works" );
|
||||
|
||||
|
||||
|
||||
|
||||
t.is( isNotEmpty("foo"), true, "3 char string is not empty" );
|
||||
t.is( isNotEmpty(""), false, "0 char string is empty" );
|
||||
t.is( isNotEmpty([1, 2, 3]), true, "3 element list is not empty" );
|
||||
t.is( isNotEmpty([]), false, "0 element list is empty" );
|
||||
|
||||
// test filter
|
||||
var greaterThanThis = function (x) { return x > this; };
|
||||
var greaterThanOne = function (x) { return x > 1; };
|
||||
var res = filter(greaterThanOne, [-1, 0, 1, 2, 3]);
|
||||
t.ok( objEqual(res, [2, 3]), "filter works" );
|
||||
var res = filter(greaterThanThis, [-1, 0, 1, 2, 3], 1);
|
||||
t.ok( objEqual(res, [2, 3]), "filter self works" );
|
||||
var res2 = xfilter(greaterThanOne, -1, 0, 1, 2, 3);
|
||||
t.ok( objEqual(res2, res), "xfilter works" );
|
||||
|
||||
t.is(objMax(1, 2, 9, 12, 42, -16, 16), 42, "objMax works (with numbers)");
|
||||
t.is(objMin(1, 2, 9, 12, 42, -16, 16), -16, "objMin works (with numbers)");
|
||||
|
||||
// test adapter registry
|
||||
|
||||
var R = new AdapterRegistry();
|
||||
R.register("callable", isCallable, function () { return "callable"; });
|
||||
R.register("arrayLike", isArrayLike, function () { return "arrayLike"; });
|
||||
t.is( R.match(function () {}), "callable", "registry found callable" );
|
||||
t.is( R.match([]), "arrayLike", "registry found ArrayLike" );
|
||||
try {
|
||||
R.match(null);
|
||||
t.ok( false, "non-matching didn't raise!" );
|
||||
} catch (e) {
|
||||
t.is( e, NotFound, "non-matching raised correctly" );
|
||||
}
|
||||
R.register("undefinedOrNull", isUndefinedOrNull, function () { return "undefinedOrNull" });
|
||||
R.register("undefined", isUndefined, function () { return "undefined" });
|
||||
t.is( R.match(undefined), "undefinedOrNull", "priorities are as documented" );
|
||||
t.ok( R.unregister("undefinedOrNull"), "removed adapter" );
|
||||
t.is( R.match(undefined), "undefined", "adapter was removed" );
|
||||
R.register("undefinedOrNull", isUndefinedOrNull, function () { return "undefinedOrNull" }, true);
|
||||
t.is( R.match(undefined), "undefinedOrNull", "override works" );
|
||||
|
||||
var a1 = {"a": 1, "b": 2, "c": 2};
|
||||
var a2 = {"a": 2, "b": 1, "c": 2};
|
||||
t.is( keyComparator("a")(a1, a2), -1, "keyComparator 1 lt" );
|
||||
t.is( keyComparator("c")(a1, a2), 0, "keyComparator 1 eq" );
|
||||
t.is( keyComparator("c", "b")(a1, a2), 1, "keyComparator 2 eq gt" );
|
||||
t.is( keyComparator("c", "a")(a1, a2), -1, "keyComparator 2 eq lt" );
|
||||
t.is( reverseKeyComparator("a")(a1, a2), 1, "reverseKeyComparator" );
|
||||
t.is( compare(concat([1], [2], [3]), [1, 2, 3]), 0, "concat" );
|
||||
t.is( repr("foo"), '"foo"', "string repr" );
|
||||
t.is( repr(1), '1', "number repr" );
|
||||
t.is( listMin([1, 3, 5, 3, -1]), -1, "listMin" );
|
||||
t.is( objMin(1, 3, 5, 3, -1), -1, "objMin" );
|
||||
t.is( listMax([1, 3, 5, 3, -1]), 5, "listMax" );
|
||||
t.is( objMax(1, 3, 5, 3, -1), 5, "objMax" );
|
||||
|
||||
var v = keys(a1);
|
||||
v.sort();
|
||||
t.is( compare(v, ["a", "b", "c"]), 0, "keys" );
|
||||
v = items(a1);
|
||||
v.sort();
|
||||
t.is( compare(v, [["a", 1], ["b", 2], ["c", 2]]), 0, "items" );
|
||||
|
||||
var StringMap = function() {};
|
||||
a = new StringMap();
|
||||
a.foo = "bar";
|
||||
b = new StringMap();
|
||||
b.foo = "bar";
|
||||
try {
|
||||
compare(a, b);
|
||||
t.ok( false, "bad comparison registered!?" );
|
||||
} catch (e) {
|
||||
t.ok( e instanceof TypeError, "bad comparison raised TypeError" );
|
||||
}
|
||||
|
||||
t.is( repr(a), "[object Object]", "default repr for StringMap" );
|
||||
var isStringMap = function () {
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
if (!(arguments[i] instanceof StringMap)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
registerRepr("stringMap",
|
||||
isStringMap,
|
||||
function (obj) {
|
||||
return "StringMap(" + repr(items(obj)) + ")";
|
||||
}
|
||||
);
|
||||
|
||||
t.is( repr(a), 'StringMap([["foo", "bar"]])', "repr worked" );
|
||||
|
||||
// not public API
|
||||
MochiKit.Base.reprRegistry.unregister("stringMap");
|
||||
|
||||
t.is( repr(a), "[object Object]", "default repr for StringMap" );
|
||||
|
||||
registerComparator("stringMap",
|
||||
isStringMap,
|
||||
function (a, b) {
|
||||
// no sorted(...) in base
|
||||
a = items(a);
|
||||
b = items(b);
|
||||
a.sort(compare);
|
||||
b.sort(compare);
|
||||
return compare(a, b);
|
||||
}
|
||||
);
|
||||
|
||||
t.is( compare(a, b), 0, "registerComparator" );
|
||||
|
||||
update(a, {"foo": "bar"}, {"wibble": "baz"}, undefined, null, {"grr": 1});
|
||||
t.is( a.foo, "bar", "update worked (first obj)" );
|
||||
t.is( a.wibble, "baz", "update worked (second obj)" );
|
||||
t.is( a.grr, 1, "update worked (skipped undefined and null)" );
|
||||
t.is( compare(a, b), 1, "update worked (comparison)" );
|
||||
|
||||
|
||||
setdefault(a, {"foo": "unf"}, {"bar": "web taco"} );
|
||||
t.is( a.foo, "bar", "setdefault worked (skipped existing)" );
|
||||
t.is( a.bar, "web taco", "setdefault worked (set non-existing)" );
|
||||
|
||||
var c = items(merge({"foo": "bar"}, {"wibble": "baz"}));
|
||||
c.sort(compare);
|
||||
t.is( compare(c, [["foo", "bar"], ["wibble", "baz"]]), 0, "merge worked" );
|
||||
|
||||
// not public API
|
||||
MochiKit.Base.comparatorRegistry.unregister("stringMap");
|
||||
|
||||
try {
|
||||
compare(a, b);
|
||||
t.ok( false, "bad comparison registered!?" );
|
||||
} catch (e) {
|
||||
t.ok( e instanceof TypeError, "bad comparison raised TypeError" );
|
||||
}
|
||||
|
||||
var o = {"__repr__": function () { return "__repr__"; }};
|
||||
t.is( repr(o), "__repr__", "__repr__ protocol" );
|
||||
t.is( repr(MochiKit.Base), MochiKit.Base.__repr__(), "__repr__ protocol when repr is defined" );
|
||||
var o = {"NAME": "NAME"};
|
||||
t.is( repr(o), "NAME", "NAME protocol (obj)" );
|
||||
o = function () { return "TACO" };
|
||||
o.NAME = "NAME";
|
||||
t.is( repr(o), "NAME", "NAME protocol (func)" );
|
||||
|
||||
t.is( repr(MochiKit.Base.nameFunctions), "MochiKit.Base.nameFunctions", "test nameFunctions" );
|
||||
// Done!
|
||||
|
||||
t.is( urlEncode("1+2=2").toUpperCase(), "1%2B2%3D2", "urlEncode" );
|
||||
t.is( queryString(["a", "b"], [1, "two"]), "a=1&b=two", "queryString");
|
||||
t.is( queryString({"a": 1}), "a=1", "one item alternate form queryString" );
|
||||
var o = {"a": 1, "b": 2, "c": function() {}};
|
||||
var res = queryString(o).split("&");
|
||||
res.sort();
|
||||
t.is( res.join("&"), "a=1&b=2", "two item alternate form queryString, function skip" );
|
||||
var res = parseQueryString("1+1=2&b=3%3D2");
|
||||
t.is( res["1 1"], "2", "parseQueryString pathological name" );
|
||||
t.is( res.b, "3=2", "parseQueryString second name:value pair" );
|
||||
var res = parseQueryString("foo=one&foo=two", true);
|
||||
t.is( res["foo"].join(" "), "one two", "parseQueryString useArrays" );
|
||||
var res = parseQueryString("?foo=2&bar=1");
|
||||
t.is( res["foo"], "2", "parseQueryString strip leading question mark");
|
||||
|
||||
t.is( serializeJSON("foo\n\r\b\f\t"), "\"foo\\n\\r\\b\\f\\t\"", "string JSON" );
|
||||
t.is( serializeJSON(null), "null", "null JSON");
|
||||
try {
|
||||
serializeJSON(undefined);
|
||||
t.ok(false, "undefined should not be serializable");
|
||||
} catch (e) {
|
||||
t.ok(e instanceof TypeError, "undefined not serializable");
|
||||
}
|
||||
t.is( serializeJSON(1), "1", "1 JSON");
|
||||
t.is( serializeJSON(1.23), "1.23", "1.23 JSON");
|
||||
t.is( serializeJSON(serializeJSON), null, "function JSON (null, not string)" );
|
||||
t.is( serializeJSON([1, "2", 3.3]), "[1, \"2\", 3.3]", "array JSON" );
|
||||
var res = evalJSON(serializeJSON({"a":1, "b":2}));
|
||||
t.is( res.a, 1, "evalJSON on an object (1)" );
|
||||
t.is( res.b, 2, "evalJSON on an object (2)" );
|
||||
var res = {"a": 1, "b": 2, "json": function () { return this; }};
|
||||
var res = evalJSON(serializeJSON(res));
|
||||
t.is( res.a, 1, "evalJSON on an object that jsons self (1)" );
|
||||
t.is( res.b, 2, "evalJSON on an object that jsons self (2)" );
|
||||
var strJSON = {"a": 1, "b": 2, "json": function () { return "json"; }};
|
||||
t.is( serializeJSON(strJSON), "\"json\"", "json serialization calling" );
|
||||
t.is( serializeJSON([strJSON]), "[\"json\"]", "json serialization calling in a structure" );
|
||||
registerJSON("isDateLike",
|
||||
isDateLike,
|
||||
function (d) {
|
||||
return "this was a date";
|
||||
}
|
||||
);
|
||||
t.is( serializeJSON(new Date()), "\"this was a date\"", "json registry" );
|
||||
MochiKit.Base.jsonRegistry.unregister("isDateLike");
|
||||
|
||||
var a = {"foo": {"bar": 12, "wibble": 13}};
|
||||
var b = {"foo": {"baz": 4, "bar": 16}, "bar": 4};
|
||||
updatetree(a, b);
|
||||
var expect = [["bar", 16], ["baz", 4], ["wibble", 13]];
|
||||
var got = items(a.foo);
|
||||
got.sort(compare);
|
||||
t.is( repr(got), repr(expect), "updatetree merge" );
|
||||
t.is( a.bar, 4, "updatetree insert" );
|
||||
|
||||
var c = counter();
|
||||
t.is( c(), 1, "counter starts at 1" );
|
||||
t.is( c(), 2, "counter increases" );
|
||||
c = counter(2);
|
||||
t.is( c(), 2, "counter starts at 2" );
|
||||
t.is( c(), 3, "counter increases" );
|
||||
|
||||
t.is( findValue([1, 2, 3], 4), -1, "findValue returns -1 on not found");
|
||||
t.is( findValue([1, 2, 3], 1), 0, "findValue returns correct index");
|
||||
t.is( findValue([1, 2, 3], 1, 1), -1, "findValue honors start");
|
||||
t.is( findValue([1, 2, 3], 2, 0, 1), -1, "findValue honors end");
|
||||
t.is( findIdentical([1, 2, 3], 4), -1, "findIdentical returns -1");
|
||||
t.is( findIdentical([1, 2, 3], 1), 0, "findIdentical returns correct index");
|
||||
t.is( findIdentical([1, 2, 3], 1, 1), -1, "findIdentical honors start");
|
||||
t.is( findIdentical([1, 2, 3], 2, 0, 1), -1, "findIdentical honors end");
|
||||
t.is( isNull(undefined), false, "isNull doesn't match undefined" );
|
||||
|
||||
var flat = flattenArguments(1, "2", 3, [4, [5, [6, 7], 8, [], 9]]);
|
||||
var expect = [1, "2", 3, 4, 5, 6, 7, 8, 9];
|
||||
t.is( repr(flat), repr(expect), "flattenArguments" );
|
||||
|
||||
var fn = function () {
|
||||
return [this, concat(arguments)];
|
||||
}
|
||||
t.is( methodcaller("toLowerCase")("FOO"), "foo", "methodcaller with a method name" );
|
||||
t.is( repr(methodcaller(fn, 2, 3)(1)), "[1, [2, 3]]", "methodcaller with a function" );
|
||||
|
||||
var f1 = function (x) { return [1, x]; };
|
||||
var f2 = function (x) { return [2, x]; };
|
||||
var f3 = function (x) { return [3, x]; };
|
||||
t.is( repr(f1(f2(f3(4)))), "[1, [2, [3, 4]]]", "test the compose test" );
|
||||
t.is( repr(compose(f1,f2,f3)(4)), "[1, [2, [3, 4]]]", "three fn composition works" );
|
||||
t.is( repr(compose(compose(f1,f2),f3)(4)), "[1, [2, [3, 4]]]", "associative left" );
|
||||
t.is( repr(compose(f1,compose(f2,f3))(4)), "[1, [2, [3, 4]]]", "associative right" );
|
||||
|
||||
try {
|
||||
compose(f1, "foo");
|
||||
t.ok( false, "wrong compose argument not raised!" );
|
||||
} catch (e) {
|
||||
t.is( e.name, 'TypeError', "wrong compose argument raised correctly" );
|
||||
}
|
||||
|
||||
t.is(camelize('one'), 'one', 'one word');
|
||||
t.is(camelize('one-two'), 'oneTwo', 'two words');
|
||||
t.is(camelize('one-two-three'), 'oneTwoThree', 'three words');
|
||||
t.is(camelize('1-one'), '1One', 'letter and word');
|
||||
t.is(camelize('one-'), 'one', 'trailing hyphen');
|
||||
t.is(camelize('-one'), 'One', 'starting hyphen');
|
||||
t.is(camelize('o-two'), 'oTwo', 'one character and word');
|
||||
|
||||
var flat = flattenArray([1, "2", 3, [4, [5, [6, 7], 8, [], 9]]]);
|
||||
var expect = [1, "2", 3, 4, 5, 6, 7, 8, 9];
|
||||
t.is( repr(flat), repr(expect), "flattenArray" );
|
||||
|
||||
/* mean */
|
||||
try {
|
||||
mean();
|
||||
t.ok( false, "no arguments didn't raise!" );
|
||||
} catch (e) {
|
||||
t.is( e.name, 'TypeError', "no arguments raised correctly" );
|
||||
}
|
||||
t.is( mean(1), 1, 'single argument (arg list)');
|
||||
t.is( mean([1]), 1, 'single argument (array)');
|
||||
t.is( mean(1,2,3), 2, 'three arguments (arg list)');
|
||||
t.is( mean([1,2,3]), 2, 'three arguments (array)');
|
||||
t.is( average(1), 1, 'test the average alias');
|
||||
|
||||
/* median */
|
||||
try {
|
||||
median();
|
||||
t.ok( false, "no arguments didn't raise!" );
|
||||
} catch (e) {
|
||||
t.is( e.name, 'TypeError', "no arguments raised correctly" );
|
||||
}
|
||||
t.is( median(1), 1, 'single argument (arg list)');
|
||||
t.is( median([1]), 1, 'single argument (array)');
|
||||
t.is( median(3,1,2), 2, 'three arguments (arg list)');
|
||||
t.is( median([3,1,2]), 2, 'three arguments (array)');
|
||||
t.is( median(3,1,2,4), 2.5, 'four arguments (arg list)');
|
||||
t.is( median([3,1,2,4]), 2.5, 'four arguments (array)');
|
||||
|
||||
/* #185 */
|
||||
t.is( serializeJSON(parseQueryString("")), "{}", "parseQueryString('')" );
|
||||
t.is( serializeJSON(parseQueryString("", true)), "{}", "parseQueryString('', true)" );
|
||||
|
||||
/* #109 */
|
||||
t.is( queryString({ids: [1,2,3]}), "ids=1&ids=2&ids=3", "queryString array value" );
|
||||
t.is( queryString({ids: "123"}), "ids=123", "queryString string value" );
|
||||
|
||||
/* test values */
|
||||
var o = {a: 1, b: 2, c: 4, d: -1};
|
||||
var got = values(o);
|
||||
got.sort();
|
||||
t.is( repr(got), repr([-1, 1, 2, 4]), "values()" );
|
||||
|
||||
};
|
|
@ -1,128 +0,0 @@
|
|||
if (typeof(dojo) != 'undefined') { dojo.require('MochiKit.Color'); }
|
||||
if (typeof(JSAN) != 'undefined') { JSAN.use('MochiKit.Color'); }
|
||||
if (typeof(tests) == 'undefined') { tests = {}; }
|
||||
|
||||
tests.test_Color = function (t) {
|
||||
var approx = function (a, b, msg) {
|
||||
return t.is(a.toPrecision(4), b.toPrecision(4), msg);
|
||||
};
|
||||
|
||||
t.is( Color.whiteColor().toHexString(), "#ffffff", "whiteColor has right hex" );
|
||||
t.is( Color.blackColor().toHexString(), "#000000", "blackColor has right hex" );
|
||||
t.is( Color.blueColor().toHexString(), "#0000ff", "blueColor has right hex" );
|
||||
t.is( Color.redColor().toHexString(), "#ff0000", "redColor has right hex" );
|
||||
t.is( Color.greenColor().toHexString(), "#00ff00", "greenColor has right hex" );
|
||||
t.is( compare(Color.whiteColor(), Color.whiteColor()), 0, "default colors compare right" );
|
||||
t.ok( Color.whiteColor() == Color.whiteColor(), "default colors are interned" );
|
||||
t.ok( Color.whiteColor().toRGBString(), "rgb(255,255,255)", "toRGBString white" );
|
||||
t.ok( Color.blueColor().toRGBString(), "rgb(0,0,255)", "toRGBString blue" );
|
||||
t.is( Color.fromRGB(190/255, 222/255, 173/255).toHexString(), "#bedead", "fromRGB works" );
|
||||
t.is( Color.fromRGB(226/255, 15.9/255, 182/255).toHexString(), "#e210b6", "fromRGB < 16 works" );
|
||||
t.is( Color.fromRGB({r:190/255,g:222/255,b:173/255}).toHexString(), "#bedead", "alt fromRGB works" );
|
||||
t.is( Color.fromHexString("#bedead").toHexString(), "#bedead", "round-trip hex" );
|
||||
t.is( Color.fromString("#bedead").toHexString(), "#bedead", "round-trip string(hex)" );
|
||||
t.is( Color.fromRGBString("rgb(190,222,173)").toHexString(), "#bedead", "round-trip rgb" );
|
||||
t.is( Color.fromString("rgb(190,222,173)").toHexString(), "#bedead", "round-trip rgb" );
|
||||
|
||||
var hsl = Color.redColor().asHSL();
|
||||
approx( hsl.h, 0.0, "red hsl.h" );
|
||||
approx( hsl.s, 1.0, "red hsl.s" );
|
||||
approx( hsl.l, 0.5, "red hsl.l" );
|
||||
hsl = Color.fromRGB(0, 0, 0.5).asHSL();
|
||||
approx( hsl.h, 2/3, "darkblue hsl.h" );
|
||||
approx( hsl.s, 1.0, "darkblue hsl.s" );
|
||||
approx( hsl.l, 0.25, "darkblue hsl.l" );
|
||||
hsl = Color.fromString("#4169E1").asHSL();
|
||||
approx( hsl.h, (5/8), "4169e1 h");
|
||||
approx( hsl.s, (8/11), "4169e1 s");
|
||||
approx( hsl.l, (29/51), "4169e1 l");
|
||||
hsl = Color.fromString("#555544").asHSL();
|
||||
approx( hsl.h, (1/6), "555544 h" );
|
||||
approx( hsl.s, (1/9), "555544 s" );
|
||||
approx( hsl.l, (3/10), "555544 l" );
|
||||
hsl = Color.fromRGB(0.5, 1, 0.5).asHSL();
|
||||
approx( hsl.h, 1/3, "aqua hsl.h" );
|
||||
approx( hsl.s, 1.0, "aqua hsl.s" );
|
||||
approx( hsl.l, 0.75, "aqua hsl.l" );
|
||||
t.is(
|
||||
Color.fromHSL(hsl.h, hsl.s, hsl.l).toHexString(),
|
||||
Color.fromRGB(0.5, 1, 0.5).toHexString(),
|
||||
"fromHSL works with components"
|
||||
);
|
||||
t.is(
|
||||
Color.fromHSL(hsl).toHexString(),
|
||||
Color.fromRGB(0.5, 1, 0.5).toHexString(),
|
||||
"fromHSL alt form"
|
||||
);
|
||||
t.is(
|
||||
Color.fromString("hsl(120,100%,75%)").toHexString(),
|
||||
"#80ff80",
|
||||
"fromHSLString"
|
||||
);
|
||||
t.is(
|
||||
Color.fromRGB(0.5, 1, 0.5).toHSLString(),
|
||||
"hsl(120,100.0%,75.00%)",
|
||||
"toHSLString"
|
||||
);
|
||||
t.is( Color.fromHSL(0, 0, 0).toHexString(), "#000000", "fromHSL to black" );
|
||||
hsl = Color.blackColor().asHSL();
|
||||
approx( hsl.h, 0.0, "black hsl.h" );
|
||||
approx( hsl.s, 0.0, "black hsl.s" );
|
||||
approx( hsl.l, 0.0, "black hsl.l" );
|
||||
hsl.h = 1.0;
|
||||
hsl = Color.blackColor().asHSL();
|
||||
approx( hsl.h, 0.0, "asHSL returns copy" );
|
||||
var rgb = Color.brownColor().asRGB();
|
||||
approx( rgb.r, 153/255, "brown rgb.r" );
|
||||
approx( rgb.g, 102/255, "brown rgb.g" );
|
||||
approx( rgb.b, 51/255, "brown rgb.b" );
|
||||
rgb.r = 0;
|
||||
rgb = Color.brownColor().asRGB();
|
||||
approx( rgb.r, 153/255, "asRGB returns copy" );
|
||||
|
||||
t.is( Color.fromName("aqua").toHexString(), "#00ffff", "aqua fromName" );
|
||||
t.is( Color.fromString("aqua").toHexString(), "#00ffff", "aqua fromString" );
|
||||
t.is( Color.fromName("transparent"), Color.transparentColor(), "transparent fromName" );
|
||||
t.is( Color.fromString("transparent"), Color.transparentColor(), "transparent fromString" );
|
||||
t.is( Color.transparentColor().toRGBString(), "rgba(0,0,0,0)", "transparent toRGBString" );
|
||||
t.is( Color.fromRGBString("rgba( 0, 255, 255, 50%)").asRGB().a, 0.5, "rgba parsing alpha correctly" );
|
||||
t.is( Color.fromRGBString("rgba( 0, 255, 255, 50%)").toRGBString(), "rgba(0,255,255,0.5)", "rgba output correctly" );
|
||||
t.is( Color.fromRGBString("rgba( 0, 255, 255, 1)").toHexString(), "#00ffff", "fromRGBString with spaces and alpha" );
|
||||
t.is( Color.fromRGBString("rgb( 0, 255, 255)").toHexString(), "#00ffff", "fromRGBString with spaces" );
|
||||
t.is( Color.fromRGBString("rgb( 0, 100%, 255)").toHexString(), "#00ffff", "fromRGBString with percents" );
|
||||
|
||||
var hsv = Color.redColor().asHSV();
|
||||
approx( hsv.h, 0.0, "red hsv.h" );
|
||||
approx( hsv.s, 1.0, "red hsv.s" );
|
||||
approx( hsv.v, 1.0, "red hsv.v" );
|
||||
t.is( Color.fromHSV(hsv).toHexString(), Color.redColor().toHexString(), "red hexstring" );
|
||||
hsv = Color.fromRGB(0, 0, 0.5).asHSV();
|
||||
approx( hsv.h, 2/3, "darkblue hsv.h" );
|
||||
approx( hsv.s, 1.0, "darkblue hsv.s" );
|
||||
approx( hsv.v, 0.5, "darkblue hsv.v" );
|
||||
t.is( Color.fromHSV(hsv).toHexString(), Color.fromRGB(0, 0, 0.5).toHexString(), "darkblue hexstring" );
|
||||
hsv = Color.fromString("#4169E1").asHSV();
|
||||
approx( hsv.h, 5/8, "4169e1 h");
|
||||
approx( hsv.s, 32/45, "4169e1 s");
|
||||
approx( hsv.v, 15/17, "4169e1 l");
|
||||
t.is( Color.fromHSV(hsv).toHexString(), "#4169e1", "4169e1 hexstring" );
|
||||
hsv = Color.fromString("#555544").asHSV();
|
||||
approx( hsv.h, 1/6, "555544 h" );
|
||||
approx( hsv.s, 1/5, "555544 s" );
|
||||
approx( hsv.v, 1/3, "555544 l" );
|
||||
t.is( Color.fromHSV(hsv).toHexString(), "#555544", "555544 hexstring" );
|
||||
hsv = Color.fromRGB(0.5, 1, 0.5).asHSV();
|
||||
approx( hsv.h, 1/3, "aqua hsv.h" );
|
||||
approx( hsv.s, 0.5, "aqua hsv.s" );
|
||||
approx( hsv.v, 1, "aqua hsv.v" );
|
||||
t.is(
|
||||
Color.fromHSV(hsv.h, hsv.s, hsv.v).toHexString(),
|
||||
Color.fromRGB(0.5, 1, 0.5).toHexString(),
|
||||
"fromHSV works with components"
|
||||
);
|
||||
t.is(
|
||||
Color.fromHSV(hsv).toHexString(),
|
||||
Color.fromRGB(0.5, 1, 0.5).toHexString(),
|
||||
"fromHSV alt form"
|
||||
);
|
||||
};
|
|
@ -1,45 +0,0 @@
|
|||
if (typeof(dojo) != 'undefined') { dojo.require('MochiKit.DateTime'); }
|
||||
if (typeof(JSAN) != 'undefined') { JSAN.use('MochiKit.DateTime'); }
|
||||
if (typeof(tests) == 'undefined') { tests = {}; }
|
||||
|
||||
tests.test_DateTime = function (t) {
|
||||
var testDate = isoDate('2005-2-3');
|
||||
t.is(testDate.getFullYear(), 2005, "isoDate year ok");
|
||||
t.is(testDate.getDate(), 3, "isoDate day ok");
|
||||
t.is(testDate.getMonth(), 1, "isoDate month ok");
|
||||
t.ok(objEqual(testDate, new Date("February 3, 2005")), "matches string date");
|
||||
t.is(toISODate(testDate), '2005-02-03', 'toISODate ok');
|
||||
|
||||
var testDate = isoDate('2005-06-08');
|
||||
t.is(testDate.getFullYear(), 2005, "isoDate year ok");
|
||||
t.is(testDate.getDate(), 8, "isoDate day ok");
|
||||
t.is(testDate.getMonth(), 5, "isoDate month ok");
|
||||
t.ok(objEqual(testDate, new Date("June 8, 2005")), "matches string date");
|
||||
t.is(toISODate(testDate), '2005-06-08', 'toISODate ok');
|
||||
|
||||
t.is(compare(new Date("February 3, 2005"), new Date(2005, 1, 3)), 0, "dates compare eq");
|
||||
t.is(compare(new Date("February 3, 2005"), new Date(2005, 2, 3)), -1, "dates compare lt");
|
||||
t.is(compare(new Date("February 3, 2005"), new Date(2005, 0, 3)), 1, "dates compare gt");
|
||||
|
||||
var testDate = isoDate('2005-2-3');
|
||||
t.is(compare(americanDate('2/3/2005'), testDate), 0, "americanDate eq");
|
||||
t.is(compare('2/3/2005', toAmericanDate(testDate)), 0, "toAmericanDate eq");
|
||||
|
||||
var testTimestamp = isoTimestamp('2005-2-3 22:01:03');
|
||||
t.is(compare(testTimestamp, new Date(2005,1,3,22,1,3)), 0, "isoTimestamp eq");
|
||||
t.is(compare(testTimestamp, isoTimestamp('2005-2-3T22:01:03')), 0, "isoTimestamp (real ISO) eq");
|
||||
t.is(compare(toISOTimestamp(testTimestamp), '2005-02-03 22:01:03'), 0, "toISOTimestamp eq");
|
||||
testTimestamp = isoTimestamp('2005-2-3T22:01:03Z');
|
||||
t.is(toISOTimestamp(testTimestamp, true), '2005-02-03T22:01:03Z', "toISOTimestamp (real ISO) eq");
|
||||
|
||||
var localTZ = Math.round((new Date(2005,1,3,22,1,3)).getTimezoneOffset()/60)
|
||||
var direction = (localTZ < 0) ? "+" : "-";
|
||||
localTZ = Math.abs(localTZ);
|
||||
localTZ = direction + ((localTZ < 10) ? "0" : "") + localTZ;
|
||||
testTimestamp = isoTimestamp("2005-2-3T22:01:03" + localTZ);
|
||||
var testDateTimestamp = new Date(2005,1,3,22,1,3);
|
||||
t.is(compare(testTimestamp, testDateTimestamp), 0, "equal with local tz");
|
||||
testTimestamp = isoTimestamp("2005-2-3T17:01:03-05");
|
||||
var testDateTimestamp = new Date(Date.UTC(2005,1,3,22,1,3));
|
||||
t.is(compare(testTimestamp, testDateTimestamp), 0, "equal with specific tz");
|
||||
};
|
|
@ -1,30 +0,0 @@
|
|||
if (typeof(dojo) != 'undefined') { dojo.require('MochiKit.Signal'); }
|
||||
if (typeof(JSAN) != 'undefined') { JSAN.use('MochiKit.Signal'); }
|
||||
if (typeof(tests) == 'undefined') { tests = {}; }
|
||||
|
||||
tests.test_DragAndDrop = function (t) {
|
||||
|
||||
var drag1 = new MochiKit.DragAndDrop.Draggable('drag1', {'revert': true, 'ghosting': true});
|
||||
|
||||
var drop1 = new MochiKit.DragAndDrop.Droppable('drop1', {'hoverclass': 'drop-hover'});
|
||||
drop1.activate();
|
||||
t.is(hasElementClass('drop1', 'drop-hover'), true, "hoverclass ok");
|
||||
drop1.deactivate();
|
||||
t.is(hasElementClass('drop1', 'drop-hover'), false, "remove hoverclass ok");
|
||||
drop1.destroy();
|
||||
|
||||
t.is( isEmpty(MochiKit.DragAndDrop.Droppables.drops), true, "Unregister droppable ok");
|
||||
|
||||
var onhover = function (element) {
|
||||
t.is(element, getElement('drag1'), 'onhover ok');
|
||||
};
|
||||
var drop2 = new MochiKit.DragAndDrop.Droppable('drop1', {'onhover': onhover});
|
||||
var pos = getElementPosition('drop1');
|
||||
pos = {"x": pos.x + 5, "y": pos.y + 5};
|
||||
MochiKit.DragAndDrop.Droppables.show({"page": pos}, getElement('drag1'));
|
||||
|
||||
drag1.destroy();
|
||||
t.is( isEmpty(MochiKit.DragAndDrop.Draggables.drops), true, "Unregister draggable ok");
|
||||
|
||||
};
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
if (typeof(dojo) != 'undefined') { dojo.require('MochiKit.Format'); }
|
||||
if (typeof(JSAN) != 'undefined') { JSAN.use('MochiKit.Format'); }
|
||||
if (typeof(tests) == 'undefined') { tests = {}; }
|
||||
|
||||
tests.test_Format = function (t) {
|
||||
t.is( truncToFixed(0.1234, 3), "0.123", "truncToFixed truncate" );
|
||||
t.is( truncToFixed(0.12, 3), "0.120", "truncToFixed trailing zeros" );
|
||||
t.is( truncToFixed(0.15, 1), "0.1", "truncToFixed no round" );
|
||||
t.is( truncToFixed(0.15, 0), "0", "truncToFixed zero (edge case)" );
|
||||
|
||||
t.is( roundToFixed(0.1234, 3), "0.123", "roundToFixed truncate" );
|
||||
t.is( roundToFixed(0.12, 3), "0.120", "roundToFixed trailing zeros" );
|
||||
t.is( roundToFixed(0.15, 1), "0.2", "roundToFixed round" );
|
||||
t.is( roundToFixed(0.15, 0), "0", "roundToFixed zero (edge case)" );
|
||||
|
||||
t.is( twoDigitFloat(-0.1234), "-0.12", "twoDigitFloat -0.1234 correct");
|
||||
t.is( twoDigitFloat(-0.1), "-0.1", "twoDigitFloat -0.1 correct");
|
||||
t.is( twoDigitFloat(-0), "0", "twoDigitFloat -0 correct");
|
||||
t.is( twoDigitFloat(0), "0", "twoDigitFloat 0 correct");
|
||||
t.is( twoDigitFloat(1), "1", "twoDigitFloat 1 correct");
|
||||
t.is( twoDigitFloat(1.0), "1", "twoDigitFloat 1.0 correct");
|
||||
t.is( twoDigitFloat(1.2), "1.2", "twoDigitFloat 1.2 correct");
|
||||
t.is( twoDigitFloat(1.234), "1.23", "twoDigitFloat 1.234 correct");
|
||||
t.is( percentFormat(123), "12300%", "percentFormat 123 correct");
|
||||
t.is( percentFormat(1.23), "123%", "percentFormat 123 correct");
|
||||
t.is( twoDigitAverage(1, 0), "0", "twoDigitAverage dbz correct");
|
||||
t.is( twoDigitAverage(1, 1), "1", "twoDigitAverage 1 correct");
|
||||
t.is( twoDigitAverage(1, 10), "0.1", "twoDigitAverage .1 correct");
|
||||
function reprIs(a, b) {
|
||||
arguments[0] = repr(a);
|
||||
arguments[1] = repr(b);
|
||||
t.is.apply(this, arguments);
|
||||
}
|
||||
reprIs( lstrip("\r\t\n foo \n\t\r"), "foo \n\t\r", "lstrip whitespace chars" );
|
||||
reprIs( rstrip("\r\t\n foo \n\t\r"), "\r\t\n foo", "rstrip whitespace chars" );
|
||||
reprIs( strip("\r\t\n foo \n\t\r"), "foo", "strip whitespace chars" );
|
||||
reprIs( lstrip("\r\n\t \r", "\r"), "\n\t \r", "lstrip custom chars" );
|
||||
reprIs( rstrip("\r\n\t \r", "\r"), "\r\n\t ", "rstrip custom chars" );
|
||||
reprIs( strip("\r\n\t \r", "\r"), "\n\t ", "strip custom chars" );
|
||||
|
||||
var nf = numberFormatter("$###,###.00 footer");
|
||||
t.is( nf(1000.1), "$1,000.10 footer", "trailing zeros" );
|
||||
t.is( nf(1000000.1), "$1,000,000.10 footer", "two seps" );
|
||||
t.is( nf(100), "$100.00 footer", "shorter than sep" );
|
||||
t.is( nf(100.555), "$100.56 footer", "rounding" );
|
||||
t.is( nf(-100.555), "$-100.56 footer", "default neg" );
|
||||
nf = numberFormatter("-$###,###.00");
|
||||
t.is( nf(-100.555), "-$100.56", "custom neg" );
|
||||
nf = numberFormatter("0000.0000");
|
||||
t.is( nf(0), "0000.0000", "leading and trailing" );
|
||||
t.is( nf(1.1), "0001.1000", "leading and trailing" );
|
||||
t.is( nf(12345.12345), "12345.1235", "no need for leading/trailing" );
|
||||
nf = numberFormatter("0000.0000");
|
||||
t.is( nf("taco"), "", "default placeholder" );
|
||||
nf = numberFormatter("###,###.00", "foo", "de_DE");
|
||||
t.is( nf("taco"), "foo", "custom placeholder" );
|
||||
t.is( nf(12345.12345), "12.345,12", "de_DE locale" );
|
||||
nf = numberFormatter("#%");
|
||||
t.is( nf(1), "100%", "trivial percent" );
|
||||
t.is( nf(0.55), "55%", "percent" );
|
||||
|
||||
var customLocale = {
|
||||
separator: " apples and ",
|
||||
decimal: " bagels at ",
|
||||
percent: "am for breakfast"};
|
||||
var customFormatter = numberFormatter("###,###.0%", "No breakfast", customLocale);
|
||||
t.is( customFormatter(23.458), "2 apples and 345 bagels at 8am for breakfast", "custom locale" );
|
||||
|
||||
nf = numberFormatter("###,###");
|
||||
t.is( nf(123), "123", "large number format" );
|
||||
t.is( nf(1234), "1,234", "large number format" );
|
||||
t.is( nf(12345), "12,345", "large number format" );
|
||||
t.is( nf(123456), "123,456", "large number format" );
|
||||
t.is( nf(1234567), "1,234,567", "large number format" );
|
||||
t.is( nf(12345678), "12,345,678", "large number format" );
|
||||
t.is( nf(123456789), "123,456,789", "large number format" );
|
||||
t.is( nf(1234567890), "1,234,567,890", "large number format" );
|
||||
t.is( nf(12345678901), "12,345,678,901", "large number format" );
|
||||
t.is( nf(123456789012), "123,456,789,012", "large number format" );
|
||||
};
|
|
@ -1,176 +0,0 @@
|
|||
if (typeof(dojo) != 'undefined') { dojo.require('MochiKit.Iter'); }
|
||||
if (typeof(JSAN) != 'undefined') { JSAN.use('MochiKit.Iter'); }
|
||||
if (typeof(tests) == 'undefined') { tests = {}; }
|
||||
|
||||
tests.test_Iter = function (t) {
|
||||
t.is( sum([1, 2, 3, 4, 5]), 15, "sum works on Arrays" );
|
||||
t.is( compare(list([1, 2, 3]), [1, 2, 3]), 0, "list([x]) == [x]" );
|
||||
t.is( compare(list(range(6, 0, -1)), [6, 5, 4, 3, 2, 1]), 0, "list(range(6, 0, -1)");
|
||||
t.is( compare(list(range(6)), [0, 1, 2, 3, 4, 5]), 0, "list(range(6))" );
|
||||
var moreThanTwo = partial(operator.lt, 2);
|
||||
t.is( sum(ifilter(moreThanTwo, range(6))), 12, "sum(ifilter(, range()))" );
|
||||
t.is( sum(ifilterfalse(moreThanTwo, range(6))), 3, "sum(ifilterfalse(, range()))" );
|
||||
|
||||
var c = count(10);
|
||||
t.is( compare([c.next(), c.next(), c.next()], [10, 11, 12]), 0, "count()" );
|
||||
c = cycle([1, 2]);
|
||||
t.is( compare([c.next(), c.next(), c.next()], [1, 2, 1]), 0, "cycle()" );
|
||||
c = repeat("foo", 3);
|
||||
t.is( compare(list(c), ["foo", "foo", "foo"]), 0, "repeat()" );
|
||||
c = izip([1, 2], [3, 4, 5], repeat("foo"));
|
||||
t.is( compare(list(c), [[1, 3, "foo"], [2, 4, "foo"]]), 0, "izip()" );
|
||||
|
||||
t.is( compare(list(range(5)), [0, 1, 2, 3, 4]), 0, "range(x)" );
|
||||
c = islice(range(10), 0, 10, 2);
|
||||
t.is( compare(list(c), [0, 2, 4, 6, 8]), 0, "islice(x, y, z)" );
|
||||
|
||||
c = imap(operator.add, [1, 2, 3], [2, 4, 6]);
|
||||
t.is( compare(list(c), [3, 6, 9]), 0, "imap(fn, p, q)" );
|
||||
|
||||
c = filter(partial(operator.lt, 1), iter([1, 2, 3]));
|
||||
t.is( compare(c, [2, 3]), 0, "filter(fn, iterable)" );
|
||||
|
||||
c = map(partial(operator.add, -1), iter([1, 2, 3]));
|
||||
t.is( compare(c, [0, 1, 2]), 0, "map(fn, iterable)" );
|
||||
|
||||
c = map(operator.add, iter([1, 2, 3]), [2, 4, 6]);
|
||||
t.is( compare(c, [3, 6, 9]), 0, "map(fn, iterable, q)" );
|
||||
|
||||
c = map(operator.add, iter([1, 2, 3]), iter([2, 4, 6]));
|
||||
t.is( compare(c, [3, 6, 9]), 0, "map(fn, iterable, iterable)" );
|
||||
|
||||
c = applymap(operator.add, [[1, 2], [2, 4], [3, 6]]);
|
||||
t.is( compare(list(c), [3, 6, 9]), 0, "applymap()" );
|
||||
|
||||
c = applymap(function (a) { return [this, a]; }, [[1], [2]], 1);
|
||||
t.is( compare(list(c), [[1, 1], [1, 2]]), 0, "applymap(self)" );
|
||||
|
||||
c = chain(range(2), range(3));
|
||||
t.is( compare(list(c), [0, 1, 0, 1, 2]), 0, "chain(p, q)" );
|
||||
|
||||
var lessThanFive = partial(operator.gt, 5);
|
||||
c = takewhile(lessThanFive, count());
|
||||
t.is( compare(list(c), [0, 1, 2, 3, 4]), 0, "takewhile()" );
|
||||
|
||||
c = dropwhile(lessThanFive, range(10));
|
||||
t.is( compare(list(c), [5, 6, 7, 8, 9]), 0, "dropwhile()" );
|
||||
|
||||
c = tee(range(5), 3);
|
||||
t.is( compare(list(c[0]), list(c[1])), 0, "tee(..., 3) p0 == p1" );
|
||||
t.is( compare(list(c[2]), [0, 1, 2, 3, 4]), 0, "tee(..., 3) p2 == fixed" );
|
||||
|
||||
t.is( compare(reduce(operator.add, range(10)), 45), 0, "reduce(op.add)" );
|
||||
|
||||
try {
|
||||
reduce(operator.add, []);
|
||||
t.ok( false, "reduce didn't raise anything with empty list and no start?!" );
|
||||
} catch (e) {
|
||||
if (e instanceof TypeError) {
|
||||
t.ok( true, "reduce raised TypeError correctly" );
|
||||
} else {
|
||||
t.ok( false, "reduce raised the wrong exception?" );
|
||||
}
|
||||
}
|
||||
|
||||
t.is( reduce(operator.add, [], 10), 10, "range initial value OK empty" );
|
||||
t.is( reduce(operator.add, [1], 10), 11, "range initial value OK populated" );
|
||||
|
||||
t.is( compare(iextend([1], range(2)), [1, 0, 1]), 0, "iextend(...)" );
|
||||
|
||||
var x = [];
|
||||
exhaust(imap(bind(x.push, x), range(5)));
|
||||
t.is( compare(x, [0, 1, 2, 3, 4]), 0, "exhaust(...)" );
|
||||
|
||||
t.is( every([1, 2, 3, 4, 5, 4], lessThanFive), false, "every false" );
|
||||
t.is( every([1, 2, 3, 4, 4], lessThanFive), true, "every true" );
|
||||
t.is( some([1, 2, 3, 4, 4], lessThanFive), true, "some true" );
|
||||
t.is( some([5, 6, 7, 8, 9], lessThanFive), false, "some false" );
|
||||
t.is( some([5, 6, 7, 8, 4], lessThanFive), true, "some true" );
|
||||
|
||||
var rval = [];
|
||||
forEach(range(2), rval.push, rval);
|
||||
t.is( compare(rval, [0, 1]), 0, "forEach works bound" );
|
||||
|
||||
function foo(o) {
|
||||
rval.push(o);
|
||||
}
|
||||
forEach(range(2), foo);
|
||||
t.is( compare(rval, [0, 1, 0, 1]), 0, "forEach works unbound" );
|
||||
|
||||
t.is( compare(sorted([3, 2, 1]), [1, 2, 3]), 0, "sorted default" );
|
||||
rval = sorted(["aaa", "bb", "c"], keyComparator("length"));
|
||||
t.is(compare(rval, ["c", "bb", "aaa"]), 0, "sorted custom");
|
||||
|
||||
t.is( compare(reversed(range(4)), [3, 2, 1, 0]), 0, "reversed iterator" );
|
||||
t.is( compare(reversed([5, 6, 7]), [7, 6, 5]), 0, "reversed list" );
|
||||
|
||||
var o = {lst: [1, 2, 3], iterateNext: function () { return this.lst.shift(); }};
|
||||
t.is( compare(list(o), [1, 2, 3]), 0, "iterateNext" );
|
||||
|
||||
|
||||
function except(exc, func) {
|
||||
try {
|
||||
func();
|
||||
t.ok(false, exc.name + " was not raised.");
|
||||
} catch (e) {
|
||||
if (e == exc) {
|
||||
t.ok( true, "raised " + exc.name + " correctly" );
|
||||
} else {
|
||||
t.ok( false, "raised the wrong exception?" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
odd = partial(operator.and, 1)
|
||||
|
||||
// empty
|
||||
grouped = groupby([]);
|
||||
except(StopIteration, grouped.next);
|
||||
|
||||
// exhaust sub-iterator
|
||||
grouped = groupby([2,4,6,7], odd);
|
||||
kv = grouped.next(); k = kv[0], subiter = kv[1];
|
||||
t.is(k, 0, "odd(2) = odd(4) = odd(6) == 0");
|
||||
t.is(subiter.next(), 2, "sub-iterator.next() == 2");
|
||||
t.is(subiter.next(), 4, "sub-iterator.next() == 4");
|
||||
t.is(subiter.next(), 6, "sub-iterator.next() == 6");
|
||||
except(StopIteration, subiter.next);
|
||||
kv = grouped.next(); key = kv[0], subiter = kv[1];
|
||||
t.is(key, 1, "odd(7) == 1");
|
||||
t.is(subiter.next(), 7, "sub-iterator.next() == 7");
|
||||
except(StopIteration, subiter.next);
|
||||
|
||||
// not consume sub-iterator
|
||||
grouped = groupby([2,4,6,7], odd);
|
||||
kv = grouped.next(); key = kv[0], subiter = kv[1];
|
||||
t.is(key, 0, "0 = odd(2) = odd(4) = odd(6)");
|
||||
kv = grouped.next(); key = kv[0], subiter = kv[1];
|
||||
t.is(key, 1, "1 = odd(7)");
|
||||
except(StopIteration, grouped.next);
|
||||
|
||||
// consume sub-iterator partially
|
||||
grouped = groupby([3,1,1,2], odd);
|
||||
kv = grouped.next(); key = kv[0], subiter = kv[1];
|
||||
t.is(key, 1, "odd(1) == 1");
|
||||
t.is(subiter.next(), 3, "sub-iterator.next() == 3");
|
||||
kv = grouped.next(); key = kv[0], v = kv[1];
|
||||
t.is(key, 0, "skip (1,1), odd(2) == 0");
|
||||
except(StopIteration, grouped.next);
|
||||
|
||||
// null
|
||||
grouped = groupby([null,null]);
|
||||
kv = grouped.next(); k = kv[0], v = kv[1];
|
||||
t.is(k, null, "null ok");
|
||||
|
||||
// groupby - array version
|
||||
isEqual = (t.isDeeply || function (a, b, msg) {
|
||||
return t.ok(compare(a, b) == 0, msg);
|
||||
});
|
||||
isEqual(groupby_as_array([ ] ), [ ], "empty");
|
||||
isEqual(groupby_as_array([1,1,1]), [ [1,[1,1,1]] ], "[1,1,1]: [1,1,1]");
|
||||
isEqual(groupby_as_array([1,2,2]), [ [1,[1] ], [2,[2,2]] ], "[1,2,2]: [1], [2,2]");
|
||||
isEqual(groupby_as_array([1,1,2]), [ [1,[1,1] ], [2,[2 ]] ], "[1,1,2]: [1,1], [2]");
|
||||
isEqual(groupby_as_array([null,null] ), [ [null,[null,null]] ], "[null,null]: [null,null]");
|
||||
grouped = groupby_as_array([1,1,3,2,4,6,8], odd);
|
||||
isEqual(grouped, [[1, [1,1,3]], [0,[2,4,6,8]]], "[1,1,3,2,4,6,7] odd: [1,1,3], [2,4,6,8]");
|
||||
};
|
|
@ -1,75 +0,0 @@
|
|||
if (typeof(dojo) != 'undefined') { dojo.require('MochiKit.Logging'); }
|
||||
if (typeof(JSAN) != 'undefined') { JSAN.use('MochiKit.Logging'); }
|
||||
if (typeof(tests) == 'undefined') { tests = {}; }
|
||||
|
||||
tests.test_Logging = function (t) {
|
||||
|
||||
// just in case
|
||||
logger.clear();
|
||||
|
||||
t.is( logLevelAtLeast('DEBUG')('INFO'), false, 'logLevelAtLeast false' );
|
||||
t.is( logLevelAtLeast('WARNING')('INFO'), false, 'logLevelAtLeast true' );
|
||||
t.ok( logger instanceof Logger, "global logger installed" );
|
||||
|
||||
var allMessages = [];
|
||||
logger.addListener("allMessages", null,
|
||||
bind(allMessages.push, allMessages));
|
||||
|
||||
var fatalMessages = [];
|
||||
logger.addListener("fatalMessages", "FATAL",
|
||||
bind(fatalMessages.push, fatalMessages));
|
||||
|
||||
var firstTwo = [];
|
||||
logger.addListener("firstTwo", null,
|
||||
bind(firstTwo.push, firstTwo));
|
||||
|
||||
|
||||
log("foo");
|
||||
var msgs = logger.getMessages();
|
||||
t.is( msgs.length, 1, 'global log() put one message in queue' );
|
||||
t.is( compare(allMessages, msgs), 0, "allMessages listener" );
|
||||
var msg = msgs.pop();
|
||||
t.is( compare(msg.info, ["foo"]), 0, "info matches" );
|
||||
t.is( msg.level, "INFO", "level matches" );
|
||||
|
||||
logDebug("debugFoo");
|
||||
t.is( msgs.length, 0, 'getMessages() returns copy' );
|
||||
msgs = logger.getMessages();
|
||||
t.is( compare(allMessages, msgs), 0, "allMessages listener" );
|
||||
t.is( msgs.length, 2, 'logDebug()' );
|
||||
msg = msgs.pop();
|
||||
t.is( compare(msg.info, ["debugFoo"]), 0, "info matches" );
|
||||
t.is( msg.level, "DEBUG", "level matches" );
|
||||
|
||||
logger.removeListener("firstTwo");
|
||||
|
||||
logError("errorFoo");
|
||||
msgs = logger.getMessages();
|
||||
t.is( compare(allMessages, msgs), 0, "allMessages listener" );
|
||||
t.is( msgs.length, 3, 'logError()' );
|
||||
msg = msgs.pop();
|
||||
t.is( compare(msg.info, ["errorFoo"]), 0, "info matches" );
|
||||
t.is( msg.level, "ERROR", "level matches" );
|
||||
|
||||
logWarning("warningFoo");
|
||||
msgs = logger.getMessages();
|
||||
t.is( compare(allMessages, msgs), 0, "allMessages listener" );
|
||||
t.is( msgs.length, 4, 'logWarning()' );
|
||||
msg = msgs.pop();
|
||||
t.is( compare(msg.info, ["warningFoo"]), 0, "info matches" );
|
||||
t.is( msg.level, "WARNING", "level matches" );
|
||||
|
||||
logFatal("fatalFoo");
|
||||
msgs = logger.getMessages();
|
||||
t.is( compare(allMessages, msgs), 0, "allMessages listener" );
|
||||
t.is( msgs.length, 5, 'logFatal()' );
|
||||
msg = msgs.pop();
|
||||
t.is( compare(fatalMessages, [msg]), 0, "fatalMessages listener" );
|
||||
t.is( compare(msg.info, ["fatalFoo"]), 0, "info matches" );
|
||||
t.is( msg.level, "FATAL", "level matches" );
|
||||
|
||||
logger.removeListener("allMessages");
|
||||
logger.removeListener("fatalMessages");
|
||||
|
||||
t.is( compare(firstTwo, logger.getMessages().slice(0, 2)), 0, "firstTwo" );
|
||||
};
|
|
@ -1,408 +0,0 @@
|
|||
<html>
|
||||
<head>
|
||||
<script type="text/javascript" src="/MochiKit/Base.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Async.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Iter.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/DOM.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Style.js"></script>
|
||||
<script type="text/javascript" src="../SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="../SimpleTest/test.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<pre id="test">
|
||||
<script type="text/javascript">
|
||||
|
||||
try {
|
||||
|
||||
var increment = function (res) {
|
||||
return res + 1;
|
||||
}
|
||||
|
||||
var throwStuff = function (res) {
|
||||
throw new GenericError(res);
|
||||
}
|
||||
|
||||
var catchStuff = function (res) {
|
||||
return res.message;
|
||||
}
|
||||
|
||||
var returnError = function (res) {
|
||||
return new GenericError(res);
|
||||
}
|
||||
|
||||
var anythingOkCallback = function (msg) {
|
||||
return function (res) {
|
||||
ok(true, msg);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
var testEqCallback = function () {
|
||||
/*
|
||||
sort of emulate how deferreds work in Twisted
|
||||
for "convenient" testing
|
||||
*/
|
||||
var args = [];
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
args.push(arguments[i]);
|
||||
}
|
||||
return function (res) {
|
||||
var nargs = args.slice();
|
||||
nargs.unshift(res);
|
||||
is.apply(this, nargs);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
var neverHappen = function (d) {
|
||||
ok(false, "this should never happen");
|
||||
}
|
||||
|
||||
/*
|
||||
Test normal Deferred operation
|
||||
*/
|
||||
var d = new Deferred();
|
||||
d.addCallback(testEqCallback(1, "pre-deferred callback"));
|
||||
d.callback(1);
|
||||
d.addCallback(increment);
|
||||
d.addCallback(testEqCallback(2, "post-deferred callback"));
|
||||
d.addCallback(throwStuff);
|
||||
d.addCallback(neverHappen);
|
||||
d.addErrback(catchStuff);
|
||||
d.addCallback(testEqCallback(2, "throw -> err, catch -> success"));
|
||||
d.addCallback(returnError);
|
||||
d.addCallback(neverHappen);
|
||||
d.addErrback(catchStuff);
|
||||
d.addCallback(testEqCallback(2, "return -> err, catch -> succcess"));
|
||||
|
||||
/*
|
||||
Test Deferred cancellation
|
||||
*/
|
||||
var cancelled = function (d) {
|
||||
ok(true, "canceller called!");
|
||||
}
|
||||
|
||||
var cancelledError = function (res) {
|
||||
ok(res instanceof CancelledError, "CancelledError here");
|
||||
}
|
||||
|
||||
d = new Deferred(cancelled);
|
||||
d.addCallback(neverHappen);
|
||||
d.addErrback(cancelledError);
|
||||
d.cancel();
|
||||
|
||||
/*
|
||||
Test succeed / fail
|
||||
*/
|
||||
|
||||
d = succeed(1).addCallback(testEqCallback(1, "succeed"));
|
||||
|
||||
// default error
|
||||
d = fail().addCallback(neverHappen);
|
||||
d = d.addErrback(anythingOkCallback("default fail"));
|
||||
|
||||
// default wrapped error
|
||||
d = fail("web taco").addCallback(neverHappen).addErrback(catchStuff);
|
||||
d = d.addCallback(testEqCallback("web taco", "wrapped fail"));
|
||||
|
||||
// default unwrapped error
|
||||
d = fail(new GenericError("ugh")).addCallback(neverHappen).addErrback(catchStuff);
|
||||
d = d.addCallback(testEqCallback("ugh", "unwrapped fail"));
|
||||
|
||||
/*
|
||||
Test deferred dependencies
|
||||
*/
|
||||
|
||||
var deferredIncrement = function (res) {
|
||||
var rval = succeed(res);
|
||||
rval.addCallback(increment);
|
||||
return rval;
|
||||
}
|
||||
|
||||
d = succeed(1).addCallback(deferredIncrement);
|
||||
d = d.addCallback(testEqCallback(2, "dependent deferred succeed"));
|
||||
|
||||
var deferredFailure = function (res) {
|
||||
return fail(res);
|
||||
}
|
||||
|
||||
d = succeed("ugh").addCallback(deferredFailure).addErrback(catchStuff);
|
||||
d = d.addCallback(testEqCallback("ugh", "dependent deferred fail"));
|
||||
|
||||
/*
|
||||
Test double-calling, double-failing, etc.
|
||||
*/
|
||||
try {
|
||||
succeed(1).callback(2);
|
||||
neverHappen();
|
||||
} catch (e) {
|
||||
ok(e instanceof AlreadyCalledError, "double-call");
|
||||
}
|
||||
try {
|
||||
fail(1).errback(2);
|
||||
neverHappen();
|
||||
} catch (e) {
|
||||
ok(e instanceof AlreadyCalledError, "double-fail");
|
||||
}
|
||||
try {
|
||||
d = succeed(1);
|
||||
d.cancel();
|
||||
d = d.callback(2);
|
||||
ok(true, "swallowed one callback, no canceller");
|
||||
d.callback(3);
|
||||
neverHappen();
|
||||
} catch (e) {
|
||||
ok(e instanceof AlreadyCalledError, "swallow cancel");
|
||||
}
|
||||
try {
|
||||
d = new Deferred(cancelled);
|
||||
d.cancel();
|
||||
d = d.callback(1);
|
||||
neverHappen();
|
||||
} catch (e) {
|
||||
ok(e instanceof AlreadyCalledError, "non-swallowed cancel");
|
||||
}
|
||||
|
||||
/* Test incorrect Deferred usage */
|
||||
|
||||
d = new Deferred();
|
||||
try {
|
||||
d.callback(new Deferred());
|
||||
neverHappen();
|
||||
} catch (e) {
|
||||
ok (e instanceof Error, "deferred not allowed for callback");
|
||||
}
|
||||
d = new Deferred();
|
||||
try {
|
||||
d.errback(new Deferred());
|
||||
neverHappen();
|
||||
} catch (e) {
|
||||
ok (e instanceof Error, "deferred not allowed for errback");
|
||||
}
|
||||
|
||||
d = new Deferred();
|
||||
(new Deferred()).addCallback(function () { return d; }).callback(1);
|
||||
try {
|
||||
d.addCallback(function () {});
|
||||
neverHappen();
|
||||
} catch (e) {
|
||||
ok (e instanceof Error, "chained deferred not allowed to be re-used");
|
||||
}
|
||||
|
||||
/*
|
||||
evalJSONRequest test
|
||||
*/
|
||||
var fakeReq = {"responseText":'[1,2,3,4,"asdf",{"a":["b", "c"]}]'};
|
||||
var obj = [1,2,3,4,"asdf",{"a":["b", "c"]}];
|
||||
isDeeply(obj, evalJSONRequest(fakeReq), "evalJSONRequest");
|
||||
|
||||
try {
|
||||
MochiKit.Async.getXMLHttpRequest();
|
||||
ok(true, "getXMLHttpRequest");
|
||||
} catch (e) {
|
||||
ok(false, "no love from getXMLHttpRequest");
|
||||
}
|
||||
|
||||
var lock = new DeferredLock();
|
||||
var lst = [];
|
||||
var pushNumber = function (x) {
|
||||
return function (res) { lst.push(x); }
|
||||
};
|
||||
lock.acquire().addCallback(pushNumber(1));
|
||||
is( compare(lst, [1]), 0, "lock acquired" );
|
||||
lock.acquire().addCallback(pushNumber(2));
|
||||
is( compare(lst, [1]), 0, "lock waiting for release" );
|
||||
lock.acquire().addCallback(pushNumber(3));
|
||||
is( compare(lst, [1]), 0, "lock waiting for release" );
|
||||
lock.release();
|
||||
is( compare(lst, [1, 2]), 0, "lock passed on" );
|
||||
lock.release();
|
||||
is( compare(lst, [1, 2, 3]), 0, "lock passed on" );
|
||||
lock.release();
|
||||
try {
|
||||
lock.release();
|
||||
ok( false, "over-release didn't raise" );
|
||||
} catch (e) {
|
||||
ok( true, "over-release raised" );
|
||||
}
|
||||
lock.acquire().addCallback(pushNumber(1));
|
||||
is( compare(lst, [1, 2, 3, 1]), 0, "lock acquired" );
|
||||
lock.release();
|
||||
is( compare(lst, [1, 2, 3, 1]), 0, "lock released" );
|
||||
|
||||
var d = new Deferred();
|
||||
lst = [];
|
||||
d.addCallback(operator.add, 2);
|
||||
d.addBoth(operator.add, 4);
|
||||
d.addCallback(bind(lst.push, lst));
|
||||
d.callback(1);
|
||||
is( lst[0], 7, "auto-partial addCallback addBoth" );
|
||||
d.addCallback(function () { throw new Error(); });
|
||||
ebTest = function(a, b) {
|
||||
map(bind(lst.push, lst), arguments);
|
||||
};
|
||||
d.addErrback(ebTest, "foo");
|
||||
is( lst[1], "foo", "auto-partial errback" );
|
||||
is( lst.length, 3, "auto-partial errback" );
|
||||
|
||||
/*
|
||||
Test DeferredList
|
||||
*/
|
||||
|
||||
var callList = [new Deferred(), new Deferred(), new Deferred()];
|
||||
callList[0].addCallback(increment);
|
||||
callList[1].addCallback(increment);
|
||||
callList[2].addCallback(increment);
|
||||
var defList = new DeferredList(callList);
|
||||
ok(defList instanceof Deferred, "DeferredList looks like a Deferred");
|
||||
|
||||
callList[0].callback(3);
|
||||
callList[1].callback(5);
|
||||
callList[2].callback(4);
|
||||
|
||||
defList.addCallback(function (lst) {
|
||||
is( arrayEqual(lst, [[true, 4], [true, 6], [true, 5]]), 1,
|
||||
"deferredlist result ok" );
|
||||
});
|
||||
|
||||
/*
|
||||
Test fireOnOneCallback
|
||||
*/
|
||||
|
||||
var callList2 = [new Deferred(), new Deferred(), new Deferred()];
|
||||
callList2[0].addCallback(increment);
|
||||
callList2[1].addCallback(increment);
|
||||
callList2[2].addCallback(increment);
|
||||
var defList2 = new DeferredList(callList2, true);
|
||||
callList2[1].callback(5);
|
||||
callList2[0].callback(3);
|
||||
callList2[2].callback(4);
|
||||
|
||||
defList2.addCallback(function (lst) {
|
||||
is( arrayEqual(lst, [1, 6]), 1, "deferredlist fireOnOneCallback ok" );
|
||||
});
|
||||
|
||||
/*
|
||||
Test fireOnOneErrback
|
||||
*/
|
||||
|
||||
var callList3 = [new Deferred(), new Deferred(), new Deferred()];
|
||||
callList3[0].addCallback(increment);
|
||||
callList3[1].addCallback(throwStuff);
|
||||
callList3[2].addCallback(increment);
|
||||
var defList3 = new DeferredList(callList3, false, true);
|
||||
defList3.callback = neverHappen;
|
||||
callList3[0].callback(3);
|
||||
callList3[1].callback("foo");
|
||||
callList3[2].callback(4);
|
||||
|
||||
defList3.addErrback(function (err) {
|
||||
is( err.message, "foo", "deferredlist fireOnOneErrback ok" );
|
||||
});
|
||||
|
||||
/*
|
||||
Test consumeErrors
|
||||
*/
|
||||
|
||||
var callList4 = [new Deferred(), new Deferred(), new Deferred()];
|
||||
callList4[0].addCallback(increment);
|
||||
callList4[1].addCallback(throwStuff);
|
||||
callList4[2].addCallback(increment);
|
||||
var defList4 = new DeferredList(callList4, false, false, true);
|
||||
defList4.addErrback(neverHappen);
|
||||
callList4[1].addCallback(function (arg) {
|
||||
is(arg, null, "deferredlist consumeErrors ok" );
|
||||
});
|
||||
callList4[0].callback(3);
|
||||
callList4[1].callback("foo");
|
||||
callList4[2].callback(4);
|
||||
|
||||
/*
|
||||
Test gatherResults
|
||||
*/
|
||||
|
||||
var callList5 = [new Deferred(), new Deferred(), new Deferred()];
|
||||
callList5[0].addCallback(increment);
|
||||
callList5[1].addCallback(increment);
|
||||
callList5[2].addCallback(increment);
|
||||
var gatherRet = gatherResults(callList5);
|
||||
callList5[0].callback(3);
|
||||
callList5[1].callback(5);
|
||||
callList5[2].callback(4);
|
||||
|
||||
gatherRet.addCallback(function (lst) {
|
||||
is( arrayEqual(lst, [4, 6, 5]), 1,
|
||||
"gatherResults result ok" );
|
||||
});
|
||||
|
||||
/*
|
||||
Test maybeDeferred
|
||||
*/
|
||||
|
||||
var maybeDef = maybeDeferred(increment, 4);
|
||||
maybeDef.addCallback(testEqCallback(5, "maybeDeferred sync ok"));
|
||||
|
||||
var maybeDef2 = deferredIncrement(8);
|
||||
maybeDef2.addCallback(testEqCallback(9, "maybeDeferred async ok"));
|
||||
|
||||
ok( true, "synchronous test suite finished!");
|
||||
|
||||
var t = (new Date().getTime());
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
checkCallLater = function (originalTime) {
|
||||
is(originalTime, t, "argument passed in OK");
|
||||
is(arguments.length, 1, "argument count right");
|
||||
};
|
||||
var lock = new DeferredLock();
|
||||
withLock = function (msg) {
|
||||
var cb = partial.apply(null, extend(null, arguments, 1));
|
||||
var d = lock.acquire().addCallback(cb);
|
||||
d.addErrback(ok, false, msg);
|
||||
d.addCallback(function () {
|
||||
ok(true, msg);
|
||||
lock.release();
|
||||
});
|
||||
return d;
|
||||
}
|
||||
withLock("callLater", function () {
|
||||
return callLater(0.05, checkCallLater, t);
|
||||
});
|
||||
withLock("wait", function () {
|
||||
return wait(0.05, t).addCallback(checkCallLater);
|
||||
});
|
||||
withLock("loadJSONDoc", function () {
|
||||
var d = loadJSONDoc("test_MochiKit-Async.json");
|
||||
d.addCallback(function (doc) {
|
||||
is(doc.passed, true, "loadJSONDoc passed");
|
||||
});
|
||||
d.addErrback(function (doc) {
|
||||
ok(false, "loadJSONDoc failed");
|
||||
});
|
||||
return d;
|
||||
});
|
||||
lock.acquire().addCallback(function () {
|
||||
ok(true, "async suite finished");
|
||||
SimpleTest.finish();
|
||||
});
|
||||
|
||||
} catch (err) {
|
||||
|
||||
var s = "test suite failure!\n";
|
||||
var o = {};
|
||||
var k = null;
|
||||
for (k in err) {
|
||||
// ensure unique keys?!
|
||||
if (!o[k]) {
|
||||
s += k + ": " + err[k] + "\n";
|
||||
o[k] = err[k];
|
||||
}
|
||||
}
|
||||
ok ( false, s );
|
||||
SimpleTest.finish();
|
||||
|
||||
}
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -1 +0,0 @@
|
|||
{"passed": true}
|
|
@ -1,34 +0,0 @@
|
|||
<html>
|
||||
<head>
|
||||
<script type="text/javascript" src="/MochiKit/Base.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Iter.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/DOM.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Style.js"></script>
|
||||
<script type="text/javascript" src="../SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="../SimpleTest/test.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<pre id="test">
|
||||
<script type="text/javascript" src="test_Base.js"></script>
|
||||
<script type="text/javascript">
|
||||
try {
|
||||
tests.test_Base({ok:ok,is:is});
|
||||
ok(true, "test suite finished!");
|
||||
} catch (err) {
|
||||
var s = "test suite failure!\n";
|
||||
var o = {};
|
||||
var k = null;
|
||||
for (k in err) {
|
||||
// ensure unique keys?!
|
||||
if (!o[k]) {
|
||||
s += k + ": " + err[k] + "\n";
|
||||
o[k] = err[k];
|
||||
}
|
||||
}
|
||||
ok ( false, s );
|
||||
}
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -1,78 +0,0 @@
|
|||
<html>
|
||||
<head>
|
||||
<script type="text/javascript" src="/MochiKit/Base.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Iter.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/DOM.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Style.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Logging.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Color.js"></script>
|
||||
<script type="text/javascript" src="../SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="../SimpleTest/test.css">
|
||||
<style type="text/css">.redtext {color: red}</style>
|
||||
</head>
|
||||
<body>
|
||||
<div style="position:absolute; top: 0px; left:0px; width:0px; height:0px">
|
||||
<span style="color: red" id="c_direct"></span>
|
||||
<span class="redtext" id="c_indirect"></span>
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script type="text/javascript" src="test_Color.js"></script>
|
||||
<script type="text/javascript">
|
||||
try {
|
||||
|
||||
var t = {ok:ok, is:is};
|
||||
tests.test_Color({ok:ok, is:is});
|
||||
is(
|
||||
Color.fromText(SPAN()).toHexString(),
|
||||
"#000000",
|
||||
"fromText no style"
|
||||
);
|
||||
|
||||
is(
|
||||
Color.fromText("c_direct").toHexString(),
|
||||
Color.fromName("red").toHexString(),
|
||||
"fromText direct style"
|
||||
);
|
||||
|
||||
is(
|
||||
Color.fromText("c_indirect").toHexString(),
|
||||
Color.fromName("red").toHexString(),
|
||||
"fromText indirect style"
|
||||
);
|
||||
|
||||
is(
|
||||
Color.fromComputedStyle("c_direct", "color").toHexString(),
|
||||
Color.fromName("red").toHexString(),
|
||||
"fromComputedStyle direct style"
|
||||
);
|
||||
|
||||
is(
|
||||
Color.fromComputedStyle("c_indirect", "color").toHexString(),
|
||||
Color.fromName("red").toHexString(),
|
||||
"fromComputedStyle indirect style"
|
||||
);
|
||||
|
||||
|
||||
// Done!
|
||||
|
||||
ok( true, "test suite finished!");
|
||||
|
||||
} catch (err) {
|
||||
|
||||
var s = "test suite failure!\n";
|
||||
var o = {};
|
||||
var k = null;
|
||||
for (k in err) {
|
||||
// ensure unique keys?!
|
||||
if (!o[k]) {
|
||||
s += k + ": " + err[k] + "\n";
|
||||
o[k] = err[k];
|
||||
}
|
||||
}
|
||||
ok ( false, s );
|
||||
|
||||
}
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -1,290 +0,0 @@
|
|||
<html>
|
||||
<head>
|
||||
<script type="text/javascript" src="/MochiKit/MockDOM.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Base.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Iter.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/DOM.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Style.js"></script>
|
||||
<script type="text/javascript" src="../SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="../SimpleTest/test.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div style="display: none;">
|
||||
<form id="form_test">
|
||||
<select name="select">
|
||||
<option value="foo" selected="selected">foo</option>
|
||||
<option value="bar">bar</option>
|
||||
<option value="baz">baz</option>
|
||||
</select>
|
||||
<select name="selmultiple" multiple="multiple">
|
||||
<option value="bar" selected="selected">bar</option>
|
||||
<option value="baz" selected="selected">baz</option>
|
||||
<option value="foo">foo</option>
|
||||
</select>
|
||||
<input type="hidden" name="hidden" value="test" />
|
||||
<input type="radio" name="radio_off" value="1" />
|
||||
<input type="radio" name="radio_off" value="2" />
|
||||
<input type="radio" name="radio_off" value="3" />
|
||||
<input type="radio" name="radio_on" value="1" />
|
||||
<input type="radio" name="radio_on" value="2" checked="checked" />
|
||||
<input type="radio" name="radio_on" value="3" />
|
||||
</form>
|
||||
<form id="form_test2">
|
||||
<select name="selempty">
|
||||
<option value="" selected="selected">foo</option>
|
||||
</select>
|
||||
<select name="selempty2">
|
||||
<option selected="selected">foo</option>
|
||||
</select>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<pre id="test">
|
||||
<script type="text/javascript">
|
||||
try {
|
||||
|
||||
lst = [];
|
||||
o = {"blah": function () { lst.push("original"); }};
|
||||
addToCallStack(o, "blah", function () { lst.push("new"); }, true);
|
||||
addToCallStack(o, "blah", function () { lst.push("stuff"); }, true);
|
||||
is( typeof(o.blah), 'function', 'addToCallStack has a function' );
|
||||
is( o.blah.callStack.length, 3, 'callStack length 3' );
|
||||
o.blah();
|
||||
is( lst.join(" "), "original new stuff", "callStack in correct order" );
|
||||
is( o.blah, null, "set to null" );
|
||||
lst = [];
|
||||
o = {"blah": function () { lst.push("original"); }};
|
||||
addToCallStack(o, "blah",
|
||||
function () { lst.push("new"); return false;}, false);
|
||||
addToCallStack(o, "blah", function () { lst.push("stuff"); }, false);
|
||||
o.blah();
|
||||
is( lst.join(" "), "original new", "callStack in correct order (abort)" );
|
||||
o.blah();
|
||||
is( lst.join(" "), "original new original new", "callStack in correct order (again)" );
|
||||
|
||||
|
||||
is( escapeHTML("<>\"&bar"), "<>"&bar", "escapeHTML" ); // for emacs highlighting: "
|
||||
|
||||
var isDOM = function (value, expected, message) {
|
||||
is( escapeHTML(toHTML(value)), escapeHTML(expected), message );
|
||||
};
|
||||
|
||||
var d = document.createElement('span');
|
||||
updateNodeAttributes(d, {"foo": "bar", "baz": "wibble"});
|
||||
isDOM( d, '<span baz="wibble" foo="bar"/>', "updateNodeAttributes" );
|
||||
|
||||
var d = document.createElement('span');
|
||||
appendChildNodes(d, 'word up', [document.createElement('span')]);
|
||||
isDOM( d, '<span>word up<span/></span>', 'appendChildNodes' );
|
||||
|
||||
replaceChildNodes(d, 'Think Different');
|
||||
isDOM( d, '<span>Think Different</span>', 'replaceChildNodes' );
|
||||
|
||||
d = createDOM("span");
|
||||
isDOM( d, "<span/>", "createDOM empty" );
|
||||
|
||||
|
||||
d = createDOM("span", {"foo": "bar", "baz": "wibble"});
|
||||
isDOM( d, '<span baz="wibble" foo="bar"/>', "createDOM attributes" );
|
||||
|
||||
d = createDOM("span", {"foo": "bar", "baz": "wibble"}, "one", "two", "three");
|
||||
is( getNodeAttribute(d, 'foo'), "bar", "createDOM attribute" );
|
||||
is( getNodeAttribute(d, 'baz'), "wibble", "createDOM attribute" );
|
||||
is( scrapeText(d), "onetwothree", "createDOM contents" );
|
||||
|
||||
isDOM( d, '<span baz="wibble" foo="bar">onetwothree</span>', "createDOM contents" );
|
||||
|
||||
d = createDOM("span", null, function (f) {
|
||||
return this.nodeName.toLowerCase() + "hi" + f.nodeName.toLowerCase();});
|
||||
isDOM( d, '<span>spanhispan</span>', 'createDOM function call' );
|
||||
|
||||
d = createDOM("span", null, {msg: "hi", dom: function (f) {
|
||||
return f.nodeName.toLowerCase() + this.msg; }});
|
||||
isDOM( d, '<span>spanhi</span>', 'createDOM this.dom() call' );
|
||||
|
||||
d = createDOM("span", null, {msg: "hi", __dom__: function (f) {
|
||||
return f.nodeName.toLowerCase() + this.msg; }});
|
||||
isDOM( d, '<span>spanhi</span>', 'createDOM this.__dom__() call' );
|
||||
|
||||
d = createDOM("span", null, range(4));
|
||||
isDOM( d, '<span>0123</span>', 'createDOM iterable' );
|
||||
|
||||
|
||||
var d = {"taco": "pork"};
|
||||
registerDOMConverter("taco",
|
||||
function (o) { return !isUndefinedOrNull(o.taco); },
|
||||
function (o) { return "Goddamn, I like " + o.taco + " tacos"; }
|
||||
);
|
||||
d = createDOM("span", null, d);
|
||||
// not yet public API
|
||||
domConverters.unregister("taco");
|
||||
|
||||
isDOM( d, "<span>Goddamn, I like pork tacos</span>", "createDOM with custom converter" );
|
||||
|
||||
is(
|
||||
escapeHTML(toHTML(SPAN(null))),
|
||||
escapeHTML(toHTML(createDOM("span", null))),
|
||||
"createDOMFunc vs createDOM"
|
||||
);
|
||||
|
||||
is( scrapeText(d), "Goddamn, I like pork tacos", "scrape OK" );
|
||||
is( scrapeText(d, true).join(""), "Goddamn, I like pork tacos", "scrape Array OK" );
|
||||
|
||||
var st = DIV(null, STRONG(null, "d"), "oor ", STRONG(null, "f", SPAN(null, "r"), "a"), "me");
|
||||
is( scrapeText(st), "door frame", "scrape in-order" );
|
||||
|
||||
|
||||
ok( !isUndefinedOrNull(getElement("test")), "getElement might work" );
|
||||
ok( !isUndefinedOrNull($("test")), "$alias$$ CASH MONEY alias might work" );
|
||||
|
||||
d = createDOM("span", null, "one", "two");
|
||||
swapDOM(d.childNodes[0], document.createTextNode("uno"));
|
||||
isDOM( d, "<span>unotwo</span>", "swapDOM" );
|
||||
|
||||
is( scrapeText(d, true).join(" "), "uno two", "multi-node scrapeText" );
|
||||
/*
|
||||
|
||||
TODO:
|
||||
addLoadEvent (async test?)
|
||||
|
||||
*/
|
||||
|
||||
d = createDOM("span", {"class": "foo"});
|
||||
setElementClass(d, "bar baz");
|
||||
ok( d.className == "bar baz", "setElementClass");
|
||||
toggleElementClass("bar", d);
|
||||
ok( d.className == "baz", "toggleElementClass: " + d.className);
|
||||
toggleElementClass("bar", d);
|
||||
ok( hasElementClass(d, "baz", "bar"),
|
||||
"toggleElementClass 2: " + d.className);
|
||||
addElementClass(d, "bar");
|
||||
ok( hasElementClass(d, "baz", "bar"),
|
||||
"toggleElementClass 3: " + d.className);
|
||||
ok( addElementClass(d, "blah"), "addElementClass return");
|
||||
ok( hasElementClass(d, "baz", "bar", "blah"), "addElementClass action");
|
||||
ok( !hasElementClass(d, "not"), "hasElementClass single");
|
||||
ok( !hasElementClass(d, "baz", "not"), "hasElementClass multiple");
|
||||
ok( removeElementClass(d, "blah"), "removeElementClass" );
|
||||
ok( !removeElementClass(d, "blah"), "removeElementClass again" );
|
||||
ok( !hasElementClass(d, "blah"), "removeElementClass again (hasElement)" );
|
||||
removeElementClass(d, "baz");
|
||||
ok( !swapElementClass(d, "blah", "baz"), "false swapElementClass" );
|
||||
ok( !hasElementClass(d, "baz"), "false swapElementClass from" );
|
||||
ok( !hasElementClass(d, "blah"), "false swapElementClass to" );
|
||||
addElementClass(d, "blah");
|
||||
ok( swapElementClass(d, "blah", "baz"), "swapElementClass" );
|
||||
ok( hasElementClass(d, "baz"), "swapElementClass has toClass" );
|
||||
ok( !hasElementClass(d, "blah"), "swapElementClass !has fromClass" );
|
||||
ok( !swapElementClass(d, "blah", "baz"), "swapElementClass twice" );
|
||||
ok( hasElementClass(d, "baz"), "swapElementClass has toClass" );
|
||||
ok( !hasElementClass(d, "blah"), "swapElementClass !has fromClass" );
|
||||
|
||||
TABLE;
|
||||
TBODY;
|
||||
TR;
|
||||
var t = TABLE(null,
|
||||
TBODY({"class": "foo bar", "id":"tbody0"},
|
||||
TR({"class": "foo", "id":"tr0"}),
|
||||
TR({"class": "bar", "id":"tr1"})
|
||||
)
|
||||
);
|
||||
|
||||
var matchElements = getElementsByTagAndClassName;
|
||||
is(
|
||||
map(itemgetter("id"), matchElements(null, "foo", t)).join(" "),
|
||||
"tbody0 tr0",
|
||||
"getElementsByTagAndClassName found all tags with foo class"
|
||||
);
|
||||
is(
|
||||
map(itemgetter("id"), matchElements("tr", "foo", t)).join(" "),
|
||||
"tr0",
|
||||
"getElementsByTagAndClassName found all tr tags with foo class"
|
||||
);
|
||||
is(
|
||||
map(itemgetter("id"), matchElements("tr", null, t)).join(" "),
|
||||
"tr0 tr1",
|
||||
"getElementsByTagAndClassName found all tr tags"
|
||||
);
|
||||
|
||||
var oldDoc = document;
|
||||
var doc = MochiKit.MockDOM.createDocument();
|
||||
is( currentDocument(), document, "currentDocument() correct" );
|
||||
withDocument(doc, function () {
|
||||
ok( document != doc, "global doc unchanged" );
|
||||
is( currentDocument(), doc, "currentDocument() correct" );
|
||||
var h1 = H1();
|
||||
var span = SPAN(null, "foo", h1);
|
||||
appendChildNodes(currentDocument().body, span);
|
||||
});
|
||||
is( document, oldDoc, "doc restored" );
|
||||
is( doc.childNodes.length, 1, "doc has one child" );
|
||||
is( doc.body.childNodes.length, 1, "body has one child" );
|
||||
var sp = doc.body.childNodes[0];
|
||||
is( sp.nodeName, "SPAN", "only child is SPAN" );
|
||||
is( sp.childNodes.length, 2, "SPAN has two childNodes" );
|
||||
is( sp.childNodes[0].nodeValue, "foo", "first node is text" );
|
||||
is( sp.childNodes[1].nodeName, "H1", "second child is H1" );
|
||||
|
||||
is( currentDocument(), document, "currentDocument() correct" );
|
||||
try {
|
||||
withDocument(doc, function () {
|
||||
ok( document != doc, "global doc unchanged" );
|
||||
is( currentDocument(), doc, "currentDocument() correct" );
|
||||
throw new Error("foo");
|
||||
});
|
||||
ok( false, "didn't throw" );
|
||||
} catch (e) {
|
||||
ok( true, "threw" );
|
||||
}
|
||||
|
||||
doc = MochiKit.MockDOM.createDocument();
|
||||
var frm;
|
||||
withDocument(doc, function () {
|
||||
frm = FORM({name: "ignore"},
|
||||
INPUT({name:"foo", value:"bar"}),
|
||||
INPUT({name:"foo", value:"bar"}),
|
||||
INPUT({name:"baz", value:"bar"})
|
||||
);
|
||||
});
|
||||
var kv = formContents(frm);
|
||||
is( kv[0].join(","), "foo,foo,baz", "mock formContents names" );
|
||||
is( kv[1].join(","), "bar,bar,bar", "mock formContents values" );
|
||||
is( queryString(frm), "foo=bar&foo=bar&baz=bar", "mock queryString hook" );
|
||||
|
||||
var kv = formContents("form_test");
|
||||
is( kv[0].join(","), "select,selmultiple,selmultiple,hidden,radio_on", "formContents names" );
|
||||
is( kv[1].join(","), "foo,bar,baz,test,2", "formContents values" );
|
||||
is( queryString("form_test"), "select=foo&selmultiple=bar&selmultiple=baz&hidden=test&radio_on=2", "queryString hook" );
|
||||
kv = formContents("form_test2");
|
||||
is( kv[0].join(","), "selempty,selempty2", "formContents names empty option values" );
|
||||
is( kv[1].join(","), ",foo", "formContents empty option values" );
|
||||
is( queryString("form_test2"), "selempty=&selempty2=foo", "queryString empty option values" );
|
||||
|
||||
var d = DIV(null, SPAN(), " \n\t", SPAN(), "foo", SPAN(), " ");
|
||||
is( d.childNodes.length, 6, "removeEmptyNodes test conditions correct" );
|
||||
removeEmptyTextNodes(d);
|
||||
is( d.childNodes.length, 4, "removeEmptyNodes" );
|
||||
|
||||
ok( true, "test suite finished!");
|
||||
|
||||
|
||||
} catch (err) {
|
||||
|
||||
var s = "test suite failure!\n";
|
||||
var o = {};
|
||||
var k = null;
|
||||
for (k in err) {
|
||||
// ensure unique keys?!
|
||||
if (!o[k]) {
|
||||
s += k + ": " + err[k] + "\n";
|
||||
o[k] = err[k];
|
||||
}
|
||||
}
|
||||
ok ( false, s );
|
||||
|
||||
}
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -1,39 +0,0 @@
|
|||
<html>
|
||||
<head>
|
||||
<script type="text/javascript" src="/MochiKit/Base.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/DateTime.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Iter.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/DOM.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Style.js"></script>
|
||||
<script type="text/javascript" src="../SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="../SimpleTest/test.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<pre id="test">
|
||||
<script type="text/javascript" src="test_DateTime.js"></script>
|
||||
<script type="text/javascript">
|
||||
try {
|
||||
|
||||
tests.test_DateTime({ok:ok, is:is});
|
||||
ok( true, "test suite finished!");
|
||||
|
||||
} catch (err) {
|
||||
|
||||
var s = "test suite failure!\n";
|
||||
var o = {};
|
||||
var k = null;
|
||||
for (k in err) {
|
||||
// ensure unique keys?!
|
||||
if (!o[k]) {
|
||||
s += k + ": " + err[k] + "\n";
|
||||
o[k] = err[k];
|
||||
}
|
||||
}
|
||||
ok ( false, s );
|
||||
|
||||
}
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -1,55 +0,0 @@
|
|||
<html>
|
||||
<head>
|
||||
<script type="text/javascript" src="/MochiKit/Base.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Iter.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/DOM.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Style.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Color.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Signal.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/New.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Visual.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/DragAndDrop.js"></script>
|
||||
<script type="text/javascript" src="../SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="../SimpleTest/test.css">
|
||||
<style type="text/css">
|
||||
.drop-hover {
|
||||
}
|
||||
#drag1 {
|
||||
visibility: hidden;
|
||||
}
|
||||
#drop1 {
|
||||
visibility: hidden;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id='drag1'>drag1</div>
|
||||
<div id='drop1'>drop1</div>
|
||||
<pre id="test">
|
||||
<script type="text/javascript" src="test_DragAndDrop.js"></script>
|
||||
<script type="text/javascript">
|
||||
try {
|
||||
|
||||
// Counting the number of tests is really lame
|
||||
tests.test_DragAndDrop({ok:ok, is:is});
|
||||
ok( true, "test suite finished!");
|
||||
|
||||
} catch (err) {
|
||||
|
||||
var s = "test suite failure!\n";
|
||||
var o = {};
|
||||
var k = null;
|
||||
for (k in err) {
|
||||
// ensure unique keys?!
|
||||
if (!o[k]) {
|
||||
s += k + ": " + err[k] + "\n";
|
||||
o[k] = err[k];
|
||||
}
|
||||
}
|
||||
ok ( false, s );
|
||||
|
||||
}
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -1,39 +0,0 @@
|
|||
<html>
|
||||
<head>
|
||||
<script type="text/javascript" src="/MochiKit/Base.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Format.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Iter.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/DOM.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Style.js"></script>
|
||||
<script type="text/javascript" src="../SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="../SimpleTest/test.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<pre id="test">
|
||||
<script type="text/javascript" src="test_Format.js"></script>
|
||||
<script type="text/javascript">
|
||||
try {
|
||||
|
||||
tests.test_Format({ok:ok, is:is});
|
||||
ok( true, "test suite finished!");
|
||||
|
||||
} catch (err) {
|
||||
|
||||
var s = "test suite failure!\n";
|
||||
var o = {};
|
||||
var k = null;
|
||||
for (k in err) {
|
||||
// ensure unique keys?!
|
||||
if (!o[k]) {
|
||||
s += k + ": " + err[k] + "\n";
|
||||
o[k] = err[k];
|
||||
}
|
||||
}
|
||||
ok ( false, s );
|
||||
|
||||
}
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -1,38 +0,0 @@
|
|||
<html>
|
||||
<head>
|
||||
<script type="text/javascript" src="/MochiKit/Base.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Iter.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/DOM.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Style.js"></script>
|
||||
<script type="text/javascript" src="../SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="../SimpleTest/test.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<pre id="test">
|
||||
<script type="text/javascript" src="test_Iter.js"></script>
|
||||
<script type="text/javascript">
|
||||
try {
|
||||
|
||||
tests.test_Iter({ok:ok, is:is});
|
||||
ok( true, "test suite finished!");
|
||||
|
||||
} catch (err) {
|
||||
|
||||
var s = "test suite failure!\n";
|
||||
var o = {};
|
||||
var k = null;
|
||||
for (k in err) {
|
||||
// ensure unique keys?!
|
||||
if (!o[k]) {
|
||||
s += k + ": " + err[k] + "\n";
|
||||
o[k] = err[k];
|
||||
}
|
||||
}
|
||||
ok ( false, s );
|
||||
|
||||
}
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -1,32 +0,0 @@
|
|||
<html>
|
||||
<head>
|
||||
<script type="text/javascript" src="JSAN.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<pre id="test">
|
||||
<script type="text/javascript">
|
||||
// TODO: Make this a harness for the other tests
|
||||
JSAN.use('Test.More');
|
||||
JSAN.addRepository('..');
|
||||
var lst = [];
|
||||
plan({"tests": 1});
|
||||
var wc = {};
|
||||
wc['MochiKit'] = true;
|
||||
for (var k in window) { wc[k] = true; }
|
||||
for (var k in window) { wc[k] = true; }
|
||||
JSAN.use('MochiKit.MochiKit', []);
|
||||
for (var k in window) {
|
||||
if (!(k in wc) && !(k.charAt(0) == '[')) {
|
||||
lst.push(k);
|
||||
}
|
||||
}
|
||||
lst.sort();
|
||||
pollution = lst.join(" ");
|
||||
is(pollution, "compare reduce", "namespace pollution?");
|
||||
JSAN.use('MochiKit.MochiKit');
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -1,40 +0,0 @@
|
|||
<html>
|
||||
<head>
|
||||
<script type="text/javascript" src="/MochiKit/Base.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Logging.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Iter.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/DOM.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Style.js"></script>
|
||||
<script type="text/javascript" src="../SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="../SimpleTest/test.css">
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<pre id="test">
|
||||
<script type="text/javascript" src="test_Logging.js"></script>
|
||||
<script type="text/javascript">
|
||||
try {
|
||||
|
||||
tests.test_Logging({ok:ok, is:is});
|
||||
ok( true, "test suite finished!");
|
||||
|
||||
} catch (err) {
|
||||
|
||||
var s = "test suite failure!\n";
|
||||
var o = {};
|
||||
var k = null;
|
||||
for (k in err) {
|
||||
// ensure unique keys?!
|
||||
if (!o[k]) {
|
||||
s += k + ": " + err[k] + "\n";
|
||||
o[k] = err[k];
|
||||
}
|
||||
}
|
||||
ok ( false, s );
|
||||
|
||||
}
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -1,18 +0,0 @@
|
|||
<html>
|
||||
<head>
|
||||
<script type="text/javascript" src="/MochiKit/packed.js"></script>
|
||||
<script type="text/javascript" src="../SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="../SimpleTest/test.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<pre id="test">
|
||||
<script type="text/javascript">
|
||||
is( isUndefined(null), false, "null is not undefined" );
|
||||
is( isUndefined(""), false, "empty string is not undefined" );
|
||||
is( isUndefined(undefined), true, "undefined is undefined" );
|
||||
is( isUndefined({}.foo), true, "missing property is undefined" );
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -1,43 +0,0 @@
|
|||
<html>
|
||||
<head>
|
||||
<script type="text/javascript" src="/MochiKit/Base.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Iter.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/DOM.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Style.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Signal.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Logging.js"></script>
|
||||
<script type="text/javascript" src="../SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="../SimpleTest/test.css">
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
Please ignore this button: <input type="submit" id="submit" /><br />
|
||||
|
||||
<pre id="test">
|
||||
<script type="text/javascript" src="test_Signal.js"></script>
|
||||
<script type="text/javascript">
|
||||
try {
|
||||
|
||||
tests.test_Signal({ok:ok, is:is});
|
||||
ok(true, "test suite finished!");
|
||||
|
||||
} catch (err) {
|
||||
|
||||
var s = "test suite failure!\n";
|
||||
var o = {};
|
||||
var k = null;
|
||||
for (k in err) {
|
||||
// ensure unique keys?!
|
||||
if (!o[k]) {
|
||||
s += k + ": " + err[k] + "\n";
|
||||
o[k] = err[k];
|
||||
}
|
||||
}
|
||||
ok(false, s);
|
||||
|
||||
}
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -1,135 +0,0 @@
|
|||
<html>
|
||||
<head>
|
||||
<script type="text/javascript" src="/MochiKit/MockDOM.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Base.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Color.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Iter.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/DOM.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Style.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Logging.js"></script>
|
||||
<script type="text/javascript" src="../SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="../SimpleTest/test.css">
|
||||
</head>
|
||||
<body style="border: 0; margin: 0; padding: 0;">
|
||||
|
||||
<div id="styleTest" style="position: absolute; left: 400px; top: 100px; width: 100px; height: 100px; background: rgb(255, 0, 0); opacity: 0.5; filter: alpha(opacity=50);">TEST</div>
|
||||
|
||||
<pre id="test">
|
||||
<script type="text/javascript">
|
||||
|
||||
try {
|
||||
|
||||
// initial
|
||||
var pos = getElementPosition('styleTest');
|
||||
is(pos.x, 400, 'initial x position');
|
||||
is(pos.y, 100, 'initial y position');
|
||||
|
||||
// moved
|
||||
var newPos = new MochiKit.Style.Coordinates(500, 200);
|
||||
setElementPosition('styleTest', newPos);
|
||||
pos = getElementPosition('styleTest');
|
||||
is(pos.x, 500, 'updated x position');
|
||||
is(pos.y, 200, 'updated y position');
|
||||
|
||||
// moved with relativeTo
|
||||
anotherPos = new MochiKit.Style.Coordinates(100, 100);
|
||||
pos = getElementPosition('styleTest', anotherPos);
|
||||
is(pos.x, 400, 'updated x position (using relativeTo parameter)');
|
||||
is(pos.y, 100, 'updated y position (using relativeTo parameter)');
|
||||
|
||||
// Coordinates object
|
||||
pos = getElementPosition({x: 123, y: 321});
|
||||
is(pos.x, 123, 'passthrough x position');
|
||||
is(pos.y, 321, 'passthrough y position');
|
||||
|
||||
// Coordinates object with relativeTo
|
||||
pos = getElementPosition({x: 123, y: 321}, {x: 100, y: 50});
|
||||
is(pos.x, 23, 'passthrough x position (using relativeTo parameter)');
|
||||
is(pos.y, 271, 'passthrough y position (using relativeTo parameter)');
|
||||
|
||||
pos = getElementPosition('garbage');
|
||||
is(typeof(pos), 'undefined',
|
||||
'invalid element should return an undefined position');
|
||||
|
||||
// Only set one coordinate
|
||||
setElementPosition('styleTest', {'x': 300});
|
||||
pos = getElementPosition('styleTest');
|
||||
is(pos.x, 300, 'updated only x position');
|
||||
is(pos.y, 200, 'not updated y position');
|
||||
|
||||
var mc = MochiKit.Color.Color;
|
||||
var red = mc.fromString('rgb(255,0,0)');
|
||||
var color = null;
|
||||
|
||||
color = mc.fromString(computedStyle('styleTest', 'background-color'));
|
||||
is(color.asRGB, red.asRGB,
|
||||
'test computedStyle selector case');
|
||||
|
||||
color = mc.fromString(computedStyle('styleTest', 'backgroundColor'));
|
||||
is(color.asRGB, red.asRGB,
|
||||
'test computedStyle camel case');
|
||||
|
||||
is(computedStyle('styleTest', 'opacity'), '0.5',
|
||||
'test computedStyle opacity');
|
||||
|
||||
is(getOpacity('styleTest'), 0.5, 'test getOpacity');
|
||||
|
||||
setOpacity('styleTest', 0.2);
|
||||
is(getOpacity('styleTest'), 0.2, 'test setOpacity');
|
||||
|
||||
setOpacity('styleTest', 0);
|
||||
is(getOpacity('styleTest'), 0, 'test setOpacity');
|
||||
|
||||
setOpacity('styleTest', 1);
|
||||
var t = getOpacity('styleTest');
|
||||
ok(t > 0.999 && t <= 1, 'test setOpacity');
|
||||
|
||||
var dims = getElementDimensions('styleTest');
|
||||
is(dims.w, 100, 'getElementDimensions w ok');
|
||||
is(dims.h, 100, 'getElementDimensions h ok');
|
||||
|
||||
setElementDimensions('styleTest', {'w': 200, 'h': 150});
|
||||
dims = getElementDimensions('styleTest');
|
||||
is(dims.w, 200, 'setElementDimensions w ok');
|
||||
is(dims.h, 150, 'setElementDimensions h ok');
|
||||
|
||||
setElementDimensions('styleTest', {'w': 150});
|
||||
dims = getElementDimensions('styleTest');
|
||||
is(dims.w, 150, 'setElementDimensions only w ok');
|
||||
is(dims.h, 150, 'setElementDimensions h not updated ok');
|
||||
|
||||
hideElement('styleTest');
|
||||
dims = getElementDimensions('styleTest');
|
||||
is(dims.w, 150, 'getElementDimensions w ok when display none');
|
||||
is(dims.h, 150, 'getElementDimensions h ok when display none');
|
||||
|
||||
dims = getViewportDimensions();
|
||||
is(dims.w > 0, true, 'test getViewportDimensions w');
|
||||
is(dims.h > 0, true, 'test getViewportDimensions h');
|
||||
|
||||
pos = getViewportPosition();
|
||||
is(pos.x, 0, 'test getViewportPosition x');
|
||||
is(pos.y, 0, 'test getViewportPosition y');
|
||||
|
||||
ok( true, "test suite finished!");
|
||||
|
||||
|
||||
} catch (err) {
|
||||
|
||||
var s = "test suite failure!\n";
|
||||
var o = {};
|
||||
var k = null;
|
||||
for (k in err) {
|
||||
// ensure unique keys?!
|
||||
if (!o[k]) {
|
||||
s += k + ": " + err[k] + "\n";
|
||||
o[k] = err[k];
|
||||
}
|
||||
}
|
||||
ok ( false, s );
|
||||
|
||||
}
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -1,107 +0,0 @@
|
|||
<html>
|
||||
<head>
|
||||
<script type="text/javascript" src="/MochiKit/Base.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Iter.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/DOM.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Async.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Style.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Color.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Signal.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/New.js"></script>
|
||||
<script type="text/javascript" src="/MochiKit/Visual.js"></script>
|
||||
<script type="text/javascript" src="../SimpleTest/SimpleTest.js"></script>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="../SimpleTest/test.css">
|
||||
<style type="text/css">
|
||||
#elt1, #elt2, #ctn1 {
|
||||
visibility: hidden;
|
||||
}
|
||||
#ctn1 {
|
||||
height: 2px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id='elt1'>elt1</div>
|
||||
<div id='ctn1'><div id='elt2'></div></div>
|
||||
<pre id="test">
|
||||
<script type="text/javascript">
|
||||
try {
|
||||
var TestQueue = function () {
|
||||
};
|
||||
|
||||
TestQueue.prototype = new MochiKit.Visual.ScopedQueue();
|
||||
|
||||
MochiKit.Base.update(TestQueue.prototype, {
|
||||
startLoop: function (func, interval) {
|
||||
this.started = true;
|
||||
var timePos = new Date().getTime();
|
||||
while (this.started) {
|
||||
timePos += interval;
|
||||
MochiKit.Base.map(function (effect) {
|
||||
effect.loop(timePos);
|
||||
}, this.effects);
|
||||
}
|
||||
},
|
||||
stopLoop: function () {
|
||||
this.started = false;
|
||||
},
|
||||
});
|
||||
|
||||
var gl = new TestQueue();
|
||||
MochiKit.Visual.Queues.instances['global'] = gl;
|
||||
MochiKit.Visual.Queues.instances['elt1'] = gl;
|
||||
MochiKit.Visual.Queue = gl;
|
||||
|
||||
fade("elt1", {duration: 0, afterFinish: function () {
|
||||
is(getElement('elt1').style.display, 'none', "fade ok");
|
||||
}});
|
||||
|
||||
appear("elt1", {afterFinish: function () {
|
||||
is(getElement('elt1').style.display != 'none', true, "appear ok");
|
||||
}});
|
||||
|
||||
toggle("elt1", "size", {afterFinish: function () {
|
||||
is(getElement('elt1').style.display, 'none', "toggle size ok");
|
||||
}});
|
||||
|
||||
toggle("elt1", "size", {afterFinish: function () {
|
||||
is(getElement('elt1').style.display != 'none', true, "toggle size reverse ok");
|
||||
}});
|
||||
|
||||
switchOff("elt1", {afterFinish: function () {
|
||||
is(getElement('elt1').style.display, 'none', "switchOff ok");
|
||||
}});
|
||||
|
||||
slideUp("ctn1", {afterFinish: function () {
|
||||
is(getElement('elt1').style.display, 'none', "slideUp ok");
|
||||
}});
|
||||
|
||||
slideDown("ctn1", {afterFinish: function () {
|
||||
is(getElement('elt1').style.display, 'none', "slideDown ok");
|
||||
}});
|
||||
|
||||
ok(true, "visual suite finished");
|
||||
|
||||
} catch (err) {
|
||||
|
||||
var s = "test suite failure!\n";
|
||||
var o = {};
|
||||
var k = null;
|
||||
for (k in err) {
|
||||
// ensure unique keys?!
|
||||
if (!o[k]) {
|
||||
s += k + ": " + err[k] + "\n";
|
||||
o[k] = err[k];
|
||||
}
|
||||
}
|
||||
ok ( false, s );
|
||||
SimpleTest.finish();
|
||||
|
||||
}
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,380 +0,0 @@
|
|||
if (typeof(dojo) != 'undefined') { dojo.require('MochiKit.Signal'); }
|
||||
if (typeof(JSAN) != 'undefined') { JSAN.use('MochiKit.Signal'); }
|
||||
if (typeof(tests) == 'undefined') { tests = {}; }
|
||||
|
||||
tests.test_Signal = function (t) {
|
||||
|
||||
var submit = MochiKit.DOM.getElement('submit');
|
||||
var ident = null;
|
||||
var i = 0;
|
||||
var aFunction = function() {
|
||||
t.ok(this === submit, "aFunction should have 'this' as submit");
|
||||
i++;
|
||||
if (typeof(this.someVar) != 'undefined') {
|
||||
i += this.someVar;
|
||||
}
|
||||
};
|
||||
|
||||
var aObject = {};
|
||||
aObject.aMethod = function() {
|
||||
t.ok(this === aObject, "aMethod should have 'this' as aObject");
|
||||
i++;
|
||||
};
|
||||
|
||||
ident = connect('submit', 'onclick', aFunction);
|
||||
MochiKit.DOM.getElement('submit').click();
|
||||
t.is(i, 1, 'HTML onclick event can be connected to a function');
|
||||
|
||||
disconnect(ident);
|
||||
MochiKit.DOM.getElement('submit').click();
|
||||
t.is(i, 1, 'HTML onclick can be disconnected from a function');
|
||||
|
||||
var submit = MochiKit.DOM.getElement('submit');
|
||||
|
||||
ident = connect(submit, 'onclick', aFunction);
|
||||
submit.click();
|
||||
t.is(i, 2, 'Checking that a DOM element can be connected to a function');
|
||||
|
||||
disconnect(ident);
|
||||
submit.click();
|
||||
t.is(i, 2, '...and then disconnected');
|
||||
|
||||
if (MochiKit.DOM.getElement('submit').fireEvent ||
|
||||
(document.createEvent &&
|
||||
typeof(document.createEvent('MouseEvents').initMouseEvent) == 'function')) {
|
||||
|
||||
/*
|
||||
|
||||
Adapted from:
|
||||
http://www.devdaily.com/java/jwarehouse/jforum/tests/selenium/javascript/htmlutils.js.shtml
|
||||
License: Apache
|
||||
Copyright: Copyright 2004 ThoughtWorks, Inc
|
||||
|
||||
*/
|
||||
var triggerMouseEvent = function(element, eventType, canBubble) {
|
||||
element = MochiKit.DOM.getElement(element);
|
||||
canBubble = (typeof(canBubble) == 'undefined') ? true : canBubble;
|
||||
if (element.fireEvent) {
|
||||
var newEvt = document.createEventObject();
|
||||
newEvt.clientX = 1;
|
||||
newEvt.clientY = 1;
|
||||
newEvt.button = 1;
|
||||
element.fireEvent('on' + eventType, newEvt);
|
||||
} else if (document.createEvent && (typeof(document.createEvent('MouseEvents').initMouseEvent) == 'function')) {
|
||||
var evt = document.createEvent('MouseEvents');
|
||||
evt.initMouseEvent(eventType, canBubble, true, // event, bubbles, cancelable
|
||||
document.defaultView, 1, // view, # of clicks
|
||||
1, 0, 0, 0, // screenX, screenY, clientX, clientY
|
||||
false, false, false, false, // ctrlKey, altKey, shiftKey, metaKey
|
||||
0, null); // buttonCode, relatedTarget
|
||||
element.dispatchEvent(evt);
|
||||
}
|
||||
};
|
||||
|
||||
var eventTest = function(e) {
|
||||
i++;
|
||||
t.ok((typeof(e.event()) === 'object'), 'checking that event() is an object');
|
||||
t.ok((typeof(e.type()) === 'string'), 'checking that type() is a string');
|
||||
t.ok((e.target() === MochiKit.DOM.getElement('submit')), 'checking that target is "submit"');
|
||||
t.ok((typeof(e.modifier()) === 'object'), 'checking that modifier() is an object');
|
||||
t.ok(e.modifier().alt === false, 'checking that modifier().alt is defined, but false');
|
||||
t.ok(e.modifier().ctrl === false, 'checking that modifier().ctrl is defined, but false');
|
||||
t.ok(e.modifier().meta === false, 'checking that modifier().meta is defined, but false');
|
||||
t.ok(e.modifier().shift === false, 'checking that modifier().shift is defined, but false');
|
||||
t.ok((typeof(e.mouse()) === 'object'), 'checking that mouse() is an object');
|
||||
t.ok((typeof(e.mouse().button) === 'object'), 'checking that mouse().button is an object');
|
||||
t.ok(e.mouse().button.left === true, 'checking that mouse().button.left is true');
|
||||
t.ok(e.mouse().button.middle === false, 'checking that mouse().button.middle is false');
|
||||
t.ok(e.mouse().button.right === false, 'checking that mouse().button.right is false');
|
||||
t.ok((typeof(e.mouse().page) === 'object'), 'checking that mouse().page is an object');
|
||||
t.ok((typeof(e.mouse().page.x) === 'number'), 'checking that mouse().page.x is a number');
|
||||
t.ok((typeof(e.mouse().page.y) === 'number'), 'checking that mouse().page.y is a number');
|
||||
t.ok((typeof(e.mouse().client) === 'object'), 'checking that mouse().client is an object');
|
||||
t.ok((typeof(e.mouse().client.x) === 'number'), 'checking that mouse().client.x is a number');
|
||||
t.ok((typeof(e.mouse().client.y) === 'number'), 'checking that mouse().client.y is a number');
|
||||
|
||||
/* these should not be defined */
|
||||
t.ok((typeof(e.relatedTarget()) === 'undefined'), 'checking that relatedTarget() is undefined');
|
||||
t.ok((typeof(e.key()) === 'undefined'), 'checking that key() is undefined');
|
||||
};
|
||||
|
||||
|
||||
ident = connect('submit', 'onmousedown', eventTest);
|
||||
triggerMouseEvent('submit', 'mousedown', false);
|
||||
t.is(i, 3, 'Connecting an event to an HTML object and firing a synthetic event');
|
||||
|
||||
disconnect(ident);
|
||||
triggerMouseEvent('submit', 'mousedown', false);
|
||||
t.is(i, 3, 'Disconnecting an event to an HTML object and firing a synthetic event');
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// non-DOM tests
|
||||
|
||||
var hasNoSignals = {};
|
||||
|
||||
var hasSignals = {someVar: 1};
|
||||
|
||||
var i = 0;
|
||||
|
||||
var aFunction = function() {
|
||||
i++;
|
||||
if (typeof(this.someVar) != 'undefined') {
|
||||
i += this.someVar;
|
||||
}
|
||||
};
|
||||
|
||||
var bFunction = function(someArg, someOtherArg) {
|
||||
i += someArg + someOtherArg;
|
||||
};
|
||||
|
||||
|
||||
var aObject = {};
|
||||
aObject.aMethod = function() {
|
||||
i++;
|
||||
};
|
||||
|
||||
aObject.bMethod = function() {
|
||||
i++;
|
||||
};
|
||||
|
||||
var bObject = {};
|
||||
bObject.bMethod = function() {
|
||||
i++;
|
||||
};
|
||||
|
||||
|
||||
ident = connect(hasSignals, 'signalOne', aFunction);
|
||||
signal(hasSignals, 'signalOne');
|
||||
t.is(i, 2, 'Connecting function');
|
||||
i = 0;
|
||||
|
||||
disconnect(ident);
|
||||
signal(hasSignals, 'signalOne');
|
||||
t.is(i, 0, 'New style disconnecting function');
|
||||
i = 0;
|
||||
|
||||
|
||||
ident = connect(hasSignals, 'signalOne', bFunction);
|
||||
signal(hasSignals, 'signalOne', 1, 2);
|
||||
t.is(i, 3, 'Connecting function');
|
||||
i = 0;
|
||||
|
||||
disconnect(ident);
|
||||
signal(hasSignals, 'signalOne', 1, 2);
|
||||
t.is(i, 0, 'New style disconnecting function');
|
||||
i = 0;
|
||||
|
||||
|
||||
connect(hasSignals, 'signalOne', aFunction);
|
||||
signal(hasSignals, 'signalOne');
|
||||
t.is(i, 2, 'Connecting function');
|
||||
i = 0;
|
||||
|
||||
disconnect(hasSignals, 'signalOne', aFunction);
|
||||
signal(hasSignals, 'signalOne');
|
||||
t.is(i, 0, 'Old style disconnecting function');
|
||||
i = 0;
|
||||
|
||||
|
||||
ident = connect(hasSignals, 'signalOne', aObject, aObject.aMethod);
|
||||
signal(hasSignals, 'signalOne');
|
||||
t.is(i, 1, 'Connecting obj-function');
|
||||
i = 0;
|
||||
|
||||
disconnect(ident);
|
||||
signal(hasSignals, 'signalOne');
|
||||
t.is(i, 0, 'New style disconnecting obj-function');
|
||||
i = 0;
|
||||
|
||||
connect(hasSignals, 'signalOne', aObject, aObject.aMethod);
|
||||
signal(hasSignals, 'signalOne');
|
||||
t.is(i, 1, 'Connecting obj-function');
|
||||
i = 0;
|
||||
|
||||
disconnect(hasSignals, 'signalOne', aObject, aObject.aMethod);
|
||||
signal(hasSignals, 'signalOne');
|
||||
t.is(i, 0, 'Disconnecting obj-function');
|
||||
i = 0;
|
||||
|
||||
|
||||
ident = connect(hasSignals, 'signalTwo', aObject, 'aMethod');
|
||||
signal(hasSignals, 'signalTwo');
|
||||
t.is(i, 1, 'Connecting obj-string');
|
||||
i = 0;
|
||||
|
||||
disconnect(ident);
|
||||
signal(hasSignals, 'signalTwo');
|
||||
t.is(i, 0, 'New style disconnecting obj-string');
|
||||
i = 0;
|
||||
|
||||
|
||||
connect(hasSignals, 'signalTwo', aObject, 'aMethod');
|
||||
signal(hasSignals, 'signalTwo');
|
||||
t.is(i, 1, 'Connecting obj-string');
|
||||
i = 0;
|
||||
|
||||
disconnect(hasSignals, 'signalTwo', aObject, 'aMethod');
|
||||
signal(hasSignals, 'signalTwo');
|
||||
t.is(i, 0, 'Old style disconnecting obj-string');
|
||||
i = 0;
|
||||
|
||||
|
||||
var shouldRaise = function() { return undefined.attr; };
|
||||
|
||||
try {
|
||||
connect(hasSignals, 'signalOne', shouldRaise);
|
||||
signal(hasSignals, 'signalOne');
|
||||
t.ok(false, 'An exception was not raised');
|
||||
} catch (e) {
|
||||
t.ok(true, 'An exception was raised');
|
||||
}
|
||||
disconnect(hasSignals, 'signalOne', shouldRaise);
|
||||
t.is(i, 0, 'Exception raised, signal should not have fired');
|
||||
i = 0;
|
||||
|
||||
|
||||
connect(hasSignals, 'signalOne', aObject, 'aMethod');
|
||||
connect(hasSignals, 'signalOne', aObject, 'bMethod');
|
||||
signal(hasSignals, 'signalOne');
|
||||
t.is(i, 2, 'Connecting one signal to two slots in one object');
|
||||
i = 0;
|
||||
|
||||
disconnect(hasSignals, 'signalOne', aObject, 'aMethod');
|
||||
disconnect(hasSignals, 'signalOne', aObject, 'bMethod');
|
||||
signal(hasSignals, 'signalOne');
|
||||
t.is(i, 0, 'Disconnecting one signal from two slots in one object');
|
||||
i = 0;
|
||||
|
||||
|
||||
connect(hasSignals, 'signalOne', aObject, 'aMethod');
|
||||
connect(hasSignals, 'signalOne', bObject, 'bMethod');
|
||||
signal(hasSignals, 'signalOne');
|
||||
t.is(i, 2, 'Connecting one signal to two slots in two objects');
|
||||
i = 0;
|
||||
|
||||
disconnect(hasSignals, 'signalOne', aObject, 'aMethod');
|
||||
disconnect(hasSignals, 'signalOne', bObject, 'bMethod');
|
||||
signal(hasSignals, 'signalOne');
|
||||
t.is(i, 0, 'Disconnecting one signal from two slots in two objects');
|
||||
i = 0;
|
||||
|
||||
|
||||
try {
|
||||
connect(nothing, 'signalOne', aObject, 'aMethod');
|
||||
signal(nothing, 'signalOne');
|
||||
t.ok(false, 'An exception was not raised when connecting undefined');
|
||||
} catch (e) {
|
||||
t.ok(true, 'An exception was raised when connecting undefined');
|
||||
}
|
||||
|
||||
try {
|
||||
disconnect(nothing, 'signalOne', aObject, 'aMethod');
|
||||
t.ok(false, 'An exception was not raised when disconnecting undefined');
|
||||
} catch (e) {
|
||||
t.ok(true, 'An exception was raised when disconnecting undefined');
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
connect(hasSignals, 'signalOne', nothing);
|
||||
signal(hasSignals, 'signalOne');
|
||||
t.ok(false, 'An exception was not raised when connecting an undefined function');
|
||||
} catch (e) {
|
||||
t.ok(true, 'An exception was raised when connecting an undefined function');
|
||||
}
|
||||
|
||||
try {
|
||||
disconnect(hasSignals, 'signalOne', nothing);
|
||||
t.ok(false, 'An exception was not raised when disconnecting an undefined function');
|
||||
} catch (e) {
|
||||
t.ok(true, 'An exception was raised when disconnecting an undefined function');
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
connect(hasSignals, 'signalOne', aObject, aObject.nothing);
|
||||
signal(hasSignals, 'signalOne');
|
||||
t.ok(false, 'An exception was not raised when connecting an undefined method');
|
||||
} catch (e) {
|
||||
t.ok(true, 'An exception was raised when connecting an undefined method');
|
||||
}
|
||||
|
||||
try {
|
||||
connect(hasSignals, 'signalOne', aObject, 'nothing');
|
||||
signal(hasSignals, 'signalOne');
|
||||
t.ok(false, 'An exception was not raised when connecting an undefined method (as string)');
|
||||
} catch (e) {
|
||||
t.ok(true, 'An exception was raised when connecting an undefined method (as string)');
|
||||
}
|
||||
|
||||
t.is(i, 0, 'Signals should not have fired');
|
||||
|
||||
connect(hasSignals, 'signalOne', aFunction);
|
||||
connect(hasSignals, 'signalOne', aObject, 'aMethod');
|
||||
disconnectAll(hasSignals, 'signalOne');
|
||||
signal(hasSignals, 'signalOne');
|
||||
t.is(i, 0, 'disconnectAll works with single explicit signal');
|
||||
i = 0;
|
||||
|
||||
connect(hasSignals, 'signalOne', aFunction);
|
||||
connect(hasSignals, 'signalOne', aObject, 'aMethod');
|
||||
connect(hasSignals, 'signalTwo', aFunction);
|
||||
connect(hasSignals, 'signalTwo', aObject, 'aMethod');
|
||||
disconnectAll(hasSignals, 'signalOne');
|
||||
signal(hasSignals, 'signalOne');
|
||||
t.is(i, 0, 'disconnectAll works with single explicit signal');
|
||||
signal(hasSignals, 'signalTwo');
|
||||
t.is(i, 3, 'disconnectAll does not disconnect unrelated signals');
|
||||
i = 0;
|
||||
|
||||
connect(hasSignals, 'signalOne', aFunction);
|
||||
connect(hasSignals, 'signalOne', aObject, 'aMethod');
|
||||
connect(hasSignals, 'signalTwo', aFunction);
|
||||
connect(hasSignals, 'signalTwo', aObject, 'aMethod');
|
||||
disconnectAll(hasSignals, 'signalOne', 'signalTwo');
|
||||
signal(hasSignals, 'signalOne');
|
||||
signal(hasSignals, 'signalTwo');
|
||||
t.is(i, 0, 'disconnectAll works with two explicit signals');
|
||||
i = 0;
|
||||
|
||||
connect(hasSignals, 'signalOne', aFunction);
|
||||
connect(hasSignals, 'signalOne', aObject, 'aMethod');
|
||||
connect(hasSignals, 'signalTwo', aFunction);
|
||||
connect(hasSignals, 'signalTwo', aObject, 'aMethod');
|
||||
disconnectAll(hasSignals, ['signalOne', 'signalTwo']);
|
||||
signal(hasSignals, 'signalOne');
|
||||
signal(hasSignals, 'signalTwo');
|
||||
t.is(i, 0, 'disconnectAll works with two explicit signals as a list');
|
||||
i = 0;
|
||||
|
||||
connect(hasSignals, 'signalOne', aFunction);
|
||||
connect(hasSignals, 'signalOne', aObject, 'aMethod');
|
||||
connect(hasSignals, 'signalTwo', aFunction);
|
||||
connect(hasSignals, 'signalTwo', aObject, 'aMethod');
|
||||
disconnectAll(hasSignals);
|
||||
signal(hasSignals, 'signalOne');
|
||||
signal(hasSignals, 'signalTwo');
|
||||
t.is(i, 0, 'disconnectAll works with implicit signals');
|
||||
i = 0;
|
||||
|
||||
var toggle = function() {
|
||||
disconnectAll(hasSignals, 'signalOne');
|
||||
connect(hasSignals, 'signalOne', aFunction);
|
||||
i++;
|
||||
};
|
||||
|
||||
connect(hasSignals, 'signalOne', aFunction);
|
||||
connect(hasSignals, 'signalTwo', function() { i++; });
|
||||
connect(hasSignals, 'signalTwo', toggle);
|
||||
connect(hasSignals, 'signalTwo', function() { i++; }); // #147
|
||||
connect(hasSignals, 'signalTwo', function() { i++; });
|
||||
signal(hasSignals, 'signalTwo');
|
||||
t.is(i, 4, 'disconnectAll fired in a signal loop works');
|
||||
i = 0;
|
||||
disconnectAll('signalOne');
|
||||
disconnectAll('signalTwo');
|
||||
|
||||
};
|
Загрузка…
Ссылка в новой задаче