From 4ccc9580eed8269e376eaa671e42590ff095c890 Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Tue, 1 Jun 2010 00:44:54 +0200 Subject: Added test for util.heir --- tests/test-util.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'tests') diff --git a/tests/test-util.js b/tests/test-util.js index 552868f..2104a2e 100644 --- a/tests/test-util.js +++ b/tests/test-util.js @@ -48,6 +48,52 @@ var areArraysEqual = function areArraysEqual(array1, array2) { return true; }; +// testing util.heir +exports.ensureHeir = function (test) { + var fedlimid = {}, naoise = {}; + + function Father(x) { + this.family = x; + } + + Father.prototype.getFamily = function getFamily() { + return this.family; + }; + + function Son(x, w) { + Father.call(this, x); + this.wife = w; + } + + Son.prototype = util.heir(Father); + Son.prototype.constructor = Son; + + Son.prototype.getWife = function getWife() { + return this.wife; + }; + + Son.prototype.getFamily = function getFamily() { + var upFamily = + Father.prototype.getFamily.call(this); + return upFamily + ", " + this.wife; + }; + + // for curious and non-Celtic + // http://en.wikipedia.org/wiki/Deirdre :) + fedlimid = new Father("mac Daill"); + naoise = new Son("Usnech", "Deirdre"); + + test.assertEqual(fedlimid.getFamily(), "mac Daill", + "checking creation of new simple object"); + + test.assertEqual(naoise.getWife(), "Deirdre", + "checking creation of new daughter object"); + + test.assertEqual(naoise.getFamily(), "Usnech, Deirdre", + "checking creation of new overloaded method"); +}; + + // testing util.isInList exports.ensureIsInListTrue = function (test) { test.assert(util.isInList("a", ["a"]), -- cgit