~jstys-z/helioviewer.org/client5

« back to all changes in this revision

Viewing changes to lib/jsunit-2.2/tests/jsUnitUtilityTests.html

  • Committer: V. Keith Hughitt
  • Date: 2009-04-01 21:08:05 UTC
  • Revision ID: hughitt1@kore-20090401210805-372f7dgih07vxk42
nightly build 04-01-2009

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 
2
 
 
3
<html>
 
4
<head>
 
5
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 
6
    <title>JsUnit Utility Tests</title>
 
7
    <link rel="stylesheet" type="text/css" href="../css/jsUnitStyle.css">
 
8
    <script language="JavaScript" type="text/javascript" src="../app/jsUnitCore.js"></script>
 
9
    <script language="JavaScript" type="text/javascript">
 
10
        function testTrim() {
 
11
            assertEquals(null, trim(null));
 
12
            assertEquals(null, trim(JSUNIT_UNDEFINED_VALUE));
 
13
            assertEquals("", trim(""));
 
14
            assertEquals("", trim("    "));
 
15
            assertEquals("string", trim("string"));
 
16
            assertEquals("str  ing", trim("str  ing"));
 
17
            assertEquals("string", trim(" string   "));
 
18
        }
 
19
 
 
20
        function testIsBlank() {
 
21
            assert(!isBlank("  string "));
 
22
            assert(isBlank(""));
 
23
            assert(isBlank("    "));
 
24
        }
 
25
 
 
26
        function testPushAndPop() {
 
27
            //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
 
28
            var anArray = Array();
 
29
            anArray[0] = "element 0";
 
30
            anArray[1] = "element 1";
 
31
            push(anArray, "element 2");
 
32
            push(anArray, "element 3");
 
33
 
 
34
            assertEquals("There should be 4 elements after 2 are pushed onto an array of size 2", 4, anArray.length);
 
35
            assertEquals("element 0", anArray[0]);
 
36
            assertEquals("element 1", anArray[1]);
 
37
            assertEquals("element 2", anArray[2]);
 
38
            assertEquals("element 3", anArray[3]);
 
39
 
 
40
            pop(anArray);
 
41
            assertEquals("Should be 3 elements after popping 1 from an array of size 4", 3, anArray.length);
 
42
            assertEquals("element 0", anArray[0]);
 
43
            assertEquals("element 1", anArray[1]);
 
44
            assertEquals("element 2", anArray[2]);
 
45
            pop(anArray);
 
46
            pop(anArray);
 
47
            pop(anArray);
 
48
            assertEquals("Should be 0 elements after popping 3 from an array of size 3", 0, anArray.length);
 
49
            pop(anArray);
 
50
            assertEquals("Should be 0 elements after trying to pop an array of size 0", 0, anArray.length);
 
51
        }
 
52
 
 
53
        function FooBarThingy() {
 
54
            this.foo = 'bar';
 
55
        }
 
56
 
 
57
        FooBarThingy.prototype.bar = function() {
 
58
            return this.foo;
 
59
        }
 
60
 
 
61
        function testTrueTypeOf() {
 
62
            assertEquals('Boolean', _trueTypeOf(true));
 
63
            assertEquals('Using new', 'Boolean', _trueTypeOf(new Boolean('1')));
 
64
 
 
65
            assertEquals('Number', _trueTypeOf(1));
 
66
            var GI = new Number(1);
 
67
            assertEquals('Using new', 'Number', _trueTypeOf(GI));
 
68
            assertEquals('Number', _trueTypeOf(1.5));
 
69
 
 
70
            assertEquals('String', _trueTypeOf('foo'));
 
71
            assertEquals('Using new', 'String', _trueTypeOf(new String('foo')));
 
72
 
 
73
            assertEquals('Using new', 'Function', _trueTypeOf(new Function()));
 
74
            assertEquals('Function', _trueTypeOf(function foo() {
 
75
            }));
 
76
            assertEquals('Function', _trueTypeOf(testTrueTypeOf));
 
77
 
 
78
            assertEquals('RegExp', _trueTypeOf(/foo/));
 
79
            assertEquals('Using new', 'RegExp', _trueTypeOf(new RegExp('foo')));
 
80
 
 
81
            var o = {foo: 'bar'};
 
82
            assertEquals('Object', _trueTypeOf(o));
 
83
            var o = new FooBarThingy();
 
84
            assertEquals('FooBarThingy', _trueTypeOf(o));
 
85
            assertEquals('String', _trueTypeOf(o.foo));
 
86
            assertEquals('String', _trueTypeOf(o.bar()));
 
87
            assertEquals('Function', _trueTypeOf(o.bar));
 
88
 
 
89
            assertEquals('Object without constructor', 'Object', _trueTypeOf(window));
 
90
        }
 
91
    </script>
 
92
</head>
 
93
 
 
94
<body>
 
95
<h1>JsUnit Utility Tests</h1>
 
96
 
 
97
<p>This page contains tests for the utility functions
 
98
    that JsUnit uses. To see them, take a look at the source.</p>
 
99
</body>
 
100
</html>