Skip to content

Commit

Permalink
test: test sys rather than common
Browse files Browse the repository at this point in the history
  • Loading branch information
Trott committed Oct 9, 2015
1 parent 47befff commit 66e13bd
Showing 1 changed file with 41 additions and 40 deletions.
81 changes: 41 additions & 40 deletions test/parallel/test-sys.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,52 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');

assert.equal('0', common.inspect(0));
assert.equal('1', common.inspect(1));
assert.equal('false', common.inspect(false));
assert.equal("''", common.inspect(''));
assert.equal("'hello'", common.inspect('hello'));
assert.equal('[Function]', common.inspect(function() {}));
assert.equal('undefined', common.inspect(undefined));
assert.equal('null', common.inspect(null));
assert.equal('/foo(bar\\n)?/gi', common.inspect(/foo(bar\n)?/gi));
var sys = require('sys');

assert.equal('0', sys.inspect(0));
assert.equal('1', sys.inspect(1));
assert.equal('false', sys.inspect(false));
assert.equal("''", sys.inspect(''));
assert.equal("'hello'", sys.inspect('hello'));
assert.equal('[Function]', sys.inspect(function() {}));
assert.equal('undefined', sys.inspect(undefined));
assert.equal('null', sys.inspect(null));
assert.equal('/foo(bar\\n)?/gi', sys.inspect(/foo(bar\n)?/gi));
assert.equal(new Date('2010-02-14T12:48:40+01:00').toString(),
common.inspect(new Date('Sun, 14 Feb 2010 11:48:40 GMT')));
sys.inspect(new Date('Sun, 14 Feb 2010 11:48:40 GMT')));

assert.equal("'\\n\\u0001'", common.inspect('\n\u0001'));
assert.equal("'\\n\\u0001'", sys.inspect('\n\u0001'));

assert.equal('[]', common.inspect([]));
assert.equal('Array {}', common.inspect(Object.create([])));
assert.equal('[ 1, 2 ]', common.inspect([1, 2]));
assert.equal('[ 1, [ 2, 3 ] ]', common.inspect([1, [2, 3]]));
assert.equal('[]', sys.inspect([]));
assert.equal('Array {}', sys.inspect(Object.create([])));
assert.equal('[ 1, 2 ]', sys.inspect([1, 2]));
assert.equal('[ 1, [ 2, 3 ] ]', sys.inspect([1, [2, 3]]));

assert.equal('{}', common.inspect({}));
assert.equal('{ a: 1 }', common.inspect({a: 1}));
assert.equal('{ a: [Function] }', common.inspect({a: function() {}}));
assert.equal('{ a: 1, b: 2 }', common.inspect({a: 1, b: 2}));
assert.equal('{ a: {} }', common.inspect({'a': {}}));
assert.equal('{ a: { b: 2 } }', common.inspect({'a': {'b': 2}}));
assert.equal('{}', sys.inspect({}));
assert.equal('{ a: 1 }', sys.inspect({a: 1}));
assert.equal('{ a: [Function] }', sys.inspect({a: function() {}}));
assert.equal('{ a: 1, b: 2 }', sys.inspect({a: 1, b: 2}));
assert.equal('{ a: {} }', sys.inspect({'a': {}}));
assert.equal('{ a: { b: 2 } }', sys.inspect({'a': {'b': 2}}));
assert.equal('{ a: { b: { c: [Object] } } }',
common.inspect({'a': {'b': { 'c': { 'd': 2 }}}}));
sys.inspect({'a': {'b': { 'c': { 'd': 2 }}}}));
assert.equal('{ a: { b: { c: { d: 2 } } } }',
common.inspect({'a': {'b': { 'c': { 'd': 2 }}}}, false, null));
assert.equal('[ 1, 2, 3, [length]: 3 ]', common.inspect([1, 2, 3], true));
sys.inspect({'a': {'b': { 'c': { 'd': 2 }}}}, false, null));
assert.equal('[ 1, 2, 3, [length]: 3 ]', sys.inspect([1, 2, 3], true));
assert.equal('{ a: [Object] }',
common.inspect({'a': {'b': { 'c': 2}}}, false, 0));
sys.inspect({'a': {'b': { 'c': 2}}}, false, 0));
assert.equal('{ a: { b: [Object] } }',
common.inspect({'a': {'b': { 'c': 2}}}, false, 1));
sys.inspect({'a': {'b': { 'c': 2}}}, false, 1));
assert.equal('{ visible: 1 }',
common.inspect(Object.create({},
sys.inspect(Object.create({},
{visible: {value: 1, enumerable: true}, hidden: {value: 2}}))
);

// Due to the hash seed randomization it's not deterministic the order that
// the following ways this hash is displayed.
// See http://codereview.chromium.org/9124004/

var out = common.inspect(Object.create({},
var out = sys.inspect(Object.create({},
{visible: {value: 1, enumerable: true}, hidden: {value: 2}}), true);
if (out !== '{ [hidden]: 2, visible: 1 }' &&
out !== '{ visible: 1, [hidden]: 2 }') {
Expand All @@ -54,7 +55,7 @@ if (out !== '{ [hidden]: 2, visible: 1 }' &&


// Objects without prototype
var out = common.inspect(Object.create(null,
var out = sys.inspect(Object.create(null,
{ name: {value: 'Tim', enumerable: true},
hidden: {value: 'secret'}}), true);
if (out !== "{ [hidden]: 'secret', name: 'Tim' }" &&
Expand All @@ -64,46 +65,46 @@ if (out !== "{ [hidden]: 'secret', name: 'Tim' }" &&


assert.equal('{ name: \'Tim\' }',
common.inspect(Object.create(null,
sys.inspect(Object.create(null,
{name: {value: 'Tim', enumerable: true},
hidden: {value: 'secret'}}))
);


// Dynamic properties
assert.equal('{ readonly: [Getter] }',
common.inspect({get readonly() {}}));
sys.inspect({get readonly() {}}));

assert.equal('{ readwrite: [Getter/Setter] }',
common.inspect({get readwrite() {}, set readwrite(val) {}}));
sys.inspect({get readwrite() {}, set readwrite(val) {}}));

assert.equal('{ writeonly: [Setter] }',
common.inspect({set writeonly(val) {}}));
sys.inspect({set writeonly(val) {}}));

var value = {};
value['a'] = value;
assert.equal('{ a: [Circular] }', common.inspect(value));
assert.equal('{ a: [Circular] }', sys.inspect(value));

// Array with dynamic properties
value = [1, 2, 3];
value.__defineGetter__('growingLength', function() {
this.push(true); return this.length;
});
assert.equal('[ 1, 2, 3, growingLength: [Getter] ]', common.inspect(value));
assert.equal('[ 1, 2, 3, growingLength: [Getter] ]', sys.inspect(value));

// Function with properties
value = function() {};
value.aprop = 42;
assert.equal('{ [Function] aprop: 42 }', common.inspect(value));
assert.equal('{ [Function] aprop: 42 }', sys.inspect(value));

// Regular expressions with properties
value = /123/ig;
value.aprop = 42;
assert.equal('{ /123/gi aprop: 42 }', common.inspect(value));
assert.equal('{ /123/gi aprop: 42 }', sys.inspect(value));

// Dates with properties
value = new Date('Sun, 14 Feb 2010 11:48:40 GMT');
value.aprop = 42;
assert.equal('{ Sun, 14 Feb 2010 11:48:40 GMT aprop: 42 }',
common.inspect(value)
sys.inspect(value)
);

0 comments on commit 66e13bd

Please sign in to comment.