Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80538 views
1
// Copyright Joyent, Inc. and other Node contributors.
2
//
3
// Permission is hereby granted, free of charge, to any person obtaining a
4
// copy of this software and associated documentation files (the
5
// "Software"), to deal in the Software without restriction, including
6
// without limitation the rights to use, copy, modify, merge, publish,
7
// distribute, sublicense, and/or sell copies of the Software, and to permit
8
// persons to whom the Software is furnished to do so, subject to the
9
// following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included
12
// in all copies or substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22
var assert = require('assert');
23
24
var util = require('../../');
25
26
suite('is');
27
28
test('util.isArray', function () {
29
assert.equal(true, util.isArray([]));
30
assert.equal(true, util.isArray(Array()));
31
assert.equal(true, util.isArray(new Array()));
32
assert.equal(true, util.isArray(new Array(5)));
33
assert.equal(true, util.isArray(new Array('with', 'some', 'entries')));
34
assert.equal(false, util.isArray({}));
35
assert.equal(false, util.isArray({ push: function() {} }));
36
assert.equal(false, util.isArray(/regexp/));
37
assert.equal(false, util.isArray(new Error()));
38
assert.equal(false, util.isArray(Object.create(Array.prototype)));
39
});
40
41
test('util.isRegExp', function () {
42
assert.equal(true, util.isRegExp(/regexp/));
43
assert.equal(true, util.isRegExp(RegExp()));
44
assert.equal(true, util.isRegExp(new RegExp()));
45
assert.equal(false, util.isRegExp({}));
46
assert.equal(false, util.isRegExp([]));
47
assert.equal(false, util.isRegExp(new Date()));
48
assert.equal(false, util.isRegExp(Object.create(RegExp.prototype)));
49
});
50
51
test('util.isDate', function () {
52
assert.equal(true, util.isDate(new Date()));
53
assert.equal(true, util.isDate(new Date(0)));
54
assert.equal(false, util.isDate(Date()));
55
assert.equal(false, util.isDate({}));
56
assert.equal(false, util.isDate([]));
57
assert.equal(false, util.isDate(new Error()));
58
assert.equal(false, util.isDate(Object.create(Date.prototype)));
59
});
60
61
test('util.isError', function () {
62
assert.equal(true, util.isError(new Error()));
63
assert.equal(true, util.isError(new TypeError()));
64
assert.equal(true, util.isError(new SyntaxError()));
65
assert.equal(false, util.isError({}));
66
assert.equal(false, util.isError({ name: 'Error', message: '' }));
67
assert.equal(false, util.isError([]));
68
assert.equal(true, util.isError(Object.create(Error.prototype)));
69
});
70
71
test('util._extend', function () {
72
assert.deepEqual(util._extend({a:1}), {a:1});
73
assert.deepEqual(util._extend({a:1}, []), {a:1});
74
assert.deepEqual(util._extend({a:1}, null), {a:1});
75
assert.deepEqual(util._extend({a:1}, true), {a:1});
76
assert.deepEqual(util._extend({a:1}, false), {a:1});
77
assert.deepEqual(util._extend({a:1}, {b:2}), {a:1, b:2});
78
assert.deepEqual(util._extend({a:1, b:2}, {b:3}), {a:1, b:3});
79
});
80
81
test('util.isBuffer', function () {
82
assert.equal(true, util.isBuffer(new Buffer(4)));
83
assert.equal(true, util.isBuffer(Buffer(4)));
84
assert.equal(true, util.isBuffer(new Buffer(4)));
85
assert.equal(true, util.isBuffer(new Buffer([1, 2, 3, 4])));
86
assert.equal(false, util.isBuffer({}));
87
assert.equal(false, util.isBuffer([]));
88
assert.equal(false, util.isBuffer(new Error()));
89
assert.equal(false, util.isRegExp(new Date()));
90
assert.equal(true, util.isBuffer(Object.create(Buffer.prototype)));
91
});
92
93