61c6ab3fb0
functional tests, unless a whole lot of mock objects are introduced, which isn't entirely out of the question). Uses JsUnit, which is included in this commit.
101 lines
4.1 KiB
HTML
101 lines
4.1 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
|
<title>JsUnit Utility Tests</title>
|
|
<link rel="stylesheet" type="text/css" href="../css/jsUnitStyle.css">
|
|
<script language="JavaScript" type="text/javascript" src="../app/jsUnitCore.js"></script>
|
|
<script language="JavaScript" type="text/javascript">
|
|
function testTrim() {
|
|
assertEquals(null, trim(null));
|
|
assertEquals(null, trim(JSUNIT_UNDEFINED_VALUE));
|
|
assertEquals("", trim(""));
|
|
assertEquals("", trim(" "));
|
|
assertEquals("string", trim("string"));
|
|
assertEquals("str ing", trim("str ing"));
|
|
assertEquals("string", trim(" string "));
|
|
}
|
|
|
|
function testIsBlank() {
|
|
assert(!isBlank(" string "));
|
|
assert(isBlank(""));
|
|
assert(isBlank(" "));
|
|
}
|
|
|
|
function testPushAndPop() {
|
|
//the functions push(anArray, anObject) and pop(anArray) exist because the JavaScript Array.push(anObject) and Array.pop() functions are not available in IE 5.0
|
|
var anArray = Array();
|
|
anArray[0] = "element 0";
|
|
anArray[1] = "element 1";
|
|
push(anArray, "element 2");
|
|
push(anArray, "element 3");
|
|
|
|
assertEquals("There should be 4 elements after 2 are pushed onto an array of size 2", 4, anArray.length);
|
|
assertEquals("element 0", anArray[0]);
|
|
assertEquals("element 1", anArray[1]);
|
|
assertEquals("element 2", anArray[2]);
|
|
assertEquals("element 3", anArray[3]);
|
|
|
|
pop(anArray);
|
|
assertEquals("Should be 3 elements after popping 1 from an array of size 4", 3, anArray.length);
|
|
assertEquals("element 0", anArray[0]);
|
|
assertEquals("element 1", anArray[1]);
|
|
assertEquals("element 2", anArray[2]);
|
|
pop(anArray);
|
|
pop(anArray);
|
|
pop(anArray);
|
|
assertEquals("Should be 0 elements after popping 3 from an array of size 3", 0, anArray.length);
|
|
pop(anArray);
|
|
assertEquals("Should be 0 elements after trying to pop an array of size 0", 0, anArray.length);
|
|
}
|
|
|
|
function FooBarThingy() {
|
|
this.foo = 'bar';
|
|
}
|
|
|
|
FooBarThingy.prototype.bar = function() {
|
|
return this.foo;
|
|
}
|
|
|
|
function testTrueTypeOf() {
|
|
assertEquals('Boolean', _trueTypeOf(true));
|
|
assertEquals('Using new', 'Boolean', _trueTypeOf(new Boolean('1')));
|
|
|
|
assertEquals('Number', _trueTypeOf(1));
|
|
var GI = new Number(1);
|
|
assertEquals('Using new', 'Number', _trueTypeOf(GI));
|
|
assertEquals('Number', _trueTypeOf(1.5));
|
|
|
|
assertEquals('String', _trueTypeOf('foo'));
|
|
assertEquals('Using new', 'String', _trueTypeOf(new String('foo')));
|
|
|
|
assertEquals('Using new', 'Function', _trueTypeOf(new Function()));
|
|
assertEquals('Function', _trueTypeOf(function foo() {
|
|
}));
|
|
assertEquals('Function', _trueTypeOf(testTrueTypeOf));
|
|
|
|
assertEquals('RegExp', _trueTypeOf(/foo/));
|
|
assertEquals('Using new', 'RegExp', _trueTypeOf(new RegExp('foo')));
|
|
|
|
var o = {foo: 'bar'};
|
|
assertEquals('Object', _trueTypeOf(o));
|
|
var o = new FooBarThingy();
|
|
assertEquals('FooBarThingy', _trueTypeOf(o));
|
|
assertEquals('String', _trueTypeOf(o.foo));
|
|
assertEquals('String', _trueTypeOf(o.bar()));
|
|
assertEquals('Function', _trueTypeOf(o.bar));
|
|
|
|
assertEquals('Object without constructor', 'Object', _trueTypeOf(window));
|
|
}
|
|
</script>
|
|
</head>
|
|
|
|
<body>
|
|
<h1>JsUnit Utility Tests</h1>
|
|
|
|
<p>This page contains tests for the utility functions
|
|
that JsUnit uses. To see them, take a look at the source.</p>
|
|
</body>
|
|
</html>
|