line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JavaScript::V8x::TestMoreish::JS; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
195
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub TestMoreish { |
7
|
|
|
|
|
|
|
<<'_END_' |
8
|
|
|
|
|
|
|
if (! _TestMoreish) |
9
|
|
|
|
|
|
|
var _TestMoreish = {}; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
(function(){ |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
var _TM = _TestMoreish; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
_TM._ok = function( ok, name ) { |
16
|
|
|
|
|
|
|
_TestMoreish_ok( ok, name ); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
_TM._diag = function( diag ) { |
20
|
|
|
|
|
|
|
_TestMoreish_diag( diag ); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
_TM._gotExpectedFailure = function( got, expected, name, _error ) { |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
var error = _error + |
26
|
|
|
|
|
|
|
"\nGot: " + got + " (" + (typeof got) + ")" + |
27
|
|
|
|
|
|
|
"\nExpected: " + expected + " (" + (typeof expected) + ")"; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
return { name: name, error: error }; |
30
|
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
_TM._gotFailure = function( got, _error ) { |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
var error = _error + |
35
|
|
|
|
|
|
|
"\nGot: " + got + " (" + (typeof got) + ")"; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
return { name: name, error: error }; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
_TM.test = { |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
areEqual: function( got, expected ) { return got == expected; }, |
44
|
|
|
|
|
|
|
areNotEqual: function( got, expected ) { return got != expected; }, |
45
|
|
|
|
|
|
|
areSame: function( got, expected ) { return got === expected; }, |
46
|
|
|
|
|
|
|
areNotSame: function( got, expected ) { return got !== expected; }, |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
isTrue: function( got ) { return got === true; }, |
49
|
|
|
|
|
|
|
isFalse: function( got ) { return got === false; }, |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
isString: function( got ) { return typeof got === 'string'; }, |
52
|
|
|
|
|
|
|
isValue: function( got ) { return this.isObject( got ) || this.isString( got ) || this.isNumber( got ) || this.isBoolean( got ); }, |
53
|
|
|
|
|
|
|
isObject: function( got ) { return (got && (typeof got === 'object' || this.isFunction( got ))) || false; }, |
54
|
|
|
|
|
|
|
isNumber: function( got ) { return typeof got === 'number' && isFinite( got ); }, |
55
|
|
|
|
|
|
|
isBoolean: function( got ) { return typeof got === 'boolean'; }, |
56
|
|
|
|
|
|
|
isFunction: function( got ) { return (typeof got === 'function') || Object.prototype.toString.apply( got ) === '[object Function]'; }, |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
like: function( got, match ) { |
59
|
|
|
|
|
|
|
if (this.isString( match )) match = new RegExp( match ); |
60
|
|
|
|
|
|
|
return this.isValue( got ) && this.isString( got ) && got.match( match ); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
}; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
_TM._areEqual = function( got, expected, name ) { |
65
|
|
|
|
|
|
|
return this.test.areEqual( got, expected ) ? { name: name } : |
66
|
|
|
|
|
|
|
this._gotExpectedFailure( got, expected, name, "Value is not equal" ); |
67
|
|
|
|
|
|
|
}; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
_TM._areNotEqual = function( got, expected, name ) { |
70
|
|
|
|
|
|
|
return this.test.areNotEqual( got, expected ) ? { name: name } : |
71
|
|
|
|
|
|
|
this._gotExpectedFailure( got, expected, name, "Value is equal" ); |
72
|
|
|
|
|
|
|
}; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
_TM._areSame = function( got, expected, name ) { |
75
|
|
|
|
|
|
|
return this.test.areSame( got, expected ) ? { name: name } : |
76
|
|
|
|
|
|
|
this._gotExpectedFailure( got, expected, name, "Value is not same" ); |
77
|
|
|
|
|
|
|
}; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
_TM._areNotSame = function( got, expected, name ) { |
80
|
|
|
|
|
|
|
return this.test.areNotSame( got, expected ) ? { name: name } : |
81
|
|
|
|
|
|
|
this._gotExpectedFailure( got, expected, name, "Value is same" ); |
82
|
|
|
|
|
|
|
}; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
_TM._isTrue = function( got, name ) { |
85
|
|
|
|
|
|
|
return this.test.isTrue( got ) ? { name: name } : |
86
|
|
|
|
|
|
|
this._gotFailure( got, name, "Value was not true" ); |
87
|
|
|
|
|
|
|
}; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
_TM._isFalse = function( got, name ) { |
90
|
|
|
|
|
|
|
return this.test.isFalse( got ) ? { name: name } : |
91
|
|
|
|
|
|
|
this._gotFailure( got, name, "Value was not false" ); |
92
|
|
|
|
|
|
|
}; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
_TM._isString = function( got, name ) { |
95
|
|
|
|
|
|
|
return this.test.isString( got ) ? { name: name } : |
96
|
|
|
|
|
|
|
this._gotFailure( got, name, "Value was not a string" ); |
97
|
|
|
|
|
|
|
}; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
_TM._isValue = function( got, name ) { |
100
|
|
|
|
|
|
|
return this.test.isValue( got ) ? { name: name } : |
101
|
|
|
|
|
|
|
this._gotFailure( got, name, "Value was not a value" ); |
102
|
|
|
|
|
|
|
}; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
_TM._isObject = function( got, name ) { |
105
|
|
|
|
|
|
|
return this.test.isNumber( got ) ? { name: name } : |
106
|
|
|
|
|
|
|
this._gotFailure( got, name, "Value was not an object" ); |
107
|
|
|
|
|
|
|
}; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
_TM._isNumber = function( got, name ) { |
110
|
|
|
|
|
|
|
return this.test.isNumber( got ) ? { name: name } : |
111
|
|
|
|
|
|
|
this._gotFailure( got, name, "Value was not a number" ); |
112
|
|
|
|
|
|
|
}; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
_TM._isBoolean = function( got, name ) { |
115
|
|
|
|
|
|
|
return this.test.isBoolean( got ) ? { name: name } : |
116
|
|
|
|
|
|
|
this._gotFailure( got, name, "Value was not a boolean" ); |
117
|
|
|
|
|
|
|
}; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
_TM._isFunction = function( got, name ) { |
120
|
|
|
|
|
|
|
return this.test.isFunction( got ) ? { name: name } : |
121
|
|
|
|
|
|
|
this._gotFailure( got, name, "Value was not a function" ); |
122
|
|
|
|
|
|
|
}; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
_TM._like = function( got, match, name ) { |
125
|
|
|
|
|
|
|
return this.test.like( got, match ) ? { name: name } : |
126
|
|
|
|
|
|
|
this._gotExpectedFailure( got, match, name, "Value does not match regular expression" ); |
127
|
|
|
|
|
|
|
}; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
_TM._fail = function( name ) { |
130
|
|
|
|
|
|
|
return { name: name, error: "Failure" }; |
131
|
|
|
|
|
|
|
}; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
// _formatMessage : function (customMessage /*:String*/, defaultMessage /*:String*/) /*:String*/ { |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
// var message = customMessage; |
136
|
|
|
|
|
|
|
// if (YAHOO.lang.isString(customMessage) && customMessage.length > 0){ |
137
|
|
|
|
|
|
|
// return YAHOO.lang.substitute(customMessage, { message: defaultMessage }); |
138
|
|
|
|
|
|
|
// } else { |
139
|
|
|
|
|
|
|
// return defaultMessage; |
140
|
|
|
|
|
|
|
// } |
141
|
|
|
|
|
|
|
// }, |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
// getMessage : function () /*:String*/ { |
144
|
|
|
|
|
|
|
// return this.message + "\nExpected: " + this.expected + " (" + (typeof this.expected) + ")" + |
145
|
|
|
|
|
|
|
// "\nActual:" + this.actual + " (" + (typeof this.actual) + ")"; |
146
|
|
|
|
|
|
|
// } |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
var _installTest = function( test ) { |
149
|
|
|
|
|
|
|
return function() { |
150
|
|
|
|
|
|
|
var tester = this['_' + test]; |
151
|
|
|
|
|
|
|
var result = tester.apply( this, arguments ); |
152
|
|
|
|
|
|
|
this._ok( result.error ? 0 : 1, result.name ); |
153
|
|
|
|
|
|
|
if ( result.error ) { |
154
|
|
|
|
|
|
|
this._diag( result.error ); |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
return result.error ? 0 : 1; |
157
|
|
|
|
|
|
|
}; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
// Public API |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
_TM.diag = function() { this._diag.apply( this, arguments ) }; |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
var _test = [ |
165
|
|
|
|
|
|
|
'areEqual', |
166
|
|
|
|
|
|
|
'areNotEqual', |
167
|
|
|
|
|
|
|
'areSame', |
168
|
|
|
|
|
|
|
'areNotSame', |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
'isTrue', |
171
|
|
|
|
|
|
|
'isFalse', |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
'isBoolean', |
174
|
|
|
|
|
|
|
'isFunction', |
175
|
|
|
|
|
|
|
'isNumber', |
176
|
|
|
|
|
|
|
'isObject', |
177
|
|
|
|
|
|
|
'isString', |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
'like', |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
'fail', |
182
|
|
|
|
|
|
|
// 'isTypeOf', |
183
|
|
|
|
|
|
|
// 'isArray', |
184
|
|
|
|
|
|
|
// 'isInstanceOf', |
185
|
|
|
|
|
|
|
// 'isNaN', |
186
|
|
|
|
|
|
|
// 'isNotNaN', |
187
|
|
|
|
|
|
|
// 'isNull', |
188
|
|
|
|
|
|
|
// 'isNotNull', |
189
|
|
|
|
|
|
|
// 'isUndefined', |
190
|
|
|
|
|
|
|
// 'isNotUndefined' |
191
|
|
|
|
|
|
|
]; |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
for (var ii = 0; ii < _test.length; ii++) { |
194
|
|
|
|
|
|
|
var name = _test[ii]; |
195
|
|
|
|
|
|
|
_TM[name] = _installTest( name ); |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
})(); |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
// //------------------------------------------------------------------------- |
201
|
|
|
|
|
|
|
// // Boolean Assertion Methods |
202
|
|
|
|
|
|
|
// //------------------------------------------------------------------------- |
203
|
|
|
|
|
|
|
// |
204
|
|
|
|
|
|
|
// /** |
205
|
|
|
|
|
|
|
// * Asserts that a value is false. This uses the triple equals sign |
206
|
|
|
|
|
|
|
// * so no type cohersion may occur. |
207
|
|
|
|
|
|
|
// * @param {Object} actual The actual value to test. |
208
|
|
|
|
|
|
|
// * @param {String} message (Optional) The message to display if the assertion fails. |
209
|
|
|
|
|
|
|
// * @method isFalse |
210
|
|
|
|
|
|
|
// * @static |
211
|
|
|
|
|
|
|
// */ |
212
|
|
|
|
|
|
|
// isFalse : function (actual /*:Boolean*/, message /*:String*/) { |
213
|
|
|
|
|
|
|
// if (false !== actual) { |
214
|
|
|
|
|
|
|
// throw new YAHOO.util.ComparisonFailure(this._formatMessage(message, "Value should be false."), false, actual); |
215
|
|
|
|
|
|
|
// } |
216
|
|
|
|
|
|
|
// }, |
217
|
|
|
|
|
|
|
// |
218
|
|
|
|
|
|
|
// /** |
219
|
|
|
|
|
|
|
// * Asserts that a value is true. This uses the triple equals sign |
220
|
|
|
|
|
|
|
// * so no type cohersion may occur. |
221
|
|
|
|
|
|
|
// * @param {Object} actual The actual value to test. |
222
|
|
|
|
|
|
|
// * @param {String} message (Optional) The message to display if the assertion fails. |
223
|
|
|
|
|
|
|
// * @method isTrue |
224
|
|
|
|
|
|
|
// * @static |
225
|
|
|
|
|
|
|
// */ |
226
|
|
|
|
|
|
|
// isTrue : function (actual /*:Boolean*/, message /*:String*/) /*:Void*/ { |
227
|
|
|
|
|
|
|
// if (true !== actual) { |
228
|
|
|
|
|
|
|
// throw new YAHOO.util.ComparisonFailure(this._formatMessage(message, "Value should be true."), true, actual); |
229
|
|
|
|
|
|
|
// } |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
// }, |
232
|
|
|
|
|
|
|
// |
233
|
|
|
|
|
|
|
// //------------------------------------------------------------------------- |
234
|
|
|
|
|
|
|
// // Special Value Assertion Methods |
235
|
|
|
|
|
|
|
// //------------------------------------------------------------------------- |
236
|
|
|
|
|
|
|
// |
237
|
|
|
|
|
|
|
// /** |
238
|
|
|
|
|
|
|
// * Asserts that a value is not a number. |
239
|
|
|
|
|
|
|
// * @param {Object} actual The value to test. |
240
|
|
|
|
|
|
|
// * @param {String} message (Optional) The message to display if the assertion fails. |
241
|
|
|
|
|
|
|
// * @method isNaN |
242
|
|
|
|
|
|
|
// * @static |
243
|
|
|
|
|
|
|
// */ |
244
|
|
|
|
|
|
|
// isNaN : function (actual /*:Object*/, message /*:String*/) /*:Void*/{ |
245
|
|
|
|
|
|
|
// if (!isNaN(actual)){ |
246
|
|
|
|
|
|
|
// throw new YAHOO.util.ComparisonFailure(this._formatMessage(message, "Value should be NaN."), NaN, actual); |
247
|
|
|
|
|
|
|
// } |
248
|
|
|
|
|
|
|
// }, |
249
|
|
|
|
|
|
|
// |
250
|
|
|
|
|
|
|
// /** |
251
|
|
|
|
|
|
|
// * Asserts that a value is not the special NaN value. |
252
|
|
|
|
|
|
|
// * @param {Object} actual The value to test. |
253
|
|
|
|
|
|
|
// * @param {String} message (Optional) The message to display if the assertion fails. |
254
|
|
|
|
|
|
|
// * @method isNotNaN |
255
|
|
|
|
|
|
|
// * @static |
256
|
|
|
|
|
|
|
// */ |
257
|
|
|
|
|
|
|
// isNotNaN : function (actual /*:Object*/, message /*:String*/) /*:Void*/{ |
258
|
|
|
|
|
|
|
// if (isNaN(actual)){ |
259
|
|
|
|
|
|
|
// throw new YAHOO.util.UnexpectedValue(this._formatMessage(message, "Values should not be NaN."), NaN); |
260
|
|
|
|
|
|
|
// } |
261
|
|
|
|
|
|
|
// }, |
262
|
|
|
|
|
|
|
// |
263
|
|
|
|
|
|
|
// /** |
264
|
|
|
|
|
|
|
// * Asserts that a value is not null. This uses the triple equals sign |
265
|
|
|
|
|
|
|
// * so no type cohersion may occur. |
266
|
|
|
|
|
|
|
// * @param {Object} actual The actual value to test. |
267
|
|
|
|
|
|
|
// * @param {String} message (Optional) The message to display if the assertion fails. |
268
|
|
|
|
|
|
|
// * @method isNotNull |
269
|
|
|
|
|
|
|
// * @static |
270
|
|
|
|
|
|
|
// */ |
271
|
|
|
|
|
|
|
// isNotNull : function (actual /*:Object*/, message /*:String*/) /*:Void*/ { |
272
|
|
|
|
|
|
|
// if (YAHOO.lang.isNull(actual)) { |
273
|
|
|
|
|
|
|
// throw new YAHOO.util.UnexpectedValue(this._formatMessage(message, "Values should not be null."), null); |
274
|
|
|
|
|
|
|
// } |
275
|
|
|
|
|
|
|
// }, |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
// /** |
278
|
|
|
|
|
|
|
// * Asserts that a value is not undefined. This uses the triple equals sign |
279
|
|
|
|
|
|
|
// * so no type cohersion may occur. |
280
|
|
|
|
|
|
|
// * @param {Object} actual The actual value to test. |
281
|
|
|
|
|
|
|
// * @param {String} message (Optional) The message to display if the assertion fails. |
282
|
|
|
|
|
|
|
// * @method isNotUndefined |
283
|
|
|
|
|
|
|
// * @static |
284
|
|
|
|
|
|
|
// */ |
285
|
|
|
|
|
|
|
// isNotUndefined : function (actual /*:Object*/, message /*:String*/) /*:Void*/ { |
286
|
|
|
|
|
|
|
// if (YAHOO.lang.isUndefined(actual)) { |
287
|
|
|
|
|
|
|
// throw new YAHOO.util.UnexpectedValue(this._formatMessage(message, "Value should not be undefined."), undefined); |
288
|
|
|
|
|
|
|
// } |
289
|
|
|
|
|
|
|
// }, |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
// /** |
292
|
|
|
|
|
|
|
// * Asserts that a value is null. This uses the triple equals sign |
293
|
|
|
|
|
|
|
// * so no type cohersion may occur. |
294
|
|
|
|
|
|
|
// * @param {Object} actual The actual value to test. |
295
|
|
|
|
|
|
|
// * @param {String} message (Optional) The message to display if the assertion fails. |
296
|
|
|
|
|
|
|
// * @method isNull |
297
|
|
|
|
|
|
|
// * @static |
298
|
|
|
|
|
|
|
// */ |
299
|
|
|
|
|
|
|
// isNull : function (actual /*:Object*/, message /*:String*/) /*:Void*/ { |
300
|
|
|
|
|
|
|
// if (!YAHOO.lang.isNull(actual)) { |
301
|
|
|
|
|
|
|
// throw new YAHOO.util.ComparisonFailure(this._formatMessage(message, "Value should be null."), null, actual); |
302
|
|
|
|
|
|
|
// } |
303
|
|
|
|
|
|
|
// }, |
304
|
|
|
|
|
|
|
// |
305
|
|
|
|
|
|
|
// /** |
306
|
|
|
|
|
|
|
// * Asserts that a value is undefined. This uses the triple equals sign |
307
|
|
|
|
|
|
|
// * so no type cohersion may occur. |
308
|
|
|
|
|
|
|
// * @param {Object} actual The actual value to test. |
309
|
|
|
|
|
|
|
// * @param {String} message (Optional) The message to display if the assertion fails. |
310
|
|
|
|
|
|
|
// * @method isUndefined |
311
|
|
|
|
|
|
|
// * @static |
312
|
|
|
|
|
|
|
// */ |
313
|
|
|
|
|
|
|
// isUndefined : function (actual /*:Object*/, message /*:String*/) /*:Void*/ { |
314
|
|
|
|
|
|
|
// if (!YAHOO.lang.isUndefined(actual)) { |
315
|
|
|
|
|
|
|
// throw new YAHOO.util.ComparisonFailure(this._formatMessage(message, "Value should be undefined."), undefined, actual); |
316
|
|
|
|
|
|
|
// } |
317
|
|
|
|
|
|
|
// }, |
318
|
|
|
|
|
|
|
// |
319
|
|
|
|
|
|
|
// //-------------------------------------------------------------------------- |
320
|
|
|
|
|
|
|
// // Instance Assertion Methods |
321
|
|
|
|
|
|
|
// //-------------------------------------------------------------------------- |
322
|
|
|
|
|
|
|
// |
323
|
|
|
|
|
|
|
// /** |
324
|
|
|
|
|
|
|
// * Asserts that a value is an array. |
325
|
|
|
|
|
|
|
// * @param {Object} actual The value to test. |
326
|
|
|
|
|
|
|
// * @param {String} message (Optional) The message to display if the assertion fails. |
327
|
|
|
|
|
|
|
// * @method isArray |
328
|
|
|
|
|
|
|
// * @static |
329
|
|
|
|
|
|
|
// */ |
330
|
|
|
|
|
|
|
// isArray : function (actual /*:Object*/, message /*:String*/) /*:Void*/ { |
331
|
|
|
|
|
|
|
// if (!YAHOO.lang.isArray(actual)){ |
332
|
|
|
|
|
|
|
// throw new YAHOO.util.UnexpectedValue(this._formatMessage(message, "Value should be an array."), actual); |
333
|
|
|
|
|
|
|
// } |
334
|
|
|
|
|
|
|
// }, |
335
|
|
|
|
|
|
|
// |
336
|
|
|
|
|
|
|
// /** |
337
|
|
|
|
|
|
|
// * Asserts that a value is a Boolean. |
338
|
|
|
|
|
|
|
// * @param {Object} actual The value to test. |
339
|
|
|
|
|
|
|
// * @param {String} message (Optional) The message to display if the assertion fails. |
340
|
|
|
|
|
|
|
// * @method isBoolean |
341
|
|
|
|
|
|
|
// * @static |
342
|
|
|
|
|
|
|
// */ |
343
|
|
|
|
|
|
|
// isBoolean : function (actual /*:Object*/, message /*:String*/) /*:Void*/ { |
344
|
|
|
|
|
|
|
// if (!YAHOO.lang.isBoolean(actual)){ |
345
|
|
|
|
|
|
|
// throw new YAHOO.util.UnexpectedValue(this._formatMessage(message, "Value should be a Boolean."), actual); |
346
|
|
|
|
|
|
|
// } |
347
|
|
|
|
|
|
|
// }, |
348
|
|
|
|
|
|
|
// |
349
|
|
|
|
|
|
|
// /** |
350
|
|
|
|
|
|
|
// * Asserts that a value is a function. |
351
|
|
|
|
|
|
|
// * @param {Object} actual The value to test. |
352
|
|
|
|
|
|
|
// * @param {String} message (Optional) The message to display if the assertion fails. |
353
|
|
|
|
|
|
|
// * @method isFunction |
354
|
|
|
|
|
|
|
// * @static |
355
|
|
|
|
|
|
|
// */ |
356
|
|
|
|
|
|
|
// isFunction : function (actual /*:Object*/, message /*:String*/) /*:Void*/ { |
357
|
|
|
|
|
|
|
// if (!YAHOO.lang.isFunction(actual)){ |
358
|
|
|
|
|
|
|
// throw new YAHOO.util.UnexpectedValue(this._formatMessage(message, "Value should be a function."), actual); |
359
|
|
|
|
|
|
|
// } |
360
|
|
|
|
|
|
|
// }, |
361
|
|
|
|
|
|
|
// |
362
|
|
|
|
|
|
|
// /** |
363
|
|
|
|
|
|
|
// * Asserts that a value is an instance of a particular object. This may return |
364
|
|
|
|
|
|
|
// * incorrect results when comparing objects from one frame to constructors in |
365
|
|
|
|
|
|
|
// * another frame. For best results, don't use in a cross-frame manner. |
366
|
|
|
|
|
|
|
// * @param {Function} expected The function that the object should be an instance of. |
367
|
|
|
|
|
|
|
// * @param {Object} actual The object to test. |
368
|
|
|
|
|
|
|
// * @param {String} message (Optional) The message to display if the assertion fails. |
369
|
|
|
|
|
|
|
// * @method isInstanceOf |
370
|
|
|
|
|
|
|
// * @static |
371
|
|
|
|
|
|
|
// */ |
372
|
|
|
|
|
|
|
// isInstanceOf : function (expected /*:Function*/, actual /*:Object*/, message /*:String*/) /*:Void*/ { |
373
|
|
|
|
|
|
|
// if (!(actual instanceof expected)){ |
374
|
|
|
|
|
|
|
// throw new YAHOO.util.ComparisonFailure(this._formatMessage(message, "Value isn't an instance of expected type."), expected, actual); |
375
|
|
|
|
|
|
|
// } |
376
|
|
|
|
|
|
|
// }, |
377
|
|
|
|
|
|
|
// |
378
|
|
|
|
|
|
|
// /** |
379
|
|
|
|
|
|
|
// * Asserts that a value is a number. |
380
|
|
|
|
|
|
|
// * @param {Object} actual The value to test. |
381
|
|
|
|
|
|
|
// * @param {String} message (Optional) The message to display if the assertion fails. |
382
|
|
|
|
|
|
|
// * @method isNumber |
383
|
|
|
|
|
|
|
// * @static |
384
|
|
|
|
|
|
|
// */ |
385
|
|
|
|
|
|
|
// isNumber : function (actual /*:Object*/, message /*:String*/) /*:Void*/ { |
386
|
|
|
|
|
|
|
// if (!YAHOO.lang.isNumber(actual)){ |
387
|
|
|
|
|
|
|
// throw new YAHOO.util.UnexpectedValue(this._formatMessage(message, "Value should be a number."), actual); |
388
|
|
|
|
|
|
|
// } |
389
|
|
|
|
|
|
|
// }, |
390
|
|
|
|
|
|
|
// |
391
|
|
|
|
|
|
|
// /** |
392
|
|
|
|
|
|
|
// * Asserts that a value is an object. |
393
|
|
|
|
|
|
|
// * @param {Object} actual The value to test. |
394
|
|
|
|
|
|
|
// * @param {String} message (Optional) The message to display if the assertion fails. |
395
|
|
|
|
|
|
|
// * @method isObject |
396
|
|
|
|
|
|
|
// * @static |
397
|
|
|
|
|
|
|
// */ |
398
|
|
|
|
|
|
|
// isObject : function (actual /*:Object*/, message /*:String*/) /*:Void*/ { |
399
|
|
|
|
|
|
|
// if (!YAHOO.lang.isObject(actual)){ |
400
|
|
|
|
|
|
|
// throw new YAHOO.util.UnexpectedValue(this._formatMessage(message, "Value should be an object."), actual); |
401
|
|
|
|
|
|
|
// } |
402
|
|
|
|
|
|
|
// }, |
403
|
|
|
|
|
|
|
// |
404
|
|
|
|
|
|
|
// /** |
405
|
|
|
|
|
|
|
// * Asserts that a value is a string. |
406
|
|
|
|
|
|
|
// * @param {Object} actual The value to test. |
407
|
|
|
|
|
|
|
// * @param {String} message (Optional) The message to display if the assertion fails. |
408
|
|
|
|
|
|
|
// * @method isString |
409
|
|
|
|
|
|
|
// * @static |
410
|
|
|
|
|
|
|
// */ |
411
|
|
|
|
|
|
|
// isString : function (actual /*:Object*/, message /*:String*/) /*:Void*/ { |
412
|
|
|
|
|
|
|
// if (!YAHOO.lang.isString(actual)){ |
413
|
|
|
|
|
|
|
// throw new YAHOO.util.UnexpectedValue(this._formatMessage(message, "Value should be a string."), actual); |
414
|
|
|
|
|
|
|
// } |
415
|
|
|
|
|
|
|
// }, |
416
|
|
|
|
|
|
|
// |
417
|
|
|
|
|
|
|
// /** |
418
|
|
|
|
|
|
|
// * Asserts that a value is of a particular type. |
419
|
|
|
|
|
|
|
// * @param {String} expectedType The expected type of the variable. |
420
|
|
|
|
|
|
|
// * @param {Object} actualValue The actual value to test. |
421
|
|
|
|
|
|
|
// * @param {String} message (Optional) The message to display if the assertion fails. |
422
|
|
|
|
|
|
|
// * @method isTypeOf |
423
|
|
|
|
|
|
|
// * @static |
424
|
|
|
|
|
|
|
// */ |
425
|
|
|
|
|
|
|
// isTypeOf : function (expected /*:String*/, actual /*:Object*/, message /*:String*/) /*:Void*/{ |
426
|
|
|
|
|
|
|
// if (typeof actual != expected){ |
427
|
|
|
|
|
|
|
// throw new YAHOO.util.ComparisonFailure(this._formatMessage(message, "Value should be of type " + expected + "."), expected, typeof actual); |
428
|
|
|
|
|
|
|
// } |
429
|
|
|
|
|
|
|
// } |
430
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
_END_ |
432
|
0
|
|
|
0
|
0
|
|
} |
433
|
|
|
|
|
|
|
|
434
|
|
|
|
|
|
|
1; |