mirror of
https://github.com/nodejs/node.git
synced 2024-11-25 08:19:38 +01:00
3e1b1dd4a9
The copyright and license notice is already in the LICENSE file. There is no justifiable reason to also require that it be included in every file, since the individual files are not individually distributed except as part of the entire package.
55 lines
1.9 KiB
JavaScript
55 lines
1.9 KiB
JavaScript
var common = require('../common');
|
|
var assert = require('assert');
|
|
var util = require('util');
|
|
|
|
assert.equal(util.format(), '');
|
|
assert.equal(util.format(''), '');
|
|
assert.equal(util.format([]), '[]');
|
|
assert.equal(util.format({}), '{}');
|
|
assert.equal(util.format(null), 'null');
|
|
assert.equal(util.format(true), 'true');
|
|
assert.equal(util.format(false), 'false');
|
|
assert.equal(util.format('test'), 'test');
|
|
|
|
// CHECKME this is for console.log() compatibility - but is it *right*?
|
|
assert.equal(util.format('foo', 'bar', 'baz'), 'foo bar baz');
|
|
|
|
assert.equal(util.format('%d', 42.0), '42');
|
|
assert.equal(util.format('%d', 42), '42');
|
|
assert.equal(util.format('%s', 42), '42');
|
|
assert.equal(util.format('%j', 42), '42');
|
|
|
|
assert.equal(util.format('%d', '42.0'), '42');
|
|
assert.equal(util.format('%d', '42'), '42');
|
|
assert.equal(util.format('%s', '42'), '42');
|
|
assert.equal(util.format('%j', '42'), '"42"');
|
|
|
|
assert.equal(util.format('%%s%s', 'foo'), '%sfoo');
|
|
|
|
assert.equal(util.format('%s'), '%s');
|
|
assert.equal(util.format('%s', undefined), 'undefined');
|
|
assert.equal(util.format('%s', 'foo'), 'foo');
|
|
assert.equal(util.format('%s:%s'), '%s:%s');
|
|
assert.equal(util.format('%s:%s', undefined), 'undefined:%s');
|
|
assert.equal(util.format('%s:%s', 'foo'), 'foo:%s');
|
|
assert.equal(util.format('%s:%s', 'foo', 'bar'), 'foo:bar');
|
|
assert.equal(util.format('%s:%s', 'foo', 'bar', 'baz'), 'foo:bar baz');
|
|
assert.equal(util.format('%%%s%%', 'hi'), '%hi%');
|
|
assert.equal(util.format('%%%s%%%%', 'hi'), '%hi%%');
|
|
|
|
(function() {
|
|
var o = {};
|
|
o.o = o;
|
|
assert.equal(util.format('%j', o), '[Circular]');
|
|
})();
|
|
|
|
// Errors
|
|
assert.equal(util.format(new Error('foo')), '[Error: foo]');
|
|
function CustomError(msg) {
|
|
Error.call(this);
|
|
Object.defineProperty(this, 'message', { value: msg, enumerable: false });
|
|
Object.defineProperty(this, 'name', { value: 'CustomError', enumerable: false });
|
|
}
|
|
util.inherits(CustomError, Error);
|
|
assert.equal(util.format(new CustomError('bar')), '[CustomError: bar]');
|