react / react-0.13.3 / examples / basic-commonjs / node_modules / browserify / node_modules / util / test / node / util.js
80742 views// Copyright Joyent, Inc. and other Node contributors.1//2// Permission is hereby granted, free of charge, to any person obtaining a3// copy of this software and associated documentation files (the4// "Software"), to deal in the Software without restriction, including5// without limitation the rights to use, copy, modify, merge, publish,6// distribute, sublicense, and/or sell copies of the Software, and to permit7// persons to whom the Software is furnished to do so, subject to the8// following conditions:9//10// The above copyright notice and this permission notice shall be included11// in all copies or substantial portions of the Software.12//13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS14// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF15// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN16// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,17// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR18// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE19// USE OR OTHER DEALINGS IN THE SOFTWARE.202122var assert = require('assert');23var context = require('vm').runInNewContext;2425var util = require('../../');2627// isArray28assert.equal(true, util.isArray([]));29assert.equal(true, util.isArray(Array()));30assert.equal(true, util.isArray(new Array()));31assert.equal(true, util.isArray(new Array(5)));32assert.equal(true, util.isArray(new Array('with', 'some', 'entries')));33assert.equal(true, util.isArray(context('Array')()));34assert.equal(false, util.isArray({}));35assert.equal(false, util.isArray({ push: function() {} }));36assert.equal(false, util.isArray(/regexp/));37assert.equal(false, util.isArray(new Error));38assert.equal(false, util.isArray(Object.create(Array.prototype)));3940// isRegExp41assert.equal(true, util.isRegExp(/regexp/));42assert.equal(true, util.isRegExp(RegExp()));43assert.equal(true, util.isRegExp(new RegExp()));44assert.equal(true, util.isRegExp(context('RegExp')()));45assert.equal(false, util.isRegExp({}));46assert.equal(false, util.isRegExp([]));47assert.equal(false, util.isRegExp(new Date()));48assert.equal(false, util.isRegExp(Object.create(RegExp.prototype)));4950// isDate51assert.equal(true, util.isDate(new Date()));52assert.equal(true, util.isDate(new Date(0)));53assert.equal(true, util.isDate(new (context('Date'))));54assert.equal(false, util.isDate(Date()));55assert.equal(false, util.isDate({}));56assert.equal(false, util.isDate([]));57assert.equal(false, util.isDate(new Error));58assert.equal(false, util.isDate(Object.create(Date.prototype)));5960// isError61assert.equal(true, util.isError(new Error));62assert.equal(true, util.isError(new TypeError));63assert.equal(true, util.isError(new SyntaxError));64assert.equal(true, util.isError(new (context('Error'))));65assert.equal(true, util.isError(new (context('TypeError'))));66assert.equal(true, util.isError(new (context('SyntaxError'))));67assert.equal(false, util.isError({}));68assert.equal(false, util.isError({ name: 'Error', message: '' }));69assert.equal(false, util.isError([]));70assert.equal(true, util.isError(Object.create(Error.prototype)));7172// isObject73assert.ok(util.isObject({}) === true);7475// _extend76assert.deepEqual(util._extend({a:1}), {a:1});77assert.deepEqual(util._extend({a:1}, []), {a:1});78assert.deepEqual(util._extend({a:1}, null), {a:1});79assert.deepEqual(util._extend({a:1}, true), {a:1});80assert.deepEqual(util._extend({a:1}, false), {a:1});81assert.deepEqual(util._extend({a:1}, {b:2}), {a:1, b:2});82assert.deepEqual(util._extend({a:1, b:2}, {b:3}), {a:1, b:3});838485