react / react-0.13.3 / examples / basic-commonjs / node_modules / browserify / node_modules / util / test / browser / is.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.2021var assert = require('assert');2223var util = require('../../');2425suite('is');2627test('util.isArray', function () {28assert.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(false, util.isArray({}));34assert.equal(false, util.isArray({ push: function() {} }));35assert.equal(false, util.isArray(/regexp/));36assert.equal(false, util.isArray(new Error()));37assert.equal(false, util.isArray(Object.create(Array.prototype)));38});3940test('util.isRegExp', function () {41assert.equal(true, util.isRegExp(/regexp/));42assert.equal(true, util.isRegExp(RegExp()));43assert.equal(true, util.isRegExp(new RegExp()));44assert.equal(false, util.isRegExp({}));45assert.equal(false, util.isRegExp([]));46assert.equal(false, util.isRegExp(new Date()));47assert.equal(false, util.isRegExp(Object.create(RegExp.prototype)));48});4950test('util.isDate', function () {51assert.equal(true, util.isDate(new Date()));52assert.equal(true, util.isDate(new Date(0)));53assert.equal(false, util.isDate(Date()));54assert.equal(false, util.isDate({}));55assert.equal(false, util.isDate([]));56assert.equal(false, util.isDate(new Error()));57assert.equal(false, util.isDate(Object.create(Date.prototype)));58});5960test('util.isError', function () {61assert.equal(true, util.isError(new Error()));62assert.equal(true, util.isError(new TypeError()));63assert.equal(true, util.isError(new SyntaxError()));64assert.equal(false, util.isError({}));65assert.equal(false, util.isError({ name: 'Error', message: '' }));66assert.equal(false, util.isError([]));67assert.equal(true, util.isError(Object.create(Error.prototype)));68});6970test('util._extend', function () {71assert.deepEqual(util._extend({a:1}), {a:1});72assert.deepEqual(util._extend({a:1}, []), {a:1});73assert.deepEqual(util._extend({a:1}, null), {a:1});74assert.deepEqual(util._extend({a:1}, true), {a:1});75assert.deepEqual(util._extend({a:1}, false), {a:1});76assert.deepEqual(util._extend({a:1}, {b:2}), {a:1, b:2});77assert.deepEqual(util._extend({a:1, b:2}, {b:3}), {a:1, b:3});78});7980test('util.isBuffer', function () {81assert.equal(true, util.isBuffer(new Buffer(4)));82assert.equal(true, util.isBuffer(Buffer(4)));83assert.equal(true, util.isBuffer(new Buffer(4)));84assert.equal(true, util.isBuffer(new Buffer([1, 2, 3, 4])));85assert.equal(false, util.isBuffer({}));86assert.equal(false, util.isBuffer([]));87assert.equal(false, util.isBuffer(new Error()));88assert.equal(false, util.isRegExp(new Date()));89assert.equal(true, util.isBuffer(Object.create(Buffer.prototype)));90});919293