Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80542 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
23
var assert = require('assert');
24
var context = require('vm').runInNewContext;
25
26
var util = require('../../');
27
28
// isArray
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(true, util.isArray(context('Array')()));
35
assert.equal(false, util.isArray({}));
36
assert.equal(false, util.isArray({ push: function() {} }));
37
assert.equal(false, util.isArray(/regexp/));
38
assert.equal(false, util.isArray(new Error));
39
assert.equal(false, util.isArray(Object.create(Array.prototype)));
40
41
// isRegExp
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(true, util.isRegExp(context('RegExp')()));
46
assert.equal(false, util.isRegExp({}));
47
assert.equal(false, util.isRegExp([]));
48
assert.equal(false, util.isRegExp(new Date()));
49
assert.equal(false, util.isRegExp(Object.create(RegExp.prototype)));
50
51
// isDate
52
assert.equal(true, util.isDate(new Date()));
53
assert.equal(true, util.isDate(new Date(0)));
54
assert.equal(true, util.isDate(new (context('Date'))));
55
assert.equal(false, util.isDate(Date()));
56
assert.equal(false, util.isDate({}));
57
assert.equal(false, util.isDate([]));
58
assert.equal(false, util.isDate(new Error));
59
assert.equal(false, util.isDate(Object.create(Date.prototype)));
60
61
// isError
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(true, util.isError(new (context('Error'))));
66
assert.equal(true, util.isError(new (context('TypeError'))));
67
assert.equal(true, util.isError(new (context('SyntaxError'))));
68
assert.equal(false, util.isError({}));
69
assert.equal(false, util.isError({ name: 'Error', message: '' }));
70
assert.equal(false, util.isError([]));
71
assert.equal(true, util.isError(Object.create(Error.prototype)));
72
73
// isObject
74
assert.ok(util.isObject({}) === true);
75
76
// _extend
77
assert.deepEqual(util._extend({a:1}), {a:1});
78
assert.deepEqual(util._extend({a:1}, []), {a:1});
79
assert.deepEqual(util._extend({a:1}, null), {a:1});
80
assert.deepEqual(util._extend({a:1}, true), {a:1});
81
assert.deepEqual(util._extend({a:1}, false), {a:1});
82
assert.deepEqual(util._extend({a:1}, {b:2}), {a:1, b:2});
83
assert.deepEqual(util._extend({a:1, b:2}, {b:3}), {a:1, b:3});
84
85