2010-03-09 00:06:29 +01:00
|
|
|
require("../common");
|
2009-12-01 11:20:14 +01:00
|
|
|
|
|
|
|
assert.equal("0", inspect(0));
|
|
|
|
assert.equal("1", inspect(1));
|
|
|
|
assert.equal("false", inspect(false));
|
2010-02-26 02:41:02 +01:00
|
|
|
assert.equal("''", inspect(""));
|
|
|
|
assert.equal("'hello'", inspect("hello"));
|
2009-12-01 11:20:14 +01:00
|
|
|
assert.equal("[Function]", inspect(function() {}));
|
|
|
|
assert.equal('undefined', inspect(undefined));
|
|
|
|
assert.equal('null', inspect(null));
|
2010-02-09 17:50:05 +01:00
|
|
|
assert.equal('/foo(bar\\n)?/gi', inspect(/foo(bar\n)?/gi));
|
2010-02-14 13:11:59 +01:00
|
|
|
assert.equal('Sun, 14 Feb 2010 11:48:40 GMT',
|
|
|
|
inspect(new Date("Sun, 14 Feb 2010 11:48:40 GMT")));
|
2009-12-01 11:20:14 +01:00
|
|
|
|
2010-02-26 02:41:02 +01:00
|
|
|
assert.equal("'\\n\\u0001'", inspect("\n\u0001"));
|
2009-12-07 05:44:41 +01:00
|
|
|
|
2009-12-01 11:20:14 +01:00
|
|
|
assert.equal('[]', inspect([]));
|
2009-12-31 18:41:35 +01:00
|
|
|
assert.equal('[]', inspect(Object.create([])));
|
2010-02-26 02:41:02 +01:00
|
|
|
assert.equal('[ 1, 2 ]', inspect([1, 2]));
|
|
|
|
assert.equal('[ 1, [ 2, 3 ] ]', inspect([1, [2, 3]]));
|
2009-12-01 11:20:14 +01:00
|
|
|
|
|
|
|
assert.equal('{}', inspect({}));
|
2010-02-26 02:41:02 +01:00
|
|
|
assert.equal('{ a: 1 }', inspect({a: 1}));
|
|
|
|
assert.equal('{ a: [Function] }', inspect({a: function() {}}));
|
|
|
|
assert.equal('{ a: 1, b: 2 }', inspect({a: 1, b: 2}));
|
|
|
|
assert.equal('{ a: {} }', inspect({'a': {}}));
|
|
|
|
assert.equal('{ a: { b: 2 } }', inspect({'a': {'b': 2}}));
|
2010-02-27 09:32:55 +01:00
|
|
|
assert.equal('{ a: { b: { c: [Object] } } }', inspect({'a': {'b': { 'c': { 'd': 2 }}}}));
|
2010-02-26 02:41:02 +01:00
|
|
|
assert.equal('{ a: { b: { c: { d: 2 } } } }', inspect({'a': {'b': { 'c': { 'd': 2 }}}}, false, null));
|
|
|
|
assert.equal('[ 1, 2, 3, [length]: 3 ]', inspect([1,2,3], true));
|
2010-02-27 09:32:55 +01:00
|
|
|
assert.equal('{ a: [Object] }', inspect({'a': {'b': { 'c': 2}}},false,0));
|
|
|
|
assert.equal('{ a: { b: [Object] } }', inspect({'a': {'b': { 'c': 2}}},false,1));
|
2010-02-26 02:41:02 +01:00
|
|
|
assert.equal("{ visible: 1 }",
|
2010-02-09 17:50:05 +01:00
|
|
|
inspect(Object.create({}, {visible:{value:1,enumerable:true},hidden:{value:2}}))
|
|
|
|
);
|
2010-02-26 02:41:02 +01:00
|
|
|
assert.equal("{ [hidden]: 2, visible: 1 }",
|
2010-02-09 17:50:05 +01:00
|
|
|
inspect(Object.create({}, {visible:{value:1,enumerable:true},hidden:{value:2}}), true)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Objects without prototype
|
|
|
|
assert.equal(
|
2010-02-26 02:41:02 +01:00
|
|
|
"{ [hidden]: 'secret', name: 'Tim' }",
|
2010-02-09 17:50:05 +01:00
|
|
|
inspect(Object.create(null, {name: {value: "Tim", enumerable: true}, hidden: {value: "secret"}}), true)
|
|
|
|
);
|
|
|
|
assert.equal(
|
2010-02-26 02:41:02 +01:00
|
|
|
"{ name: 'Tim' }",
|
2010-02-09 17:50:05 +01:00
|
|
|
inspect(Object.create(null, {name: {value: "Tim", enumerable: true}, hidden: {value: "secret"}}))
|
|
|
|
);
|
|
|
|
|
2009-12-01 11:20:14 +01:00
|
|
|
|
2010-01-03 01:25:09 +01:00
|
|
|
// Dynamic properties
|
|
|
|
assert.equal(
|
2010-02-26 02:41:02 +01:00
|
|
|
"{ readonly: [Getter] }",
|
|
|
|
inspect({get readonly(){}})
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
"{ readwrite: [Getter/Setter] }",
|
|
|
|
inspect({get readwrite(){},set readwrite(val){}})
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
"{ writeonly: [Setter] }",
|
|
|
|
inspect({set writeonly(val){}})
|
2010-01-03 01:25:09 +01:00
|
|
|
);
|
|
|
|
|
2009-12-31 18:41:35 +01:00
|
|
|
var value = {};
|
2009-12-01 11:20:14 +01:00
|
|
|
value['a'] = value;
|
2010-02-26 02:41:02 +01:00
|
|
|
assert.equal('{ a: [Circular] }', inspect(value));
|
2009-12-31 18:41:35 +01:00
|
|
|
value = Object.create([]);
|
|
|
|
value.push(1);
|
2010-02-26 02:41:02 +01:00
|
|
|
assert.equal("[ 1, length: 1 ]", inspect(value));
|
2010-01-03 01:25:09 +01:00
|
|
|
|
|
|
|
// Array with dynamic properties
|
|
|
|
value = [1,2,3];
|
|
|
|
value.__defineGetter__('growingLength', function () { this.push(true); return this.length; });
|
|
|
|
assert.equal(
|
2010-02-26 02:41:02 +01:00
|
|
|
"[ 1, 2, 3, growingLength: [Getter] ]",
|
2010-01-03 01:25:09 +01:00
|
|
|
inspect(value)
|
2010-02-09 17:50:05 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
// Function with properties
|
|
|
|
value = function () {};
|
|
|
|
value.aprop = 42;
|
|
|
|
assert.equal(
|
2010-02-26 02:41:02 +01:00
|
|
|
"{ [Function] aprop: 42 }",
|
2010-02-09 17:50:05 +01:00
|
|
|
inspect(value)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Regular expressions with properties
|
|
|
|
value = /123/ig;
|
|
|
|
value.aprop = 42;
|
|
|
|
assert.equal(
|
2010-02-26 02:41:02 +01:00
|
|
|
"{ /123/gi aprop: 42 }",
|
2010-02-09 17:50:05 +01:00
|
|
|
inspect(value)
|
|
|
|
);
|
2010-02-14 13:11:59 +01:00
|
|
|
|
|
|
|
// Dates with properties
|
|
|
|
value = new Date("Sun, 14 Feb 2010 11:48:40 GMT");
|
|
|
|
value.aprop = 42;
|
|
|
|
assert.equal(
|
2010-02-26 02:41:02 +01:00
|
|
|
"{ Sun, 14 Feb 2010 11:48:40 GMT aprop: 42 }",
|
2010-02-14 13:11:59 +01:00
|
|
|
inspect(value)
|
|
|
|
);
|