summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/ajax/prototype/test/unit/unittest_test.js
blob: e7afdd60bf2c6dde3c49f23ac6ef91df509ad1ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
var testObj = {
  isNice: function() {
    return true;
  },
  isBroken: function() {
    return false;
  }
}

new Test.Unit.Runner({

  testBuildMessage:  function() {
    this.assertEqual("'foo' 'bar'", this.buildMessage('', '? ?', 'foo', 'bar'))
  },
  
  testAssertEqual: function() {
    this.assertEqual(0, 0);
    this.assertEqual(0, 0, "test");
    
    this.assertEqual(0,'0');
    this.assertEqual(65.0, 65);
    
    this.assertEqual("a", "a");
    this.assertEqual("a", "a", "test");
    
    this.assertNotEqual(0, 1);
    this.assertNotEqual("a","b");
    this.assertNotEqual({},{});
    this.assertNotEqual([],[]);
    this.assertNotEqual([],{});
  },

  testAssertEnumEqual: function() {
    this.assertEnumEqual([], []);
    this.assertEnumEqual(['a', 'b'], ['a', 'b']);
    this.assertEnumEqual(['1', '2'], [1, 2]);
    this.assertEnumNotEqual(['1', '2'], [1, 2, 3]);
  },
  
  testAssertHashEqual: function() {
    this.assertHashEqual({}, {});
    this.assertHashEqual({a:'b'}, {a:'b'});
    this.assertHashEqual({a:'b', c:'d'}, {c:'d', a:'b'});
    this.assertHashNotEqual({a:'b', c:'d'}, {c:'d', a:'boo!'});
  },
  
  testAssertRespondsTo: function() {
    this.assertRespondsTo('isNice', testObj);
    this.assertRespondsTo('isBroken', testObj);
  },
  
  testAssertIdentical: function() { 
    this.assertIdentical(0, 0); 
    this.assertIdentical(0, 0, "test"); 
    this.assertIdentical(1, 1); 
    this.assertIdentical('a', 'a'); 
    this.assertIdentical('a', 'a', "test"); 
    this.assertIdentical('', ''); 
    this.assertIdentical(undefined, undefined); 
    this.assertIdentical(null, null); 
    this.assertIdentical(true, true); 
    this.assertIdentical(false, false); 
    
    var obj = {a:'b'};
    this.assertIdentical(obj, obj);
    
    this.assertNotIdentical({1:2,3:4},{1:2,3:4});
    
    this.assertIdentical(1, 1.0); // both are typeof == 'number'
    
    this.assertNotIdentical(1, '1');
    this.assertNotIdentical(1, '1.0');
  },
  
  testAssertNullAndAssertUndefined: function() {
    this.assertNull(null);
    this.assertNotNull(undefined);
    this.assertNotNull(0);
    this.assertNotNull('');
    this.assertNotUndefined(null);
    this.assertUndefined(undefined);
    this.assertNotUndefined(0);
    this.assertNotUndefined('');
    this.assertNullOrUndefined(null);
    this.assertNullOrUndefined(undefined);
    this.assertNotNullOrUndefined(0);
    this.assertNotNullOrUndefined('');
  },
  
  testAssertMatch: function() {
    this.assertMatch(/knowmad.jpg$/, 'http://script.aculo.us/images/knowmad.jpg');
    this.assertMatch(/Fuc/, 'Thomas Fuchs');
    this.assertMatch(/^\$(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$/, '$19.95');
    this.assertMatch(/(\d{3}\) ?)|(\d{3}[- \.])?\d{3}[- \.]\d{4}(\s(x\d+)?){0,1}$/, '704-343-9330');
    this.assertMatch(/^(?:(?:(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(\/|-|\.)(?:0?2\1(?:29)))|(?:(?:(?:1[6-9]|[2-9]\d)?\d{2})(\/|-|\.)(?:(?:(?:0?[13578]|1[02])\2(?:31))|(?:(?:0?[1,3-9]|1[0-2])\2(29|30))|(?:(?:0?[1-9])|(?:1[0-2]))\2(?:0?[1-9]|1\d|2[0-8]))))$/, '2001-06-16');
    this.assertMatch(/^((0?[123456789])|(1[012]))\s*:\s*([012345]\d)(\s*:\s*([012345]\d))?\s*[ap]m\s*-\s*((0?[123456789])|(1[012]))\s*:\s*([012345]\d)(\s*:\s*([012345]\d))?\s*[ap]m$/i, '2:00PM-2:15PM');
    this.assertNoMatch(/zubar/, 'foo bar');
  },
  
  testAssertInstanceOf: function() {
    this.assertInstanceOf(String, new String);
    this.assertInstanceOf(RegExp, /foo/);
    this.assertNotInstanceOf(String, {});
  },
  
  testAssertVisible: function() {
    this.assertVisible('testcss1');
    this.assertNotVisible('testcss1_span');
    //this.assertNotVisible('testcss2', "Due to a Safari bug, this test fails in Safari.");
    
    Element.hide('testcss1');
    this.assertNotVisible('testcss1');
    this.assertNotVisible('testcss1_span');
    Element.show('testcss1');
    this.assertVisible('testcss1');
    this.assertNotVisible('testcss1_span');
    
    Element.show('testcss1_span');
    this.assertVisible('testcss1_span');
    Element.hide('testcss1');
    this.assertNotVisible('testcss1_span'); // hidden by parent
  },

  testAssertElementsMatch: function() {
    this.assertElementsMatch($$('#tlist'), '#tlist');   
    this.assertElementMatches($('tlist'), '#tlist');   
  }
});

/* This test was disabled in bug 486256, because we don't support having two
 * Runners in one file.
 */
/*
new Test.Unit.Runner({
  testDummy: function() {
    this.assert(true);
  },
  
  testMultipleTestRunner: function() {
    this.assertEqual('passed', $('testlog_2').down('td', 1).innerHTML);
  }
}, {testLog: 'testlog_2'});
*/