react / react-0.13.3 / examples / basic-commonjs / node_modules / browserify / node_modules / util / test / node / format.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.2021222324var assert = require('assert');25var util = require('../../');2627assert.equal(util.format(), '');28assert.equal(util.format(''), '');29assert.equal(util.format([]), '[]');30assert.equal(util.format({}), '{}');31assert.equal(util.format(null), 'null');32assert.equal(util.format(true), 'true');33assert.equal(util.format(false), 'false');34assert.equal(util.format('test'), 'test');3536// CHECKME this is for console.log() compatibility - but is it *right*?37assert.equal(util.format('foo', 'bar', 'baz'), 'foo bar baz');3839assert.equal(util.format('%d', 42.0), '42');40assert.equal(util.format('%d', 42), '42');41assert.equal(util.format('%s', 42), '42');42assert.equal(util.format('%j', 42), '42');4344assert.equal(util.format('%d', '42.0'), '42');45assert.equal(util.format('%d', '42'), '42');46assert.equal(util.format('%s', '42'), '42');47assert.equal(util.format('%j', '42'), '"42"');4849assert.equal(util.format('%%s%s', 'foo'), '%sfoo');5051assert.equal(util.format('%s'), '%s');52assert.equal(util.format('%s', undefined), 'undefined');53assert.equal(util.format('%s', 'foo'), 'foo');54assert.equal(util.format('%s:%s'), '%s:%s');55assert.equal(util.format('%s:%s', undefined), 'undefined:%s');56assert.equal(util.format('%s:%s', 'foo'), 'foo:%s');57assert.equal(util.format('%s:%s', 'foo', 'bar'), 'foo:bar');58assert.equal(util.format('%s:%s', 'foo', 'bar', 'baz'), 'foo:bar baz');59assert.equal(util.format('%%%s%%', 'hi'), '%hi%');60assert.equal(util.format('%%%s%%%%', 'hi'), '%hi%%');6162(function() {63var o = {};64o.o = o;65assert.equal(util.format('%j', o), '[Circular]');66})();6768// Errors69assert.equal(util.format(new Error('foo')), '[Error: foo]');70function CustomError(msg) {71Error.call(this);72Object.defineProperty(this, 'message', { value: msg, enumerable: false });73Object.defineProperty(this, 'name', { value: 'CustomError', enumerable: false });74}75util.inherits(CustomError, Error);76assert.equal(util.format(new CustomError('bar')), '[CustomError: bar]');777879