mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
move test reporting functions out of globals
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
|
||||
test("htmljs", function() {
|
||||
test("htmljs", function (test) {
|
||||
|
||||
// Make sure "style" works, which has to be special-cased for IE.
|
||||
assert.equal(DIV({style:"display:none"}).style.display, "none");
|
||||
test.equal(DIV({style:"display:none"}).style.display, "none");
|
||||
});
|
||||
@@ -1,9 +1,10 @@
|
||||
// XXX should probably move this into a testing helpers package so it
|
||||
// can be used by other tests
|
||||
|
||||
var ExpectationManager = function (onComplete) {
|
||||
var ExpectationManager = function (test, onComplete) {
|
||||
var self = this;
|
||||
|
||||
self.test = test;
|
||||
self.onComplete = onComplete;
|
||||
self.closed = false;
|
||||
self.dead = false;
|
||||
@@ -27,7 +28,7 @@ _.extend(ExpectationManager.prototype, {
|
||||
if (typeof expected === "function")
|
||||
expected.apply({}, arguments);
|
||||
else
|
||||
assert.equal(_.toArray(arguments), expected);
|
||||
self.test.equal(_.toArray(arguments), expected);
|
||||
|
||||
self.outstanding--;
|
||||
self._check_complete();
|
||||
@@ -57,7 +58,7 @@ _.extend(ExpectationManager.prototype, {
|
||||
var testAsyncMulti = function (name, funcs) {
|
||||
var timeout = 5000;
|
||||
|
||||
testAsync(name, function (onComplete) {
|
||||
testAsync(name, function (test, onComplete) {
|
||||
var remaining = _.clone(funcs);
|
||||
|
||||
var runNext = function () {
|
||||
@@ -65,7 +66,7 @@ var testAsyncMulti = function (name, funcs) {
|
||||
if (!func)
|
||||
onComplete();
|
||||
else {
|
||||
var em = new ExpectationManager(function () {
|
||||
var em = new ExpectationManager(test, function () {
|
||||
Meteor.clearTimeout(timer);
|
||||
runNext();
|
||||
});
|
||||
@@ -78,7 +79,7 @@ var testAsyncMulti = function (name, funcs) {
|
||||
}, timeout);
|
||||
|
||||
try {
|
||||
func(_.bind(em.expect, em));
|
||||
func(test, _.bind(em.expect, em));
|
||||
} catch (exception) {
|
||||
em.cancel();
|
||||
test.exception(exception);
|
||||
@@ -97,137 +98,137 @@ var testAsyncMulti = function (name, funcs) {
|
||||
/******************************************************************************/
|
||||
|
||||
// XXX should check error codes
|
||||
var failure = function (code, reason) {
|
||||
var failure = function (test, code, reason) {
|
||||
return function (error, result) {
|
||||
assert.equal(result, undefined);
|
||||
assert.isTrue(error && typeof error === "object");
|
||||
test.equal(result, undefined);
|
||||
test.isTrue(error && typeof error === "object");
|
||||
if (error && typeof error === "object") {
|
||||
code && assert.equal(error.error, code);
|
||||
reason && assert.equal(error.reason, reason);
|
||||
code && test.equal(error.error, code);
|
||||
reason && test.equal(error.reason, reason);
|
||||
// XXX should check that other keys aren't present.. should
|
||||
// probably use something like the Matcher we used to have
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
test("livedata - methods with colliding names", function () {
|
||||
test("livedata - methods with colliding names", function (test) {
|
||||
var x = LocalCollection.uuid();
|
||||
var m = {};
|
||||
m[x] = function () {};
|
||||
App.methods(m);
|
||||
|
||||
assert.throws(function () {
|
||||
test.throws(function () {
|
||||
App.methods(m);
|
||||
});
|
||||
});
|
||||
|
||||
testAsyncMulti("livedata - basic method invocation", [
|
||||
function (expect) {
|
||||
function (test, expect) {
|
||||
try {
|
||||
var ret = App.call("unknown method",
|
||||
expect(failure(404, "Method not found")));
|
||||
expect(failure(test, 404, "Method not found")));
|
||||
} catch (e) {
|
||||
// throws immediately on server, but still calls callback
|
||||
assert.isTrue(Meteor.is_server);
|
||||
test.isTrue(Meteor.is_server);
|
||||
return;
|
||||
}
|
||||
|
||||
// returns undefined on client, then calls callback
|
||||
assert.isTrue(Meteor.is_client);
|
||||
assert.equal(ret, undefined);
|
||||
test.isTrue(Meteor.is_client);
|
||||
test.equal(ret, undefined);
|
||||
},
|
||||
|
||||
function (expect) {
|
||||
function (test, expect) {
|
||||
var ret = App.call("echo", expect(undefined, []));
|
||||
assert.equal(ret, []);
|
||||
test.equal(ret, []);
|
||||
},
|
||||
|
||||
function (expect) {
|
||||
function (test, expect) {
|
||||
var ret = App.call("echo", 12, expect(undefined, [12]));
|
||||
assert.equal(ret, [12]);
|
||||
test.equal(ret, [12]);
|
||||
},
|
||||
|
||||
function (expect) {
|
||||
function (test, expect) {
|
||||
var ret = App.call("echo", 12, {x: 13}, expect(undefined, [12, {x: 13}]));
|
||||
assert.equal(ret, [12, {x: 13}]);
|
||||
test.equal(ret, [12, {x: 13}]);
|
||||
},
|
||||
|
||||
function (expect) {
|
||||
assert.throws(function () {
|
||||
function (test, expect) {
|
||||
test.throws(function () {
|
||||
var ret = App.call("exception", "both",
|
||||
expect(failure(500, "Internal server error")));
|
||||
expect(failure(test, 500, "Internal server error")));
|
||||
});
|
||||
},
|
||||
|
||||
function (expect) {
|
||||
function (test, expect) {
|
||||
try {
|
||||
var ret = App.call("exception", "server",
|
||||
expect(failure(500, "Internal server error")));
|
||||
expect(failure(test, 500, "Internal server error")));
|
||||
} catch (e) {
|
||||
assert.isTrue(Meteor.is_server);
|
||||
test.isTrue(Meteor.is_server);
|
||||
return;
|
||||
}
|
||||
|
||||
assert.isTrue(Meteor.is_client);
|
||||
assert.equal(ret, undefined);
|
||||
test.isTrue(Meteor.is_client);
|
||||
test.equal(ret, undefined);
|
||||
},
|
||||
|
||||
function (expect) {
|
||||
function (test, expect) {
|
||||
if (Meteor.is_client) {
|
||||
assert.throws(function () {
|
||||
test.throws(function () {
|
||||
var ret = App.call("exception", "client", expect(undefined, undefined));
|
||||
});
|
||||
} else {
|
||||
var ret = App.call("exception", "client", expect(undefined, undefined));
|
||||
assert.equal(ret, undefined);
|
||||
test.equal(ret, undefined);
|
||||
}
|
||||
}
|
||||
|
||||
]);
|
||||
|
||||
|
||||
var checkBalances = function (a, b) {
|
||||
var checkBalances = function (test, a, b) {
|
||||
var alice = Ledger.findOne({name: "alice", world: test.runId()});
|
||||
var bob = Ledger.findOne({name: "bob", world: test.runId()});
|
||||
assert.equal(alice.balance, a);
|
||||
assert.equal(bob.balance, b);
|
||||
test.equal(alice.balance, a);
|
||||
test.equal(bob.balance, b);
|
||||
}
|
||||
|
||||
// would be nice to have a database-aware test harness of some kind --
|
||||
// this is a big hack (and XXX pollutes the global test namespace)
|
||||
testAsyncMulti("livedata - compound methods", [
|
||||
function () {
|
||||
function (test) {
|
||||
if (Meteor.is_client)
|
||||
Meteor.subscribe("ledger", {world: test.runId()});
|
||||
Ledger.insert({name: "alice", balance: 100, world: test.runId()});
|
||||
Ledger.insert({name: "bob", balance: 50, world: test.runId()});
|
||||
},
|
||||
function (expect) {
|
||||
function (test, expect) {
|
||||
App.call('ledger/transfer', test.runId(), "alice", "bob", 10,
|
||||
expect(undefined, undefined));
|
||||
|
||||
checkBalances(90, 60);
|
||||
checkBalances(test, 90, 60);
|
||||
|
||||
var release = expect();
|
||||
App.onQuiesce(function () {
|
||||
checkBalances(90, 60);
|
||||
checkBalances(test, 90, 60);
|
||||
Meteor.defer(release);
|
||||
});
|
||||
},
|
||||
function (expect) {
|
||||
function (test, expect) {
|
||||
App.call('ledger/transfer', test.runId(), "alice", "bob", 100, true,
|
||||
expect(failure(409)));
|
||||
expect(failure(test, 409)));
|
||||
|
||||
if (Meteor.is_client)
|
||||
// client can fool itself by cheating, but only until the sync
|
||||
// finishes
|
||||
checkBalances(-10, 160);
|
||||
checkBalances(test, -10, 160);
|
||||
else
|
||||
checkBalances(90, 60);
|
||||
checkBalances(test, 90, 60);
|
||||
|
||||
var release = expect();
|
||||
App.onQuiesce(function () {
|
||||
checkBalances(90, 60);
|
||||
checkBalances(test, 90, 60);
|
||||
Meteor.defer(release);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@ var dump = function (what, tag) {
|
||||
};
|
||||
|
||||
// actual can be a range or a fragment
|
||||
var assert_dump = function (expected, actual, tag) {
|
||||
assert.equal(dump(actual), expected, "Tree doesn't match");
|
||||
var assert_dump = function (test, expected, actual, tag) {
|
||||
test.equal(dump(actual), expected, "Tree doesn't match");
|
||||
if (actual instanceof Meteor.ui._LiveRange)
|
||||
check_liverange_integrity(actual);
|
||||
else {
|
||||
@@ -88,198 +88,198 @@ var assert_contained = function (r, expected) {
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
test("liverange - single node", function () {
|
||||
test("liverange - single node", function (test) {
|
||||
var f = frag("<div id=1></div>");
|
||||
var r_a = create("a", f);
|
||||
assert.instanceOf(r_a, Meteor.ui._LiveRange);
|
||||
assert_dump("<a><1></1></a>", r_a);
|
||||
assert_dump("<a><1></1></a>", f);
|
||||
test.instanceOf(r_a, Meteor.ui._LiveRange);
|
||||
assert_dump(test, "<a><1></1></a>", r_a);
|
||||
assert_dump(test, "<a><1></1></a>", f);
|
||||
assert_contained(r_a, {range: r_a, children: []});
|
||||
|
||||
var r_b = create("b", f);
|
||||
assert_dump("<a><1></1></a>", r_a);
|
||||
assert_dump("<b><a><1></1></a></b>", r_b);
|
||||
assert_dump("<b><a><1></1></a></b>", f);
|
||||
assert_dump(test, "<a><1></1></a>", r_a);
|
||||
assert_dump(test, "<b><a><1></1></a></b>", r_b);
|
||||
assert_dump(test, "<b><a><1></1></a></b>", f);
|
||||
assert_contained(r_a, {range: r_a, children: []});
|
||||
assert_contained(r_b, {range: r_b, children: [{range: r_a, children: []}]});
|
||||
assert.equal(r_a.firstNode(), f.firstChild);
|
||||
assert.equal(r_a.lastNode(), f.lastChild);
|
||||
assert.equal(r_b.firstNode(), f.firstChild);
|
||||
assert.equal(r_b.lastNode(), f.lastChild);
|
||||
test.equal(r_a.firstNode(), f.firstChild);
|
||||
test.equal(r_a.lastNode(), f.lastChild);
|
||||
test.equal(r_b.firstNode(), f.firstChild);
|
||||
test.equal(r_b.lastNode(), f.lastChild);
|
||||
|
||||
var ret1 = r_a.replace_contents(frag("<div id=2></div>"));
|
||||
assert.equal(ret1.nodeType, 11 /* DocumentFragment */);
|
||||
assert_dump("<1></1>", ret1);
|
||||
assert_dump("<a><2></2></a>", r_a);
|
||||
assert_dump("<b><a><2></2></a></b>", r_b);
|
||||
assert_dump("<b><a><2></2></a></b>", f);
|
||||
test.equal(ret1.nodeType, 11 /* DocumentFragment */);
|
||||
assert_dump(test, "<1></1>", ret1);
|
||||
assert_dump(test, "<a><2></2></a>", r_a);
|
||||
assert_dump(test, "<b><a><2></2></a></b>", r_b);
|
||||
assert_dump(test, "<b><a><2></2></a></b>", f);
|
||||
|
||||
var ret2 = r_b.replace_contents(frag("<div id=3></div>"));
|
||||
assert_dump("<a><2></2></a>", ret2);
|
||||
assert_dump("<a><2></2></a>", r_a);
|
||||
assert_dump("<b><3></3></b>", r_b);
|
||||
assert_dump("<b><3></3></b>", f);
|
||||
assert_dump(test, "<a><2></2></a>", ret2);
|
||||
assert_dump(test, "<a><2></2></a>", r_a);
|
||||
assert_dump(test, "<b><3></3></b>", r_b);
|
||||
assert_dump(test, "<b><3></3></b>", f);
|
||||
|
||||
r_a.destroy();
|
||||
assert_dump("<2></2>", ret2);
|
||||
assert_dump(test, "<2></2>", ret2);
|
||||
|
||||
var r_c = create("c", f);
|
||||
var r_d = create("d", f);
|
||||
var r_e = create("e", f);
|
||||
assert_dump("<c><b><3></3></b></c>", r_c);
|
||||
assert_dump("<d><c><b><3></3></b></c></d>", r_d);
|
||||
assert_dump("<e><d><c><b><3></3></b></c></d></e>", r_e);
|
||||
assert_dump("<1></1>", ret1);
|
||||
assert_dump("<b><3></3></b>", r_b);
|
||||
assert_dump(test, "<c><b><3></3></b></c>", r_c);
|
||||
assert_dump(test, "<d><c><b><3></3></b></c></d>", r_d);
|
||||
assert_dump(test, "<e><d><c><b><3></3></b></c></d></e>", r_e);
|
||||
assert_dump(test, "<1></1>", ret1);
|
||||
assert_dump(test, "<b><3></3></b>", r_b);
|
||||
|
||||
r_d.destroy();
|
||||
assert_dump("<b><3></3></b>", r_b);
|
||||
assert_dump("<c><b><3></3></b></c>", r_c);
|
||||
assert_dump("<e><c><b><3></3></b></c></e>", r_e);
|
||||
assert_dump("<1></1>", ret1);
|
||||
assert_dump(test, "<b><3></3></b>", r_b);
|
||||
assert_dump(test, "<c><b><3></3></b></c>", r_c);
|
||||
assert_dump(test, "<e><c><b><3></3></b></c></e>", r_e);
|
||||
assert_dump(test, "<1></1>", ret1);
|
||||
|
||||
assert_contained(r_e,
|
||||
{range: r_e,
|
||||
children: [{range: r_c,
|
||||
children: [{range: r_b, children: []}]}]});
|
||||
|
||||
assert.equal(r_b.firstNode(), f.firstChild);
|
||||
assert.equal(r_b.lastNode(), f.lastChild);
|
||||
assert.equal(r_c.firstNode(), f.firstChild);
|
||||
assert.equal(r_c.lastNode(), f.lastChild);
|
||||
assert.equal(r_e.firstNode(), f.firstChild);
|
||||
assert.equal(r_e.lastNode(), f.lastChild);
|
||||
test.equal(r_b.firstNode(), f.firstChild);
|
||||
test.equal(r_b.lastNode(), f.lastChild);
|
||||
test.equal(r_c.firstNode(), f.firstChild);
|
||||
test.equal(r_c.lastNode(), f.lastChild);
|
||||
test.equal(r_e.firstNode(), f.firstChild);
|
||||
test.equal(r_e.lastNode(), f.lastChild);
|
||||
|
||||
r_b.destroy();
|
||||
assert_dump("<c><3></3></c>", r_c);
|
||||
assert_dump("<e><c><3></3></c></e>", r_e);
|
||||
assert_dump(test, "<c><3></3></c>", r_c);
|
||||
assert_dump(test, "<e><c><3></3></c></e>", r_e);
|
||||
|
||||
r_e.destroy();
|
||||
assert_dump("<c><3></3></c>", r_c);
|
||||
assert_dump(test, "<c><3></3></c>", r_c);
|
||||
});
|
||||
|
||||
test("liverange - multiple nodes", function () {
|
||||
test("liverange - multiple nodes", function (test) {
|
||||
var f = frag("<div id=1></div><div id=2></div><div id=3></div><div id=4></div><div id=5></div>");
|
||||
assert_dump("<1></1><2></2><3></3><4></4><5></5>", f);
|
||||
assert_dump(test, "<1></1><2></2><3></3><4></4><5></5>", f);
|
||||
|
||||
var r_a = create("a", f.childNodes[2], f.childNodes[3]);
|
||||
assert_dump("<1></1><2></2><a><3></3><4></4></a><5></5>", f);
|
||||
assert_dump("<a><3></3><4></4></a>", r_a);
|
||||
assert_dump(test, "<1></1><2></2><a><3></3><4></4></a><5></5>", f);
|
||||
assert_dump(test, "<a><3></3><4></4></a>", r_a);
|
||||
|
||||
var r_b = create("b", f.childNodes[3], f.childNodes[3]);
|
||||
assert_dump("<1></1><2></2><a><3></3><b><4></4></b></a><5></5>", f);
|
||||
assert_dump("<a><3></3><b><4></4></b></a>", r_a);
|
||||
assert_dump("<b><4></4></b>", r_b);
|
||||
assert_dump(test, "<1></1><2></2><a><3></3><b><4></4></b></a><5></5>", f);
|
||||
assert_dump(test, "<a><3></3><b><4></4></b></a>", r_a);
|
||||
assert_dump(test, "<b><4></4></b>", r_b);
|
||||
|
||||
var r_c = create("c", f.childNodes[2], f.childNodes[3]);
|
||||
assert_dump("<1></1><2></2><c><a><3></3><b><4></4></b></a></c><5></5>", f);
|
||||
assert_dump("<a><3></3><b><4></4></b></a>", r_a);
|
||||
assert_dump("<b><4></4></b>", r_b);
|
||||
assert_dump("<c><a><3></3><b><4></4></b></a></c>", r_c);
|
||||
assert_dump(test, "<1></1><2></2><c><a><3></3><b><4></4></b></a></c><5></5>", f);
|
||||
assert_dump(test, "<a><3></3><b><4></4></b></a>", r_a);
|
||||
assert_dump(test, "<b><4></4></b>", r_b);
|
||||
assert_dump(test, "<c><a><3></3><b><4></4></b></a></c>", r_c);
|
||||
|
||||
var r_d = create("d", f.childNodes[3], f.childNodes[3]);
|
||||
assert_dump("<1></1><2></2><c><a><3></3><d><b><4></4></b></d></a></c><5></5>", f);
|
||||
assert_dump("<a><3></3><d><b><4></4></b></d></a>", r_a);
|
||||
assert_dump("<b><4></4></b>", r_b);
|
||||
assert_dump("<c><a><3></3><d><b><4></4></b></d></a></c>", r_c);
|
||||
assert_dump("<d><b><4></4></b></d>", r_d);
|
||||
assert_dump(test, "<1></1><2></2><c><a><3></3><d><b><4></4></b></d></a></c><5></5>", f);
|
||||
assert_dump(test, "<a><3></3><d><b><4></4></b></d></a>", r_a);
|
||||
assert_dump(test, "<b><4></4></b>", r_b);
|
||||
assert_dump(test, "<c><a><3></3><d><b><4></4></b></d></a></c>", r_c);
|
||||
assert_dump(test, "<d><b><4></4></b></d>", r_d);
|
||||
|
||||
var r_e = create("e", f.childNodes[2], f.childNodes[2]);
|
||||
assert_dump("<1></1><2></2><c><a><e><3></3></e><d><b><4></4></b></d></a></c><5></5>", f);
|
||||
assert_dump("<a><e><3></3></e><d><b><4></4></b></d></a>", r_a);
|
||||
assert_dump("<b><4></4></b>", r_b);
|
||||
assert_dump("<c><a><e><3></3></e><d><b><4></4></b></d></a></c>", r_c);
|
||||
assert_dump("<d><b><4></4></b></d>", r_d);
|
||||
assert_dump("<e><3></3></e>", r_e);
|
||||
assert_dump(test, "<1></1><2></2><c><a><e><3></3></e><d><b><4></4></b></d></a></c><5></5>", f);
|
||||
assert_dump(test, "<a><e><3></3></e><d><b><4></4></b></d></a>", r_a);
|
||||
assert_dump(test, "<b><4></4></b>", r_b);
|
||||
assert_dump(test, "<c><a><e><3></3></e><d><b><4></4></b></d></a></c>", r_c);
|
||||
assert_dump(test, "<d><b><4></4></b></d>", r_d);
|
||||
assert_dump(test, "<e><3></3></e>", r_e);
|
||||
|
||||
var r_f = create("f", f.childNodes[2], f.childNodes[3]);
|
||||
assert_dump("<1></1><2></2><f><c><a><e><3></3></e><d><b><4></4></b></d></a></c></f><5></5>", f);
|
||||
assert_dump("<a><e><3></3></e><d><b><4></4></b></d></a>", r_a);
|
||||
assert_dump("<b><4></4></b>", r_b);
|
||||
assert_dump("<c><a><e><3></3></e><d><b><4></4></b></d></a></c>", r_c);
|
||||
assert_dump("<d><b><4></4></b></d>", r_d);
|
||||
assert_dump("<e><3></3></e>", r_e);
|
||||
assert_dump("<f><c><a><e><3></3></e><d><b><4></4></b></d></a></c></f>", r_f);
|
||||
assert_dump(test, "<1></1><2></2><f><c><a><e><3></3></e><d><b><4></4></b></d></a></c></f><5></5>", f);
|
||||
assert_dump(test, "<a><e><3></3></e><d><b><4></4></b></d></a>", r_a);
|
||||
assert_dump(test, "<b><4></4></b>", r_b);
|
||||
assert_dump(test, "<c><a><e><3></3></e><d><b><4></4></b></d></a></c>", r_c);
|
||||
assert_dump(test, "<d><b><4></4></b></d>", r_d);
|
||||
assert_dump(test, "<e><3></3></e>", r_e);
|
||||
assert_dump(test, "<f><c><a><e><3></3></e><d><b><4></4></b></d></a></c></f>", r_f);
|
||||
|
||||
assert_contained(r_f, {range: r_f, children: [{range: r_c, children: [{range: r_a, children: [{range: r_e, children: []},{range: r_d, children: [{range: r_b, children: []}]}]}]}]});
|
||||
|
||||
var r_g = create("g", f.childNodes[0], f.childNodes[3]);
|
||||
var r_h = create("h", f.childNodes[0], f.childNodes[3]);
|
||||
var r_i = create("i", f.childNodes[1], f.childNodes[3]);
|
||||
assert_dump("<h><g><1></1><i><2></2><f><c><a><e><3></3></e><d><b><4></4></b></d></a></c></f></i></g></h><5></5>", f);
|
||||
assert_dump("<a><e><3></3></e><d><b><4></4></b></d></a>", r_a);
|
||||
assert_dump("<b><4></4></b>", r_b);
|
||||
assert_dump("<c><a><e><3></3></e><d><b><4></4></b></d></a></c>", r_c);
|
||||
assert_dump("<d><b><4></4></b></d>", r_d);
|
||||
assert_dump("<e><3></3></e>", r_e);
|
||||
assert_dump("<f><c><a><e><3></3></e><d><b><4></4></b></d></a></c></f>", r_f);
|
||||
assert_dump("<g><1></1><i><2></2><f><c><a><e><3></3></e><d><b><4></4></b></d></a></c></f></i></g>", r_g);
|
||||
assert_dump("<h><g><1></1><i><2></2><f><c><a><e><3></3></e><d><b><4></4></b></d></a></c></f></i></g></h>", r_h);
|
||||
assert_dump("<i><2></2><f><c><a><e><3></3></e><d><b><4></4></b></d></a></c></f></i>", r_i);
|
||||
assert_dump(test, "<h><g><1></1><i><2></2><f><c><a><e><3></3></e><d><b><4></4></b></d></a></c></f></i></g></h><5></5>", f);
|
||||
assert_dump(test, "<a><e><3></3></e><d><b><4></4></b></d></a>", r_a);
|
||||
assert_dump(test, "<b><4></4></b>", r_b);
|
||||
assert_dump(test, "<c><a><e><3></3></e><d><b><4></4></b></d></a></c>", r_c);
|
||||
assert_dump(test, "<d><b><4></4></b></d>", r_d);
|
||||
assert_dump(test, "<e><3></3></e>", r_e);
|
||||
assert_dump(test, "<f><c><a><e><3></3></e><d><b><4></4></b></d></a></c></f>", r_f);
|
||||
assert_dump(test, "<g><1></1><i><2></2><f><c><a><e><3></3></e><d><b><4></4></b></d></a></c></f></i></g>", r_g);
|
||||
assert_dump(test, "<h><g><1></1><i><2></2><f><c><a><e><3></3></e><d><b><4></4></b></d></a></c></f></i></g></h>", r_h);
|
||||
assert_dump(test, "<i><2></2><f><c><a><e><3></3></e><d><b><4></4></b></d></a></c></f></i>", r_i);
|
||||
|
||||
var f2 = frag("<div id=6></div><div id=7></div><div id=8></div>");
|
||||
f2.childNodes[1].appendChild(f);
|
||||
assert_dump("", f);
|
||||
assert_dump("<6></6><7><h><g><1></1><i><2></2><f><c><a><e><3></3></e><d><b><4></4></b></d></a></c></f></i></g></h><5></5></7><8></8>", f2);
|
||||
assert_dump("<a><e><3></3></e><d><b><4></4></b></d></a>", r_a);
|
||||
assert_dump("<b><4></4></b>", r_b);
|
||||
assert_dump("<c><a><e><3></3></e><d><b><4></4></b></d></a></c>", r_c);
|
||||
assert_dump("<d><b><4></4></b></d>", r_d);
|
||||
assert_dump("<e><3></3></e>", r_e);
|
||||
assert_dump("<f><c><a><e><3></3></e><d><b><4></4></b></d></a></c></f>", r_f);
|
||||
assert_dump("<g><1></1><i><2></2><f><c><a><e><3></3></e><d><b><4></4></b></d></a></c></f></i></g>", r_g);
|
||||
assert_dump("<h><g><1></1><i><2></2><f><c><a><e><3></3></e><d><b><4></4></b></d></a></c></f></i></g></h>", r_h);
|
||||
assert_dump("<i><2></2><f><c><a><e><3></3></e><d><b><4></4></b></d></a></c></f></i>", r_i);
|
||||
assert_dump(test, "", f);
|
||||
assert_dump(test, "<6></6><7><h><g><1></1><i><2></2><f><c><a><e><3></3></e><d><b><4></4></b></d></a></c></f></i></g></h><5></5></7><8></8>", f2);
|
||||
assert_dump(test, "<a><e><3></3></e><d><b><4></4></b></d></a>", r_a);
|
||||
assert_dump(test, "<b><4></4></b>", r_b);
|
||||
assert_dump(test, "<c><a><e><3></3></e><d><b><4></4></b></d></a></c>", r_c);
|
||||
assert_dump(test, "<d><b><4></4></b></d>", r_d);
|
||||
assert_dump(test, "<e><3></3></e>", r_e);
|
||||
assert_dump(test, "<f><c><a><e><3></3></e><d><b><4></4></b></d></a></c></f>", r_f);
|
||||
assert_dump(test, "<g><1></1><i><2></2><f><c><a><e><3></3></e><d><b><4></4></b></d></a></c></f></i></g>", r_g);
|
||||
assert_dump(test, "<h><g><1></1><i><2></2><f><c><a><e><3></3></e><d><b><4></4></b></d></a></c></f></i></g></h>", r_h);
|
||||
assert_dump(test, "<i><2></2><f><c><a><e><3></3></e><d><b><4></4></b></d></a></c></f></i>", r_i);
|
||||
|
||||
var r_j = create("j", f2.childNodes[1], f2.childNodes[2]);
|
||||
var r_k = create("k", f2.childNodes[0], f2.childNodes[2]);
|
||||
var r_l = create("l", f2.childNodes[0], f2.childNodes[2]);
|
||||
assert_dump("<l><k><6></6><j><7><h><g><1></1><i><2></2><f><c><a><e><3></3></e><d><b><4></4></b></d></a></c></f></i></g></h><5></5></7><8></8></j></k></l>", f2);
|
||||
assert_dump(test, "<l><k><6></6><j><7><h><g><1></1><i><2></2><f><c><a><e><3></3></e><d><b><4></4></b></d></a></c></f></i></g></h><5></5></7><8></8></j></k></l>", f2);
|
||||
|
||||
var f3 = frag("<div id=9></div><div id=10></div><div id=11></div>");
|
||||
var r_m = create("m", f3.childNodes[0], f3.childNodes[2]);
|
||||
var r_n = create("n", f3.childNodes[0], f3.childNodes[0]);
|
||||
var r_o = create("o", f3.childNodes[0], f3.childNodes[0]);
|
||||
assert_dump("<m><o><n><9></9></n></o><10></10><11></11></m>", f3);
|
||||
assert_dump(test, "<m><o><n><9></9></n></o><10></10><11></11></m>", f3);
|
||||
|
||||
var ret1 = r_i.replace_contents(f3);
|
||||
assert_dump("", f3);
|
||||
assert_dump("<2></2><f><c><a><e><3></3></e><d><b><4></4></b></d></a></c></f>", ret1);
|
||||
assert_dump("<l><k><6></6><j><7><h><g><1></1><i><m><o><n><9></9></n></o><10></10><11></11></m></i></g></h><5></5></7><8></8></j></k></l>", f2);
|
||||
assert_dump("<a><e><3></3></e><d><b><4></4></b></d></a>", r_a);
|
||||
assert_dump("<b><4></4></b>", r_b);
|
||||
assert_dump("<c><a><e><3></3></e><d><b><4></4></b></d></a></c>", r_c);
|
||||
assert_dump("<d><b><4></4></b></d>", r_d);
|
||||
assert_dump("<e><3></3></e>", r_e);
|
||||
assert_dump("<f><c><a><e><3></3></e><d><b><4></4></b></d></a></c></f>", r_f);
|
||||
assert_dump("<g><1></1><i><m><o><n><9></9></n></o><10></10><11></11></m></i></g>", r_g);
|
||||
assert_dump("<h><g><1></1><i><m><o><n><9></9></n></o><10></10><11></11></m></i></g></h>", r_h);
|
||||
assert_dump("<i><m><o><n><9></9></n></o><10></10><11></11></m></i>",r_i);
|
||||
assert_dump("<j><7><h><g><1></1><i><m><o><n><9></9></n></o><10></10><11></11></m></i></g></h><5></5></7><8></8></j>", r_j);
|
||||
assert_dump("<k><6></6><j><7><h><g><1></1><i><m><o><n><9></9></n></o><10></10><11></11></m></i></g></h><5></5></7><8></8></j></k>", r_k);
|
||||
assert_dump("<l><k><6></6><j><7><h><g><1></1><i><m><o><n><9></9></n></o><10></10><11></11></m></i></g></h><5></5></7><8></8></j></k></l>", r_l);
|
||||
assert_dump(test, "", f3);
|
||||
assert_dump(test, "<2></2><f><c><a><e><3></3></e><d><b><4></4></b></d></a></c></f>", ret1);
|
||||
assert_dump(test, "<l><k><6></6><j><7><h><g><1></1><i><m><o><n><9></9></n></o><10></10><11></11></m></i></g></h><5></5></7><8></8></j></k></l>", f2);
|
||||
assert_dump(test, "<a><e><3></3></e><d><b><4></4></b></d></a>", r_a);
|
||||
assert_dump(test, "<b><4></4></b>", r_b);
|
||||
assert_dump(test, "<c><a><e><3></3></e><d><b><4></4></b></d></a></c>", r_c);
|
||||
assert_dump(test, "<d><b><4></4></b></d>", r_d);
|
||||
assert_dump(test, "<e><3></3></e>", r_e);
|
||||
assert_dump(test, "<f><c><a><e><3></3></e><d><b><4></4></b></d></a></c></f>", r_f);
|
||||
assert_dump(test, "<g><1></1><i><m><o><n><9></9></n></o><10></10><11></11></m></i></g>", r_g);
|
||||
assert_dump(test, "<h><g><1></1><i><m><o><n><9></9></n></o><10></10><11></11></m></i></g></h>", r_h);
|
||||
assert_dump(test, "<i><m><o><n><9></9></n></o><10></10><11></11></m></i>",r_i);
|
||||
assert_dump(test, "<j><7><h><g><1></1><i><m><o><n><9></9></n></o><10></10><11></11></m></i></g></h><5></5></7><8></8></j>", r_j);
|
||||
assert_dump(test, "<k><6></6><j><7><h><g><1></1><i><m><o><n><9></9></n></o><10></10><11></11></m></i></g></h><5></5></7><8></8></j></k>", r_k);
|
||||
assert_dump(test, "<l><k><6></6><j><7><h><g><1></1><i><m><o><n><9></9></n></o><10></10><11></11></m></i></g></h><5></5></7><8></8></j></k></l>", r_l);
|
||||
|
||||
r_h.destroy();
|
||||
assert_dump("<l><k><6></6><j><7><g><1></1><i><m><o><n><9></9></n></o><10></10><11></11></m></i></g><5></5></7><8></8></j></k></l>", f2);
|
||||
assert_dump(test, "<l><k><6></6><j><7><g><1></1><i><m><o><n><9></9></n></o><10></10><11></11></m></i></g><5></5></7><8></8></j></k></l>", f2);
|
||||
r_m.destroy();
|
||||
assert_dump("<l><k><6></6><j><7><g><1></1><i><o><n><9></9></n></o><10></10><11></11></i></g><5></5></7><8></8></j></k></l>", f2);
|
||||
assert_dump(test, "<l><k><6></6><j><7><g><1></1><i><o><n><9></9></n></o><10></10><11></11></i></g><5></5></7><8></8></j></k></l>", f2);
|
||||
r_n.destroy();
|
||||
assert_dump("<l><k><6></6><j><7><g><1></1><i><o><9></9></o><10></10><11></11></i></g><5></5></7><8></8></j></k></l>", f2);
|
||||
assert_dump(test, "<l><k><6></6><j><7><g><1></1><i><o><9></9></o><10></10><11></11></i></g><5></5></7><8></8></j></k></l>", f2);
|
||||
r_j.destroy();
|
||||
assert_dump("<l><k><6></6><7><g><1></1><i><o><9></9></o><10></10><11></11></i></g><5></5></7><8></8></k></l>", f2);
|
||||
assert_dump(test, "<l><k><6></6><7><g><1></1><i><o><9></9></o><10></10><11></11></i></g><5></5></7><8></8></k></l>", f2);
|
||||
r_o.destroy();
|
||||
assert_dump("<l><k><6></6><7><g><1></1><i><9></9><10></10><11></11></i></g><5></5></7><8></8></k></l>", f2);
|
||||
assert_dump(test, "<l><k><6></6><7><g><1></1><i><9></9><10></10><11></11></i></g><5></5></7><8></8></k></l>", f2);
|
||||
r_g.destroy();
|
||||
assert_dump("<l><k><6></6><7><1></1><i><9></9><10></10><11></11></i><5></5></7><8></8></k></l>", f2);
|
||||
assert_dump(test, "<l><k><6></6><7><1></1><i><9></9><10></10><11></11></i><5></5></7><8></8></k></l>", f2);
|
||||
r_l.destroy();
|
||||
assert_dump("<k><6></6><7><1></1><i><9></9><10></10><11></11></i><5></5></7><8></8></k>", f2);
|
||||
assert_dump(test, "<k><6></6><7><1></1><i><9></9><10></10><11></11></i><5></5></7><8></8></k>", f2);
|
||||
r_i.destroy();
|
||||
assert_dump("<k><6></6><7><1></1><9></9><10></10><11></11><5></5></7><8></8></k>", f2);
|
||||
assert_dump(test, "<k><6></6><7><1></1><9></9><10></10><11></11><5></5></7><8></8></k>", f2);
|
||||
r_k.destroy();
|
||||
assert_dump("<6></6><7><1></1><9></9><10></10><11></11><5></5></7><8></8>", f2);
|
||||
assert_dump(test, "<6></6><7><1></1><9></9><10></10><11></11><5></5></7><8></8>", f2);
|
||||
});
|
||||
|
||||
test("liverange - deep visit", function () {
|
||||
test("liverange - deep visit", function (test) {
|
||||
|
||||
var f = frag("<div id=1><div id=2><div id=3><div id=4><div id=5></div></div></div></div></div>");
|
||||
|
||||
@@ -294,71 +294,71 @@ test("liverange - deep visit", function () {
|
||||
var r_c = create("c", dive(f, 2), dive(f, 2));
|
||||
var r_d = create("d", f);
|
||||
|
||||
assert_dump("<d><1><c><2><b><3><4><a><5></5></a></4></3></b></2></c></1></d>",
|
||||
assert_dump(test, "<d><1><c><2><b><3><4><a><5></5></a></4></3></b></2></c></1></d>",
|
||||
f);
|
||||
|
||||
assert_contained(r_d,
|
||||
{range: r_d, children: [{range: r_c, children: [{range: r_b, children: [{range: r_a, children: []}]}]}]});
|
||||
});
|
||||
|
||||
test("liverange - create inner", function () {
|
||||
test("liverange - create inner", function (test) {
|
||||
// Basics
|
||||
|
||||
var f = frag("<div id=1></div><div id=2></div><div id=3></div><div id=4></div><div id=5></div>");
|
||||
assert_dump("<1></1><2></2><3></3><4></4><5></5>", f);
|
||||
assert_dump(test, "<1></1><2></2><3></3><4></4><5></5>", f);
|
||||
|
||||
var r_a = create("a", f.childNodes[2], f.childNodes[4], true);
|
||||
assert_dump("<1></1><2></2><a><3></3><4></4><5></5></a>", f);
|
||||
assert_dump(test, "<1></1><2></2><a><3></3><4></4><5></5></a>", f);
|
||||
|
||||
var r_b = create("b", f.childNodes[2], f.childNodes[4], true);
|
||||
assert_dump("<1></1><2></2><a><b><3></3><4></4><5></5></b></a>", f);
|
||||
assert_dump(test, "<1></1><2></2><a><b><3></3><4></4><5></5></b></a>", f);
|
||||
|
||||
var r_c = create("c", f.childNodes[2], f.childNodes[4]);
|
||||
assert_dump("<1></1><2></2><c><a><b><3></3><4></4><5></5></b></a></c>", f);
|
||||
assert_dump(test, "<1></1><2></2><c><a><b><3></3><4></4><5></5></b></a></c>", f);
|
||||
|
||||
// [{[a] [b]}]
|
||||
|
||||
var r_d = create("d", f.childNodes[0], f.childNodes[0]);
|
||||
var r_e = create("e", f.childNodes[1], f.childNodes[1]);
|
||||
var r_f = create("f", f.childNodes[0], f.childNodes[1]);
|
||||
assert_dump("<f><d><1></1></d><e><2></2></e></f><c><a><b><3></3><4></4><5></5></b></a></c>", f);
|
||||
assert_dump(test, "<f><d><1></1></d><e><2></2></e></f><c><a><b><3></3><4></4><5></5></b></a></c>", f);
|
||||
|
||||
var r_g = create("g", f.childNodes[0], f.childNodes[1], true);
|
||||
assert_dump("<f><g><d><1></1></d><e><2></2></e></g></f><c><a><b><3></3><4></4><5></5></b></a></c>", f);
|
||||
assert_dump(test, "<f><g><d><1></1></d><e><2></2></e></g></f><c><a><b><3></3><4></4><5></5></b></a></c>", f);
|
||||
|
||||
var r_h = create("h", f.childNodes[0], f.childNodes[1]);
|
||||
assert_dump("<h><f><g><d><1></1></d><e><2></2></e></g></f></h><c><a><b><3></3><4></4><5></5></b></a></c>", f);
|
||||
assert_dump(test, "<h><f><g><d><1></1></d><e><2></2></e></g></f></h><c><a><b><3></3><4></4><5></5></b></a></c>", f);
|
||||
|
||||
var r_i = create("i", f.childNodes[0], f.childNodes[1], true);
|
||||
assert_dump("<h><f><g><i><d><1></1></d><e><2></2></e></i></g></f></h><c><a><b><3></3><4></4><5></5></b></a></c>", f);
|
||||
assert_dump(test, "<h><f><g><i><d><1></1></d><e><2></2></e></i></g></f></h><c><a><b><3></3><4></4><5></5></b></a></c>", f);
|
||||
|
||||
var r_j = create("j", f.childNodes[0], f.childNodes[0], true);
|
||||
assert_dump("<h><f><g><i><d><j><1></1></j></d><e><2></2></e></i></g></f></h><c><a><b><3></3><4></4><5></5></b></a></c>", f);
|
||||
assert_dump(test, "<h><f><g><i><d><j><1></1></j></d><e><2></2></e></i></g></f></h><c><a><b><3></3><4></4><5></5></b></a></c>", f);
|
||||
|
||||
var r_k = create("k", f.childNodes[0], f.childNodes[0]);
|
||||
assert_dump("<h><f><g><i><k><d><j><1></1></j></d></k><e><2></2></e></i></g></f></h><c><a><b><3></3><4></4><5></5></b></a></c>", f);
|
||||
assert_dump(test, "<h><f><g><i><k><d><j><1></1></j></d></k><e><2></2></e></i></g></f></h><c><a><b><3></3><4></4><5></5></b></a></c>", f);
|
||||
|
||||
var r_l = create("l", f.childNodes[0], f.childNodes[1], true);
|
||||
assert_dump("<h><f><g><i><l><k><d><j><1></1></j></d></k><e><2></2></e></l></i></g></f></h><c><a><b><3></3><4></4><5></5></b></a></c>", f);
|
||||
assert_dump("<c><a><b><3></3><4></4><5></5></b></a></c>", r_c);
|
||||
assert_dump("<b><3></3><4></4><5></5></b>", r_b);
|
||||
assert_dump("<a><b><3></3><4></4><5></5></b></a>", r_a);
|
||||
assert_dump("<d><j><1></1></j></d>", r_d);
|
||||
assert_dump("<e><2></2></e>", r_e);
|
||||
assert_dump("<f><g><i><l><k><d><j><1></1></j></d></k><e><2></2></e></l></i></g></f>", r_f);
|
||||
assert_dump("<g><i><l><k><d><j><1></1></j></d></k><e><2></2></e></l></i></g>", r_g);
|
||||
assert_dump("<h><f><g><i><l><k><d><j><1></1></j></d></k><e><2></2></e></l></i></g></f></h>", r_h);
|
||||
assert_dump("<i><l><k><d><j><1></1></j></d></k><e><2></2></e></l></i>", r_i);
|
||||
assert_dump("<j><1></1></j>", r_j);
|
||||
assert_dump("<k><d><j><1></1></j></d></k>", r_k);
|
||||
assert_dump("<l><k><d><j><1></1></j></d></k><e><2></2></e></l>", r_l);
|
||||
assert_dump(test, "<h><f><g><i><l><k><d><j><1></1></j></d></k><e><2></2></e></l></i></g></f></h><c><a><b><3></3><4></4><5></5></b></a></c>", f);
|
||||
assert_dump(test, "<c><a><b><3></3><4></4><5></5></b></a></c>", r_c);
|
||||
assert_dump(test, "<b><3></3><4></4><5></5></b>", r_b);
|
||||
assert_dump(test, "<a><b><3></3><4></4><5></5></b></a>", r_a);
|
||||
assert_dump(test, "<d><j><1></1></j></d>", r_d);
|
||||
assert_dump(test, "<e><2></2></e>", r_e);
|
||||
assert_dump(test, "<f><g><i><l><k><d><j><1></1></j></d></k><e><2></2></e></l></i></g></f>", r_f);
|
||||
assert_dump(test, "<g><i><l><k><d><j><1></1></j></d></k><e><2></2></e></l></i></g>", r_g);
|
||||
assert_dump(test, "<h><f><g><i><l><k><d><j><1></1></j></d></k><e><2></2></e></l></i></g></f></h>", r_h);
|
||||
assert_dump(test, "<i><l><k><d><j><1></1></j></d></k><e><2></2></e></l></i>", r_i);
|
||||
assert_dump(test, "<j><1></1></j>", r_j);
|
||||
assert_dump(test, "<k><d><j><1></1></j></d></k>", r_k);
|
||||
assert_dump(test, "<l><k><d><j><1></1></j></d></k><e><2></2></e></l>", r_l);
|
||||
|
||||
// [{a b [c]}]
|
||||
f = frag("<div id=1></div><div id=2></div><div id=3></div>");
|
||||
r_a = create("a", f.childNodes[2], f.childNodes[2]);
|
||||
r_b = create("b", f.childNodes[0], f.childNodes[2]);
|
||||
r_c = create("c", f.childNodes[0], f.childNodes[2], true);
|
||||
assert_dump("<b><c><1></1><2></2><a><3></3></a></c></b>", f);
|
||||
assert_dump(test, "<b><c><1></1><2></2><a><3></3></a></c></b>", f);
|
||||
|
||||
// [{[a] b c}]
|
||||
|
||||
@@ -366,7 +366,7 @@ test("liverange - create inner", function () {
|
||||
r_a = create("a", f.childNodes[0], f.childNodes[0]);
|
||||
r_b = create("b", f.childNodes[0], f.childNodes[2]);
|
||||
r_c = create("c", f.childNodes[0], f.childNodes[2], true);
|
||||
assert_dump("<b><c><a><1></1></a><2></2><3></3></c></b>", f);
|
||||
assert_dump(test, "<b><c><a><1></1></a><2></2><3></3></c></b>", f);
|
||||
|
||||
// [{[a b] c}]
|
||||
|
||||
@@ -374,7 +374,7 @@ test("liverange - create inner", function () {
|
||||
r_a = create("a", f.childNodes[0], f.childNodes[1]);
|
||||
r_b = create("b", f.childNodes[0], f.childNodes[2]);
|
||||
r_c = create("c", f.childNodes[0], f.childNodes[2], true);
|
||||
assert_dump("<b><c><a><1></1><2></2></a><3></3></c></b>", f);
|
||||
assert_dump(test, "<b><c><a><1></1><2></2></a><3></3></c></b>", f);
|
||||
|
||||
// Cases where start and end have no common ranges, and so the
|
||||
// balance counter will have to run
|
||||
@@ -382,22 +382,22 @@ test("liverange - create inner", function () {
|
||||
f = frag("<div id=1></div><div id=2></div><div id=3></div>");
|
||||
r_a = create("a", f.childNodes[0], f.childNodes[0]);
|
||||
r_b = create("b", f.childNodes[0], f.childNodes[2]);
|
||||
assert_dump("<b><a><1></1></a><2></2><3></3></b>", f);
|
||||
assert_dump(test, "<b><a><1></1></a><2></2><3></3></b>", f);
|
||||
|
||||
f = frag("<div id=1></div><div id=2></div><div id=3></div>");
|
||||
r_a = create("a", f.childNodes[0], f.childNodes[2]);
|
||||
r_b = create("b", f.childNodes[0], f.childNodes[0]);
|
||||
assert_dump("<a><b><1></1></b><2></2><3></3></a>", f);
|
||||
assert_dump(test, "<a><b><1></1></b><2></2><3></3></a>", f);
|
||||
|
||||
f = frag("<div id=1></div><div id=2></div><div id=3></div>");
|
||||
r_a = create("a", f.childNodes[2], f.childNodes[2]);
|
||||
r_b = create("b", f.childNodes[0], f.childNodes[2]);
|
||||
assert_dump("<b><1></1><2></2><a><3></3></a></b>", f);
|
||||
assert_dump(test, "<b><1></1><2></2><a><3></3></a></b>", f);
|
||||
|
||||
f = frag("<div id=1></div><div id=2></div><div id=3></div>");
|
||||
r_a = create("a", f.childNodes[0], f.childNodes[2]);
|
||||
r_b = create("b", f.childNodes[2], f.childNodes[2]);
|
||||
assert_dump("<a><1></1><2></2><b><3></3></b></a>", f);
|
||||
assert_dump(test, "<a><1></1><2></2><b><3></3></b></a>", f);
|
||||
|
||||
f = frag("<div id=1></div><div id=2></div><div id=3></div>");
|
||||
r_a = create("a", f.childNodes[0], f.childNodes[0]);
|
||||
@@ -405,14 +405,14 @@ test("liverange - create inner", function () {
|
||||
r_c = create("c", f.childNodes[2], f.childNodes[2]);
|
||||
r_d = create("d", f.childNodes[2], f.childNodes[2]);
|
||||
r_e = create("e", f.childNodes[0], f.childNodes[2]);
|
||||
assert_dump("<e><b><a><1></1></a></b><2></2><d><c><3></3></c></d></e>", f);
|
||||
assert_dump(test, "<e><b><a><1></1></a></b><2></2><d><c><3></3></c></d></e>", f);
|
||||
|
||||
f = frag("<div id=1></div><div id=2></div><div id=3></div>");
|
||||
r_a = create("a", f.childNodes[0], f.childNodes[0]);
|
||||
r_b = create("b", f.childNodes[0], f.childNodes[0]);
|
||||
r_c = create("c", f.childNodes[2], f.childNodes[2]);
|
||||
r_e = create("e", f.childNodes[0], f.childNodes[2]);
|
||||
assert_dump("<e><b><a><1></1></a></b><2></2><c><3></3></c></e>", f);
|
||||
assert_dump(test, "<e><b><a><1></1></a></b><2></2><c><3></3></c></e>", f);
|
||||
|
||||
try_all_permutations(
|
||||
function () {
|
||||
@@ -424,7 +424,7 @@ test("liverange - create inner", function () {
|
||||
function () { create("c", f.childNodes[0], f.childNodes[2]); }
|
||||
],
|
||||
function () {
|
||||
assert_dump("<c><1></1><a><2></2><b><3></3></b></a></c>", f);
|
||||
assert_dump(test, "<c><1></1><a><2></2><b><3></3></b></a></c>", f);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -438,7 +438,7 @@ test("liverange - create inner", function () {
|
||||
function () { create("c", f.childNodes[0], f.childNodes[2]); }
|
||||
],
|
||||
function () {
|
||||
assert_dump("<c><b><a><1></1></a><2></2></b><3></3></c>", f);
|
||||
assert_dump(test, "<c><b><a><1></1></a><2></2></b><3></3></c>", f);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
@@ -30,13 +30,13 @@ var dump_frag = function (frag) {
|
||||
// if expected includes '~', it will be interpreted to mean "either
|
||||
// <!----> or nothing". this is useful because LiveRange is sometimes
|
||||
// forced to insert placeholder comments on older versions of IE.
|
||||
var assert_frag = function (expected, actual_frag) {
|
||||
var assert_frag = function (test, expected, actual_frag) {
|
||||
var expected1 = expected.replace(/~/g, "");
|
||||
var expected2 = expected.replace(/~/g, "<!---->");
|
||||
var actual = dump_frag(actual_frag);
|
||||
|
||||
if (actual !== expected1 && actual !== expected2)
|
||||
assert.equal(actual, expected, "Fragment doesn't match pattern");
|
||||
test.equal(actual, expected, "Fragment doesn't match pattern");
|
||||
|
||||
if (actual.firstChild) {
|
||||
/* XXX get Meteor.ui._tag in a cleaner way */
|
||||
@@ -66,58 +66,58 @@ var set_weather = function (where, what) {
|
||||
|
||||
// XXX SECTION: LiveUI
|
||||
|
||||
test("render - coercion", function () {
|
||||
test("render - coercion", function (test) {
|
||||
|
||||
assert_frag("<a></a>", Meteor.ui.render(function () {
|
||||
assert_frag(test, "<a></a>", Meteor.ui.render(function () {
|
||||
return DIV({id: "a"});
|
||||
}));
|
||||
|
||||
assert_frag("<b></b><c></c>", Meteor.ui.render(function () {
|
||||
assert_frag(test, "<b></b><c></c>", Meteor.ui.render(function () {
|
||||
var f = document.createDocumentFragment();
|
||||
f.appendChild(DIV({id: "b"}));
|
||||
f.appendChild(DIV({id: "c"}));
|
||||
return f;
|
||||
}));
|
||||
|
||||
assert_frag("<d></d><e></e>", Meteor.ui.render(function () {
|
||||
assert_frag(test, "<d></d><e></e>", Meteor.ui.render(function () {
|
||||
return [
|
||||
DIV({id: "d"}),
|
||||
DIV({id: "e"})
|
||||
];
|
||||
}));
|
||||
|
||||
assert_frag("<f></f><g></g>", Meteor.ui.render(function () {
|
||||
assert_frag(test, "<f></f><g></g>", Meteor.ui.render(function () {
|
||||
return $('<div id="f"></div><div id="g"></div>');
|
||||
}));
|
||||
|
||||
assert_frag("~hi~", Meteor.ui.render(function () {
|
||||
assert_frag(test, "~hi~", Meteor.ui.render(function () {
|
||||
return document.createTextNode("hi");
|
||||
}));
|
||||
|
||||
assert_frag("~igloo~", Meteor.ui.render(function () {
|
||||
assert_frag(test, "~igloo~", Meteor.ui.render(function () {
|
||||
return "igloo";
|
||||
}));
|
||||
|
||||
assert_frag("<!---->", Meteor.ui.render(function () {
|
||||
assert_frag(test, "<!---->", Meteor.ui.render(function () {
|
||||
return document.createComment('');
|
||||
}));
|
||||
});
|
||||
|
||||
test("render - updating and GC", function () {
|
||||
test("render - updating and GC", function (test) {
|
||||
set_weather("here", "cloudy");
|
||||
assert.length(_.keys(weather_listeners.here), 0);
|
||||
test.length(_.keys(weather_listeners.here), 0);
|
||||
var r = Meteor.ui.render(function () {
|
||||
return get_weather("here");
|
||||
});
|
||||
assert.length(_.keys(weather_listeners.here), 1);
|
||||
assert_frag("~cloudy~", r);
|
||||
test.length(_.keys(weather_listeners.here), 1);
|
||||
assert_frag(test, "~cloudy~", r);
|
||||
|
||||
set_weather("here", "icy");
|
||||
assert.length(_.keys(weather_listeners.here), 1);
|
||||
assert_frag("~cloudy~", r);
|
||||
test.length(_.keys(weather_listeners.here), 1);
|
||||
assert_frag(test, "~cloudy~", r);
|
||||
Meteor.flush(); // not onscreen -- gets GC'd
|
||||
assert.length(_.keys(weather_listeners.here), 0);
|
||||
assert_frag("~cloudy~", r);
|
||||
test.length(_.keys(weather_listeners.here), 0);
|
||||
assert_frag(test, "~cloudy~", r);
|
||||
|
||||
r = Meteor.ui.render(function () {
|
||||
return get_weather("here");
|
||||
@@ -126,36 +126,36 @@ test("render - updating and GC", function () {
|
||||
onscreen.appendChild(r);
|
||||
document.body.appendChild(onscreen);
|
||||
|
||||
assert_frag("~icy~", onscreen);
|
||||
assert.length(_.keys(weather_listeners.here), 1);
|
||||
assert_frag(test, "~icy~", onscreen);
|
||||
test.length(_.keys(weather_listeners.here), 1);
|
||||
|
||||
set_weather("here", "vanilla");
|
||||
assert.length(_.keys(weather_listeners.here), 1);
|
||||
assert_frag("~icy~", onscreen);
|
||||
test.length(_.keys(weather_listeners.here), 1);
|
||||
assert_frag(test, "~icy~", onscreen);
|
||||
Meteor.flush();
|
||||
assert.length(_.keys(weather_listeners.here), 1);
|
||||
assert_frag("~vanilla~", onscreen);
|
||||
test.length(_.keys(weather_listeners.here), 1);
|
||||
assert_frag(test, "~vanilla~", onscreen);
|
||||
|
||||
document.body.removeChild(onscreen);
|
||||
Meteor.flush();
|
||||
assert.length(_.keys(weather_listeners.here), 1);
|
||||
test.length(_.keys(weather_listeners.here), 1);
|
||||
|
||||
set_weather("here", "curious"); // safe from GC until flush
|
||||
document.body.appendChild(onscreen);
|
||||
Meteor.flush();
|
||||
assert.length(_.keys(weather_listeners.here), 1);
|
||||
assert_frag("~curious~", onscreen);
|
||||
test.length(_.keys(weather_listeners.here), 1);
|
||||
assert_frag(test, "~curious~", onscreen);
|
||||
|
||||
document.body.removeChild(onscreen);
|
||||
set_weather("here", "penguins");
|
||||
assert.length(_.keys(weather_listeners.here), 1);
|
||||
assert_frag("~curious~", onscreen);
|
||||
test.length(_.keys(weather_listeners.here), 1);
|
||||
assert_frag(test, "~curious~", onscreen);
|
||||
Meteor.flush();
|
||||
assert.length(_.keys(weather_listeners.here), 0);
|
||||
assert_frag("~curious~", onscreen);
|
||||
test.length(_.keys(weather_listeners.here), 0);
|
||||
assert_frag(test, "~curious~", onscreen);
|
||||
});
|
||||
|
||||
test("render - recursive", function () {
|
||||
test("render - recursive", function (test) {
|
||||
set_weather("there", "wet");
|
||||
|
||||
var outer_count = 0;
|
||||
@@ -172,51 +172,51 @@ test("render - recursive", function () {
|
||||
})
|
||||
]);
|
||||
document.body.appendChild(onscreen);
|
||||
assert_frag("<outer>penguins~wet~</outer>", onscreen);
|
||||
assert.equal(outer_count, 1);
|
||||
assert.equal(inner_count, 1);
|
||||
assert.length(_.keys(weather_listeners.here), 1);
|
||||
assert.length(_.keys(weather_listeners.there), 1);
|
||||
assert_frag(test, "<outer>penguins~wet~</outer>", onscreen);
|
||||
test.equal(outer_count, 1);
|
||||
test.equal(inner_count, 1);
|
||||
test.length(_.keys(weather_listeners.here), 1);
|
||||
test.length(_.keys(weather_listeners.there), 1);
|
||||
|
||||
set_weather("there", "dry");
|
||||
Meteor.flush();
|
||||
assert_frag("<outer>penguins~dry~</outer>", onscreen);
|
||||
assert.equal(outer_count, 1);
|
||||
assert.equal(inner_count, 2);
|
||||
assert.length(_.keys(weather_listeners.here), 1);
|
||||
assert.length(_.keys(weather_listeners.there), 1);
|
||||
assert_frag(test, "<outer>penguins~dry~</outer>", onscreen);
|
||||
test.equal(outer_count, 1);
|
||||
test.equal(inner_count, 2);
|
||||
test.length(_.keys(weather_listeners.here), 1);
|
||||
test.length(_.keys(weather_listeners.there), 1);
|
||||
|
||||
set_weather("here", "chocolate");
|
||||
Meteor.flush();
|
||||
assert_frag("<outer>chocolate~dry~</outer>", onscreen);
|
||||
assert.equal(outer_count, 2);
|
||||
assert.equal(inner_count, 3);
|
||||
assert.length(_.keys(weather_listeners.here), 1);
|
||||
assert.length(_.keys(weather_listeners.there), 1);
|
||||
assert_frag(test, "<outer>chocolate~dry~</outer>", onscreen);
|
||||
test.equal(outer_count, 2);
|
||||
test.equal(inner_count, 3);
|
||||
test.length(_.keys(weather_listeners.here), 1);
|
||||
test.length(_.keys(weather_listeners.there), 1);
|
||||
|
||||
document.body.removeChild(onscreen);
|
||||
set_weather("there", "melting"); // safe from GC until flush
|
||||
assert.length(_.keys(weather_listeners.here), 1);
|
||||
assert.length(_.keys(weather_listeners.there), 1);
|
||||
test.length(_.keys(weather_listeners.here), 1);
|
||||
test.length(_.keys(weather_listeners.there), 1);
|
||||
document.body.appendChild(onscreen);
|
||||
Meteor.flush();
|
||||
assert_frag("<outer>chocolate~melting~</outer>", onscreen);
|
||||
assert.equal(outer_count, 2);
|
||||
assert.equal(inner_count, 4);
|
||||
assert.length(_.keys(weather_listeners.here), 1);
|
||||
assert.length(_.keys(weather_listeners.there), 1);
|
||||
assert_frag(test, "<outer>chocolate~melting~</outer>", onscreen);
|
||||
test.equal(outer_count, 2);
|
||||
test.equal(inner_count, 4);
|
||||
test.length(_.keys(weather_listeners.here), 1);
|
||||
test.length(_.keys(weather_listeners.there), 1);
|
||||
|
||||
document.body.removeChild(onscreen);
|
||||
set_weather("here", "silent");
|
||||
Meteor.flush();
|
||||
assert_frag("<outer>chocolate~melting~</outer>", onscreen);
|
||||
assert.equal(outer_count, 2);
|
||||
assert.equal(inner_count, 4);
|
||||
assert.length(_.keys(weather_listeners.here), 0);
|
||||
assert.length(_.keys(weather_listeners.there), 0);
|
||||
assert_frag(test, "<outer>chocolate~melting~</outer>", onscreen);
|
||||
test.equal(outer_count, 2);
|
||||
test.equal(inner_count, 4);
|
||||
test.length(_.keys(weather_listeners.here), 0);
|
||||
test.length(_.keys(weather_listeners.there), 0);
|
||||
});
|
||||
|
||||
test("render - events", function () {
|
||||
test("render - events", function (test) {
|
||||
var evts = '';
|
||||
var onscreen = DIV({style: "display: none;"}, [
|
||||
Meteor.ui.render(function () {
|
||||
@@ -246,27 +246,27 @@ test("render - events", function () {
|
||||
];
|
||||
}, {
|
||||
"click": function (e) {
|
||||
assert.equal(12, this.x);
|
||||
test.equal(12, this.x);
|
||||
evts += "a" + e.originalEvent.data;
|
||||
},
|
||||
"mousedown #outer": function (e) {
|
||||
assert.equal(12, this.x);
|
||||
test.equal(12, this.x);
|
||||
evts += "b" + e.originalEvent.data;
|
||||
},
|
||||
"mouseup #inner1": function (e) {
|
||||
assert.equal(12, this.x);
|
||||
test.equal(12, this.x);
|
||||
evts += "c1" + e.originalEvent.data;
|
||||
},
|
||||
"mouseup #inner2": function (e) {
|
||||
assert.equal(12, this.x);
|
||||
test.equal(12, this.x);
|
||||
evts += "c2" + e.originalEvent.data;
|
||||
},
|
||||
"keypress, keydown #inner2": function (e) {
|
||||
assert.equal(12, this.x);
|
||||
test.equal(12, this.x);
|
||||
evts += "de" + e.originalEvent.data;
|
||||
},
|
||||
"keyup #wrapper": function (e) {
|
||||
assert.equal(12, this.x);
|
||||
test.equal(12, this.x);
|
||||
evts += "f" + e.originalEvent.data;
|
||||
}
|
||||
}, {x : 12})
|
||||
@@ -291,7 +291,7 @@ test("render - events", function () {
|
||||
var test_event = function (expected, id, event, args) {
|
||||
evts = "";
|
||||
simulate($('#' + id), event, args);
|
||||
assert.equal(evts, expected);
|
||||
test.equal(evts, expected);
|
||||
}
|
||||
|
||||
var main_event_tests = function () {
|
||||
@@ -346,7 +346,7 @@ test("render - events", function () {
|
||||
document.body.removeChild(onscreen);
|
||||
});
|
||||
|
||||
test("renderList - basics", function () {
|
||||
test("renderList - basics", function (test) {
|
||||
var c = new LocalCollection();
|
||||
|
||||
var r = Meteor.ui.renderList(c.find({}, {sort: ['id']}), {
|
||||
@@ -358,20 +358,20 @@ test("renderList - basics", function () {
|
||||
}
|
||||
});
|
||||
|
||||
assert_frag("<empty></empty>", r);
|
||||
assert_frag(test, "<empty></empty>", r);
|
||||
|
||||
// Insertion
|
||||
|
||||
c.insert({id: "D"});
|
||||
assert_frag("<D></D>", r);
|
||||
assert_frag(test, "<D></D>", r);
|
||||
c.insert({id: "E"});
|
||||
assert_frag("<D></D><E></E>", r);
|
||||
assert_frag(test, "<D></D><E></E>", r);
|
||||
c.insert({id: "F"});
|
||||
assert_frag("<D></D><E></E><F></F>", r);
|
||||
assert_frag(test, "<D></D><E></E><F></F>", r);
|
||||
c.insert({id: "C"});
|
||||
assert_frag("<C></C><D></D><E></E><F></F>", r);
|
||||
assert_frag(test, "<C></C><D></D><E></E><F></F>", r);
|
||||
c.insert({id: "D2"});
|
||||
assert_frag("<C></C><D></D><D2></D2><E></E><F></F>", r);
|
||||
assert_frag(test, "<C></C><D></D><D2></D2><E></E><F></F>", r);
|
||||
|
||||
// this should hit all of the edge cases in insert_before
|
||||
var parts;
|
||||
@@ -379,13 +379,13 @@ test("renderList - basics", function () {
|
||||
c.insert({id: id});
|
||||
parts.push("<" + id + "></" + id + ">");
|
||||
parts.sort();
|
||||
assert_frag(parts.join(''), r);
|
||||
assert_frag(test, parts.join(''), r);
|
||||
};
|
||||
try_all_permutations(
|
||||
function () {
|
||||
c.remove();
|
||||
parts = [];
|
||||
assert_frag("<empty></empty>", r);
|
||||
assert_frag(test, "<empty></empty>", r);
|
||||
},
|
||||
[
|
||||
_.bind(do_insert, null, "D"),
|
||||
@@ -394,7 +394,7 @@ test("renderList - basics", function () {
|
||||
_.bind(do_insert, null, "G")
|
||||
],
|
||||
function () {
|
||||
assert_frag("<D></D><E></E><F></F><G></G>", r);
|
||||
assert_frag(test, "<D></D><E></E><F></F><G></G>", r);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -405,14 +405,14 @@ test("renderList - basics", function () {
|
||||
// Change without move
|
||||
|
||||
c.update({id: "E"}, {$set: {id: "E2"}});
|
||||
assert_frag("<C></C><D></D><D2></D2><E2></E2><F></F>", r);
|
||||
assert_frag(test, "<C></C><D></D><D2></D2><E2></E2><F></F>", r);
|
||||
c.update({id: "F"}, {$set: {id: "F2"}});
|
||||
assert_frag("<C></C><D></D><D2></D2><E2></E2><F2></F2>", r);
|
||||
assert_frag(test, "<C></C><D></D><D2></D2><E2></E2><F2></F2>", r);
|
||||
c.update({id: "C"}, {$set: {id: "C2"}});
|
||||
assert_frag("<C2></C2><D></D><D2></D2><E2></E2><F2></F2>", r);
|
||||
assert_frag(test, "<C2></C2><D></D><D2></D2><E2></E2><F2></F2>", r);
|
||||
});
|
||||
|
||||
test("renderList - removal", function () {
|
||||
test("renderList - removal", function (test) {
|
||||
var c = new LocalCollection();
|
||||
// (test is written in this weird way for historical reasons; feel
|
||||
// free to refactor)
|
||||
@@ -437,21 +437,21 @@ test("renderList - removal", function () {
|
||||
});
|
||||
|
||||
c.remove({id: "D2"});
|
||||
assert_frag("<C2></C2><D></D><E2></E2><F2></F2>", r);
|
||||
assert_frag(test, "<C2></C2><D></D><E2></E2><F2></F2>", r);
|
||||
c.remove({id: "F2"});
|
||||
assert_frag("<C2></C2><D></D><E2></E2>", r);
|
||||
assert_frag(test, "<C2></C2><D></D><E2></E2>", r);
|
||||
c.remove({id: "C2"});
|
||||
assert_frag("<D></D><E2></E2>", r);
|
||||
assert_frag(test, "<D></D><E2></E2>", r);
|
||||
c.remove({id: "E2"});
|
||||
assert_frag("<D></D>", r);
|
||||
assert_frag(test, "<D></D>", r);
|
||||
c.remove({id: "D"});
|
||||
assert_frag("<empty></empty>", r);
|
||||
assert_frag(test, "<empty></empty>", r);
|
||||
|
||||
// this should hit all of the edge cases in extract
|
||||
var do_remove = function (id) {
|
||||
c.remove({id: id});
|
||||
delete parts["<" + id + "></" + id + ">"];
|
||||
assert_frag(_.keys(parts).sort().join('') || '<empty></empty>', r);
|
||||
assert_frag(test, _.keys(parts).sort().join('') || '<empty></empty>', r);
|
||||
};
|
||||
try_all_permutations(
|
||||
function () {
|
||||
@@ -460,7 +460,7 @@ test("renderList - removal", function () {
|
||||
c.insert({id: id});
|
||||
parts["<" + id + "></" + id + ">"] = true;
|
||||
});
|
||||
assert_frag("<D></D><E></E><F></F><G></G>", r);
|
||||
assert_frag(test, "<D></D><E></E><F></F><G></G>", r);
|
||||
},
|
||||
[
|
||||
_.bind(do_remove, null, "D"),
|
||||
@@ -469,12 +469,12 @@ test("renderList - removal", function () {
|
||||
_.bind(do_remove, null, "G")
|
||||
],
|
||||
function () {
|
||||
assert_frag("<empty></empty>", r);
|
||||
assert_frag(test, "<empty></empty>", r);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
test("renderList - default render empty", function () {
|
||||
test("renderList - default render empty", function (test) {
|
||||
var c = new LocalCollection();
|
||||
|
||||
var r = Meteor.ui.renderList(c.find({}, {sort: ['id']}), {
|
||||
@@ -482,15 +482,15 @@ test("renderList - default render empty", function () {
|
||||
return DIV({id: doc.id});
|
||||
}
|
||||
});
|
||||
assert_frag("<!---->", r);
|
||||
assert_frag(test, "<!---->", r);
|
||||
|
||||
c.insert({id: "D"});
|
||||
assert_frag("<D></D>", r);
|
||||
assert_frag(test, "<D></D>", r);
|
||||
c.remove({id: "D"});
|
||||
assert_frag("<!---->", r);
|
||||
assert_frag(test, "<!---->", r);
|
||||
});
|
||||
|
||||
test("renderList - change and move", function () {
|
||||
test("renderList - change and move", function (test) {
|
||||
var c = new LocalCollection();
|
||||
|
||||
var r = Meteor.ui.renderList(c.find({}, {sort: ['id']}), {
|
||||
@@ -501,28 +501,28 @@ test("renderList - change and move", function () {
|
||||
|
||||
c.insert({id: "D"});
|
||||
c.insert({id: "E"});
|
||||
assert_frag("<D></D><E></E>", r);
|
||||
assert_frag(test, "<D></D><E></E>", r);
|
||||
c.update({id: "D"}, {id: "F"});
|
||||
assert_frag("<E></E><F></F>", r);
|
||||
assert_frag(test, "<E></E><F></F>", r);
|
||||
c.update({id: "E"}, {id: "G"});
|
||||
assert_frag("<F></F><G></G>", r);
|
||||
assert_frag(test, "<F></F><G></G>", r);
|
||||
c.update({id: "G"}, {id: "C"});
|
||||
assert_frag("<C></C><F></F>", r);
|
||||
assert_frag(test, "<C></C><F></F>", r);
|
||||
c.insert({id: "E"});
|
||||
assert_frag("<C></C><E></E><F></F>", r);
|
||||
assert_frag(test, "<C></C><E></E><F></F>", r);
|
||||
c.insert({id: "D"});
|
||||
assert_frag("<C></C><D></D><E></E><F></F>", r);
|
||||
assert_frag(test, "<C></C><D></D><E></E><F></F>", r);
|
||||
c.update({id: "C"}, {id: "D2"});
|
||||
assert_frag("<D></D><D2></D2><E></E><F></F>", r);
|
||||
assert_frag(test, "<D></D><D2></D2><E></E><F></F>", r);
|
||||
c.update({id: "F"}, {id: "D3"});
|
||||
assert_frag("<D></D><D2></D2><D3></D3><E></E>", r);
|
||||
assert_frag(test, "<D></D><D2></D2><D3></D3><E></E>", r);
|
||||
c.update({id: "D3"}, {id: "C"});
|
||||
assert_frag("<C></C><D></D><D2></D2><E></E>", r);
|
||||
assert_frag(test, "<C></C><D></D><D2></D2><E></E>", r);
|
||||
c.update({id: "D2"}, {id: "F"});
|
||||
assert_frag("<C></C><D></D><E></E><F></F>", r);
|
||||
assert_frag(test, "<C></C><D></D><E></E><F></F>", r);
|
||||
});
|
||||
|
||||
test("renderList - termination", function () {
|
||||
test("renderList - termination", function (test) {
|
||||
var c = new LocalCollection();
|
||||
|
||||
var r = Meteor.ui.renderList(c.find({}, {sort: ['id']}), {
|
||||
@@ -533,14 +533,14 @@ test("renderList - termination", function () {
|
||||
|
||||
c.remove();
|
||||
c.insert({id: "A"});
|
||||
assert_frag("<A></A>", r);
|
||||
assert_frag(test, "<A></A>", r);
|
||||
Meteor.flush(); // not onscreen, so terminates
|
||||
c.insert({id: "B"});
|
||||
assert_frag("<A></A>", r);
|
||||
assert_frag(test, "<A></A>", r);
|
||||
c.remove({id: "A"});
|
||||
assert_frag("<A></A>", r);
|
||||
assert_frag(test, "<A></A>", r);
|
||||
Meteor.flush();
|
||||
assert_frag("<A></A>", r);
|
||||
assert_frag(test, "<A></A>", r);
|
||||
|
||||
var before_flush;
|
||||
var should_gc;
|
||||
@@ -557,7 +557,7 @@ test("renderList - termination", function () {
|
||||
return DIV({id: doc.id});
|
||||
}
|
||||
});
|
||||
assert_frag("<A></A><B></B>", r);
|
||||
assert_frag(test, "<A></A><B></B>", r);
|
||||
should_gc = false;
|
||||
onscreen = null;
|
||||
second_is_noop = false;
|
||||
@@ -572,7 +572,7 @@ test("renderList - termination", function () {
|
||||
],
|
||||
function () {
|
||||
before_flush = dump_frag(r);
|
||||
assert.notEqual("<A></A><B></B>", before_flush);
|
||||
test.notEqual("<A></A><B></B>", before_flush);
|
||||
},
|
||||
// Possibly put onscreen.
|
||||
[1,
|
||||
@@ -603,9 +603,9 @@ test("renderList - termination", function () {
|
||||
// triggered.
|
||||
function () {
|
||||
if (should_gc || second_is_noop)
|
||||
assert_frag(before_flush, onscreen || r);
|
||||
assert_frag(test, before_flush, onscreen || r);
|
||||
else
|
||||
assert.notEqual(before_flush, dump_frag(onscreen || r));
|
||||
test.notEqual(before_flush, dump_frag(onscreen || r));
|
||||
|
||||
if (onscreen)
|
||||
document.body.removeChild(onscreen);
|
||||
@@ -613,7 +613,7 @@ test("renderList - termination", function () {
|
||||
);
|
||||
});
|
||||
|
||||
test("renderList - list items are reactive", function () {
|
||||
test("renderList - list items are reactive", function (test) {
|
||||
var c = new LocalCollection();
|
||||
|
||||
set_weather("here", "cloudy");
|
||||
@@ -633,74 +633,74 @@ test("renderList - list items are reactive", function () {
|
||||
onscreen.appendChild(r);
|
||||
document.body.appendChild(onscreen);
|
||||
|
||||
assert.equal(render_count, 0);
|
||||
test.equal(render_count, 0);
|
||||
c.insert({id: "A", want_weather: "here"});
|
||||
assert.equal(render_count, 1);
|
||||
assert_frag("<A_cloudy></A_cloudy>", onscreen);
|
||||
test.equal(render_count, 1);
|
||||
assert_frag(test, "<A_cloudy></A_cloudy>", onscreen);
|
||||
|
||||
c.insert({id: "B", want_weather: "here"});
|
||||
assert.equal(render_count, 2);
|
||||
assert.length(_.keys(weather_listeners.here), 2);
|
||||
assert_frag("<A_cloudy></A_cloudy><B_cloudy></B_cloudy>", onscreen);
|
||||
test.equal(render_count, 2);
|
||||
test.length(_.keys(weather_listeners.here), 2);
|
||||
assert_frag(test, "<A_cloudy></A_cloudy><B_cloudy></B_cloudy>", onscreen);
|
||||
|
||||
c.insert({id: "C"});
|
||||
assert.equal(render_count, 3);
|
||||
assert.length(_.keys(weather_listeners.here), 2);
|
||||
assert_frag("<A_cloudy></A_cloudy><B_cloudy></B_cloudy><C></C>", onscreen);
|
||||
test.equal(render_count, 3);
|
||||
test.length(_.keys(weather_listeners.here), 2);
|
||||
assert_frag(test, "<A_cloudy></A_cloudy><B_cloudy></B_cloudy><C></C>", onscreen);
|
||||
|
||||
c.update({id: "B"}, {$set: {id: "B2"}});
|
||||
assert.equal(render_count, 4);
|
||||
assert.length(_.keys(weather_listeners.here), 3);
|
||||
assert_frag("<A_cloudy></A_cloudy><B2_cloudy></B2_cloudy><C></C>", onscreen);
|
||||
test.equal(render_count, 4);
|
||||
test.length(_.keys(weather_listeners.here), 3);
|
||||
assert_frag(test, "<A_cloudy></A_cloudy><B2_cloudy></B2_cloudy><C></C>", onscreen);
|
||||
|
||||
Meteor.flush();
|
||||
assert.equal(render_count, 4);
|
||||
assert.length(_.keys(weather_listeners.here), 2);
|
||||
assert_frag("<A_cloudy></A_cloudy><B2_cloudy></B2_cloudy><C></C>", onscreen);
|
||||
test.equal(render_count, 4);
|
||||
test.length(_.keys(weather_listeners.here), 2);
|
||||
assert_frag(test, "<A_cloudy></A_cloudy><B2_cloudy></B2_cloudy><C></C>", onscreen);
|
||||
|
||||
c.update({id: "B2"}, {$set: {id: "D"}});
|
||||
assert.equal(render_count, 5); // move doesn't rerender
|
||||
assert.length(_.keys(weather_listeners.here), 3);
|
||||
assert_frag("<A_cloudy></A_cloudy><C></C><D_cloudy></D_cloudy>", onscreen);
|
||||
test.equal(render_count, 5); // move doesn't rerender
|
||||
test.length(_.keys(weather_listeners.here), 3);
|
||||
assert_frag(test, "<A_cloudy></A_cloudy><C></C><D_cloudy></D_cloudy>", onscreen);
|
||||
|
||||
Meteor.flush();
|
||||
assert.equal(render_count, 5);
|
||||
assert.length(_.keys(weather_listeners.here), 2);
|
||||
assert_frag("<A_cloudy></A_cloudy><C></C><D_cloudy></D_cloudy>", onscreen);
|
||||
test.equal(render_count, 5);
|
||||
test.length(_.keys(weather_listeners.here), 2);
|
||||
assert_frag(test, "<A_cloudy></A_cloudy><C></C><D_cloudy></D_cloudy>", onscreen);
|
||||
|
||||
set_weather("here", "sunny");
|
||||
assert.equal(render_count, 5);
|
||||
assert.length(_.keys(weather_listeners.here), 2);
|
||||
assert_frag("<A_cloudy></A_cloudy><C></C><D_cloudy></D_cloudy>", onscreen);
|
||||
test.equal(render_count, 5);
|
||||
test.length(_.keys(weather_listeners.here), 2);
|
||||
assert_frag(test, "<A_cloudy></A_cloudy><C></C><D_cloudy></D_cloudy>", onscreen);
|
||||
|
||||
Meteor.flush();
|
||||
assert.equal(render_count, 7);
|
||||
assert.length(_.keys(weather_listeners.here), 2);
|
||||
assert_frag("<A_sunny></A_sunny><C></C><D_sunny></D_sunny>", onscreen);
|
||||
test.equal(render_count, 7);
|
||||
test.length(_.keys(weather_listeners.here), 2);
|
||||
assert_frag(test, "<A_sunny></A_sunny><C></C><D_sunny></D_sunny>", onscreen);
|
||||
|
||||
c.remove({id: "A"});
|
||||
assert.equal(render_count, 7);
|
||||
assert.length(_.keys(weather_listeners.here), 2);
|
||||
assert_frag("<C></C><D_sunny></D_sunny>", onscreen);
|
||||
test.equal(render_count, 7);
|
||||
test.length(_.keys(weather_listeners.here), 2);
|
||||
assert_frag(test, "<C></C><D_sunny></D_sunny>", onscreen);
|
||||
|
||||
Meteor.flush();
|
||||
assert.equal(render_count, 7);
|
||||
assert.length(_.keys(weather_listeners.here), 1);
|
||||
assert.length(_.keys(weather_listeners.there), 0);
|
||||
assert_frag("<C></C><D_sunny></D_sunny>", onscreen);
|
||||
test.equal(render_count, 7);
|
||||
test.length(_.keys(weather_listeners.here), 1);
|
||||
test.length(_.keys(weather_listeners.there), 0);
|
||||
assert_frag(test, "<C></C><D_sunny></D_sunny>", onscreen);
|
||||
|
||||
c.insert({id: "F", want_weather: "there"});
|
||||
assert.equal(render_count, 8);
|
||||
assert.length(_.keys(weather_listeners.here), 1);
|
||||
assert.length(_.keys(weather_listeners.there), 1);
|
||||
assert_frag("<C></C><D_sunny></D_sunny><F_cloudy></F_cloudy>", onscreen);
|
||||
test.equal(render_count, 8);
|
||||
test.length(_.keys(weather_listeners.here), 1);
|
||||
test.length(_.keys(weather_listeners.there), 1);
|
||||
assert_frag(test, "<C></C><D_sunny></D_sunny><F_cloudy></F_cloudy>", onscreen);
|
||||
|
||||
r.appendChild(onscreen); // take offscreen
|
||||
Meteor.flush();
|
||||
assert.equal(render_count, 8);
|
||||
assert.length(_.keys(weather_listeners.here), 1);
|
||||
assert.length(_.keys(weather_listeners.there), 1);
|
||||
assert_frag("<C></C><D_sunny></D_sunny><F_cloudy></F_cloudy>", onscreen);
|
||||
test.equal(render_count, 8);
|
||||
test.length(_.keys(weather_listeners.here), 1);
|
||||
test.length(_.keys(weather_listeners.there), 1);
|
||||
assert_frag(test, "<C></C><D_sunny></D_sunny><F_cloudy></F_cloudy>", onscreen);
|
||||
|
||||
// it's offscreen, but it wasn't taken off through a mechanism that
|
||||
// calls Meteor.ui._cleanup, so we take the slow GC path. the entries
|
||||
@@ -709,34 +709,34 @@ test("renderList - list items are reactive", function () {
|
||||
// entries will get torn down too.)
|
||||
set_weather("here", "ducky");
|
||||
Meteor.flush();
|
||||
assert.equal(render_count, 8);
|
||||
assert.length(_.keys(weather_listeners.here), 0);
|
||||
assert.length(_.keys(weather_listeners.there), 1);
|
||||
assert_frag("<C></C><D_sunny></D_sunny><F_cloudy></F_cloudy>", onscreen);
|
||||
test.equal(render_count, 8);
|
||||
test.length(_.keys(weather_listeners.here), 0);
|
||||
test.length(_.keys(weather_listeners.there), 1);
|
||||
assert_frag(test, "<C></C><D_sunny></D_sunny><F_cloudy></F_cloudy>", onscreen);
|
||||
|
||||
c.insert({id: "E"});
|
||||
// insert renders the doc -- it has to, since renderList GC happens
|
||||
// only on flush
|
||||
assert.equal(render_count, 9);
|
||||
assert.length(_.keys(weather_listeners.here), 0);
|
||||
assert.length(_.keys(weather_listeners.there), 1);
|
||||
assert_frag("<C></C><D_sunny></D_sunny><E></E><F_cloudy></F_cloudy>", onscreen);
|
||||
test.equal(render_count, 9);
|
||||
test.length(_.keys(weather_listeners.here), 0);
|
||||
test.length(_.keys(weather_listeners.there), 1);
|
||||
assert_frag(test, "<C></C><D_sunny></D_sunny><E></E><F_cloudy></F_cloudy>", onscreen);
|
||||
|
||||
Meteor.flush();
|
||||
assert.equal(render_count, 9);
|
||||
assert.length(_.keys(weather_listeners.here), 0);
|
||||
assert.length(_.keys(weather_listeners.there), 0);
|
||||
assert_frag("<C></C><D_sunny></D_sunny><E></E><F_cloudy></F_cloudy>", onscreen);
|
||||
test.equal(render_count, 9);
|
||||
test.length(_.keys(weather_listeners.here), 0);
|
||||
test.length(_.keys(weather_listeners.there), 0);
|
||||
assert_frag(test, "<C></C><D_sunny></D_sunny><E></E><F_cloudy></F_cloudy>", onscreen);
|
||||
|
||||
c.insert({id: "G"});
|
||||
Meteor.flush();
|
||||
assert.equal(render_count, 9);
|
||||
assert.length(_.keys(weather_listeners.here), 0);
|
||||
assert.length(_.keys(weather_listeners.there), 0);
|
||||
assert_frag("<C></C><D_sunny></D_sunny><E></E><F_cloudy></F_cloudy>", onscreen);
|
||||
test.equal(render_count, 9);
|
||||
test.length(_.keys(weather_listeners.here), 0);
|
||||
test.length(_.keys(weather_listeners.there), 0);
|
||||
assert_frag(test, "<C></C><D_sunny></D_sunny><E></E><F_cloudy></F_cloudy>", onscreen);
|
||||
});
|
||||
|
||||
test("renderList - multiple elements in an item", function () {
|
||||
test("renderList - multiple elements in an item", function (test) {
|
||||
var c = new LocalCollection();
|
||||
var r;
|
||||
|
||||
@@ -776,7 +776,7 @@ test("renderList - multiple elements in an item", function () {
|
||||
if (lengths[index] === 0)
|
||||
expected += "<!---->";
|
||||
});
|
||||
assert_frag(expected || "<!---->", r);
|
||||
assert_frag(test, expected || "<!---->", r);
|
||||
};
|
||||
/* Consider uncommenting the 6 lines below in a "slow tests" mode */
|
||||
try_all_permutations(
|
||||
@@ -832,7 +832,7 @@ test("renderList - multiple elements in an item", function () {
|
||||
);
|
||||
});
|
||||
|
||||
test("renderList - #each", function () {
|
||||
test("renderList - #each", function (test) {
|
||||
var c = new LocalCollection();
|
||||
|
||||
var render_count = 0;
|
||||
@@ -856,35 +856,35 @@ test("renderList - #each", function () {
|
||||
onscreen.appendChild(Template.test_renderList_each());
|
||||
document.body.appendChild(onscreen);
|
||||
|
||||
assert_frag("~Before0<!---->Middle~Else~After~", onscreen);
|
||||
assert.length(_.keys(weather_listeners.here), 0);
|
||||
assert_frag(test, "~Before0<!---->Middle~Else~After~", onscreen);
|
||||
test.length(_.keys(weather_listeners.here), 0);
|
||||
|
||||
c.insert({x: 2, name: "A"});
|
||||
assert_frag("~Before0~Aducky~Middle~Else~After~", onscreen);
|
||||
assert.length(_.keys(weather_listeners.here), 1);
|
||||
assert_frag(test, "~Before0~Aducky~Middle~Else~After~", onscreen);
|
||||
test.length(_.keys(weather_listeners.here), 1);
|
||||
|
||||
c.insert({x: 3, name: "B"});
|
||||
assert_frag("~Before0~Aducky~~Bducky~Middle~Else~After~", onscreen);
|
||||
assert.length(_.keys(weather_listeners.here), 2);
|
||||
assert_frag(test, "~Before0~Aducky~~Bducky~Middle~Else~After~", onscreen);
|
||||
test.length(_.keys(weather_listeners.here), 2);
|
||||
|
||||
set_weather("here", "clear");
|
||||
assert_frag("~Before0~Aducky~~Bducky~Middle~Else~After~", onscreen);
|
||||
assert.length(_.keys(weather_listeners.here), 2);
|
||||
assert_frag(test, "~Before0~Aducky~~Bducky~Middle~Else~After~", onscreen);
|
||||
test.length(_.keys(weather_listeners.here), 2);
|
||||
Meteor.flush();
|
||||
assert_frag("~Before0~Aclear~~Bclear~Middle~Else~After~", onscreen);
|
||||
assert.length(_.keys(weather_listeners.here), 2);
|
||||
assert_frag(test, "~Before0~Aclear~~Bclear~Middle~Else~After~", onscreen);
|
||||
test.length(_.keys(weather_listeners.here), 2);
|
||||
|
||||
c.update({x: 3}, {$set: {x: 8}}, {multi: true});
|
||||
assert_frag("~Before0~Aclear~Middle~B~After~", onscreen);
|
||||
assert.length(_.keys(weather_listeners.here), 2);
|
||||
assert_frag(test, "~Before0~Aclear~Middle~B~After~", onscreen);
|
||||
test.length(_.keys(weather_listeners.here), 2);
|
||||
Meteor.flush();
|
||||
assert.length(_.keys(weather_listeners.here), 1);
|
||||
test.length(_.keys(weather_listeners.here), 1);
|
||||
|
||||
c.update({}, {$set: {x: 5}}, {multi: true});
|
||||
assert_frag("~Before0<!---->Middle~Else~After~", onscreen);
|
||||
assert.length(_.keys(weather_listeners.here), 1);
|
||||
assert_frag(test, "~Before0<!---->Middle~Else~After~", onscreen);
|
||||
test.length(_.keys(weather_listeners.here), 1);
|
||||
Meteor.flush();
|
||||
assert.length(_.keys(weather_listeners.here), 0);
|
||||
test.length(_.keys(weather_listeners.here), 0);
|
||||
|
||||
document.body.removeChild(onscreen);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
test("logging", function() {
|
||||
test("logging", function (test) {
|
||||
|
||||
// Just run a log statement and make sure it doesn't explode.
|
||||
Meteor._debug();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
test("environment - client basics", function () {
|
||||
assert.isTrue(Meteor.is_client);
|
||||
assert.isFalse(Meteor.is_server);
|
||||
test("environment - client basics", function (test) {
|
||||
test.isTrue(Meteor.is_client);
|
||||
test.isFalse(Meteor.is_server);
|
||||
});
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
CurrentFoo = new Meteor.DynamicVariable;
|
||||
|
||||
test("environment - dynamic variables", function () {
|
||||
assert.equal(CurrentFoo.get(), undefined);
|
||||
test("environment - dynamic variables", function (test) {
|
||||
test.equal(CurrentFoo.get(), undefined);
|
||||
|
||||
CurrentFoo.withValue(17, function () {
|
||||
assert.equal(CurrentFoo.get(), 17);
|
||||
test.equal(CurrentFoo.get(), 17);
|
||||
|
||||
CurrentFoo.withValue(22, function () {
|
||||
assert.equal(CurrentFoo.get(), 22);
|
||||
test.equal(CurrentFoo.get(), 22);
|
||||
});
|
||||
|
||||
assert.equal(CurrentFoo.get(), 17);
|
||||
test.equal(CurrentFoo.get(), 17);
|
||||
});
|
||||
|
||||
assert.equal(CurrentFoo.get(), undefined);
|
||||
test.equal(CurrentFoo.get(), undefined);
|
||||
});
|
||||
|
||||
test("environment - bindEnvironment", function () {
|
||||
test("environment - bindEnvironment", function (test) {
|
||||
var raised_f;
|
||||
|
||||
var f = CurrentFoo.withValue(17, function () {
|
||||
return Meteor.bindEnvironment(function (flag) {
|
||||
assert.equal(CurrentFoo.get(), 17);
|
||||
test.equal(CurrentFoo.get(), 17);
|
||||
if (flag)
|
||||
throw "test";
|
||||
return 12;
|
||||
}, function (e) {
|
||||
assert.equal(CurrentFoo.get(), 17);
|
||||
test.equal(CurrentFoo.get(), 17);
|
||||
raised_f = e;
|
||||
});
|
||||
});
|
||||
@@ -34,27 +34,27 @@ test("environment - bindEnvironment", function () {
|
||||
var test_f = function () {
|
||||
raised_f = null;
|
||||
|
||||
assert.equal(f(false), 12);
|
||||
assert.equal(raised_f, null);
|
||||
test.equal(f(false), 12);
|
||||
test.equal(raised_f, null);
|
||||
|
||||
assert.equal(f(true), undefined);
|
||||
assert.equal(raised_f, "test");
|
||||
test.equal(f(true), undefined);
|
||||
test.equal(raised_f, "test");
|
||||
};
|
||||
|
||||
// At top level
|
||||
|
||||
assert.equal(CurrentFoo.get(), undefined);
|
||||
test.equal(CurrentFoo.get(), undefined);
|
||||
test_f();
|
||||
|
||||
// Inside a withValue
|
||||
|
||||
CurrentFoo.withValue(22, function () {
|
||||
assert.equal(CurrentFoo.get(), 22);
|
||||
test.equal(CurrentFoo.get(), 22);
|
||||
test_f();
|
||||
assert.equal(CurrentFoo.get(), 22);
|
||||
test.equal(CurrentFoo.get(), 22);
|
||||
});
|
||||
|
||||
assert.equal(CurrentFoo.get(), undefined);
|
||||
test.equal(CurrentFoo.get(), undefined);
|
||||
|
||||
// Multiple environment-bound functions on the stack (in the nodejs
|
||||
// implementation, this needs to avoid creating additional fibers)
|
||||
@@ -63,7 +63,7 @@ test("environment - bindEnvironment", function () {
|
||||
|
||||
var g = CurrentFoo.withValue(99, function () {
|
||||
return Meteor.bindEnvironment(function (flag) {
|
||||
assert.equal(CurrentFoo.get(), 99);
|
||||
test.equal(CurrentFoo.get(), 99);
|
||||
|
||||
if (flag)
|
||||
throw "trial";
|
||||
@@ -71,7 +71,7 @@ test("environment - bindEnvironment", function () {
|
||||
test_f();
|
||||
return 88;
|
||||
}, function (e) {
|
||||
assert.equal(CurrentFoo.get(), 99);
|
||||
test.equal(CurrentFoo.get(), 99);
|
||||
raised_g = e;
|
||||
});
|
||||
});
|
||||
@@ -79,29 +79,29 @@ test("environment - bindEnvironment", function () {
|
||||
var test_g = function () {
|
||||
raised_g = null;
|
||||
|
||||
assert.equal(g(false), 88);
|
||||
assert.equal(raised_g, null);
|
||||
test.equal(g(false), 88);
|
||||
test.equal(raised_g, null);
|
||||
|
||||
assert.equal(g(true), undefined);
|
||||
assert.equal(raised_g, "trial");
|
||||
test.equal(g(true), undefined);
|
||||
test.equal(raised_g, "trial");
|
||||
};
|
||||
|
||||
test_g();
|
||||
|
||||
CurrentFoo.withValue(77, function () {
|
||||
assert.equal(CurrentFoo.get(), 77);
|
||||
test.equal(CurrentFoo.get(), 77);
|
||||
test_g();
|
||||
assert.equal(CurrentFoo.get(), 77);
|
||||
test.equal(CurrentFoo.get(), 77);
|
||||
});
|
||||
|
||||
assert.equal(CurrentFoo.get(), undefined);
|
||||
test.equal(CurrentFoo.get(), undefined);
|
||||
});
|
||||
|
||||
testAsync("environment - bare bindEnvironment", function (onComplete) {
|
||||
testAsync("environment - bare bindEnvironment", function (test, onComplete) {
|
||||
// this will have to create a fiber in nodejs
|
||||
CurrentFoo.withValue(68, function () {
|
||||
var f = Meteor.bindEnvironment(function () {
|
||||
assert.equal(CurrentFoo.get(), 68);
|
||||
test.equal(CurrentFoo.get(), 68);
|
||||
onComplete();
|
||||
}, function () {});
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
test("environment - server basics", function () {
|
||||
assert.isFalse(Meteor.is_client);
|
||||
assert.isTrue(Meteor.is_server);
|
||||
test("environment - server basics", function (test) {
|
||||
test.isFalse(Meteor.is_client);
|
||||
test.isTrue(Meteor.is_server);
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// assert that f is a strcmp-style comparison function that puts
|
||||
// 'values' in the provided order
|
||||
assert_ordering = function (f, values) {
|
||||
assert_ordering = function (test, f, values) {
|
||||
for (var i = 0; i < values.length; i++) {
|
||||
var x = f(values[i], values[i]);
|
||||
if (x !== 0) {
|
||||
@@ -37,7 +37,7 @@ assert_ordering = function (f, values) {
|
||||
|
||||
// XXX test shared structure in all MM entrypoints
|
||||
|
||||
test("minimongo - basics", function () {
|
||||
test("minimongo - basics", function (test) {
|
||||
var c = new LocalCollection();
|
||||
|
||||
c.insert({type: "kitten", name: "fluffy"});
|
||||
@@ -45,62 +45,62 @@ test("minimongo - basics", function () {
|
||||
c.insert({type: "cryptographer", name: "alice"});
|
||||
c.insert({type: "cryptographer", name: "bob"});
|
||||
c.insert({type: "cryptographer", name: "cara"});
|
||||
assert.equal(c.find().count(), 5);
|
||||
assert.equal(c.find({type: "kitten"}).count(), 2);
|
||||
assert.equal(c.find({type: "cryptographer"}).count(), 3);
|
||||
assert.length(c.find({type: "kitten"}).fetch(), 2);
|
||||
assert.length(c.find({type: "cryptographer"}).fetch(), 3);
|
||||
test.equal(c.find().count(), 5);
|
||||
test.equal(c.find({type: "kitten"}).count(), 2);
|
||||
test.equal(c.find({type: "cryptographer"}).count(), 3);
|
||||
test.length(c.find({type: "kitten"}).fetch(), 2);
|
||||
test.length(c.find({type: "cryptographer"}).fetch(), 3);
|
||||
|
||||
c.remove({name: "cara"});
|
||||
assert.equal(c.find().count(), 4);
|
||||
assert.equal(c.find({type: "kitten"}).count(), 2);
|
||||
assert.equal(c.find({type: "cryptographer"}).count(), 2);
|
||||
assert.length(c.find({type: "kitten"}).fetch(), 2);
|
||||
assert.length(c.find({type: "cryptographer"}).fetch(), 2);
|
||||
test.equal(c.find().count(), 4);
|
||||
test.equal(c.find({type: "kitten"}).count(), 2);
|
||||
test.equal(c.find({type: "cryptographer"}).count(), 2);
|
||||
test.length(c.find({type: "kitten"}).fetch(), 2);
|
||||
test.length(c.find({type: "cryptographer"}).fetch(), 2);
|
||||
|
||||
c.update({name: "snookums"}, {$set: {type: "cryptographer"}});
|
||||
assert.equal(c.find().count(), 4);
|
||||
assert.equal(c.find({type: "kitten"}).count(), 1);
|
||||
assert.equal(c.find({type: "cryptographer"}).count(), 3);
|
||||
assert.length(c.find({type: "kitten"}).fetch(), 1);
|
||||
assert.length(c.find({type: "cryptographer"}).fetch(), 3);
|
||||
test.equal(c.find().count(), 4);
|
||||
test.equal(c.find({type: "kitten"}).count(), 1);
|
||||
test.equal(c.find({type: "cryptographer"}).count(), 3);
|
||||
test.length(c.find({type: "kitten"}).fetch(), 1);
|
||||
test.length(c.find({type: "cryptographer"}).fetch(), 3);
|
||||
|
||||
c.remove(null);
|
||||
c.remove(false);
|
||||
c.remove(undefined);
|
||||
assert.equal(c.find().count(), 4);
|
||||
test.equal(c.find().count(), 4);
|
||||
|
||||
c.remove({_id: null});
|
||||
c.remove({_id: false});
|
||||
c.remove({_id: undefined});
|
||||
assert.equal(c.find().count(), 4);
|
||||
test.equal(c.find().count(), 4);
|
||||
|
||||
c.remove();
|
||||
assert.equal(0, c.find().count());
|
||||
test.equal(0, c.find().count());
|
||||
|
||||
c.insert({_id: 1, name: "strawberry", tags: ["fruit", "red", "squishy"]});
|
||||
c.insert({_id: 2, name: "apple", tags: ["fruit", "red", "hard"]});
|
||||
c.insert({_id: 3, name: "rose", tags: ["flower", "red", "squishy"]});
|
||||
|
||||
assert.equal(c.find({tags: "flower"}).count(), 1);
|
||||
assert.equal(c.find({tags: "fruit"}).count(), 2);
|
||||
assert.equal(c.find({tags: "red"}).count(), 3);
|
||||
assert.length(c.find({tags: "flower"}).fetch(), 1);
|
||||
assert.length(c.find({tags: "fruit"}).fetch(), 2);
|
||||
assert.length(c.find({tags: "red"}).fetch(), 3);
|
||||
test.equal(c.find({tags: "flower"}).count(), 1);
|
||||
test.equal(c.find({tags: "fruit"}).count(), 2);
|
||||
test.equal(c.find({tags: "red"}).count(), 3);
|
||||
test.length(c.find({tags: "flower"}).fetch(), 1);
|
||||
test.length(c.find({tags: "fruit"}).fetch(), 2);
|
||||
test.length(c.find({tags: "red"}).fetch(), 3);
|
||||
|
||||
assert.equal(c.findOne(1).name, "strawberry");
|
||||
assert.equal(c.findOne(2).name, "apple");
|
||||
assert.equal(c.findOne(3).name, "rose");
|
||||
assert.equal(c.findOne(4), undefined);
|
||||
assert.equal(c.findOne("abc"), undefined);
|
||||
assert.equal(c.findOne(undefined), undefined);
|
||||
test.equal(c.findOne(1).name, "strawberry");
|
||||
test.equal(c.findOne(2).name, "apple");
|
||||
test.equal(c.findOne(3).name, "rose");
|
||||
test.equal(c.findOne(4), undefined);
|
||||
test.equal(c.findOne("abc"), undefined);
|
||||
test.equal(c.findOne(undefined), undefined);
|
||||
|
||||
assert.equal(c.find(1).count(), 1);
|
||||
assert.equal(c.find(4).count(), 0);
|
||||
assert.equal(c.find("abc").count(), 0);
|
||||
assert.equal(c.find(undefined).count(), 0);
|
||||
assert.equal(c.find().count(), 3);
|
||||
test.equal(c.find(1).count(), 1);
|
||||
test.equal(c.find(4).count(), 0);
|
||||
test.equal(c.find("abc").count(), 0);
|
||||
test.equal(c.find(undefined).count(), 0);
|
||||
test.equal(c.find().count(), 3);
|
||||
|
||||
var ev = "";
|
||||
var makecb = function (tag) {
|
||||
@@ -111,7 +111,7 @@ test("minimongo - basics", function () {
|
||||
};
|
||||
};
|
||||
var expect = function (x) {
|
||||
assert.equal(ev, x);
|
||||
test.equal(ev, x);
|
||||
ev = "";
|
||||
};
|
||||
c.find({tags: "flower"}).observe(makecb('a'));
|
||||
@@ -128,7 +128,7 @@ test("minimongo - basics", function () {
|
||||
expect("aa4_");
|
||||
});
|
||||
|
||||
test("minimongo - cursors", function () {
|
||||
test("minimongo - cursors", function (test) {
|
||||
var c = new LocalCollection();
|
||||
var res;
|
||||
|
||||
@@ -136,65 +136,65 @@ test("minimongo - cursors", function () {
|
||||
c.insert({i: i});
|
||||
|
||||
var q = c.find();
|
||||
assert.equal(q.count(), 20);
|
||||
test.equal(q.count(), 20);
|
||||
|
||||
// fetch
|
||||
res = q.fetch();
|
||||
assert.length(res, 20);
|
||||
test.length(res, 20);
|
||||
for (var i = 0; i < 20; i++)
|
||||
assert.equal(res[i].i, i);
|
||||
test.equal(res[i].i, i);
|
||||
// everything empty
|
||||
assert.length(q.fetch(), 0);
|
||||
test.length(q.fetch(), 0);
|
||||
q.rewind();
|
||||
|
||||
// forEach
|
||||
var count = 0;
|
||||
q.forEach(function (obj) {
|
||||
assert.equal(obj.i, count++);
|
||||
test.equal(obj.i, count++);
|
||||
});
|
||||
assert.equal(count, 20);
|
||||
test.equal(count, 20);
|
||||
// everything empty
|
||||
assert.length(q.fetch(), 0);
|
||||
test.length(q.fetch(), 0);
|
||||
q.rewind();
|
||||
|
||||
// map
|
||||
res = q.map(function (obj) { return obj.i * 2; });
|
||||
assert.length(res, 20);
|
||||
test.length(res, 20);
|
||||
for (var i = 0; i < 20; i++)
|
||||
assert.equal(res[i], i * 2);
|
||||
test.equal(res[i], i * 2);
|
||||
// everything empty
|
||||
assert.length(q.fetch(), 0);
|
||||
test.length(q.fetch(), 0);
|
||||
|
||||
// findOne (and no rewind first)
|
||||
assert.equal(c.findOne({i: 0}).i, 0);
|
||||
assert.equal(c.findOne({i: 1}).i, 1);
|
||||
test.equal(c.findOne({i: 0}).i, 0);
|
||||
test.equal(c.findOne({i: 1}).i, 1);
|
||||
var id = c.findOne({i: 2})._id;
|
||||
assert.equal(c.findOne(id).i, 2);
|
||||
test.equal(c.findOne(id).i, 2);
|
||||
});
|
||||
|
||||
test("minimongo - misc", function () {
|
||||
test("minimongo - misc", function (test) {
|
||||
// deepcopy
|
||||
var a = {a: [1, 2, 3], b: "x", c: true, d: {x: 12, y: [12]},
|
||||
f: null};
|
||||
var b = LocalCollection._deepcopy(a);
|
||||
assert.isTrue(LocalCollection._f._equal(a, b));
|
||||
test.isTrue(LocalCollection._f._equal(a, b));
|
||||
a.a.push(4);
|
||||
assert.length(b.a, 3);
|
||||
test.length(b.a, 3);
|
||||
a.c = false;
|
||||
assert.isTrue(b.c);
|
||||
test.isTrue(b.c);
|
||||
b.d.z = 15;
|
||||
a.d.z = 14;
|
||||
assert.equal(b.d.z, 15);
|
||||
test.equal(b.d.z, 15);
|
||||
a.d.y.push(88);
|
||||
assert.length(b.d.y, 1);
|
||||
test.length(b.d.y, 1);
|
||||
|
||||
a = {x: function () {}};
|
||||
b = LocalCollection._deepcopy(a);
|
||||
a.x.a = 14;
|
||||
assert.equal(b.x.a, 14); // just to document current behavior
|
||||
test.equal(b.x.a, 14); // just to document current behavior
|
||||
});
|
||||
|
||||
test("minimongo - selector_compiler", function () {
|
||||
test("minimongo - selector_compiler", function (test) {
|
||||
var matches = function (should_match, selector, doc) {
|
||||
var does_match = LocalCollection._matches(selector, doc);
|
||||
if (does_match != should_match) {
|
||||
@@ -476,10 +476,10 @@ test("minimongo - selector_compiler", function () {
|
||||
match({a: /a/}, {a: ['dog', 'cat']});
|
||||
nomatch({a: /a/}, {a: ['dog', 'puppy']});
|
||||
|
||||
assert.throws(function () {
|
||||
test.throws(function () {
|
||||
match({a: {$regex: /a/, $options: 'x'}}, {a: 'cat'});
|
||||
});
|
||||
assert.throws(function () {
|
||||
test.throws(function () {
|
||||
match({a: {$regex: /a/, $options: 's'}}, {a: 'cat'});
|
||||
});
|
||||
|
||||
@@ -506,9 +506,9 @@ test("minimongo - selector_compiler", function () {
|
||||
// - non-scalar arguments to $gt, $lt, etc
|
||||
});
|
||||
|
||||
test("minimongo - ordering", function () {
|
||||
test("minimongo - ordering", function (test) {
|
||||
// value ordering
|
||||
assert_ordering(LocalCollection._f._cmp, [
|
||||
assert_ordering(test, LocalCollection._f._cmp, [
|
||||
null,
|
||||
1, 2.2, 3,
|
||||
"03", "1", "11", "2", "a", "aaa",
|
||||
@@ -521,7 +521,7 @@ test("minimongo - ordering", function () {
|
||||
// document ordering under a sort specification
|
||||
var verify = function (sorts, docs) {
|
||||
_.each(sorts, function (sort) {
|
||||
assert_ordering(LocalCollection._compileSort(sort), docs);
|
||||
assert_ordering(test, LocalCollection._compileSort(sort), docs);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -538,24 +538,24 @@ test("minimongo - ordering", function () {
|
||||
[["a", "asc"], ["b", "asc"]]],
|
||||
[{c: 1}, {a: 1, b: 2}, {a: 1, b: 3}, {a: 2, b: 0}]);
|
||||
|
||||
assert.throws(function () {
|
||||
test.throws(function () {
|
||||
LocalCollection._compileSort("a");
|
||||
});
|
||||
|
||||
assert.throws(function () {
|
||||
test.throws(function () {
|
||||
LocalCollection._compileSort(123);
|
||||
});
|
||||
|
||||
assert.equal(LocalCollection._compileSort({})({a:1}, {a:2}), 0);
|
||||
test.equal(LocalCollection._compileSort({})({a:1}, {a:2}), 0);
|
||||
});
|
||||
|
||||
test("minimongo - sort", function () {
|
||||
test("minimongo - sort", function (test) {
|
||||
var c = new LocalCollection();
|
||||
for (var i = 0; i < 50; i++)
|
||||
for (var j = 0; j < 2; j++)
|
||||
c.insert({a: i, b: j, _id: i + "_" + j});
|
||||
|
||||
assert.equal(
|
||||
test.equal(
|
||||
c.find({a: {$gt: 10}}, {sort: {b: -1, a: 1}, limit: 5}).fetch(), [
|
||||
{a: 11, b: 1, _id: "11_1"},
|
||||
{a: 12, b: 1, _id: "12_1"},
|
||||
@@ -563,7 +563,7 @@ test("minimongo - sort", function () {
|
||||
{a: 14, b: 1, _id: "14_1"},
|
||||
{a: 15, b: 1, _id: "15_1"}]);
|
||||
|
||||
assert.equal(
|
||||
test.equal(
|
||||
c.find({a: {$gt: 10}}, {sort: {b: -1, a: 1}, skip: 3, limit: 5}).fetch(), [
|
||||
{a: 14, b: 1, _id: "14_1"},
|
||||
{a: 15, b: 1, _id: "15_1"},
|
||||
@@ -571,7 +571,7 @@ test("minimongo - sort", function () {
|
||||
{a: 17, b: 1, _id: "17_1"},
|
||||
{a: 18, b: 1, _id: "18_1"}]);
|
||||
|
||||
assert.equal(
|
||||
test.equal(
|
||||
c.find({a: {$gte: 20}}, {sort: {a: 1, b: -1}, skip: 50, limit: 5}).fetch(), [
|
||||
{a: 45, b: 1, _id: "45_1"},
|
||||
{a: 45, b: 0, _id: "45_0"},
|
||||
@@ -580,7 +580,7 @@ test("minimongo - sort", function () {
|
||||
{a: 47, b: 1, _id: "47_1"}]);
|
||||
});
|
||||
|
||||
test("minimongo - modify", function () {
|
||||
test("minimongo - modify", function (test) {
|
||||
var modify = function (doc, mod, result) {
|
||||
var copy = LocalCollection._deepcopy(doc);
|
||||
LocalCollection._modify(copy, mod);
|
||||
@@ -598,7 +598,7 @@ test("minimongo - modify", function () {
|
||||
}
|
||||
};
|
||||
var exception = function (doc, mod) {
|
||||
assert.throws(function () {
|
||||
test.throws(function () {
|
||||
LocalCollection._modify(LocalCollection._deepcopy(doc), mod);
|
||||
});
|
||||
};
|
||||
@@ -824,7 +824,7 @@ test("minimongo - modify", function () {
|
||||
|
||||
// XXX test update() (selecting docs, multi, upsert..)
|
||||
|
||||
test("minimongo - observe", function () {
|
||||
test("minimongo - observe", function (test) {
|
||||
var operations = [];
|
||||
var cbs = {
|
||||
added: function (obj, idx) {
|
||||
@@ -849,41 +849,41 @@ test("minimongo - observe", function () {
|
||||
|
||||
var c = new LocalCollection();
|
||||
handle = c.find({}, {sort: {a: 1}}).observe(cbs);
|
||||
assert.isTrue(handle.collection === c);
|
||||
test.isTrue(handle.collection === c);
|
||||
|
||||
c.insert({a:1});
|
||||
assert.equal(operations.shift(), ['added', {a:1}, 0]);
|
||||
test.equal(operations.shift(), ['added', {a:1}, 0]);
|
||||
c.update({a:1}, {$set: {a: 2}});
|
||||
assert.equal(operations.shift(), ['changed', {a:2}, 0, {a:1}]);
|
||||
test.equal(operations.shift(), ['changed', {a:2}, 0, {a:1}]);
|
||||
c.insert({a:10});
|
||||
assert.equal(operations.shift(), ['added', {a:10}, 1]);
|
||||
test.equal(operations.shift(), ['added', {a:10}, 1]);
|
||||
c.update({}, {$inc: {a: 1}}, {multi: true});
|
||||
assert.equal(operations.shift(), ['changed', {a:3}, 0, {a:2}]);
|
||||
assert.equal(operations.shift(), ['changed', {a:11}, 1, {a:10}]);
|
||||
test.equal(operations.shift(), ['changed', {a:3}, 0, {a:2}]);
|
||||
test.equal(operations.shift(), ['changed', {a:11}, 1, {a:10}]);
|
||||
c.update({a:11}, {a:1});
|
||||
assert.equal(operations.shift(), ['changed', {a:1}, 1, {a:11}]);
|
||||
assert.equal(operations.shift(), ['moved', {a:1}, 1, 0]);
|
||||
test.equal(operations.shift(), ['changed', {a:1}, 1, {a:11}]);
|
||||
test.equal(operations.shift(), ['moved', {a:1}, 1, 0]);
|
||||
c.remove({a:2});
|
||||
assert.equal(operations.shift(), undefined);
|
||||
test.equal(operations.shift(), undefined);
|
||||
var id = c.findOne({a:3})._id;
|
||||
c.remove({a:3});
|
||||
assert.equal(operations.shift(), ['removed', id, 1, {a:3}]);
|
||||
test.equal(operations.shift(), ['removed', id, 1, {a:3}]);
|
||||
|
||||
// test stop
|
||||
handle.stop();
|
||||
c.insert({a:2});
|
||||
assert.equal(operations.shift(), undefined);
|
||||
test.equal(operations.shift(), undefined);
|
||||
|
||||
// test initial inserts (and backwards sort)
|
||||
handle = c.find({}, {sort: {a: -1}}).observe(cbs);
|
||||
assert.equal(operations.shift(), ['added', {a:2}, 0]);
|
||||
assert.equal(operations.shift(), ['added', {a:1}, 1]);
|
||||
test.equal(operations.shift(), ['added', {a:2}, 0]);
|
||||
test.equal(operations.shift(), ['added', {a:1}, 1]);
|
||||
handle.stop();
|
||||
|
||||
// test _suppress_initial
|
||||
handle = c.find({}, {sort: {a: -1}}).observe(_.extend(cbs, {_suppress_initial: true}));
|
||||
assert.equal(operations.shift(), undefined);
|
||||
test.equal(operations.shift(), undefined);
|
||||
c.insert({a:100});
|
||||
assert.equal(operations.shift(), ['added', {a:100}, 0]);
|
||||
test.equal(operations.shift(), ['added', {a:100}, 0]);
|
||||
handle.stop();
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
test("stream - status", function () {
|
||||
test("stream - status", function (test) {
|
||||
// Very basic test. Just see that it runs and returns something. Not a
|
||||
// lot of coverage, but enough that it would have caught a recent bug.
|
||||
var status = Meteor.status();
|
||||
assert.equal(typeof status, "object");
|
||||
assert.isTrue(status.status);
|
||||
test.equal(typeof status, "object");
|
||||
test.isTrue(status.status);
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
test("template assembly", function () {
|
||||
test("template assembly", function (test) {
|
||||
var minusEmptyComments = function(s) {
|
||||
return String(s).replace(/<!---->/g, '');
|
||||
};
|
||||
@@ -7,7 +7,7 @@ test("template assembly", function () {
|
||||
// Test for a bug that made it to production -- after a replacement,
|
||||
// we need to also check the newly replaced node for replacements
|
||||
var frag = Template.test_assembly_a0();
|
||||
assert.equal(minusEmptyComments(Meteor._fragmentToHtml(frag)), "Hi");
|
||||
test.equal(minusEmptyComments(Meteor._fragmentToHtml(frag)), "Hi");
|
||||
|
||||
// Another production bug -- we must use LiveRange to replace the
|
||||
// placeholder, or risk breaking other LiveRanges
|
||||
@@ -17,10 +17,10 @@ test("template assembly", function () {
|
||||
};
|
||||
var onscreen = DIV({style: "display: none"}, [Template.test_assembly_b0()]);
|
||||
document.body.appendChild(onscreen);
|
||||
assert.equal(minusEmptyComments(onscreen.innerHTML), "xyhi");
|
||||
test.equal(minusEmptyComments(onscreen.innerHTML), "xyhi");
|
||||
Session.set("stuff", false);
|
||||
Meteor.flush();
|
||||
assert.equal(minusEmptyComments(onscreen.innerHTML), "xhi");
|
||||
test.equal(minusEmptyComments(onscreen.innerHTML), "xhi");
|
||||
document.body.removeChild(onscreen);
|
||||
});
|
||||
|
||||
@@ -32,7 +32,7 @@ test("template assembly", function () {
|
||||
|
||||
|
||||
|
||||
test("template table assembly", function() {
|
||||
test("template table assembly", function(test) {
|
||||
var childWithTag = function(node, tag) {
|
||||
return _.find(node.childNodes, function(n) {
|
||||
return n.nodeName === tag;
|
||||
@@ -46,11 +46,11 @@ test("template table assembly", function() {
|
||||
// table.rows is a great test, as it fails not only when TR/TD tags are
|
||||
// stripped due to improper html-to-fragment, but also when they are present
|
||||
// but don't show up because we didn't create a TBODY for IE.
|
||||
assert.equal(table.rows.length, 3);
|
||||
test.equal(table.rows.length, 3);
|
||||
|
||||
// this time with an explicit TBODY
|
||||
table = childWithTag(Template.test_table_b0(), "TABLE");
|
||||
assert.equal(table.rows.length, 3);
|
||||
test.equal(table.rows.length, 3);
|
||||
|
||||
var c = new LocalCollection();
|
||||
c.insert({bar:'a'});
|
||||
@@ -61,12 +61,12 @@ test("template table assembly", function() {
|
||||
document.body.appendChild(onscreen);
|
||||
table = childWithTag(onscreen, "TABLE");
|
||||
|
||||
assert.equal(table.rows.length, 3);
|
||||
test.equal(table.rows.length, 3);
|
||||
var tds = onscreen.getElementsByTagName("TD");
|
||||
assert.equal(tds.length, 3);
|
||||
assert.equal(tds[0].innerHTML, "a");
|
||||
assert.equal(tds[1].innerHTML, "b");
|
||||
assert.equal(tds[2].innerHTML, "c");
|
||||
test.equal(tds.length, 3);
|
||||
test.equal(tds[0].innerHTML, "a");
|
||||
test.equal(tds[1].innerHTML, "b");
|
||||
test.equal(tds[2].innerHTML, "c");
|
||||
|
||||
|
||||
document.body.removeChild(onscreen);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// XXX SECTION: Meta tests
|
||||
|
||||
test("try_all_permutations", function () {
|
||||
test("try_all_permutations", function (test) {
|
||||
// Have a good test of try_all_permutations, because it would suck
|
||||
// if try_all_permutations didn't actually run anything and so none
|
||||
// of our other tests actually did any testing.
|
||||
@@ -16,7 +16,7 @@ test("try_all_permutations", function () {
|
||||
function () {out += ".";}
|
||||
);
|
||||
|
||||
assert.equal(out, ":ABC.:ACB.:BAC.:BCA.:CAB.:CBA.");
|
||||
test.equal(out, ":ABC.:ACB.:BAC.:BCA.:CAB.:CBA.");
|
||||
|
||||
out = "";
|
||||
try_all_permutations(
|
||||
@@ -36,7 +36,7 @@ test("try_all_permutations", function () {
|
||||
function () {out += ".";}
|
||||
);
|
||||
|
||||
assert.equal(out, ":AB.:AC.:BA.:BC.:CA.:CB.");
|
||||
test.equal(out, ":AB.:AC.:BA.:BC.:CA.:CB.");
|
||||
|
||||
out = "";
|
||||
try_all_permutations(
|
||||
@@ -53,9 +53,9 @@ test("try_all_permutations", function () {
|
||||
],
|
||||
function () {out += ".";}
|
||||
);
|
||||
assert.equal(out, "ABXY.ABYX.ACXY.ACYX.ADXY.ADYX.BAXY.BAYX.BCXY.BCYX.BDXY.BDYX.CAXY.CAYX.CBXY.CBYX.CDXY.CDYX.DAXY.DAYX.DBXY.DBYX.DCXY.DCYX.");
|
||||
test.equal(out, "ABXY.ABYX.ACXY.ACYX.ADXY.ADYX.BAXY.BAYX.BCXY.BCYX.BDXY.BDYX.CAXY.CAYX.CBXY.CBYX.CDXY.CDYX.DAXY.DAYX.DBXY.DBYX.DCXY.DCYX.");
|
||||
|
||||
var test = function (n) {
|
||||
var examine = function (n) {
|
||||
var fs = [];
|
||||
var seq = "";
|
||||
var seen = {};
|
||||
@@ -75,11 +75,11 @@ test("try_all_permutations", function () {
|
||||
var expected_count = 1;
|
||||
for (var i = n; i >= 1; i--)
|
||||
expected_count *= i;
|
||||
assert.equal(_.keys(seen).length, expected_count);
|
||||
test.equal(_.keys(seen).length, expected_count);
|
||||
};
|
||||
|
||||
for (var i = 1; i <= 5; i++)
|
||||
test(i);
|
||||
examine(i);
|
||||
|
||||
try_all_permutations();
|
||||
});
|
||||
|
||||
@@ -4,7 +4,122 @@
|
||||
var CurrentTestRun = new Meteor.DynamicVariable;
|
||||
|
||||
// XXX namespacing
|
||||
// XXX audit for use on server (eg, stupid globals hacks)
|
||||
|
||||
/******************************************************************************/
|
||||
/* TestResultsReporter */
|
||||
/******************************************************************************/
|
||||
|
||||
Meteor._TestResultsReporter = function (run) {
|
||||
var self = this;
|
||||
self.run = run;
|
||||
};
|
||||
|
||||
_.extend(Meteor._TestResultsReporter.prototype, {
|
||||
ok: function (doc) {
|
||||
this.run.ok(doc);
|
||||
},
|
||||
|
||||
expect_fail: function () {
|
||||
this.run.expect_fail();
|
||||
},
|
||||
|
||||
fail: function (doc) {
|
||||
this.run.fail(doc);
|
||||
},
|
||||
|
||||
exception: function (exception) {
|
||||
this.run.exception(exception);
|
||||
},
|
||||
|
||||
// returns a unique ID for this test run, for convenience use by
|
||||
// your tests
|
||||
runId: function () {
|
||||
return this.run.id;
|
||||
},
|
||||
|
||||
// === Following patterned after http://vowsjs.org/#reference ===
|
||||
|
||||
// XXX eliminate 'message' and 'not' arguments
|
||||
equal: function (actual, expected, message, not) {
|
||||
/* If expected is a DOM node, do a literal '===' comparison with
|
||||
* actual. Otherwise compare the JSON stringifications of expected
|
||||
* and actual. (It's no good to stringify a DOM node. Circular
|
||||
* references, to start with..) */
|
||||
|
||||
// XXX WE REALLY SHOULD NOT BE USING
|
||||
// STRINGIFY. stringify([undefined]) === stringify([null]). should use
|
||||
// deep equality instead.
|
||||
|
||||
// XXX remove cruft specific to liverange
|
||||
if (typeof expected === "object" && expected && expected.nodeType) {
|
||||
var matched = expected === actual;
|
||||
expected = "[Node]";
|
||||
actual = "[Unknown]";
|
||||
} else {
|
||||
expected = JSON.stringify(expected);
|
||||
actual = JSON.stringify(actual);
|
||||
var matched = expected === actual;
|
||||
}
|
||||
|
||||
if (matched === !!not) {
|
||||
this.fail({type: "assert_equal", message: message,
|
||||
expected: expected, actual: actual, not: !!not});
|
||||
} else
|
||||
this.ok();
|
||||
},
|
||||
|
||||
notEqual: function (actual, expected, message) {
|
||||
this.equal(actual, expected, message, true);
|
||||
},
|
||||
|
||||
instanceOf: function (obj, klass) {
|
||||
if (obj instanceof klass)
|
||||
this.ok();
|
||||
else
|
||||
this.fail({type: "instanceOf"}); // XXX what other data?
|
||||
},
|
||||
|
||||
// XXX should be length(), but on Chrome, functions always have a
|
||||
// length property that is permanently 0 and can't be assigned to
|
||||
// (it's a noop). How does vows do it??
|
||||
length: function (obj, expected_length) {
|
||||
if (obj.length === expected_length)
|
||||
this.ok();
|
||||
else
|
||||
this.fail({type: "length"}); // XXX what other data?
|
||||
},
|
||||
|
||||
// XXX nodejs assert.throws can take an expected error, as a class,
|
||||
// regular expression, or predicate function..
|
||||
throws: function (f) {
|
||||
var actual;
|
||||
|
||||
try {
|
||||
f();
|
||||
} catch (exception) {
|
||||
actual = exception;
|
||||
}
|
||||
|
||||
if (actual)
|
||||
this.ok({message: actual.message});
|
||||
else
|
||||
this.fail({type: "throws"});
|
||||
},
|
||||
|
||||
isTrue: function (v) {
|
||||
if (v)
|
||||
this.ok();
|
||||
else
|
||||
this.fail({type: "true"});
|
||||
},
|
||||
|
||||
isFalse: function (v) {
|
||||
if (v)
|
||||
this.fail({type: "true"});
|
||||
else
|
||||
this.ok();
|
||||
}
|
||||
});
|
||||
|
||||
/******************************************************************************/
|
||||
/* TestCase */
|
||||
@@ -27,13 +142,14 @@ Meteor._TestCase = function (name, func, async) {
|
||||
_.extend(Meteor._TestCase.prototype, {
|
||||
// Run the test asynchronously, then call onComplete() on success,
|
||||
// or else onException(e) if the test raised an exception.
|
||||
run: function (onComplete, onException) {
|
||||
run: function (run, onComplete, onException) {
|
||||
var self = this;
|
||||
var reporter = new Meteor._TestResultsReporter(run);
|
||||
_.defer(Meteor.bindEnvironment(function () {
|
||||
if (self.async)
|
||||
self.func(onComplete);
|
||||
self.func(reporter, onComplete);
|
||||
else {
|
||||
self.func();
|
||||
self.func(reporter);
|
||||
onComplete();
|
||||
}
|
||||
}, onException));
|
||||
@@ -95,12 +211,9 @@ _.extend(Meteor._TestRun.prototype, {
|
||||
self.current_fail_count = 0;
|
||||
self.stop_at_offset = stopAtOffset;
|
||||
|
||||
var original_assert = globals.assert;
|
||||
globals.assert = test_assert;
|
||||
var startTime = (+new Date);
|
||||
|
||||
var cleanup = function () {
|
||||
globals.assert = original_assert;
|
||||
self.current_test = null;
|
||||
self.current_fail_count = null;
|
||||
self.stop_at_offset = null;
|
||||
@@ -125,7 +238,7 @@ _.extend(Meteor._TestRun.prototype, {
|
||||
onComplete();
|
||||
};
|
||||
|
||||
test.run(function () {
|
||||
test.run(self, function () {
|
||||
/* onComplete */
|
||||
cleanup();
|
||||
|
||||
@@ -228,94 +341,6 @@ _.extend(Meteor._TestRun.prototype, {
|
||||
}
|
||||
});
|
||||
|
||||
/******************************************************************************/
|
||||
/* Helpers */
|
||||
/******************************************************************************/
|
||||
|
||||
// Patterned after http://vowsjs.org/#reference
|
||||
var test_assert = {
|
||||
// XXX eliminate 'message' and 'not' arguments
|
||||
equal: function (actual, expected, message, not) {
|
||||
/* If expected is a DOM node, do a literal '===' comparison with
|
||||
* actual. Otherwise compare the JSON stringifications of expected
|
||||
* and actual. (It's no good to stringify a DOM node. Circular
|
||||
* references, to start with..) */
|
||||
|
||||
// XXX WE REALLY SHOULD NOT BE USING
|
||||
// STRINGIFY. stringify([undefined]) === stringify([null]). should use
|
||||
// deep equality instead.
|
||||
|
||||
// XXX remove cruft specific to liverange
|
||||
if (typeof expected === "object" && expected && expected.nodeType) {
|
||||
var matched = expected === actual;
|
||||
expected = "[Node]";
|
||||
actual = "[Unknown]";
|
||||
} else {
|
||||
expected = JSON.stringify(expected);
|
||||
actual = JSON.stringify(actual);
|
||||
var matched = expected === actual;
|
||||
}
|
||||
|
||||
if (matched === !!not) {
|
||||
test.fail({type: "assert_equal", message: message,
|
||||
expected: expected, actual: actual, not: !!not});
|
||||
} else
|
||||
test.ok();
|
||||
},
|
||||
|
||||
notEqual: function (actual, expected, message) {
|
||||
test_assert.equal(actual, expected, message, true);
|
||||
},
|
||||
|
||||
instanceOf: function (obj, klass) {
|
||||
if (obj instanceof klass)
|
||||
test.ok();
|
||||
else
|
||||
test.fail({type: "instanceOf"}); // XXX what other data?
|
||||
},
|
||||
|
||||
// XXX should be length(), but on Chrome, functions always have a
|
||||
// length property that is permanently 0 and can't be assigned to
|
||||
// (it's a noop). How does vows do it??
|
||||
length: function (obj, expected_length) {
|
||||
if (obj.length === expected_length)
|
||||
test.ok();
|
||||
else
|
||||
test.fail({type: "length"}); // XXX what other data?
|
||||
},
|
||||
|
||||
// XXX nodejs assert.throws can take an expected error, as a class,
|
||||
// regular expression, or predicate function..
|
||||
throws: function (f) {
|
||||
var actual;
|
||||
|
||||
try {
|
||||
f();
|
||||
} catch (exception) {
|
||||
actual = exception;
|
||||
}
|
||||
|
||||
if (actual)
|
||||
test.ok({message: actual.message});
|
||||
else
|
||||
test.fail({type: "throws"});
|
||||
},
|
||||
|
||||
isTrue: function (v) {
|
||||
if (v)
|
||||
test.ok();
|
||||
else
|
||||
test.fail({type: "true"});
|
||||
},
|
||||
|
||||
isFalse: function (v) {
|
||||
if (v)
|
||||
test.fail({type: "true"});
|
||||
else
|
||||
test.ok();
|
||||
}
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
/* Public API */
|
||||
/******************************************************************************/
|
||||
@@ -331,30 +356,4 @@ globals.testAsync = function (name, func) {
|
||||
Meteor._TestManager.addCase(new Meteor._TestCase(name, func, true));
|
||||
};
|
||||
|
||||
|
||||
_.extend(globals.test, {
|
||||
|
||||
ok: function (doc) {
|
||||
CurrentTestRun.get().ok(doc);
|
||||
},
|
||||
|
||||
expect_fail: function () {
|
||||
CurrentTestRun.get().expect_fail();
|
||||
},
|
||||
|
||||
fail: function (doc) {
|
||||
CurrentTestRun.get().fail(doc);
|
||||
},
|
||||
|
||||
exception: function (exception) {
|
||||
CurrentTestRun.get().exception(exception);
|
||||
},
|
||||
|
||||
// returns a unique ID for this test run, for convenience use by
|
||||
// your tests
|
||||
runId: function () {
|
||||
return CurrentTestRun.get().id;
|
||||
}
|
||||
});
|
||||
|
||||
})();
|
||||
Reference in New Issue
Block a user