1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-22 15:06:54 -05:00
denoland-deno/tests/node_compat/test/parallel/test-util.js
Matt Mastracci f5e46c9bf2
chore: move cli/tests/ -> tests/ (#22369)
This looks like a massive PR, but it's only a move from cli/tests ->
tests, and updates of relative paths for files.

This is the first step towards aggregate all of the integration test
files under tests/, which will lead to a set of integration tests that
can run without the CLI binary being built.

While we could leave these tests under `cli`, it would require us to
keep a more complex directory structure for the various test runners. In
addition, we have a lot of complexity to ignore various test files in
the `cli` project itself (cargo publish exclusion rules, autotests =
false, etc).

And finally, the `tests/` folder will eventually house the `test_ffi`,
`test_napi` and other testing code, reducing the size of the root repo
directory.

For easier review, the extremely large and noisy "move" is in the first
commit (with no changes -- just a move), while the remainder of the
changes to actual files is in the second commit.
2024-02-10 20:22:13 +00:00

202 lines
8.4 KiB
JavaScript

// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 16.13.0
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
// Flags: --expose-internals
const common = require('../common');
const assert = require('assert');
const util = require('util');
const errors = require('internal/errors');
// TODO(wafuwafu13): Enable this when "vm" is ready.
// const context = require('vm').runInNewContext;
// isArray
assert.strictEqual(util.isArray([]), true);
assert.strictEqual(util.isArray(Array()), true);
assert.strictEqual(util.isArray(new Array()), true);
assert.strictEqual(util.isArray(new Array(5)), true);
assert.strictEqual(util.isArray(new Array('with', 'some', 'entries')), true);
// TODO(wafuwafu13): Enable this when "vm" is ready.
// assert.strictEqual(util.isArray(context('Array')()), true);
assert.strictEqual(util.isArray({}), false);
assert.strictEqual(util.isArray({ push: function() {} }), false);
assert.strictEqual(util.isArray(/regexp/), false);
assert.strictEqual(util.isArray(new Error()), false);
assert.strictEqual(util.isArray(Object.create(Array.prototype)), false);
// isRegExp
assert.strictEqual(util.isRegExp(/regexp/), true);
assert.strictEqual(util.isRegExp(RegExp(), 'foo'), true);
assert.strictEqual(util.isRegExp(new RegExp()), true);
// TODO(wafuwafu13): Enable this when "vm" is ready.
// assert.strictEqual(util.isRegExp(context('RegExp')()), true);
assert.strictEqual(util.isRegExp({}), false);
assert.strictEqual(util.isRegExp([]), false);
assert.strictEqual(util.isRegExp(new Date()), false);
// TODO(wafuwafu13): Enable this.
assert.strictEqual(util.isRegExp(Object.create(RegExp.prototype)), false);
// isDate
assert.strictEqual(util.isDate(new Date()), true);
assert.strictEqual(util.isDate(new Date(0), 'foo'), true);
// TODO(wafuwafu13): Enable this when "vm" is ready.
// assert.strictEqual(util.isDate(new (context('Date'))()), true);
assert.strictEqual(util.isDate(Date()), false);
assert.strictEqual(util.isDate({}), false);
assert.strictEqual(util.isDate([]), false);
assert.strictEqual(util.isDate(new Error()), false);
assert.strictEqual(util.isDate(Object.create(Date.prototype)), false);
// isError
assert.strictEqual(util.isError(new Error()), true);
assert.strictEqual(util.isError(new TypeError()), true);
assert.strictEqual(util.isError(new SyntaxError()), true);
// TODO(wafuwafu13): Enable this when "vm" is ready.
// assert.strictEqual(util.isError(new (context('Error'))()), true);
// assert.strictEqual(util.isError(new (context('TypeError'))()), true);
// assert.strictEqual(util.isError(new (context('SyntaxError'))()), true);
assert.strictEqual(util.isError({}), false);
assert.strictEqual(util.isError({ name: 'Error', message: '' }), false);
assert.strictEqual(util.isError([]), false);
assert.strictEqual(util.isError(Object.create(Error.prototype)), true);
// isObject
assert.strictEqual(util.isObject({}), true);
assert.strictEqual(util.isObject([]), true);
assert.strictEqual(util.isObject(new Number(3)), true);
assert.strictEqual(util.isObject(Number(4)), false);
assert.strictEqual(util.isObject(1), false);
// isPrimitive
assert.strictEqual(util.isPrimitive({}), false);
assert.strictEqual(util.isPrimitive(new Error()), false);
assert.strictEqual(util.isPrimitive(new Date()), false);
assert.strictEqual(util.isPrimitive([]), false);
assert.strictEqual(util.isPrimitive(/regexp/), false);
assert.strictEqual(util.isPrimitive(function() {}), false);
assert.strictEqual(util.isPrimitive(new Number(1)), false);
assert.strictEqual(util.isPrimitive(new String('bla')), false);
assert.strictEqual(util.isPrimitive(new Boolean(true)), false);
assert.strictEqual(util.isPrimitive(1), true);
assert.strictEqual(util.isPrimitive('bla'), true);
assert.strictEqual(util.isPrimitive(true), true);
assert.strictEqual(util.isPrimitive(undefined), true);
assert.strictEqual(util.isPrimitive(null), true);
assert.strictEqual(util.isPrimitive(Infinity), true);
assert.strictEqual(util.isPrimitive(NaN), true);
assert.strictEqual(util.isPrimitive(Symbol('symbol')), true);
// isBuffer
assert.strictEqual(util.isBuffer('foo'), false);
assert.strictEqual(util.isBuffer(Buffer.from('foo')), true);
// _extend
assert.deepStrictEqual(util._extend({ a: 1 }), { a: 1 });
assert.deepStrictEqual(util._extend({ a: 1 }, []), { a: 1 });
assert.deepStrictEqual(util._extend({ a: 1 }, null), { a: 1 });
assert.deepStrictEqual(util._extend({ a: 1 }, true), { a: 1 });
assert.deepStrictEqual(util._extend({ a: 1 }, false), { a: 1 });
assert.deepStrictEqual(util._extend({ a: 1 }, { b: 2 }), { a: 1, b: 2 });
assert.deepStrictEqual(util._extend({ a: 1, b: 2 }, { b: 3 }), { a: 1, b: 3 });
// deprecated
assert.strictEqual(util.isBoolean(true), true);
assert.strictEqual(util.isBoolean(false), true);
assert.strictEqual(util.isBoolean('string'), false);
assert.strictEqual(util.isNull(null), true);
assert.strictEqual(util.isNull(undefined), false);
assert.strictEqual(util.isNull(), false);
assert.strictEqual(util.isNull('string'), false);
assert.strictEqual(util.isUndefined(undefined), true);
assert.strictEqual(util.isUndefined(), true);
assert.strictEqual(util.isUndefined(null), false);
assert.strictEqual(util.isUndefined('string'), false);
assert.strictEqual(util.isNullOrUndefined(null), true);
assert.strictEqual(util.isNullOrUndefined(undefined), true);
assert.strictEqual(util.isNullOrUndefined(), true);
assert.strictEqual(util.isNullOrUndefined('string'), false);
assert.strictEqual(util.isNumber(42), true);
assert.strictEqual(util.isNumber(), false);
assert.strictEqual(util.isNumber('string'), false);
assert.strictEqual(util.isString('string'), true);
assert.strictEqual(util.isString(), false);
assert.strictEqual(util.isString(42), false);
assert.strictEqual(util.isSymbol(Symbol()), true);
assert.strictEqual(util.isSymbol(), false);
assert.strictEqual(util.isSymbol('string'), false);
assert.strictEqual(util.isFunction(() => {}), true);
assert.strictEqual(util.isFunction(function() {}), true);
assert.strictEqual(util.isFunction(), false);
assert.strictEqual(util.isFunction('string'), false);
assert.strictEqual(util.toUSVString('string\ud801'), 'string\ufffd');
{
assert.strictEqual(util.types.isNativeError(new Error()), true);
assert.strictEqual(util.types.isNativeError(new TypeError()), true);
assert.strictEqual(util.types.isNativeError(new SyntaxError()), true);
// TODO(wafuwafu13): Enable this when "vm" is ready.
// assert.strictEqual(util.types.isNativeError(new (context('Error'))()), true);
// assert.strictEqual(
// util.types.isNativeError(new (context('TypeError'))()),
// true
// );
// assert.strictEqual(
// util.types.isNativeError(new (context('SyntaxError'))()),
// true
// );
assert.strictEqual(util.types.isNativeError({}), false);
assert.strictEqual(
util.types.isNativeError({ name: 'Error', message: '' }),
false
);
assert.strictEqual(util.types.isNativeError([]), false);
assert.strictEqual(
util.types.isNativeError(Object.create(Error.prototype)),
false
);
assert.strictEqual(
util.types.isNativeError(new errors.codes.ERR_IPC_CHANNEL_CLOSED()),
true
);
}
assert.throws(() => {
util.stripVTControlCharacters({});
}, {
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "str" argument must be of type string.' +
common.invalidArgTypeHelper({})
});