mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
test(ext/node): more node compat tests (#17827)
This PR adds the remaining ~650 Node.js compat test cases from std/node. Among these 650 cases, about 130 cases are now failing. These failing cases are prefixed with `TODO:` in `tests/node_compat/config.json`. These will be addressed in later PRs.
This commit is contained in:
parent
a1cd2a5915
commit
6915a9b7a7
686 changed files with 65430 additions and 10 deletions
|
@ -22,6 +22,7 @@
|
|||
"cli/bench/testdata/express-router.js",
|
||||
"cli/bench/testdata/npm/*",
|
||||
"cli/tsc/dts/*.d.ts",
|
||||
"cli/tests/node_compat/test",
|
||||
"cli/tests/testdata/fmt/badly_formatted.json",
|
||||
"cli/tests/testdata/fmt/badly_formatted.md",
|
||||
"cli/tests/testdata/byte_order_mark.ts",
|
||||
|
|
|
@ -1,13 +1,847 @@
|
|||
{
|
||||
"nodeVersion": "18.12.1",
|
||||
"ignore": {},
|
||||
"tests": {
|
||||
"ignore": {
|
||||
"common": ["index.js", "internet.js", "tmpdir.js"],
|
||||
"fixtures": [
|
||||
"child-process-spawn-node.js",
|
||||
"echo.js",
|
||||
"elipses.txt",
|
||||
"empty.txt",
|
||||
"exit.js",
|
||||
"print-chars.js",
|
||||
"x.txt"
|
||||
],
|
||||
"internet": [
|
||||
"test-dns-any.js",
|
||||
"test-dns-ipv4.js",
|
||||
"test-dns-ipv6.js",
|
||||
"test-dns.js"
|
||||
],
|
||||
"parallel": [
|
||||
"test-assert-fail.js",
|
||||
"test-assert-strict-exists.js",
|
||||
"test-btoa-atob.js"
|
||||
"test-assert.js",
|
||||
"test-buffer-alloc.js",
|
||||
"test-buffer-arraybuffer.js",
|
||||
"test-buffer-bytelength.js",
|
||||
"test-buffer-from.js",
|
||||
"test-buffer-includes.js",
|
||||
"test-buffer-indexof.js",
|
||||
"test-child-process-exec-abortcontroller-promisified.js",
|
||||
"test-child-process-exec-encoding.js",
|
||||
"test-child-process-exec-kill-throws.js",
|
||||
"test-child-process-exec-maxbuf.js",
|
||||
"test-child-process-exec-std-encoding.js",
|
||||
"test-child-process-exec-timeout-expire.js",
|
||||
"test-child-process-exec-timeout-kill.js",
|
||||
"test-child-process-exec-timeout-not-expired.js",
|
||||
"test-child-process-execFile-promisified-abortController.js",
|
||||
"test-child-process-execfile.js",
|
||||
"test-child-process-execsync-maxbuf.js",
|
||||
"test-child-process-exit-code.js",
|
||||
"test-child-process-ipc.js",
|
||||
"test-child-process-spawnsync-env.js",
|
||||
"test-child-process-stdio-inherit.js",
|
||||
"test-child-process-stdout-flush-exit.js",
|
||||
"test-child-process-stdout-flush.js",
|
||||
"test-console-instance.js",
|
||||
"test-crypto-hmac.js",
|
||||
"test-dgram-custom-lookup.js",
|
||||
"test-dgram-ipv6only.js",
|
||||
"test-dgram-send-cb-quelches-error.js",
|
||||
"test-dgram-socket-buffer-size.js",
|
||||
"test-dgram-udp6-link-local-address.js",
|
||||
"test-dns-lookup.js",
|
||||
"test-dns-resolveany.js",
|
||||
"test-dns.js",
|
||||
"test-event-emitter-max-listeners.js",
|
||||
"test-event-emitter-no-error-provided-to-error-event.js",
|
||||
"test-event-emitter-prepend.js",
|
||||
"test-events-once.js",
|
||||
"test-fs-append-file.js",
|
||||
"test-fs-chmod-mask.js",
|
||||
"test-fs-chmod.js",
|
||||
"test-fs-mkdir.js",
|
||||
"test-fs-open.js",
|
||||
"test-fs-opendir.js",
|
||||
"test-fs-rmdir-recursive.js",
|
||||
"test-fs-write-file.js",
|
||||
"test-fs-write.js",
|
||||
"test-net-better-error-messages-path.js",
|
||||
"test-net-connect-buffer.js",
|
||||
"test-net-connect-buffer2.js",
|
||||
"test-net-end-close.js",
|
||||
"test-net-listen-invalid-port.js",
|
||||
"test-net-server-call-listen-multiple-times.js",
|
||||
"test-net-server-listen-path.js",
|
||||
"test-net-server-try-ports.js",
|
||||
"test-net-socket-timeout.js",
|
||||
"test-net-write-arguments.js",
|
||||
"test-os.js",
|
||||
"test-path-resolve.js",
|
||||
"test-path.js",
|
||||
"test-querystring.js",
|
||||
"test-readline-interface.js",
|
||||
"test-stdin-from-file-spawn.js",
|
||||
"test-url-urltooptions.js",
|
||||
"test-util-format.js",
|
||||
"test-util-inspect-namespace.js",
|
||||
"test-util-inspect-proxy.js",
|
||||
"test-util-inspect.js",
|
||||
"test-util-isDeepStrictEqual.js",
|
||||
"test-util-promisify.js",
|
||||
"test-util-types.js",
|
||||
"test-util.js",
|
||||
"test-webcrypto-sign-verify.js",
|
||||
"test-whatwg-url-properties.js",
|
||||
"test-zlib-convenience-methods.js",
|
||||
"test-zlib-empty-buffer.js",
|
||||
"test-zlib-invalid-input.js",
|
||||
"test-zlib-random-byte-pipes.js",
|
||||
"test-zlib-write-after-flush.js",
|
||||
"test-zlib-zero-byte.js",
|
||||
"test-zlib-zero-windowBits.js"
|
||||
],
|
||||
"pummel": [
|
||||
"test-net-bytes-per-incoming-chunk-overhead.js",
|
||||
"test-net-write-callbacks.js"
|
||||
],
|
||||
"sequential": [
|
||||
"test-child-process-exit.js"
|
||||
]
|
||||
},
|
||||
"windowsIgnore": {},
|
||||
"darwinIgnore": {}
|
||||
"tests": {
|
||||
"common": [
|
||||
"child_process.js",
|
||||
"countdown.js",
|
||||
"dns.js",
|
||||
"duplexpair.js",
|
||||
"fixtures.js",
|
||||
"hijackstdio",
|
||||
"index.mjs",
|
||||
"internet.js"
|
||||
],
|
||||
"fixtures": [
|
||||
"GH-1899-output.js",
|
||||
"a.js",
|
||||
"child-process-spawn-node.js",
|
||||
"child_process_should_emit_error.js",
|
||||
"echo.js",
|
||||
"elipses.txt",
|
||||
"empty.txt",
|
||||
"exit.js",
|
||||
"loop.js",
|
||||
"print-chars.js",
|
||||
"x.txt"
|
||||
],
|
||||
"fixtures/keys": [
|
||||
"agent1-cert.pem",
|
||||
"agent1-key.pem"
|
||||
],
|
||||
"internet": [
|
||||
"TODO:test-dgram-connect.js",
|
||||
"test-dns-any.js",
|
||||
"test-dns-idna2008.js",
|
||||
"test-dns-ipv4.js",
|
||||
"test-dns-ipv6.js",
|
||||
"test-dns-lookup.js",
|
||||
"test-dns-promises-resolve.js",
|
||||
"test-dns-regress-6244.js",
|
||||
"test-dns-setserver-in-callback-of-resolve4.js",
|
||||
"test-dns.js"
|
||||
],
|
||||
"parallel": [
|
||||
"test-assert-async.js",
|
||||
"test-assert-fail.js",
|
||||
"test-assert-strict-exists.js",
|
||||
"test-assert.js",
|
||||
"test-bad-unicode.js",
|
||||
"test-btoa-atob.js",
|
||||
"TODO:test-buffer-alloc.js",
|
||||
"test-buffer-arraybuffer.js",
|
||||
"test-buffer-ascii.js",
|
||||
"test-buffer-badhex.js",
|
||||
"test-buffer-bigint64.js",
|
||||
"test-buffer-bytelength.js",
|
||||
"test-buffer-compare-offset.js",
|
||||
"test-buffer-concat.js",
|
||||
"test-buffer-constants.js",
|
||||
"test-buffer-copy.js",
|
||||
"test-buffer-equals.js",
|
||||
"test-buffer-failed-alloc-typed-arrays.js",
|
||||
"test-buffer-fakes.js",
|
||||
"test-buffer-from.js",
|
||||
"test-buffer-includes.js",
|
||||
"TODO:test-buffer-indexof.js",
|
||||
"test-buffer-inheritance.js",
|
||||
"test-buffer-isencoding.js",
|
||||
"test-buffer-iterator.js",
|
||||
"test-buffer-new.js",
|
||||
"test-buffer-no-negative-allocation.js",
|
||||
"test-buffer-nopendingdep-map.js",
|
||||
"test-buffer-of-no-deprecation.js",
|
||||
"test-buffer-over-max-length.js",
|
||||
"test-buffer-parent-property.js",
|
||||
"test-buffer-read.js",
|
||||
"test-buffer-readdouble.js",
|
||||
"test-buffer-readfloat.js",
|
||||
"test-buffer-readint.js",
|
||||
"test-buffer-readuint.js",
|
||||
"test-buffer-safe-unsafe.js",
|
||||
"TODO:test-buffer-sharedarraybuffer.js",
|
||||
"test-buffer-slice.js",
|
||||
"test-buffer-slow.js",
|
||||
"test-buffer-swap.js",
|
||||
"test-buffer-tojson.js",
|
||||
"test-buffer-tostring-range.js",
|
||||
"test-buffer-tostring-rangeerror.js",
|
||||
"test-buffer-tostring.js",
|
||||
"TODO:test-buffer-write.js",
|
||||
"test-buffer-writedouble.js",
|
||||
"test-buffer-writefloat.js",
|
||||
"test-buffer-writeint.js",
|
||||
"test-buffer-writeuint.js",
|
||||
"test-buffer-zero-fill-cli.js",
|
||||
"test-buffer-zero-fill-reset.js",
|
||||
"test-buffer-zero-fill.js",
|
||||
"test-child-process-can-write-to-stdout.js",
|
||||
"test-child-process-default-options.js",
|
||||
"test-child-process-double-pipe.js",
|
||||
"test-child-process-exec-abortcontroller-promisified.js",
|
||||
"test-child-process-exec-cwd.js",
|
||||
"TODO:test-child-process-exec-encoding.js",
|
||||
"test-child-process-exec-env.js",
|
||||
"test-child-process-exec-error.js",
|
||||
"test-child-process-exec-kill-throws.js",
|
||||
"test-child-process-exec-maxbuf.js",
|
||||
"TODO:test-child-process-exec-std-encoding.js",
|
||||
"test-child-process-exec-stdout-stderr-data-string.js",
|
||||
"test-child-process-exec-timeout-expire.js",
|
||||
"test-child-process-exec-timeout-kill.js",
|
||||
"TODO:test-child-process-exec-timeout-not-expired.js",
|
||||
"test-child-process-execFile-promisified-abortController.js",
|
||||
"test-child-process-execfile-maxbuf.js",
|
||||
"TODO:test-child-process-execfile.js",
|
||||
"test-child-process-execfilesync-maxbuf.js",
|
||||
"test-child-process-execsync-maxbuf.js",
|
||||
"TODO:test-child-process-exit-code.js",
|
||||
"test-child-process-flush-stdio.js",
|
||||
"TODO:test-child-process-ipc.js",
|
||||
"test-child-process-kill.js",
|
||||
"test-child-process-set-blocking.js",
|
||||
"test-child-process-spawn-args.js",
|
||||
"test-child-process-spawn-event.js",
|
||||
"test-child-process-spawnsync-args.js",
|
||||
"TODO:test-child-process-spawnsync-env.js",
|
||||
"test-child-process-spawnsync-maxbuf.js",
|
||||
"test-child-process-spawnsync-validation-errors.js",
|
||||
"test-child-process-spawnsync.js",
|
||||
"TODO:test-child-process-stdio-inherit.js",
|
||||
"TODO:test-child-process-stdout-flush-exit.js",
|
||||
"TODO:test-child-process-stdout-flush.js",
|
||||
"test-client-request-destroy.js",
|
||||
"test-console-async-write-error.js",
|
||||
"test-console-group.js",
|
||||
"TODO:test-console-instance.js",
|
||||
"test-console-log-stdio-broken-dest.js",
|
||||
"test-console-log-throw-primitive.js",
|
||||
"test-console-no-swallow-stack-overflow.js",
|
||||
"test-console-sync-write-error.js",
|
||||
"test-console-table.js",
|
||||
"test-console-tty-colors.js",
|
||||
"test-crypto-hmac.js",
|
||||
"TODO:test-dgram-address.js",
|
||||
"TODO:test-dgram-bind-default-address.js",
|
||||
"TODO:test-dgram-bind.js",
|
||||
"TODO:test-dgram-bytes-length.js",
|
||||
"test-dgram-close-during-bind.js",
|
||||
"TODO:test-dgram-close-in-listening.js",
|
||||
"TODO:test-dgram-close-is-not-callback.js",
|
||||
"test-dgram-close-signal.js",
|
||||
"TODO:test-dgram-close.js",
|
||||
"TODO:test-dgram-connect-send-callback-buffer-length.js",
|
||||
"TODO:test-dgram-connect-send-callback-buffer.js",
|
||||
"TODO:test-dgram-connect-send-callback-multi-buffer.js",
|
||||
"TODO:test-dgram-connect-send-default-host.js",
|
||||
"TODO:test-dgram-connect-send-empty-array.js",
|
||||
"TODO:test-dgram-connect-send-empty-buffer.js",
|
||||
"TODO:test-dgram-connect-send-empty-packet.js",
|
||||
"TODO:test-dgram-connect-send-multi-buffer-copy.js",
|
||||
"TODO:test-dgram-connect-send-multi-string-array.js",
|
||||
"TODO:test-dgram-connect.js",
|
||||
"TODO:test-dgram-createSocket-type.js",
|
||||
"TODO:test-dgram-custom-lookup.js",
|
||||
"TODO:test-dgram-error-message-address.js",
|
||||
"TODO:test-dgram-implicit-bind.js",
|
||||
"TODO:test-dgram-ipv6only.js",
|
||||
"TODO:test-dgram-listen-after-bind.js",
|
||||
"TODO:test-dgram-msgsize.js",
|
||||
"TODO:test-dgram-oob-buffer.js",
|
||||
"TODO:test-dgram-recv-error.js",
|
||||
"TODO:test-dgram-send-bad-arguments.js",
|
||||
"TODO:test-dgram-send-callback-buffer-empty-address.js",
|
||||
"TODO:test-dgram-send-callback-buffer-length-empty-address.js",
|
||||
"TODO:test-dgram-send-callback-buffer-length.js",
|
||||
"TODO:test-dgram-send-callback-buffer.js",
|
||||
"TODO:test-dgram-send-callback-multi-buffer-empty-address.js",
|
||||
"TODO:test-dgram-send-callback-multi-buffer.js",
|
||||
"TODO:test-dgram-send-callback-recursive.js",
|
||||
"TODO:test-dgram-send-cb-quelches-error.js",
|
||||
"TODO:test-dgram-send-default-host.js",
|
||||
"TODO:test-dgram-send-empty-array.js",
|
||||
"TODO:test-dgram-send-empty-buffer.js",
|
||||
"TODO:test-dgram-send-empty-packet.js",
|
||||
"TODO:test-dgram-send-error.js",
|
||||
"TODO:test-dgram-send-invalid-msg-type.js",
|
||||
"TODO:test-dgram-send-multi-buffer-copy.js",
|
||||
"TODO:test-dgram-send-multi-string-array.js",
|
||||
"TODO:test-dgram-socket-buffer-size.js",
|
||||
"TODO:test-dgram-udp4.js",
|
||||
"TODO:test-dgram-udp6-link-local-address.js",
|
||||
"TODO:test-dgram-udp6-send-default-host.js",
|
||||
"test-diagnostics-channel-has-subscribers.js",
|
||||
"TODO:test-diagnostics-channel-net.js",
|
||||
"test-diagnostics-channel-object-channel-pub-sub.js",
|
||||
"test-diagnostics-channel-pub-sub.js",
|
||||
"test-diagnostics-channel-symbol-named.js",
|
||||
"test-diagnostics-channel-udp.js",
|
||||
"test-dns-lookup.js",
|
||||
"test-dns-memory-error.js",
|
||||
"TODO:test-dns-multi-channel.js",
|
||||
"test-dns-promises-exists.js",
|
||||
"TODO:test-dns-resolveany.js",
|
||||
"test-dns-resolvens-typeerror.js",
|
||||
"test-dns-setservers-type-check.js",
|
||||
"TODO:test-dns.js",
|
||||
"test-eval-strict-referenceerror.js",
|
||||
"test-eval.js",
|
||||
"test-event-emitter-add-listeners.js",
|
||||
"TODO:test-event-emitter-check-listener-leaks.js",
|
||||
"test-event-emitter-emit-context.js",
|
||||
"test-event-emitter-error-monitor.js",
|
||||
"test-event-emitter-errors.js",
|
||||
"test-event-emitter-get-max-listeners.js",
|
||||
"test-event-emitter-invalid-listener.js",
|
||||
"test-event-emitter-listener-count.js",
|
||||
"test-event-emitter-listeners-side-effects.js",
|
||||
"test-event-emitter-listeners.js",
|
||||
"TODO:test-event-emitter-max-listeners-warning-for-null.js",
|
||||
"TODO:test-event-emitter-max-listeners-warning-for-symbol.js",
|
||||
"TODO:test-event-emitter-max-listeners-warning.js",
|
||||
"test-event-emitter-max-listeners.js",
|
||||
"test-event-emitter-method-names.js",
|
||||
"test-event-emitter-modify-in-emit.js",
|
||||
"test-event-emitter-no-error-provided-to-error-event.js",
|
||||
"test-event-emitter-num-args.js",
|
||||
"test-event-emitter-once.js",
|
||||
"test-event-emitter-prepend.js",
|
||||
"test-event-emitter-remove-all-listeners.js",
|
||||
"test-event-emitter-remove-listeners.js",
|
||||
"test-event-emitter-set-max-listeners-side-effects.js",
|
||||
"test-event-emitter-special-event-names.js",
|
||||
"test-event-emitter-subclass.js",
|
||||
"test-event-emitter-symbols.js",
|
||||
"test-events-list.js",
|
||||
"test-events-on-async-iterator.js",
|
||||
"test-events-once.js",
|
||||
"test-events-uncaught-exception-stack.js",
|
||||
"test-eventtarget-brandcheck.js",
|
||||
"test-exception-handler.js",
|
||||
"test-exception-handler2.js",
|
||||
"test-file-read-noexist.js",
|
||||
"test-file-write-stream.js",
|
||||
"test-file-write-stream2.js",
|
||||
"test-file-write-stream3.js",
|
||||
"test-file-write-stream4.js",
|
||||
"test-fs-access.js",
|
||||
"test-fs-append-file-sync.js",
|
||||
"test-fs-append-file.js",
|
||||
"test-fs-chmod-mask.js",
|
||||
"test-fs-chmod.js",
|
||||
"test-fs-chown-type-check.js",
|
||||
"test-fs-copyfile.js",
|
||||
"test-fs-empty-readStream.js",
|
||||
"test-fs-mkdir.js",
|
||||
"test-fs-open-flags.js",
|
||||
"test-fs-open-mode-mask.js",
|
||||
"test-fs-open-no-close.js",
|
||||
"test-fs-open-numeric-flags.js",
|
||||
"test-fs-open.js",
|
||||
"test-fs-opendir.js",
|
||||
"test-fs-read-stream-autoClose.js",
|
||||
"test-fs-read-stream-concurrent-reads.js",
|
||||
"test-fs-read-stream-double-close.js",
|
||||
"test-fs-read-stream-encoding.js",
|
||||
"test-fs-read-stream-fd.js",
|
||||
"test-fs-read-stream-inherit.js",
|
||||
"test-fs-read-stream-patch-open.js",
|
||||
"test-fs-read-stream-resume.js",
|
||||
"test-fs-read-stream-throw-type-error.js",
|
||||
"test-fs-read-stream.js",
|
||||
"test-fs-read-type.js",
|
||||
"test-fs-read-zero-length.js",
|
||||
"test-fs-read.js",
|
||||
"test-fs-readdir-stack-overflow.js",
|
||||
"test-fs-readdir.js",
|
||||
"test-fs-readfile-empty.js",
|
||||
"test-fs-realpath-native.js",
|
||||
"TODO:test-fs-rm.js",
|
||||
"test-fs-rmdir-recursive-sync-warns-not-found.js",
|
||||
"test-fs-rmdir-recursive-sync-warns-on-file.js",
|
||||
"test-fs-rmdir-recursive-throws-not-found.js",
|
||||
"test-fs-rmdir-recursive-throws-on-file.js",
|
||||
"test-fs-rmdir-recursive-warns-not-found.js",
|
||||
"test-fs-rmdir-recursive-warns-on-file.js",
|
||||
"test-fs-rmdir-recursive.js",
|
||||
"test-fs-rmdir-type-check.js",
|
||||
"TODO:test-fs-watch.js",
|
||||
"test-fs-watchfile.js",
|
||||
"test-fs-write-buffer.js",
|
||||
"test-fs-write-file-buffer.js",
|
||||
"test-fs-write-file-invalid-path.js",
|
||||
"test-fs-write-file-sync.js",
|
||||
"test-fs-write-file.js",
|
||||
"test-fs-write-no-fd.js",
|
||||
"test-fs-write-stream-autoclose-option.js",
|
||||
"test-fs-write-stream-close-without-callback.js",
|
||||
"test-fs-write-stream-double-close.js",
|
||||
"test-fs-write-stream-end.js",
|
||||
"test-fs-write-stream-fs.js",
|
||||
"test-fs-write-stream-throw-type-error.js",
|
||||
"test-fs-write-stream.js",
|
||||
"test-fs-write-sync.js",
|
||||
"test-fs-write.js",
|
||||
"test-fs-writev-sync.js",
|
||||
"TODO:test-fs-writev.js",
|
||||
"test-handle-wrap-close-abort.js",
|
||||
"test-http-agent-getname.js",
|
||||
"test-http-client-get-url.js",
|
||||
"test-http-client-read-in-error.js",
|
||||
"test-http-outgoing-buffer.js",
|
||||
"TODO:test-http-outgoing-destroy.js",
|
||||
"TODO:test-http-outgoing-finish-writable.js",
|
||||
"test-http-outgoing-internal-headernames-getter.js",
|
||||
"test-http-outgoing-internal-headernames-setter.js",
|
||||
"test-http-outgoing-internal-headers.js",
|
||||
"test-http-outgoing-message-inheritance.js",
|
||||
"test-http-outgoing-renderHeaders.js",
|
||||
"test-http-outgoing-settimeout.js",
|
||||
"test-http-url.parse-auth.js",
|
||||
"test-http-url.parse-path.js",
|
||||
"test-http-url.parse-post.js",
|
||||
"test-http-url.parse-search.js",
|
||||
"test-net-access-byteswritten.js",
|
||||
"TODO:test-net-after-close.js",
|
||||
"TODO:test-net-allow-half-open.js",
|
||||
"test-net-better-error-messages-listen-path.js",
|
||||
"TODO:test-net-better-error-messages-listen.js",
|
||||
"test-net-better-error-messages-path.js",
|
||||
"test-net-better-error-messages-port-hostname.js",
|
||||
"TODO:test-net-bind-twice.js",
|
||||
"TODO:test-net-buffersize.js",
|
||||
"TODO:test-net-bytes-written-large.js",
|
||||
"TODO:test-net-can-reset-timeout.js",
|
||||
"test-net-connect-after-destroy.js",
|
||||
"TODO:test-net-connect-buffer.js",
|
||||
"TODO:test-net-connect-buffer2.js",
|
||||
"TODO:test-net-connect-call-socket-connect.js",
|
||||
"test-net-connect-destroy.js",
|
||||
"test-net-connect-immediate-destroy.js",
|
||||
"test-net-connect-immediate-finish.js",
|
||||
"test-net-connect-no-arg.js",
|
||||
"TODO:test-net-connect-options-ipv6.js",
|
||||
"TODO:test-net-connect-options-port.js",
|
||||
"TODO:test-net-dns-custom-lookup.js",
|
||||
"test-net-dns-error.js",
|
||||
"TODO:test-net-dns-lookup-skip.js",
|
||||
"TODO:test-net-dns-lookup.js",
|
||||
"test-net-during-close.js",
|
||||
"TODO:test-net-eaddrinuse.js",
|
||||
"test-net-end-close.js",
|
||||
"TODO:test-net-end-destroyed.js",
|
||||
"test-net-end-without-connect.js",
|
||||
"test-net-isip.js",
|
||||
"test-net-isipv4.js",
|
||||
"test-net-isipv6.js",
|
||||
"TODO:test-net-listen-after-destroying-stdin.js",
|
||||
"test-net-listen-close-server-callback-is-not-function.js",
|
||||
"test-net-listen-close-server.js",
|
||||
"TODO:test-net-listen-error.js",
|
||||
"test-net-listen-invalid-port.js",
|
||||
"test-net-listening.js",
|
||||
"TODO:test-net-local-address-port.js",
|
||||
"test-net-localerror.js",
|
||||
"test-net-options-lookup.js",
|
||||
"TODO:test-net-pause-resume-connecting.js",
|
||||
"TODO:test-net-persistent-ref-unref.js",
|
||||
"test-net-pipe-connect-errors.js",
|
||||
"TODO:test-net-remote-address-port.js",
|
||||
"TODO:test-net-server-call-listen-multiple-times.js",
|
||||
"TODO:test-net-server-capture-rejection.js",
|
||||
"TODO:test-net-server-close.js",
|
||||
"test-net-server-listen-options-signal.js",
|
||||
"test-net-server-listen-options.js",
|
||||
"test-net-server-listen-path.js",
|
||||
"test-net-server-listen-remove-callback.js",
|
||||
"TODO:test-net-server-max-connections.js",
|
||||
"test-net-server-options.js",
|
||||
"TODO:test-net-server-pause-on-connect.js",
|
||||
"TODO:test-net-server-try-ports.js",
|
||||
"test-net-server-unref-persistent.js",
|
||||
"test-net-server-unref.js",
|
||||
"TODO:test-net-socket-close-after-end.js",
|
||||
"TODO:test-net-socket-connect-without-cb.js",
|
||||
"TODO:test-net-socket-connecting.js",
|
||||
"TODO:test-net-socket-destroy-send.js",
|
||||
"test-net-socket-destroy-twice.js",
|
||||
"TODO:test-net-socket-end-before-connect.js",
|
||||
"TODO:test-net-socket-end-callback.js",
|
||||
"test-net-socket-no-halfopen-enforcer.js",
|
||||
"TODO:test-net-socket-ready-without-cb.js",
|
||||
"TODO:test-net-socket-timeout.js",
|
||||
"TODO:test-net-socket-write-after-close.js",
|
||||
"TODO:test-net-socket-write-error.js",
|
||||
"TODO:test-net-sync-cork.js",
|
||||
"test-net-timeout-no-handle.js",
|
||||
"TODO:test-net-writable.js",
|
||||
"TODO:test-net-write-after-end-nt.js",
|
||||
"test-net-write-arguments.js",
|
||||
"TODO:test-net-write-fully-async-buffer.js",
|
||||
"TODO:test-net-write-fully-async-hex-string.js",
|
||||
"TODO:test-net-write-slow.js",
|
||||
"test-next-tick-doesnt-hang.js",
|
||||
"test-next-tick-fixed-queue-regression.js",
|
||||
"test-next-tick-intentional-starvation.js",
|
||||
"test-next-tick-ordering.js",
|
||||
"test-next-tick-ordering2.js",
|
||||
"test-next-tick-when-exiting.js",
|
||||
"test-next-tick.js",
|
||||
"test-nodeeventtarget.js",
|
||||
"TODO:test-os.js",
|
||||
"test-outgoing-message-destroy.js",
|
||||
"test-outgoing-message-pipe.js",
|
||||
"test-path-basename.js",
|
||||
"test-path-dirname.js",
|
||||
"test-path-extname.js",
|
||||
"test-path-isabsolute.js",
|
||||
"test-path-join.js",
|
||||
"test-path-makelong.js",
|
||||
"test-path-normalize.js",
|
||||
"test-path-parse-format.js",
|
||||
"test-path-posix-exists.js",
|
||||
"test-path-relative.js",
|
||||
"test-path-resolve.js",
|
||||
"test-path-win32-exists.js",
|
||||
"test-path-zero-length-strings.js",
|
||||
"test-path.js",
|
||||
"test-process-beforeexit.js",
|
||||
"test-process-binding-internalbinding-allowlist.js",
|
||||
"test-process-env-allowed-flags.js",
|
||||
"test-process-exit-from-before-exit.js",
|
||||
"test-process-exit-handler.js",
|
||||
"test-process-exit-recursive.js",
|
||||
"test-process-exit.js",
|
||||
"test-process-kill-pid.js",
|
||||
"TODO:test-process-uptime.js",
|
||||
"test-promise-unhandled-silent.js",
|
||||
"test-promise-unhandled-throw-handler.js",
|
||||
"TODO:test-punycode.js",
|
||||
"test-querystring-escape.js",
|
||||
"test-querystring-maxKeys-non-finite.js",
|
||||
"test-querystring-multichar-separator.js",
|
||||
"test-querystring.js",
|
||||
"TODO:test-readline-csi.js",
|
||||
"test-readline-emit-keypress-events.js",
|
||||
"test-readline-interface-escapecodetimeout.js",
|
||||
"TODO:test-readline-interface.js",
|
||||
"test-readline-keys.js",
|
||||
"test-readline-position.js",
|
||||
"TODO:test-readline-promises-csi.mjs",
|
||||
"TODO:test-readline-promises-interface.js",
|
||||
"test-readline-reopen.js",
|
||||
"test-readline-set-raw-mode.js",
|
||||
"test-readline-undefined-columns.js",
|
||||
"test-readline.js",
|
||||
"test-stdin-from-file-spawn.js",
|
||||
"test-stream-add-abort-signal.js",
|
||||
"test-stream-aliases-legacy.js",
|
||||
"TODO:test-stream-asIndexedPairs.mjs",
|
||||
"test-stream-auto-destroy.js",
|
||||
"test-stream-await-drain-writers-in-synchronously-recursion-write.js",
|
||||
"test-stream-backpressure.js",
|
||||
"test-stream-big-packet.js",
|
||||
"test-stream-big-push.js",
|
||||
"test-stream-buffer-list.js",
|
||||
"TODO:test-stream-catch-rejections.js",
|
||||
"test-stream-construct.js",
|
||||
"test-stream-destroy-event-order.js",
|
||||
"test-stream-duplex-destroy.js",
|
||||
"test-stream-duplex-end.js",
|
||||
"TODO:test-stream-duplex-from.js",
|
||||
"test-stream-duplex-props.js",
|
||||
"test-stream-duplex-readable-end.js",
|
||||
"test-stream-duplex-writable-finished.js",
|
||||
"test-stream-duplex.js",
|
||||
"test-stream-end-paused.js",
|
||||
"test-stream-error-once.js",
|
||||
"test-stream-events-prepend.js",
|
||||
"test-stream-inheritance.js",
|
||||
"test-stream-ispaused.js",
|
||||
"test-stream-objectmode-undefined.js",
|
||||
"test-stream-once-readable-pipe.js",
|
||||
"test-stream-pipe-after-end.js",
|
||||
"test-stream-pipe-await-drain-manual-resume.js",
|
||||
"test-stream-pipe-await-drain-push-while-write.js",
|
||||
"test-stream-pipe-await-drain.js",
|
||||
"test-stream-pipe-cleanup-pause.js",
|
||||
"test-stream-pipe-cleanup.js",
|
||||
"test-stream-pipe-error-handling.js",
|
||||
"test-stream-pipe-event.js",
|
||||
"test-stream-pipe-flow-after-unpipe.js",
|
||||
"test-stream-pipe-flow.js",
|
||||
"test-stream-pipe-manual-resume.js",
|
||||
"test-stream-pipe-multiple-pipes.js",
|
||||
"test-stream-pipe-needDrain.js",
|
||||
"test-stream-pipe-same-destination-twice.js",
|
||||
"test-stream-pipe-unpipe-streams.js",
|
||||
"test-stream-pipe-without-listenerCount.js",
|
||||
"TODO:test-stream-pipeline-async-iterator.js",
|
||||
"TODO:test-stream-pipeline-queued-end-in-destroy.js",
|
||||
"TODO:test-stream-pipeline-with-empty-string.js",
|
||||
"test-stream-push-strings.js",
|
||||
"test-stream-readable-aborted.js",
|
||||
"test-stream-readable-add-chunk-during-data.js",
|
||||
"test-stream-readable-constructor-set-methods.js",
|
||||
"test-stream-readable-data.js",
|
||||
"test-stream-readable-destroy.js",
|
||||
"test-stream-readable-didRead.js",
|
||||
"test-stream-readable-emit-readable-short-stream.js",
|
||||
"test-stream-readable-emittedReadable.js",
|
||||
"test-stream-readable-end-destroyed.js",
|
||||
"test-stream-readable-ended.js",
|
||||
"test-stream-readable-error-end.js",
|
||||
"test-stream-readable-event.js",
|
||||
"test-stream-readable-flow-recursion.js",
|
||||
"test-stream-readable-hwm-0-async.js",
|
||||
"test-stream-readable-hwm-0-no-flow-data.js",
|
||||
"test-stream-readable-hwm-0.js",
|
||||
"test-stream-readable-infinite-read.js",
|
||||
"test-stream-readable-invalid-chunk.js",
|
||||
"test-stream-readable-needReadable.js",
|
||||
"test-stream-readable-next-no-null.js",
|
||||
"test-stream-readable-no-unneeded-readable.js",
|
||||
"test-stream-readable-object-multi-push-async.js",
|
||||
"test-stream-readable-pause-and-resume.js",
|
||||
"test-stream-readable-readable-then-resume.js",
|
||||
"test-stream-readable-readable.js",
|
||||
"test-stream-readable-reading-readingMore.js",
|
||||
"test-stream-readable-resume-hwm.js",
|
||||
"test-stream-readable-resumeScheduled.js",
|
||||
"test-stream-readable-setEncoding-existing-buffers.js",
|
||||
"test-stream-readable-setEncoding-null.js",
|
||||
"test-stream-readable-unshift.js",
|
||||
"test-stream-readable-with-unimplemented-_read.js",
|
||||
"test-stream-readableListening-state.js",
|
||||
"TODO:test-stream-some-find-every.mjs",
|
||||
"test-stream-transform-callback-twice.js",
|
||||
"test-stream-transform-constructor-set-methods.js",
|
||||
"test-stream-transform-destroy.js",
|
||||
"test-stream-transform-final-sync.js",
|
||||
"test-stream-transform-final.js",
|
||||
"test-stream-transform-flush-data.js",
|
||||
"test-stream-transform-objectmode-falsey-value.js",
|
||||
"test-stream-transform-split-highwatermark.js",
|
||||
"test-stream-transform-split-objectmode.js",
|
||||
"test-stream-uint8array.js",
|
||||
"test-stream-unpipe-event.js",
|
||||
"test-stream-unshift-empty-chunk.js",
|
||||
"test-stream-unshift-read-race.js",
|
||||
"test-stream-writable-change-default-encoding.js",
|
||||
"test-stream-writable-clear-buffer.js",
|
||||
"test-stream-writable-constructor-set-methods.js",
|
||||
"test-stream-writable-decoded-encoding.js",
|
||||
"test-stream-writable-destroy.js",
|
||||
"test-stream-writable-end-cb-error.js",
|
||||
"test-stream-writable-end-multiple.js",
|
||||
"test-stream-writable-ended-state.js",
|
||||
"test-stream-writable-finish-destroyed.js",
|
||||
"test-stream-writable-finished-state.js",
|
||||
"test-stream-writable-finished.js",
|
||||
"test-stream-writable-invalid-chunk.js",
|
||||
"test-stream-writable-needdrain-state.js",
|
||||
"test-stream-writable-null.js",
|
||||
"test-stream-writable-properties.js",
|
||||
"test-stream-writable-writable.js",
|
||||
"test-stream-writable-write-cb-error.js",
|
||||
"test-stream-writable-write-cb-twice.js",
|
||||
"test-stream-writable-write-error.js",
|
||||
"test-stream-writable-write-writev-finish.js",
|
||||
"test-stream-writableState-ending.js",
|
||||
"test-stream-writableState-uncorked-bufferedRequestCount.js",
|
||||
"test-stream-write-destroy.js",
|
||||
"test-stream-write-drain.js",
|
||||
"test-stream-write-final.js",
|
||||
"test-stream-writev.js",
|
||||
"test-stream2-base64-single-char-read-end.js",
|
||||
"test-stream2-basic.js",
|
||||
"test-stream2-compatibility.js",
|
||||
"test-stream2-decode-partial.js",
|
||||
"test-stream2-finish-pipe.js",
|
||||
"test-stream2-large-read-stall.js",
|
||||
"test-stream2-objects.js",
|
||||
"test-stream2-pipe-error-handling.js",
|
||||
"test-stream2-pipe-error-once-listener.js",
|
||||
"test-stream2-push.js",
|
||||
"test-stream2-read-sync-stack.js",
|
||||
"test-stream2-readable-empty-buffer-no-eof.js",
|
||||
"test-stream2-readable-from-list.js",
|
||||
"test-stream2-readable-legacy-drain.js",
|
||||
"test-stream2-readable-non-empty-end.js",
|
||||
"test-stream2-readable-wrap-destroy.js",
|
||||
"test-stream2-readable-wrap-empty.js",
|
||||
"test-stream2-readable-wrap-error.js",
|
||||
"test-stream2-readable-wrap.js",
|
||||
"test-stream2-set-encoding.js",
|
||||
"test-stream2-transform.js",
|
||||
"test-stream2-unpipe-drain.js",
|
||||
"test-stream2-unpipe-leak.js",
|
||||
"test-stream2-writable.js",
|
||||
"test-stream3-cork-end.js",
|
||||
"test-stream3-cork-uncork.js",
|
||||
"test-stream3-pause-then-read.js",
|
||||
"test-streams-highwatermark.js",
|
||||
"test-timers-api-refs.js",
|
||||
"test-timers-args.js",
|
||||
"test-timers-clear-null-does-not-throw-error.js",
|
||||
"test-timers-clear-object-does-not-throw-error.js",
|
||||
"test-timers-clear-timeout-interval-equivalent.js",
|
||||
"test-timers-clearImmediate.js",
|
||||
"test-timers-interval-throw.js",
|
||||
"test-timers-non-integer-delay.js",
|
||||
"test-timers-refresh.js",
|
||||
"test-timers-same-timeout-wrong-list-deleted.js",
|
||||
"test-timers-timeout-with-non-integer.js",
|
||||
"test-timers-uncaught-exception.js",
|
||||
"test-timers-unref-throw-then-ref.js",
|
||||
"test-timers-user-call.js",
|
||||
"test-timers-zero-timeout.js",
|
||||
"TODO:test-tls-connect-simple.js",
|
||||
"test-url-domain-ascii-unicode.js",
|
||||
"test-url-fileurltopath.js",
|
||||
"test-url-format-invalid-input.js",
|
||||
"test-url-format-whatwg.js",
|
||||
"test-url-format.js",
|
||||
"test-url-parse-format.js",
|
||||
"test-url-parse-invalid-input.js",
|
||||
"test-url-parse-query.js",
|
||||
"test-url-pathtofileurl.js",
|
||||
"test-url-relative.js",
|
||||
"test-url-urltooptions.js",
|
||||
"test-util-deprecate-invalid-code.js",
|
||||
"test-util-deprecate.js",
|
||||
"test-util-format.js",
|
||||
"test-util-inherits.js",
|
||||
"test-util-inspect-long-running.js",
|
||||
"test-util-inspect-namespace.js",
|
||||
"test-util-inspect-proxy.js",
|
||||
"test-util-inspect.js",
|
||||
"test-util-isDeepStrictEqual.js",
|
||||
"test-util-promisify.js",
|
||||
"test-util-types-exists.js",
|
||||
"TODO:test-util-types.js",
|
||||
"test-util.js",
|
||||
"test-vm-static-this.js",
|
||||
"TODO:test-webcrypto-sign-verify.js",
|
||||
"test-whatwg-encoding-custom-api-basics.js",
|
||||
"test-whatwg-encoding-custom-fatal-streaming.js",
|
||||
"test-whatwg-encoding-custom-textdecoder-fatal.js",
|
||||
"test-whatwg-encoding-custom-textdecoder-ignorebom.js",
|
||||
"test-whatwg-encoding-custom-textdecoder-streaming.js",
|
||||
"test-whatwg-encoding-custom-textdecoder-utf16-surrogates.js",
|
||||
"test-whatwg-events-add-event-listener-options-passive.js",
|
||||
"test-whatwg-events-add-event-listener-options-signal.js",
|
||||
"test-whatwg-events-customevent.js",
|
||||
"test-whatwg-url-custom-deepequal.js",
|
||||
"test-whatwg-url-custom-domainto.js",
|
||||
"test-whatwg-url-custom-global.js",
|
||||
"test-whatwg-url-custom-href-side-effect.js",
|
||||
"test-whatwg-url-custom-inspect.js",
|
||||
"test-whatwg-url-custom-parsing.js",
|
||||
"test-whatwg-url-custom-setters.js",
|
||||
"test-whatwg-url-custom-tostringtag.js",
|
||||
"test-whatwg-url-override-hostname.js",
|
||||
"test-whatwg-url-properties.js",
|
||||
"test-whatwg-url-toascii.js",
|
||||
"test-zlib-close-after-error.js",
|
||||
"test-zlib-close-after-write.js",
|
||||
"test-zlib-convenience-methods.js",
|
||||
"test-zlib-deflate-raw-inherits.js",
|
||||
"test-zlib-destroy-pipe.js",
|
||||
"test-zlib-empty-buffer.js",
|
||||
"test-zlib-from-string.js",
|
||||
"test-zlib-invalid-input.js",
|
||||
"test-zlib-no-stream.js",
|
||||
"test-zlib-random-byte-pipes.js",
|
||||
"test-zlib-sync-no-event.js",
|
||||
"test-zlib-truncated.js",
|
||||
"test-zlib-unzip-one-byte-chunks.js",
|
||||
"test-zlib-write-after-end.js",
|
||||
"test-zlib-write-after-flush.js",
|
||||
"test-zlib-zero-byte.js",
|
||||
"test-zlib-zero-windowBits.js"
|
||||
],
|
||||
"pseudo-tty": [
|
||||
"console-dumb-tty.js",
|
||||
"console_colors.js",
|
||||
"no_dropped_stdio.js",
|
||||
"no_interleaved_stdio.js",
|
||||
"test-tty-color-support-warning-2.js",
|
||||
"test-tty-color-support-warning.js",
|
||||
"test-tty-stdin-end.js",
|
||||
"test-tty-stdout-end.js"
|
||||
],
|
||||
"pummel": [
|
||||
"TODO:test-net-bytes-per-incoming-chunk-overhead.js",
|
||||
"TODO:test-net-pingpong-delay.js",
|
||||
"TODO:test-net-write-callbacks.js"
|
||||
],
|
||||
"sequential": [
|
||||
"test-child-process-exit.js"
|
||||
]
|
||||
},
|
||||
"windowsIgnore": {
|
||||
"parallel": [
|
||||
"test-child-process-exec-abortcontroller-promisified.js",
|
||||
"test-console-log-throw-primitive.js",
|
||||
"test-console-no-swallow-stack-overflow.js",
|
||||
"test-console-sync-write-error.js",
|
||||
"test-dns.js",
|
||||
"test-dns-resolveany.js",
|
||||
"test-fs-access.js",
|
||||
"test-fs-mkdir.js",
|
||||
"test-fs-open-mode-mask.js",
|
||||
"test-fs-readdir-stack-overflow.js",
|
||||
"test-fs-rm.js",
|
||||
"test-fs-watchfile.js",
|
||||
"test-fs-write-file-invalid-path.js",
|
||||
"test-fs-write-file-sync.js",
|
||||
"test-fs-write-file.js",
|
||||
"test-http-client-get-url.js",
|
||||
"test-http-client-reject-cr-no-lf.js",
|
||||
"test-net-allow-half-open.js",
|
||||
"test-net-better-error-messages-listen-path.js",
|
||||
"test-net-better-error-messages-path.js",
|
||||
"test-net-pipe-connect-errors.js",
|
||||
"test-net-server-listen-path.js",
|
||||
"test-net-socket-close-after-end.js",
|
||||
"test-util-inspect-long-running.js",
|
||||
"test-util-inspect.js"
|
||||
]
|
||||
},
|
||||
"darwinIgnore": {
|
||||
"parallel": [
|
||||
"test-net-allow-half-open.js",
|
||||
"test-net-socket-close-after-end.js"
|
||||
]
|
||||
},
|
||||
"suitesFolder": "test",
|
||||
"versionsFolder": "versions"
|
||||
}
|
||||
|
|
|
@ -39,9 +39,10 @@ for await (const path of testPaths) {
|
|||
) {
|
||||
continue;
|
||||
}
|
||||
const isTodo = path.includes("TODO");
|
||||
const ignore =
|
||||
(Deno.build.os === "windows" && windowsIgnorePaths.has(path)) ||
|
||||
(Deno.build.os === "darwin" && darwinIgnorePaths.has(path));
|
||||
(Deno.build.os === "darwin" && darwinIgnorePaths.has(path)) || isTodo;
|
||||
Deno.test({
|
||||
name: `Node.js compatibility "${path}"`,
|
||||
ignore,
|
||||
|
@ -60,7 +61,7 @@ for await (const path of testPaths) {
|
|||
"-A",
|
||||
"--quiet",
|
||||
"--unstable",
|
||||
"--unsafely-ignore-certificate-errors",
|
||||
//"--unsafely-ignore-certificate-errors",
|
||||
"--v8-flags=" + v8Flags.join(),
|
||||
testCase.endsWith(".mjs") ? "--import-map=" + importMap : "runner.ts",
|
||||
testCase,
|
||||
|
@ -94,7 +95,8 @@ for await (const path of testPaths) {
|
|||
}
|
||||
|
||||
function checkConfigTestFilesOrder(testFileLists: Array<string[]>) {
|
||||
for (const testFileList of testFileLists) {
|
||||
for (let testFileList of testFileLists) {
|
||||
testFileList = testFileList.filter((name) => !name.startsWith("TODO:"));
|
||||
const sortedTestList = JSON.parse(JSON.stringify(testFileList));
|
||||
sortedTestList.sort();
|
||||
if (JSON.stringify(testFileList) !== JSON.stringify(sortedTestList)) {
|
||||
|
|
56
cli/tests/node_compat/test/common/child_process.js
Normal file
56
cli/tests/node_compat/test/common/child_process.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const common = require('./');
|
||||
|
||||
// Workaround for Windows Server 2008R2
|
||||
// When CMD is used to launch a process and CMD is killed too quickly, the
|
||||
// process can stay behind running in suspended state, never completing.
|
||||
function cleanupStaleProcess(filename) {
|
||||
if (!common.isWindows) {
|
||||
return;
|
||||
}
|
||||
process.once('beforeExit', () => {
|
||||
const basename = filename.replace(/.*[/\\]/g, '');
|
||||
try {
|
||||
require('child_process')
|
||||
.execFileSync(`${process.env.SystemRoot}\\System32\\wbem\\WMIC.exe`, [
|
||||
'process',
|
||||
'where',
|
||||
`commandline like '%${basename}%child'`,
|
||||
'delete',
|
||||
'/nointeractive',
|
||||
]);
|
||||
} catch {
|
||||
// Ignore failures, there might not be any stale process to clean up.
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// This should keep the child process running long enough to expire
|
||||
// the timeout.
|
||||
const kExpiringChildRunTime = common.platformTimeout(20 * 1000);
|
||||
const kExpiringParentTimer = 1;
|
||||
assert(kExpiringChildRunTime > kExpiringParentTimer);
|
||||
|
||||
function logAfterTime(time) {
|
||||
setTimeout(() => {
|
||||
// The following console statements are part of the test.
|
||||
console.log('child stdout');
|
||||
console.error('child stderr');
|
||||
}, time);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
cleanupStaleProcess,
|
||||
logAfterTime,
|
||||
kExpiringChildRunTime,
|
||||
kExpiringParentTimer
|
||||
};
|
35
cli/tests/node_compat/test/common/countdown.js
Normal file
35
cli/tests/node_compat/test/common/countdown.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const kLimit = Symbol('limit');
|
||||
const kCallback = Symbol('callback');
|
||||
const common = require('./');
|
||||
|
||||
class Countdown {
|
||||
constructor(limit, cb) {
|
||||
assert.strictEqual(typeof limit, 'number');
|
||||
assert.strictEqual(typeof cb, 'function');
|
||||
this[kLimit] = limit;
|
||||
this[kCallback] = common.mustCall(cb);
|
||||
}
|
||||
|
||||
dec() {
|
||||
assert(this[kLimit] > 0, 'Countdown expired');
|
||||
if (--this[kLimit] === 0)
|
||||
this[kCallback]();
|
||||
return this[kLimit];
|
||||
}
|
||||
|
||||
get remaining() {
|
||||
return this[kLimit];
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Countdown;
|
327
cli/tests/node_compat/test/common/dns.js
Normal file
327
cli/tests/node_compat/test/common/dns.js
Normal file
|
@ -0,0 +1,327 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const os = require('os');
|
||||
|
||||
const types = {
|
||||
A: 1,
|
||||
AAAA: 28,
|
||||
NS: 2,
|
||||
CNAME: 5,
|
||||
SOA: 6,
|
||||
PTR: 12,
|
||||
MX: 15,
|
||||
TXT: 16,
|
||||
ANY: 255,
|
||||
CAA: 257
|
||||
};
|
||||
|
||||
const classes = {
|
||||
IN: 1
|
||||
};
|
||||
|
||||
// Naïve DNS parser/serializer.
|
||||
|
||||
function readDomainFromPacket(buffer, offset) {
|
||||
assert.ok(offset < buffer.length);
|
||||
const length = buffer[offset];
|
||||
if (length === 0) {
|
||||
return { nread: 1, domain: '' };
|
||||
} else if ((length & 0xC0) === 0) {
|
||||
offset += 1;
|
||||
const chunk = buffer.toString('ascii', offset, offset + length);
|
||||
// Read the rest of the domain.
|
||||
const { nread, domain } = readDomainFromPacket(buffer, offset + length);
|
||||
return {
|
||||
nread: 1 + length + nread,
|
||||
domain: domain ? `${chunk}.${domain}` : chunk
|
||||
};
|
||||
}
|
||||
// Pointer to another part of the packet.
|
||||
assert.strictEqual(length & 0xC0, 0xC0);
|
||||
// eslint-disable-next-line space-infix-ops, space-unary-ops
|
||||
const pointeeOffset = buffer.readUInt16BE(offset) &~ 0xC000;
|
||||
return {
|
||||
nread: 2,
|
||||
domain: readDomainFromPacket(buffer, pointeeOffset)
|
||||
};
|
||||
}
|
||||
|
||||
function parseDNSPacket(buffer) {
|
||||
assert.ok(buffer.length > 12);
|
||||
|
||||
const parsed = {
|
||||
id: buffer.readUInt16BE(0),
|
||||
flags: buffer.readUInt16BE(2),
|
||||
};
|
||||
|
||||
const counts = [
|
||||
['questions', buffer.readUInt16BE(4)],
|
||||
['answers', buffer.readUInt16BE(6)],
|
||||
['authorityAnswers', buffer.readUInt16BE(8)],
|
||||
['additionalRecords', buffer.readUInt16BE(10)],
|
||||
];
|
||||
|
||||
let offset = 12;
|
||||
for (const [ sectionName, count ] of counts) {
|
||||
parsed[sectionName] = [];
|
||||
for (let i = 0; i < count; ++i) {
|
||||
const { nread, domain } = readDomainFromPacket(buffer, offset);
|
||||
offset += nread;
|
||||
|
||||
const type = buffer.readUInt16BE(offset);
|
||||
|
||||
const rr = {
|
||||
domain,
|
||||
cls: buffer.readUInt16BE(offset + 2),
|
||||
};
|
||||
offset += 4;
|
||||
|
||||
for (const name in types) {
|
||||
if (types[name] === type)
|
||||
rr.type = name;
|
||||
}
|
||||
|
||||
if (sectionName !== 'questions') {
|
||||
rr.ttl = buffer.readInt32BE(offset);
|
||||
const dataLength = buffer.readUInt16BE(offset);
|
||||
offset += 6;
|
||||
|
||||
switch (type) {
|
||||
case types.A:
|
||||
assert.strictEqual(dataLength, 4);
|
||||
rr.address = `${buffer[offset + 0]}.${buffer[offset + 1]}.` +
|
||||
`${buffer[offset + 2]}.${buffer[offset + 3]}`;
|
||||
break;
|
||||
case types.AAAA:
|
||||
assert.strictEqual(dataLength, 16);
|
||||
rr.address = buffer.toString('hex', offset, offset + 16)
|
||||
.replace(/(.{4}(?!$))/g, '$1:');
|
||||
break;
|
||||
case types.TXT:
|
||||
{
|
||||
let position = offset;
|
||||
rr.entries = [];
|
||||
while (position < offset + dataLength) {
|
||||
const txtLength = buffer[offset];
|
||||
rr.entries.push(buffer.toString('utf8',
|
||||
position + 1,
|
||||
position + 1 + txtLength));
|
||||
position += 1 + txtLength;
|
||||
}
|
||||
assert.strictEqual(position, offset + dataLength);
|
||||
break;
|
||||
}
|
||||
case types.MX:
|
||||
{
|
||||
rr.priority = buffer.readInt16BE(buffer, offset);
|
||||
offset += 2;
|
||||
const { nread, domain } = readDomainFromPacket(buffer, offset);
|
||||
rr.exchange = domain;
|
||||
assert.strictEqual(nread, dataLength);
|
||||
break;
|
||||
}
|
||||
case types.NS:
|
||||
case types.CNAME:
|
||||
case types.PTR:
|
||||
{
|
||||
const { nread, domain } = readDomainFromPacket(buffer, offset);
|
||||
rr.value = domain;
|
||||
assert.strictEqual(nread, dataLength);
|
||||
break;
|
||||
}
|
||||
case types.SOA:
|
||||
{
|
||||
const mname = readDomainFromPacket(buffer, offset);
|
||||
const rname = readDomainFromPacket(buffer, offset + mname.nread);
|
||||
rr.nsname = mname.domain;
|
||||
rr.hostmaster = rname.domain;
|
||||
const trailerOffset = offset + mname.nread + rname.nread;
|
||||
rr.serial = buffer.readUInt32BE(trailerOffset);
|
||||
rr.refresh = buffer.readUInt32BE(trailerOffset + 4);
|
||||
rr.retry = buffer.readUInt32BE(trailerOffset + 8);
|
||||
rr.expire = buffer.readUInt32BE(trailerOffset + 12);
|
||||
rr.minttl = buffer.readUInt32BE(trailerOffset + 16);
|
||||
|
||||
assert.strictEqual(trailerOffset + 20, dataLength);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new Error(`Unknown RR type ${rr.type}`);
|
||||
}
|
||||
offset += dataLength;
|
||||
}
|
||||
|
||||
parsed[sectionName].push(rr);
|
||||
|
||||
assert.ok(offset <= buffer.length);
|
||||
}
|
||||
}
|
||||
|
||||
assert.strictEqual(offset, buffer.length);
|
||||
return parsed;
|
||||
}
|
||||
|
||||
function writeIPv6(ip) {
|
||||
const parts = ip.replace(/^:|:$/g, '').split(':');
|
||||
const buf = Buffer.alloc(16);
|
||||
|
||||
let offset = 0;
|
||||
for (const part of parts) {
|
||||
if (part === '') {
|
||||
offset += 16 - 2 * (parts.length - 1);
|
||||
} else {
|
||||
buf.writeUInt16BE(parseInt(part, 16), offset);
|
||||
offset += 2;
|
||||
}
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
function writeDomainName(domain) {
|
||||
return Buffer.concat(domain.split('.').map((label) => {
|
||||
assert(label.length < 64);
|
||||
return Buffer.concat([
|
||||
Buffer.from([label.length]),
|
||||
Buffer.from(label, 'ascii'),
|
||||
]);
|
||||
}).concat([Buffer.alloc(1)]));
|
||||
}
|
||||
|
||||
function writeDNSPacket(parsed) {
|
||||
const buffers = [];
|
||||
const kStandardResponseFlags = 0x8180;
|
||||
|
||||
buffers.push(new Uint16Array([
|
||||
parsed.id,
|
||||
parsed.flags === undefined ? kStandardResponseFlags : parsed.flags,
|
||||
parsed.questions && parsed.questions.length,
|
||||
parsed.answers && parsed.answers.length,
|
||||
parsed.authorityAnswers && parsed.authorityAnswers.length,
|
||||
parsed.additionalRecords && parsed.additionalRecords.length,
|
||||
]));
|
||||
|
||||
for (const q of parsed.questions) {
|
||||
assert(types[q.type]);
|
||||
buffers.push(writeDomainName(q.domain));
|
||||
buffers.push(new Uint16Array([
|
||||
types[q.type],
|
||||
q.cls === undefined ? classes.IN : q.cls,
|
||||
]));
|
||||
}
|
||||
|
||||
for (const rr of [].concat(parsed.answers,
|
||||
parsed.authorityAnswers,
|
||||
parsed.additionalRecords)) {
|
||||
if (!rr) continue;
|
||||
|
||||
assert(types[rr.type]);
|
||||
buffers.push(writeDomainName(rr.domain));
|
||||
buffers.push(new Uint16Array([
|
||||
types[rr.type],
|
||||
rr.cls === undefined ? classes.IN : rr.cls,
|
||||
]));
|
||||
buffers.push(new Int32Array([rr.ttl]));
|
||||
|
||||
const rdLengthBuf = new Uint16Array(1);
|
||||
buffers.push(rdLengthBuf);
|
||||
|
||||
switch (rr.type) {
|
||||
case 'A':
|
||||
rdLengthBuf[0] = 4;
|
||||
buffers.push(new Uint8Array(rr.address.split('.')));
|
||||
break;
|
||||
case 'AAAA':
|
||||
rdLengthBuf[0] = 16;
|
||||
buffers.push(writeIPv6(rr.address));
|
||||
break;
|
||||
case 'TXT': {
|
||||
const total = rr.entries.map((s) => s.length).reduce((a, b) => a + b);
|
||||
// Total length of all strings + 1 byte each for their lengths.
|
||||
rdLengthBuf[0] = rr.entries.length + total;
|
||||
for (const txt of rr.entries) {
|
||||
buffers.push(new Uint8Array([Buffer.byteLength(txt)]));
|
||||
buffers.push(Buffer.from(txt));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'MX':
|
||||
rdLengthBuf[0] = 2;
|
||||
buffers.push(new Uint16Array([rr.priority]));
|
||||
// fall through
|
||||
case 'NS':
|
||||
case 'CNAME':
|
||||
case 'PTR':
|
||||
{
|
||||
const domain = writeDomainName(rr.exchange || rr.value);
|
||||
rdLengthBuf[0] += domain.length;
|
||||
buffers.push(domain);
|
||||
break;
|
||||
}
|
||||
case 'SOA':
|
||||
{
|
||||
const mname = writeDomainName(rr.nsname);
|
||||
const rname = writeDomainName(rr.hostmaster);
|
||||
rdLengthBuf[0] = mname.length + rname.length + 20;
|
||||
buffers.push(mname, rname);
|
||||
buffers.push(new Uint32Array([
|
||||
rr.serial, rr.refresh, rr.retry, rr.expire, rr.minttl,
|
||||
]));
|
||||
break;
|
||||
}
|
||||
case 'CAA':
|
||||
{
|
||||
rdLengthBuf[0] = 5 + rr.issue.length + 2;
|
||||
buffers.push(Buffer.from([Number(rr.critical)]));
|
||||
buffers.push(Buffer.from([Number(5)]));
|
||||
buffers.push(Buffer.from('issue' + rr.issue));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new Error(`Unknown RR type ${rr.type}`);
|
||||
}
|
||||
}
|
||||
|
||||
return Buffer.concat(buffers.map((typedArray) => {
|
||||
const buf = Buffer.from(typedArray.buffer,
|
||||
typedArray.byteOffset,
|
||||
typedArray.byteLength);
|
||||
if (os.endianness() === 'LE') {
|
||||
if (typedArray.BYTES_PER_ELEMENT === 2) buf.swap16();
|
||||
if (typedArray.BYTES_PER_ELEMENT === 4) buf.swap32();
|
||||
}
|
||||
return buf;
|
||||
}));
|
||||
}
|
||||
|
||||
const mockedErrorCode = 'ENOTFOUND';
|
||||
const mockedSysCall = 'getaddrinfo';
|
||||
|
||||
function errorLookupMock(code = mockedErrorCode, syscall = mockedSysCall) {
|
||||
return function lookupWithError(hostname, dnsopts, cb) {
|
||||
const err = new Error(`${syscall} ${code} ${hostname}`);
|
||||
err.code = code;
|
||||
err.errno = code;
|
||||
err.syscall = syscall;
|
||||
err.hostname = hostname;
|
||||
cb(err);
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
types,
|
||||
classes,
|
||||
writeDNSPacket,
|
||||
parseDNSPacket,
|
||||
errorLookupMock,
|
||||
mockedErrorCode,
|
||||
mockedSysCall
|
||||
};
|
55
cli/tests/node_compat/test/common/duplexpair.js
Normal file
55
cli/tests/node_compat/test/common/duplexpair.js
Normal file
|
@ -0,0 +1,55 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
const { Duplex } = require('stream');
|
||||
const assert = require('assert');
|
||||
|
||||
const kCallback = Symbol('Callback');
|
||||
const kOtherSide = Symbol('Other');
|
||||
|
||||
class DuplexSocket extends Duplex {
|
||||
constructor() {
|
||||
super();
|
||||
this[kCallback] = null;
|
||||
this[kOtherSide] = null;
|
||||
}
|
||||
|
||||
_read() {
|
||||
const callback = this[kCallback];
|
||||
if (callback) {
|
||||
this[kCallback] = null;
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
_write(chunk, encoding, callback) {
|
||||
assert.notStrictEqual(this[kOtherSide], null);
|
||||
assert.strictEqual(this[kOtherSide][kCallback], null);
|
||||
if (chunk.length === 0) {
|
||||
process.nextTick(callback);
|
||||
} else {
|
||||
this[kOtherSide].push(chunk);
|
||||
this[kOtherSide][kCallback] = callback;
|
||||
}
|
||||
}
|
||||
|
||||
_final(callback) {
|
||||
this[kOtherSide].on('end', callback);
|
||||
this[kOtherSide].push(null);
|
||||
}
|
||||
}
|
||||
|
||||
function makeDuplexPair() {
|
||||
const clientSide = new DuplexSocket();
|
||||
const serverSide = new DuplexSocket();
|
||||
clientSide[kOtherSide] = serverSide;
|
||||
serverSide[kOtherSide] = clientSide;
|
||||
return { clientSide, serverSide };
|
||||
}
|
||||
|
||||
module.exports = makeDuplexPair;
|
45
cli/tests/node_compat/test/common/fixtures.js
Normal file
45
cli/tests/node_compat/test/common/fixtures.js
Normal file
|
@ -0,0 +1,45 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const { pathToFileURL } = require('url');
|
||||
|
||||
const fixturesDir = path.join(__dirname, '..', 'fixtures');
|
||||
|
||||
function fixturesPath(...args) {
|
||||
return path.join(fixturesDir, ...args);
|
||||
}
|
||||
|
||||
function fixturesFileURL(...args) {
|
||||
return pathToFileURL(fixturesPath(...args));
|
||||
}
|
||||
|
||||
function readFixtureSync(args, enc) {
|
||||
if (Array.isArray(args))
|
||||
return fs.readFileSync(fixturesPath(...args), enc);
|
||||
return fs.readFileSync(fixturesPath(args), enc);
|
||||
}
|
||||
|
||||
function readFixtureKey(name, enc) {
|
||||
return fs.readFileSync(fixturesPath('keys', name), enc);
|
||||
}
|
||||
|
||||
function readFixtureKeys(enc, ...names) {
|
||||
return names.map((name) => readFixtureKey(name, enc));
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
fixturesDir,
|
||||
path: fixturesPath,
|
||||
fileURL: fixturesFileURL,
|
||||
readSync: readFixtureSync,
|
||||
readKey: readFixtureKey,
|
||||
readKeys: readFixtureKeys,
|
||||
};
|
39
cli/tests/node_compat/test/common/hijackstdio.js
Normal file
39
cli/tests/node_compat/test/common/hijackstdio.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
// Hijack stdout and stderr
|
||||
const stdWrite = {};
|
||||
function hijackStdWritable(name, listener) {
|
||||
const stream = process[name];
|
||||
const _write = stdWrite[name] = stream.write;
|
||||
|
||||
stream.writeTimes = 0;
|
||||
stream.write = function(data, callback) {
|
||||
try {
|
||||
listener(data);
|
||||
} catch (e) {
|
||||
process.nextTick(() => { throw e; });
|
||||
}
|
||||
|
||||
_write.call(stream, data, callback);
|
||||
stream.writeTimes++;
|
||||
};
|
||||
}
|
||||
|
||||
function restoreWritable(name) {
|
||||
process[name].write = stdWrite[name];
|
||||
delete process[name].writeTimes;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
hijackStdout: hijackStdWritable.bind(null, 'stdout'),
|
||||
hijackStderr: hijackStdWritable.bind(null, 'stderr'),
|
||||
restoreStdout: restoreWritable.bind(null, 'stdout'),
|
||||
restoreStderr: restoreWritable.bind(null, 'stderr')
|
||||
};
|
113
cli/tests/node_compat/test/common/index.mjs
Normal file
113
cli/tests/node_compat/test/common/index.mjs
Normal file
|
@ -0,0 +1,113 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
import { createRequire } from 'module';
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const common = require('./index.js');
|
||||
|
||||
const {
|
||||
isMainThread,
|
||||
isWindows,
|
||||
isAIX,
|
||||
isIBMi,
|
||||
isLinuxPPCBE,
|
||||
isSunOS,
|
||||
isDumbTerminal,
|
||||
isFreeBSD,
|
||||
isOpenBSD,
|
||||
isLinux,
|
||||
isOSX,
|
||||
enoughTestMem,
|
||||
buildType,
|
||||
localIPv6Hosts,
|
||||
opensslCli,
|
||||
PIPE,
|
||||
hasCrypto,
|
||||
hasIPv6,
|
||||
childShouldThrowAndAbort,
|
||||
checkoutEOL,
|
||||
createZeroFilledFile,
|
||||
platformTimeout,
|
||||
allowGlobals,
|
||||
mustCall,
|
||||
mustCallAtLeast,
|
||||
mustSucceed,
|
||||
hasMultiLocalhost,
|
||||
skipIfDumbTerminal,
|
||||
skipIfEslintMissing,
|
||||
canCreateSymLink,
|
||||
getCallSite,
|
||||
mustNotCall,
|
||||
mustNotMutateObjectDeep,
|
||||
printSkipMessage,
|
||||
skip,
|
||||
nodeProcessAborted,
|
||||
isAlive,
|
||||
expectWarning,
|
||||
expectsError,
|
||||
skipIfInspectorDisabled,
|
||||
skipIf32Bits,
|
||||
getArrayBufferViews,
|
||||
getBufferSources,
|
||||
getTTYfd,
|
||||
runWithInvalidFD,
|
||||
spawnPromisified,
|
||||
} = common;
|
||||
|
||||
const getPort = () => common.PORT;
|
||||
|
||||
export {
|
||||
isMainThread,
|
||||
isWindows,
|
||||
isAIX,
|
||||
isIBMi,
|
||||
isLinuxPPCBE,
|
||||
isSunOS,
|
||||
isDumbTerminal,
|
||||
isFreeBSD,
|
||||
isOpenBSD,
|
||||
isLinux,
|
||||
isOSX,
|
||||
enoughTestMem,
|
||||
buildType,
|
||||
localIPv6Hosts,
|
||||
opensslCli,
|
||||
PIPE,
|
||||
hasCrypto,
|
||||
hasIPv6,
|
||||
childShouldThrowAndAbort,
|
||||
checkoutEOL,
|
||||
createZeroFilledFile,
|
||||
platformTimeout,
|
||||
allowGlobals,
|
||||
mustCall,
|
||||
mustCallAtLeast,
|
||||
mustSucceed,
|
||||
hasMultiLocalhost,
|
||||
skipIfDumbTerminal,
|
||||
skipIfEslintMissing,
|
||||
canCreateSymLink,
|
||||
getCallSite,
|
||||
mustNotCall,
|
||||
mustNotMutateObjectDeep,
|
||||
printSkipMessage,
|
||||
skip,
|
||||
nodeProcessAborted,
|
||||
isAlive,
|
||||
expectWarning,
|
||||
expectsError,
|
||||
skipIfInspectorDisabled,
|
||||
skipIf32Bits,
|
||||
getArrayBufferViews,
|
||||
getBufferSources,
|
||||
getTTYfd,
|
||||
runWithInvalidFD,
|
||||
createRequire,
|
||||
spawnPromisified,
|
||||
getPort,
|
||||
};
|
68
cli/tests/node_compat/test/common/internet.js
Normal file
68
cli/tests/node_compat/test/common/internet.js
Normal file
|
@ -0,0 +1,68 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.0
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
// Utilities for internet-related tests
|
||||
|
||||
const addresses = {
|
||||
// A generic host that has registered common DNS records,
|
||||
// supports both IPv4 and IPv6, and provides basic HTTP/HTTPS services
|
||||
INET_HOST: 'nodejs.org',
|
||||
// A host that provides IPv4 services
|
||||
INET4_HOST: 'nodejs.org',
|
||||
// A host that provides IPv6 services
|
||||
INET6_HOST: 'nodejs.org',
|
||||
// An accessible IPv4 IP,
|
||||
// defaults to the Google Public DNS IPv4 address
|
||||
INET4_IP: '8.8.8.8',
|
||||
// An accessible IPv6 IP,
|
||||
// defaults to the Google Public DNS IPv6 address
|
||||
INET6_IP: '2001:4860:4860::8888',
|
||||
// An invalid host that cannot be resolved
|
||||
// See https://tools.ietf.org/html/rfc2606#section-2
|
||||
INVALID_HOST: 'something.invalid',
|
||||
// A host with MX records registered
|
||||
MX_HOST: 'nodejs.org',
|
||||
// On some systems, .invalid returns a server failure/try again rather than
|
||||
// record not found. Use this to guarantee record not found.
|
||||
NOT_FOUND: 'come.on.fhqwhgads.test',
|
||||
// A host with SRV records registered
|
||||
// TODO(kt3k): Temporarily use _caldav._tcp.google.com instead of
|
||||
// _jabber._tcp.google.com, which currently doesn't respond
|
||||
// SRV_HOST: '_jabber._tcp.google.com',
|
||||
SRV_HOST: '_caldav._tcp.google.com',
|
||||
// A host with PTR records registered
|
||||
PTR_HOST: '8.8.8.8.in-addr.arpa',
|
||||
// A host with NAPTR records registered
|
||||
NAPTR_HOST: 'sip2sip.info',
|
||||
// A host with SOA records registered
|
||||
SOA_HOST: 'nodejs.org',
|
||||
// A host with CAA record registered
|
||||
CAA_HOST: 'google.com',
|
||||
// A host with CNAME records registered
|
||||
CNAME_HOST: 'blog.nodejs.org',
|
||||
// A host with NS records registered
|
||||
NS_HOST: 'nodejs.org',
|
||||
// A host with TXT records registered
|
||||
TXT_HOST: 'nodejs.org',
|
||||
// An accessible IPv4 DNS server
|
||||
DNS4_SERVER: '8.8.8.8',
|
||||
// An accessible IPv4 DNS server
|
||||
DNS6_SERVER: '2001:4860:4860::8888'
|
||||
};
|
||||
|
||||
for (const key of Object.keys(addresses)) {
|
||||
const envName = `NODE_TEST_${key}`;
|
||||
if (process.env[envName]) {
|
||||
addresses[key] = process.env[envName];
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
addresses
|
||||
};
|
30
cli/tests/node_compat/test/fixtures/GH-1899-output.js
vendored
Normal file
30
cli/tests/node_compat/test/fixtures/GH-1899-output.js
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// 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.
|
||||
|
||||
console.log('hello, world!');
|
||||
|
53
cli/tests/node_compat/test/fixtures/a.js
vendored
Normal file
53
cli/tests/node_compat/test/fixtures/a.js
vendored
Normal file
|
@ -0,0 +1,53 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// 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.
|
||||
|
||||
const c = require('./b/c');
|
||||
|
||||
console.error('load fixtures/a.js');
|
||||
|
||||
var string = 'A';
|
||||
|
||||
exports.SomeClass = c.SomeClass;
|
||||
|
||||
exports.A = function() {
|
||||
return string;
|
||||
};
|
||||
|
||||
exports.C = function() {
|
||||
return c.C();
|
||||
};
|
||||
|
||||
exports.D = function() {
|
||||
return c.D();
|
||||
};
|
||||
|
||||
exports.number = 42;
|
||||
|
||||
process.on('exit', function() {
|
||||
string = 'A done';
|
||||
});
|
14
cli/tests/node_compat/test/fixtures/child-process-spawn-node.js
vendored
Normal file
14
cli/tests/node_compat/test/fixtures/child-process-spawn-node.js
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
const assert = require('assert');
|
||||
// TODO(kt3k): Uncomment this when util.debuglog is added
|
||||
// const debug = require('util').debuglog('test');
|
||||
const debug = console.log;
|
||||
|
||||
function onmessage(m) {
|
||||
debug('CHILD got message:', m);
|
||||
assert.ok(m.hello);
|
||||
process.removeListener('message', onmessage);
|
||||
}
|
||||
|
||||
process.on('message', onmessage);
|
||||
// TODO(kt3k): Uncomment the below when the ipc features are ready
|
||||
// process.send({ foo: 'bar' });
|
36
cli/tests/node_compat/test/fixtures/child_process_should_emit_error.js
vendored
Normal file
36
cli/tests/node_compat/test/fixtures/child_process_should_emit_error.js
vendored
Normal file
|
@ -0,0 +1,36 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// 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.
|
||||
|
||||
const exec = require('child_process').exec;
|
||||
|
||||
[0, 1].forEach(function(i) {
|
||||
exec('ls', function(err, stdout, stderr) {
|
||||
console.log(i);
|
||||
throw new Error('hello world');
|
||||
});
|
||||
});
|
41
cli/tests/node_compat/test/fixtures/echo.js
vendored
Normal file
41
cli/tests/node_compat/test/fixtures/echo.js
vendored
Normal file
|
@ -0,0 +1,41 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// 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.
|
||||
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
process.stdout.write('hello world\r\n');
|
||||
|
||||
// TODO(PolarETech): process.openStdin() is not yet implemented.
|
||||
// Use process.stdin instead.
|
||||
var stdin = process.stdin;
|
||||
// var stdin = process.openStdin();
|
||||
|
||||
stdin.on('data', function(data) {
|
||||
process.stdout.write(data.toString());
|
||||
});
|
1
cli/tests/node_compat/test/fixtures/elipses.txt
vendored
Normal file
1
cli/tests/node_compat/test/fixtures/elipses.txt
vendored
Normal file
File diff suppressed because one or more lines are too long
0
cli/tests/node_compat/test/fixtures/empty.txt
vendored
Normal file
0
cli/tests/node_compat/test/fixtures/empty.txt
vendored
Normal file
31
cli/tests/node_compat/test/fixtures/exit.js
vendored
Normal file
31
cli/tests/node_compat/test/fixtures/exit.js
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// 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.
|
||||
|
||||
// TODO(PolarETech): The process.argv[3] should be argv[2].
|
||||
|
||||
process.exit(process.argv[3] || 1);
|
30
cli/tests/node_compat/test/fixtures/keys/agent1-cert.pem
vendored
Normal file
30
cli/tests/node_compat/test/fixtures/keys/agent1-cert.pem
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIID6DCCAtCgAwIBAgIUFH02wcL3Qgben6tfIibXitsApCYwDQYJKoZIhvcNAQEL
|
||||
BQAwejELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMQswCQYDVQQHDAJTRjEPMA0G
|
||||
A1UECgwGSm95ZW50MRAwDgYDVQQLDAdOb2RlLmpzMQwwCgYDVQQDDANjYTExIDAe
|
||||
BgkqhkiG9w0BCQEWEXJ5QHRpbnljbG91ZHMub3JnMCAXDTIyMDkwMzIxNDAzN1oY
|
||||
DzIyOTYwNjE3MjE0MDM3WjB9MQswCQYDVQQGEwJVUzELMAkGA1UECAwCQ0ExCzAJ
|
||||
BgNVBAcMAlNGMQ8wDQYDVQQKDAZKb3llbnQxEDAOBgNVBAsMB05vZGUuanMxDzAN
|
||||
BgNVBAMMBmFnZW50MTEgMB4GCSqGSIb3DQEJARYRcnlAdGlueWNsb3Vkcy5vcmcw
|
||||
ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDUVjIK+yDTgnCT3CxChO0E
|
||||
37q9VuHdrlKeKLeQzUJW2yczSfNzX/0zfHpjY+zKWie39z3HCJqWxtiG2wxiOI8c
|
||||
3WqWOvzVmdWADlh6EfkIlg+E7VC6JaKDA+zabmhPvnuu3JzogBMnsWl68lCXzuPx
|
||||
deQAmEwNtqjrh74DtM+Ud0ulb//Ixjxo1q3rYKu+aaexSramuee6qJta2rjrB4l8
|
||||
B/bU+j1mDf9XQQfSjo9jRnp4hiTFdBl2k+lZzqE2L/rhu6EMjA2IhAq/7xA2MbLo
|
||||
9cObVUin6lfoo5+JKRgT9Fp2xEgDOit+2EA/S6oUfPNeLSVUqmXOSWlXlwlb9Nxr
|
||||
AgMBAAGjYTBfMF0GCCsGAQUFBwEBBFEwTzAjBggrBgEFBQcwAYYXaHR0cDovL29j
|
||||
c3Aubm9kZWpzLm9yZy8wKAYIKwYBBQUHMAKGHGh0dHA6Ly9jYS5ub2RlanMub3Jn
|
||||
L2NhLmNlcnQwDQYJKoZIhvcNAQELBQADggEBAMM0mBBjLMt9pYXePtUeNO0VTw9y
|
||||
FWCM8nAcAO2kRNwkJwcsispNpkcsHZ5o8Xf5mpCotdvziEWG1hyxwU6nAWyNOLcN
|
||||
G0a0KUfbMO3B6ZYe1GwPDjXaQnv75SkAdxgX5zOzca3xnhITcjUUGjQ0fbDfwFV5
|
||||
ix8mnzvfXjDONdEznVa7PFcN6QliFUMwR/h8pCRHtE5+a10OSPeJSrGG+FtrGnRW
|
||||
G1IJUv6oiGF/MvWCr84REVgc1j78xomGANJIu2hN7bnD1nEMON6em8IfnDOUtynV
|
||||
9wfWTqiQYD5Zifj6WcGa0aAHMuetyFG4lIfMAHmd3gaKpks7j9l26LwRPvI=
|
||||
-----END CERTIFICATE-----
|
34
cli/tests/node_compat/test/fixtures/keys/agent1-key.pem
vendored
Normal file
34
cli/tests/node_compat/test/fixtures/keys/agent1-key.pem
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIEpAIBAAKCAQEA1FYyCvsg04Jwk9wsQoTtBN+6vVbh3a5Snii3kM1CVtsnM0nz
|
||||
c1/9M3x6Y2Psylont/c9xwialsbYhtsMYjiPHN1qljr81ZnVgA5YehH5CJYPhO1Q
|
||||
uiWigwPs2m5oT757rtyc6IATJ7FpevJQl87j8XXkAJhMDbao64e+A7TPlHdLpW//
|
||||
yMY8aNat62CrvmmnsUq2prnnuqibWtq46weJfAf21Po9Zg3/V0EH0o6PY0Z6eIYk
|
||||
xXQZdpPpWc6hNi/64buhDIwNiIQKv+8QNjGy6PXDm1VIp+pX6KOfiSkYE/RadsRI
|
||||
AzorfthAP0uqFHzzXi0lVKplzklpV5cJW/TcawIDAQABAoIBAAvbtHfAhpjJVBgt
|
||||
15rvaX04MWmZjIugzKRgib/gdq/7FTlcC+iJl85kSUF7tyGl30n62MxgwqFhAX6m
|
||||
hQ6HMhbelrFFIhGbwbyhEHfgwROlrcAysKt0pprCgVvBhrnNXYLqdyjU3jz9P3LK
|
||||
TY3s0/YMK2uNFdI+PTjKH+Z9Foqn9NZUnUonEDepGyuRO7fLeccWJPv2L4CR4a/5
|
||||
ku4VbDgVpvVSVRG3PSVzbmxobnpdpl52og+T7tPx1cLnIknPtVljXPWtZdfekh2E
|
||||
eAp2KxCCHOKzzG3ItBKsVu0woeqEpy8JcoO6LbgmEoVnZpgmtQClbBgef8+i+oGE
|
||||
BgW9nmECgYEA8gA63QQuZOUC56N1QXURexN2PogF4wChPaCTFbQSJXvSBkQmbqfL
|
||||
qRSD8P0t7GOioPrQK6pDwFf4BJB01AvkDf8Z6DxxOJ7cqIC7LOwDupXocWX7Q0Qk
|
||||
O6cwclBVsrDZK00v60uRRpl/a39GW2dx7IiQDkKQndLh3/0TbMIWHNcCgYEA4J6r
|
||||
yinZbLpKw2+ezhi4B4GT1bMLoKboJwpZVyNZZCzYR6ZHv+lS7HR/02rcYMZGoYbf
|
||||
n7OHwF4SrnUS7vPhG4g2ZsOhKQnMvFSQqpGmK1ZTuoKGAevyvtouhK/DgtLWzGvX
|
||||
9fSahiq/UvfXs/z4M11q9Rv9ztPCmG1cwSEHlo0CgYEAogQNZJK8DMhVnYcNpXke
|
||||
7uskqtCeQE/Xo06xqkIYNAgloBRYNpUYAGa/vsOBz1UVN/kzDUi8ezVp0oRz8tLT
|
||||
J5u2WIi+tE2HJTiqF3UbOfvK1sCT64DfUSCpip7GAQ/tFNRkVH8PD9kMOYfILsGe
|
||||
v+DdsO5Xq5HXrwHb02BNNZkCgYBsl8lt33WiPx5OBfS8pu6xkk+qjPkeHhM2bKZs
|
||||
nkZlS9j0KsudWGwirN/vkkYg8zrKdK5AQ0dqFRDrDuasZ3N5IA1M+V88u+QjWK7o
|
||||
B6pSYVXxYZDv9OZSpqC+vUrEQLJf+fNakXrzSk9dCT1bYv2Lt6ox/epix7XYg2bI
|
||||
Z/OHMQKBgQC2FUGhlndGeugTJaoJ8nhT/0VfRUX/h6sCgSerk5qFr/hNCBV4T022
|
||||
x0NDR2yLG6MXyqApJpG6rh3QIDElQoQCNlI3/KJ6JfEfmqrLLN2OigTvA5sE4fGU
|
||||
Dp/ha8OQAx95EwXuaG7LgARduvOIK3x8qi8KsZoUGJcg2ywurUbkWA==
|
||||
-----END RSA PRIVATE KEY-----
|
17
cli/tests/node_compat/test/fixtures/loop.js
vendored
Normal file
17
cli/tests/node_compat/test/fixtures/loop.js
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
var t = 1;
|
||||
var k = 1;
|
||||
console.log('A message', 5);
|
||||
while (t > 0) {
|
||||
if (t++ === 1000) {
|
||||
t = 0;
|
||||
console.log(`Outputted message #${k++}`);
|
||||
}
|
||||
}
|
||||
process.exit(55);
|
1
cli/tests/node_compat/test/fixtures/package.json
vendored
Normal file
1
cli/tests/node_compat/test/fixtures/package.json
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{}
|
35
cli/tests/node_compat/test/fixtures/print-chars.js
vendored
Normal file
35
cli/tests/node_compat/test/fixtures/print-chars.js
vendored
Normal file
|
@ -0,0 +1,35 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// 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.
|
||||
|
||||
// TODO(PolarETech): The process.argv[3] should be argv[2].
|
||||
|
||||
const assert = require('assert');
|
||||
|
||||
var n = parseInt(process.argv[3]);
|
||||
|
||||
process.stdout.write('c'.repeat(n));
|
1
cli/tests/node_compat/test/fixtures/x.txt
vendored
Normal file
1
cli/tests/node_compat/test/fixtures/x.txt
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
xyz
|
1
cli/tests/node_compat/test/internet/package.json
Normal file
1
cli/tests/node_compat/test/internet/package.json
Normal file
|
@ -0,0 +1 @@
|
|||
{}
|
26
cli/tests/node_compat/test/internet/test-dgram-connect.js
Normal file
26
cli/tests/node_compat/test/internet/test-dgram-connect.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
const { addresses } = require('../common/internet');
|
||||
const assert = require('assert');
|
||||
const dgram = require('dgram');
|
||||
|
||||
const client = dgram.createSocket('udp4');
|
||||
client.connect(common.PORT, addresses.INVALID_HOST, common.mustCall((err) => {
|
||||
assert.ok(err.code === 'ENOTFOUND' || err.code === 'EAI_AGAIN');
|
||||
|
||||
client.once('error', common.mustCall((err) => {
|
||||
assert.ok(err.code === 'ENOTFOUND' || err.code === 'EAI_AGAIN');
|
||||
client.once('connect', common.mustCall(() => client.close()));
|
||||
client.connect(common.PORT);
|
||||
}));
|
||||
|
||||
client.connect(common.PORT, addresses.INVALID_HOST);
|
||||
}));
|
192
cli/tests/node_compat/test/internet/test-dns-any.js
Normal file
192
cli/tests/node_compat/test/internet/test-dns-any.js
Normal file
|
@ -0,0 +1,192 @@
|
|||
// 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
|
||||
|
||||
// TODO(cmorten): enable remaining tests once functionality is implemented.
|
||||
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
|
||||
const assert = require('assert');
|
||||
const dns = require('dns');
|
||||
const net = require('net');
|
||||
|
||||
let running = false;
|
||||
const queue = [];
|
||||
|
||||
const dnsPromises = dns.promises;
|
||||
const isIPv4 = net.isIPv4;
|
||||
const isIPv6 = net.isIPv6;
|
||||
|
||||
dns.setServers([ '8.8.8.8', '8.8.4.4' ]);
|
||||
|
||||
function checkWrap(req) {
|
||||
assert.ok(typeof req === 'object');
|
||||
}
|
||||
|
||||
const checkers = {
|
||||
checkA(r) {
|
||||
assert.ok(isIPv4(r.address));
|
||||
// assert.strictEqual(typeof r.ttl, 'number');
|
||||
assert.strictEqual(r.type, 'A');
|
||||
},
|
||||
checkAAAA(r) {
|
||||
assert.ok(isIPv6(r.address));
|
||||
// assert.strictEqual(typeof r.ttl, 'number');
|
||||
assert.strictEqual(r.type, 'AAAA');
|
||||
},
|
||||
checkCNAME(r) {
|
||||
assert.ok(r.value);
|
||||
assert.strictEqual(typeof r.value, 'string');
|
||||
assert.strictEqual(r.type, 'CNAME');
|
||||
},
|
||||
checkMX(r) {
|
||||
assert.strictEqual(typeof r.exchange, 'string');
|
||||
assert.strictEqual(typeof r.priority, 'number');
|
||||
assert.strictEqual(r.type, 'MX');
|
||||
},
|
||||
checkNAPTR(r) {
|
||||
assert.strictEqual(typeof r.flags, 'string');
|
||||
assert.strictEqual(typeof r.service, 'string');
|
||||
assert.strictEqual(typeof r.regexp, 'string');
|
||||
assert.strictEqual(typeof r.replacement, 'string');
|
||||
assert.strictEqual(typeof r.order, 'number');
|
||||
assert.strictEqual(typeof r.preference, 'number');
|
||||
assert.strictEqual(r.type, 'NAPTR');
|
||||
},
|
||||
checkNS(r) {
|
||||
assert.strictEqual(typeof r.value, 'string');
|
||||
assert.strictEqual(r.type, 'NS');
|
||||
},
|
||||
checkPTR(r) {
|
||||
assert.strictEqual(typeof r.value, 'string');
|
||||
assert.strictEqual(r.type, 'PTR');
|
||||
},
|
||||
checkTXT(r) {
|
||||
assert.ok(Array.isArray(r.entries));
|
||||
assert.ok(r.entries.length > 0);
|
||||
assert.strictEqual(r.type, 'TXT');
|
||||
},
|
||||
checkSOA(r) {
|
||||
assert.strictEqual(typeof r.nsname, 'string');
|
||||
assert.strictEqual(typeof r.hostmaster, 'string');
|
||||
assert.strictEqual(typeof r.serial, 'number');
|
||||
assert.strictEqual(typeof r.refresh, 'number');
|
||||
assert.strictEqual(typeof r.retry, 'number');
|
||||
assert.strictEqual(typeof r.expire, 'number');
|
||||
assert.strictEqual(typeof r.minttl, 'number');
|
||||
assert.strictEqual(r.type, 'SOA');
|
||||
},
|
||||
checkSRV(r) {
|
||||
assert.strictEqual(typeof r.name, 'string');
|
||||
assert.strictEqual(typeof r.port, 'number');
|
||||
assert.strictEqual(typeof r.priority, 'number');
|
||||
assert.strictEqual(typeof r.weight, 'number');
|
||||
assert.strictEqual(r.type, 'SRV');
|
||||
}
|
||||
};
|
||||
|
||||
function TEST(f) {
|
||||
function next() {
|
||||
const f = queue.shift();
|
||||
if (f) {
|
||||
running = true;
|
||||
f(done);
|
||||
}
|
||||
}
|
||||
|
||||
function done() {
|
||||
running = false;
|
||||
process.nextTick(next);
|
||||
}
|
||||
|
||||
queue.push(f);
|
||||
|
||||
if (!running) {
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
||||
function processResult(res) {
|
||||
assert.ok(Array.isArray(res));
|
||||
assert.ok(res.length > 0);
|
||||
|
||||
const types = {};
|
||||
res.forEach((obj) => {
|
||||
types[obj.type] = true;
|
||||
checkers[`check${obj.type}`](obj);
|
||||
});
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
TEST(async function test_sip2sip_for_naptr(done) {
|
||||
function validateResult(res) {
|
||||
const types = processResult(res);
|
||||
assert.ok(
|
||||
types.A && types.NS && types.NAPTR && types.SOA,
|
||||
`Missing record type, found ${Object.keys(types)}`
|
||||
);
|
||||
}
|
||||
|
||||
validateResult(await dnsPromises.resolve('sip2sip.info', 'ANY'));
|
||||
|
||||
const req = dns.resolve(
|
||||
'sip2sip.info',
|
||||
'ANY',
|
||||
common.mustSucceed((ret) => {
|
||||
validateResult(ret);
|
||||
done();
|
||||
}));
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
TEST(async function test_google_for_cname_and_srv(done) {
|
||||
function validateResult(res) {
|
||||
const types = processResult(res);
|
||||
assert.ok(types.SRV);
|
||||
}
|
||||
|
||||
// TODO(kt3k): Temporarily use _caldav._tcp.google.com instead of
|
||||
// _jabber._tcp.google.com, which currently doesn't respond
|
||||
// validateResult(await dnsPromises.resolve('_jabber._tcp.google.com', 'ANY'));
|
||||
validateResult(await dnsPromises.resolve('_caldav._tcp.google.com', 'ANY'));
|
||||
|
||||
|
||||
// TODO(kt3k): Temporarily use _caldav._tcp.google.com instead of
|
||||
// _jabber._tcp.google.com, which currently doesn't respond
|
||||
const req = dns.resolve(
|
||||
// '_jabber._tcp.google.com',
|
||||
'_caldav._tcp.google.com',
|
||||
'ANY',
|
||||
common.mustSucceed((ret) => {
|
||||
validateResult(ret);
|
||||
done();
|
||||
}));
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
TEST(async function test_ptr(done) {
|
||||
function validateResult(res) {
|
||||
const types = processResult(res);
|
||||
assert.ok(types.PTR);
|
||||
}
|
||||
|
||||
validateResult(await dnsPromises.resolve('8.8.8.8.in-addr.arpa', 'ANY'));
|
||||
|
||||
const req = dns.resolve(
|
||||
'8.8.8.8.in-addr.arpa',
|
||||
'ANY',
|
||||
common.mustSucceed((ret) => {
|
||||
validateResult(ret);
|
||||
done();
|
||||
}));
|
||||
|
||||
checkWrap(req);
|
||||
});
|
76
cli/tests/node_compat/test/internet/test-dns-idna2008.js
Normal file
76
cli/tests/node_compat/test/internet/test-dns-idna2008.js
Normal file
|
@ -0,0 +1,76 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
// Verify that non-ASCII hostnames are handled correctly as IDNA 2008.
|
||||
//
|
||||
// * Tests will fail with NXDOMAIN when UTF-8 leaks through to a getaddrinfo()
|
||||
// that doesn't support IDNA at all.
|
||||
//
|
||||
// * "straße.de" will resolve to the wrong address when the resolver supports
|
||||
// only IDNA 2003 (e.g., glibc until 2.28) because it encodes it wrong.
|
||||
|
||||
const { mustCall } = require('../common');
|
||||
const assert = require('assert');
|
||||
const dns = require('dns');
|
||||
const { addresses } = require('../common/internet');
|
||||
|
||||
const fixture = {
|
||||
hostname: 'straße.de',
|
||||
expectedAddress: '81.169.145.78',
|
||||
dnsServer: addresses.DNS4_SERVER,
|
||||
family: 4,
|
||||
};
|
||||
|
||||
// Explicitly use well-behaved DNS servers that are known to be able to resolve
|
||||
// the query (which is a.k.a xn--strae-oqa.de).
|
||||
dns.setServers([fixture.dnsServer]);
|
||||
|
||||
dns.lookup(
|
||||
fixture.hostname,
|
||||
{ family: fixture.family },
|
||||
mustCall((err, address) => {
|
||||
if (err && err.errno === 'ESERVFAIL') {
|
||||
assert.ok(err.message.includes('queryA ESERVFAIL straße.de'));
|
||||
return;
|
||||
}
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(address, fixture.expectedAddress);
|
||||
})
|
||||
);
|
||||
|
||||
dns.promises.lookup(fixture.hostname, { family: fixture.family })
|
||||
.then(({ address }) => {
|
||||
assert.strictEqual(address, fixture.expectedAddress);
|
||||
}, (err) => {
|
||||
if (err && err.errno === 'ESERVFAIL') {
|
||||
assert.ok(err.message.includes('queryA ESERVFAIL straße.de'));
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}).finally(mustCall());
|
||||
|
||||
dns.resolve4(fixture.hostname, mustCall((err, addresses) => {
|
||||
if (err && err.errno === 'ESERVFAIL') {
|
||||
assert.ok(err.message.includes('queryA ESERVFAIL straße.de'));
|
||||
return;
|
||||
}
|
||||
assert.ifError(err);
|
||||
assert.deepStrictEqual(addresses, [fixture.expectedAddress]);
|
||||
}));
|
||||
|
||||
const p = new dns.promises.Resolver().resolve4(fixture.hostname);
|
||||
p.then((addresses) => {
|
||||
assert.deepStrictEqual(addresses, [fixture.expectedAddress]);
|
||||
}, (err) => {
|
||||
if (err && err.errno === 'ESERVFAIL') {
|
||||
assert.ok(err.message.includes('queryA ESERVFAIL straße.de'));
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}).finally(mustCall());
|
257
cli/tests/node_compat/test/internet/test-dns-ipv4.js
Normal file
257
cli/tests/node_compat/test/internet/test-dns-ipv4.js
Normal file
|
@ -0,0 +1,257 @@
|
|||
// 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
|
||||
|
||||
'use strict';
|
||||
|
||||
// TODO: enable remaining tests once functionality is implemented.
|
||||
|
||||
const common = require('../common');
|
||||
const { addresses } = require('../common/internet');
|
||||
const assert = require('assert');
|
||||
const dns = require('dns');
|
||||
const net = require('net');
|
||||
// const util = require('util');
|
||||
const isIPv4 = net.isIPv4;
|
||||
|
||||
const dnsPromises = dns.promises;
|
||||
let running = false;
|
||||
const queue = [];
|
||||
|
||||
function TEST(f) {
|
||||
function next() {
|
||||
const f = queue.shift();
|
||||
if (f) {
|
||||
running = true;
|
||||
console.log(f.name);
|
||||
f(done);
|
||||
}
|
||||
}
|
||||
|
||||
function done() {
|
||||
running = false;
|
||||
process.nextTick(next);
|
||||
}
|
||||
|
||||
queue.push(f);
|
||||
|
||||
if (!running) {
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
||||
function checkWrap(req) {
|
||||
assert.ok(typeof req === 'object');
|
||||
}
|
||||
|
||||
TEST(async function test_resolve4(done) {
|
||||
function validateResult(res) {
|
||||
assert.ok(res.length > 0);
|
||||
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
assert.ok(isIPv4(res[i]));
|
||||
}
|
||||
}
|
||||
|
||||
validateResult(await dnsPromises.resolve4(addresses.INET4_HOST));
|
||||
|
||||
const req = dns.resolve4(
|
||||
addresses.INET4_HOST,
|
||||
common.mustSucceed((ips) => {
|
||||
validateResult(ips);
|
||||
done();
|
||||
}));
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
// TEST(async function test_reverse_ipv4(done) {
|
||||
// function validateResult(res) {
|
||||
// assert.ok(res.length > 0);
|
||||
|
||||
// for (let i = 0; i < res.length; i++) {
|
||||
// assert.ok(res[i]);
|
||||
// assert.ok(typeof res[i] === 'string');
|
||||
// }
|
||||
// }
|
||||
|
||||
// validateResult(await dnsPromises.reverse(addresses.INET4_IP));
|
||||
|
||||
// const req = dns.reverse(
|
||||
// addresses.INET4_IP,
|
||||
// common.mustSucceed((domains) => {
|
||||
// validateResult(domains);
|
||||
// done();
|
||||
// }));
|
||||
|
||||
// checkWrap(req);
|
||||
// });
|
||||
|
||||
TEST(async function test_lookup_ipv4_explicit(done) {
|
||||
function validateResult(res) {
|
||||
assert.ok(net.isIPv4(res.address));
|
||||
assert.strictEqual(res.family, 4);
|
||||
}
|
||||
|
||||
validateResult(await dnsPromises.lookup(addresses.INET4_HOST, 4));
|
||||
|
||||
const req = dns.lookup(
|
||||
addresses.INET4_HOST, 4,
|
||||
common.mustSucceed((ip, family) => {
|
||||
validateResult({ address: ip, family });
|
||||
done();
|
||||
}));
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
TEST(async function test_lookup_ipv4_implicit(done) {
|
||||
function validateResult(res) {
|
||||
assert.ok(net.isIPv4(res.address));
|
||||
assert.strictEqual(res.family, 4);
|
||||
}
|
||||
|
||||
validateResult(await dnsPromises.lookup(addresses.INET4_HOST));
|
||||
|
||||
const req = dns.lookup(
|
||||
addresses.INET4_HOST,
|
||||
common.mustSucceed((ip, family) => {
|
||||
validateResult({ address: ip, family });
|
||||
done();
|
||||
}));
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
TEST(async function test_lookup_ipv4_explicit_object(done) {
|
||||
function validateResult(res) {
|
||||
assert.ok(net.isIPv4(res.address));
|
||||
assert.strictEqual(res.family, 4);
|
||||
}
|
||||
|
||||
validateResult(await dnsPromises.lookup(addresses.INET4_HOST, { family: 4 }));
|
||||
|
||||
const req = dns.lookup(addresses.INET4_HOST, {
|
||||
family: 4
|
||||
}, common.mustSucceed((ip, family) => {
|
||||
validateResult({ address: ip, family });
|
||||
done();
|
||||
}));
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
TEST(async function test_lookup_ipv4_hint_addrconfig(done) {
|
||||
function validateResult(res) {
|
||||
assert.ok(net.isIPv4(res.address));
|
||||
assert.strictEqual(res.family, 4);
|
||||
}
|
||||
|
||||
validateResult(await dnsPromises.lookup(addresses.INET4_HOST, {
|
||||
hints: dns.ADDRCONFIG
|
||||
}));
|
||||
|
||||
const req = dns.lookup(addresses.INET4_HOST, {
|
||||
hints: dns.ADDRCONFIG
|
||||
}, common.mustSucceed((ip, family) => {
|
||||
validateResult({ address: ip, family });
|
||||
done();
|
||||
}));
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
TEST(async function test_lookup_ip_ipv4(done) {
|
||||
function validateResult(res) {
|
||||
assert.strictEqual(res.address, '127.0.0.1');
|
||||
assert.strictEqual(res.family, 4);
|
||||
}
|
||||
|
||||
validateResult(await dnsPromises.lookup('127.0.0.1'));
|
||||
|
||||
const req = dns.lookup('127.0.0.1',
|
||||
common.mustSucceed((ip, family) => {
|
||||
validateResult({ address: ip, family });
|
||||
done();
|
||||
}));
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
TEST(async function test_lookup_localhost_ipv4(done) {
|
||||
function validateResult(res) {
|
||||
assert.strictEqual(res.address, '127.0.0.1');
|
||||
assert.strictEqual(res.family, 4);
|
||||
}
|
||||
|
||||
validateResult(await dnsPromises.lookup('localhost', 4));
|
||||
|
||||
const req = dns.lookup('localhost', 4,
|
||||
common.mustSucceed((ip, family) => {
|
||||
validateResult({ address: ip, family });
|
||||
done();
|
||||
}));
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
TEST(async function test_lookup_all_ipv4(done) {
|
||||
function validateResult(res) {
|
||||
assert.ok(Array.isArray(res));
|
||||
assert.ok(res.length > 0);
|
||||
|
||||
res.forEach((ip) => {
|
||||
assert.ok(isIPv4(ip.address));
|
||||
assert.strictEqual(ip.family, 4);
|
||||
});
|
||||
}
|
||||
|
||||
validateResult(await dnsPromises.lookup(addresses.INET4_HOST, {
|
||||
all: true,
|
||||
family: 4
|
||||
}));
|
||||
|
||||
const req = dns.lookup(
|
||||
addresses.INET4_HOST,
|
||||
{ all: true, family: 4 },
|
||||
common.mustSucceed((ips) => {
|
||||
validateResult(ips);
|
||||
done();
|
||||
})
|
||||
);
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
// TEST(async function test_lookupservice_ip_ipv4(done) {
|
||||
// function validateResult(res) {
|
||||
// assert.strictEqual(typeof res.hostname, 'string');
|
||||
// assert(res.hostname);
|
||||
// assert(['http', 'www', '80'].includes(res.service));
|
||||
// }
|
||||
|
||||
// validateResult(await dnsPromises.lookupService('127.0.0.1', 80));
|
||||
|
||||
// const req = dns.lookupService(
|
||||
// '127.0.0.1', 80,
|
||||
// common.mustSucceed((hostname, service) => {
|
||||
// validateResult({ hostname, service });
|
||||
// done();
|
||||
// })
|
||||
// );
|
||||
|
||||
// checkWrap(req);
|
||||
// });
|
||||
|
||||
// TEST(function test_lookupservice_ip_ipv4_promise(done) {
|
||||
// util.promisify(dns.lookupService)('127.0.0.1', 80)
|
||||
// .then(common.mustCall(({ hostname, service }) => {
|
||||
// assert.strictEqual(typeof hostname, 'string');
|
||||
// assert(hostname.length > 0);
|
||||
// assert(['http', 'www', '80'].includes(service));
|
||||
// done();
|
||||
// }));
|
||||
// });
|
250
cli/tests/node_compat/test/internet/test-dns-ipv6.js
Normal file
250
cli/tests/node_compat/test/internet/test-dns-ipv6.js
Normal file
|
@ -0,0 +1,250 @@
|
|||
// 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
|
||||
|
||||
'use strict';
|
||||
|
||||
// TODO: enable remaining tests once functionality is implemented.
|
||||
|
||||
const common = require('../common');
|
||||
const { addresses } = require('../common/internet');
|
||||
if (!common.hasIPv6)
|
||||
common.skip('this test, no IPv6 support');
|
||||
|
||||
const assert = require('assert');
|
||||
const dns = require('dns');
|
||||
const net = require('net');
|
||||
const dnsPromises = dns.promises;
|
||||
const isIPv6 = net.isIPv6;
|
||||
|
||||
let running = false;
|
||||
const queue = [];
|
||||
|
||||
function TEST(f) {
|
||||
function next() {
|
||||
const f = queue.shift();
|
||||
if (f) {
|
||||
running = true;
|
||||
console.log(f.name);
|
||||
f(done);
|
||||
}
|
||||
}
|
||||
|
||||
function done() {
|
||||
running = false;
|
||||
process.nextTick(next);
|
||||
}
|
||||
|
||||
queue.push(f);
|
||||
|
||||
if (!running) {
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
||||
function checkWrap(req) {
|
||||
assert.ok(typeof req === 'object');
|
||||
}
|
||||
|
||||
TEST(async function test_resolve6(done) {
|
||||
function validateResult(res) {
|
||||
assert.ok(res.length > 0);
|
||||
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
assert.ok(isIPv6(res[i]));
|
||||
}
|
||||
}
|
||||
|
||||
validateResult(await dnsPromises.resolve6(addresses.INET6_HOST));
|
||||
|
||||
const req = dns.resolve6(
|
||||
addresses.INET6_HOST,
|
||||
common.mustSucceed((ips) => {
|
||||
validateResult(ips);
|
||||
done();
|
||||
}));
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
// TEST(async function test_reverse_ipv6(done) {
|
||||
// function validateResult(res) {
|
||||
// assert.ok(res.length > 0);
|
||||
|
||||
// for (let i = 0; i < res.length; i++) {
|
||||
// assert.ok(typeof res[i] === 'string');
|
||||
// }
|
||||
// }
|
||||
|
||||
// validateResult(await dnsPromises.reverse(addresses.INET6_IP));
|
||||
|
||||
// const req = dns.reverse(
|
||||
// addresses.INET6_IP,
|
||||
// common.mustSucceed((domains) => {
|
||||
// validateResult(domains);
|
||||
// done();
|
||||
// }));
|
||||
|
||||
// checkWrap(req);
|
||||
// });
|
||||
|
||||
TEST(async function test_lookup_ipv6_explicit(done) {
|
||||
function validateResult(res) {
|
||||
assert.ok(isIPv6(res.address));
|
||||
assert.strictEqual(res.family, 6);
|
||||
}
|
||||
|
||||
validateResult(await dnsPromises.lookup(addresses.INET6_HOST, 6));
|
||||
|
||||
const req = dns.lookup(
|
||||
addresses.INET6_HOST,
|
||||
6,
|
||||
common.mustSucceed((ip, family) => {
|
||||
validateResult({ address: ip, family });
|
||||
done();
|
||||
}));
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
// This ends up just being too problematic to test
|
||||
// TEST(function test_lookup_ipv6_implicit(done) {
|
||||
// var req = dns.lookup(addresses.INET6_HOST, function(err, ip, family) {
|
||||
// assert.ifError(err);
|
||||
// assert.ok(net.isIPv6(ip));
|
||||
// assert.strictEqual(family, 6);
|
||||
|
||||
// done();
|
||||
// });
|
||||
|
||||
// checkWrap(req);
|
||||
// });
|
||||
|
||||
TEST(async function test_lookup_ipv6_explicit_object(done) {
|
||||
function validateResult(res) {
|
||||
assert.ok(isIPv6(res.address));
|
||||
assert.strictEqual(res.family, 6);
|
||||
}
|
||||
|
||||
validateResult(await dnsPromises.lookup(addresses.INET6_HOST, { family: 6 }));
|
||||
|
||||
const req = dns.lookup(addresses.INET6_HOST, {
|
||||
family: 6
|
||||
}, common.mustSucceed((ip, family) => {
|
||||
validateResult({ address: ip, family });
|
||||
done();
|
||||
}));
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
TEST(function test_lookup_ipv6_hint(done) {
|
||||
const req = dns.lookup(addresses.INET6_HOST, {
|
||||
family: 6,
|
||||
hints: dns.V4MAPPED
|
||||
}, common.mustCall((err, ip, family) => {
|
||||
if (err) {
|
||||
// FreeBSD does not support V4MAPPED
|
||||
if (common.isFreeBSD) {
|
||||
assert(err instanceof Error);
|
||||
assert.strictEqual(err.code, 'EAI_BADFLAGS');
|
||||
assert.strictEqual(err.hostname, addresses.INET_HOST);
|
||||
assert.match(err.message, /getaddrinfo EAI_BADFLAGS/);
|
||||
done();
|
||||
return;
|
||||
}
|
||||
|
||||
assert.ifError(err);
|
||||
}
|
||||
|
||||
assert.ok(isIPv6(ip));
|
||||
assert.strictEqual(family, 6);
|
||||
|
||||
done();
|
||||
}));
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
TEST(async function test_lookup_ip_ipv6(done) {
|
||||
function validateResult(res) {
|
||||
assert.ok(isIPv6(res.address));
|
||||
assert.strictEqual(res.family, 6);
|
||||
}
|
||||
|
||||
validateResult(await dnsPromises.lookup('::1'));
|
||||
|
||||
const req = dns.lookup(
|
||||
'::1',
|
||||
common.mustSucceed((ip, family) => {
|
||||
validateResult({ address: ip, family });
|
||||
done();
|
||||
}));
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
TEST(async function test_lookup_all_ipv6(done) {
|
||||
function validateResult(res) {
|
||||
assert.ok(Array.isArray(res));
|
||||
assert.ok(res.length > 0);
|
||||
|
||||
res.forEach((ip) => {
|
||||
assert.ok(isIPv6(ip.address),
|
||||
`Invalid IPv6: ${ip.address.toString()}`);
|
||||
assert.strictEqual(ip.family, 6);
|
||||
});
|
||||
}
|
||||
|
||||
validateResult(await dnsPromises.lookup(addresses.INET6_HOST, {
|
||||
all: true,
|
||||
family: 6
|
||||
}));
|
||||
|
||||
const req = dns.lookup(
|
||||
addresses.INET6_HOST,
|
||||
{ all: true, family: 6 },
|
||||
common.mustSucceed((ips) => {
|
||||
validateResult(ips);
|
||||
done();
|
||||
})
|
||||
);
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
// TEST(function test_lookupservice_ip_ipv6(done) {
|
||||
// const req = dns.lookupService(
|
||||
// '::1', 80,
|
||||
// common.mustCall((err, host, service) => {
|
||||
// if (err) {
|
||||
// // Not skipping the test, rather checking an alternative result,
|
||||
// // i.e. that ::1 may not be configured (e.g. in /etc/hosts)
|
||||
// assert.strictEqual(err.code, 'ENOTFOUND');
|
||||
// return done();
|
||||
// }
|
||||
// assert.strictEqual(typeof host, 'string');
|
||||
// assert(host);
|
||||
// assert(['http', 'www', '80'].includes(service));
|
||||
// done();
|
||||
// })
|
||||
// );
|
||||
|
||||
// checkWrap(req);
|
||||
// });
|
||||
|
||||
// Disabled because it appears to be not working on Linux.
|
||||
// TEST(function test_lookup_localhost_ipv6(done) {
|
||||
// var req = dns.lookup('localhost', 6, function(err, ip, family) {
|
||||
// assert.ifError(err);
|
||||
// assert.ok(net.isIPv6(ip));
|
||||
// assert.strictEqual(family, 6);
|
||||
//
|
||||
// done();
|
||||
// });
|
||||
//
|
||||
// checkWrap(req);
|
||||
// });
|
61
cli/tests/node_compat/test/internet/test-dns-lookup.js
Normal file
61
cli/tests/node_compat/test/internet/test-dns-lookup.js
Normal file
|
@ -0,0 +1,61 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const common = require('../common');
|
||||
const dns = require('dns');
|
||||
const dnsPromises = dns.promises;
|
||||
const { addresses } = require('../common/internet');
|
||||
const assert = require('assert');
|
||||
|
||||
assert.rejects(
|
||||
dnsPromises.lookup(addresses.NOT_FOUND, {
|
||||
hints: 0,
|
||||
family: 0,
|
||||
all: false
|
||||
}),
|
||||
{
|
||||
code: 'ENOTFOUND',
|
||||
message: `getaddrinfo ENOTFOUND ${addresses.NOT_FOUND}`
|
||||
}
|
||||
);
|
||||
|
||||
assert.rejects(
|
||||
dnsPromises.lookup(addresses.NOT_FOUND, {
|
||||
hints: 0,
|
||||
family: 0,
|
||||
all: true
|
||||
}),
|
||||
{
|
||||
code: 'ENOTFOUND',
|
||||
message: `getaddrinfo ENOTFOUND ${addresses.NOT_FOUND}`
|
||||
}
|
||||
);
|
||||
|
||||
dns.lookup(addresses.NOT_FOUND, {
|
||||
hints: 0,
|
||||
family: 0,
|
||||
all: true
|
||||
}, common.mustCall((error) => {
|
||||
assert.strictEqual(error.code, 'ENOTFOUND');
|
||||
assert.strictEqual(
|
||||
error.message,
|
||||
`getaddrinfo ENOTFOUND ${addresses.NOT_FOUND}`
|
||||
);
|
||||
assert.strictEqual(error.syscall, 'getaddrinfo');
|
||||
assert.strictEqual(error.hostname, addresses.NOT_FOUND);
|
||||
}));
|
||||
|
||||
assert.throws(
|
||||
() => dnsPromises.lookup(addresses.NOT_FOUND, {
|
||||
family: 'ipv4',
|
||||
all: 'all'
|
||||
}),
|
||||
{ code: 'ERR_INVALID_ARG_VALUE' }
|
||||
);
|
|
@ -0,0 +1,49 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
const dnsPromises = require('dns').promises;
|
||||
|
||||
// Error when rrtype is invalid.
|
||||
{
|
||||
const rrtype = 'DUMMY';
|
||||
assert.throws(
|
||||
() => dnsPromises.resolve('example.org', rrtype),
|
||||
{
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
name: 'TypeError',
|
||||
message: `The argument 'rrtype' is invalid. Received '${rrtype}'`
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Error when rrtype is a number.
|
||||
{
|
||||
const rrtype = 0;
|
||||
assert.throws(
|
||||
() => dnsPromises.resolve('example.org', rrtype),
|
||||
{
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
name: 'TypeError',
|
||||
message: 'The "rrtype" argument must be of type string. ' +
|
||||
`Received type ${typeof rrtype} (${rrtype})`
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Setting rrtype to undefined should work like resolve4.
|
||||
{
|
||||
(async function() {
|
||||
const rrtype = undefined;
|
||||
const result = await dnsPromises.resolve('example.org', rrtype);
|
||||
assert.ok(result !== undefined);
|
||||
assert.ok(result.length > 0);
|
||||
})().then(common.mustCall());
|
||||
}
|
35
cli/tests/node_compat/test/internet/test-dns-regress-6244.js
Normal file
35
cli/tests/node_compat/test/internet/test-dns-regress-6244.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// 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';
|
||||
const common = require('../common');
|
||||
const dns = require('dns');
|
||||
|
||||
// Should not segfault.
|
||||
// Ref: https://github.com/nodejs/node-v0.x-archive/issues/6244
|
||||
dns.resolve4('127.0.0.1', common.mustCall());
|
|
@ -0,0 +1,25 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
// We don't care about `err` in the callback function of `dns.resolve4`. We just
|
||||
// want to test whether `dns.setServers` that is run after `resolve4` will cause
|
||||
// a crash or not. If it doesn't crash, the test succeeded.
|
||||
|
||||
const common = require('../common');
|
||||
const { addresses } = require('../common/internet');
|
||||
const dns = require('dns');
|
||||
|
||||
dns.resolve4(
|
||||
addresses.INET4_HOST,
|
||||
common.mustCall(function(/* err, nameServers */) {
|
||||
dns.setServers([ addresses.DNS4_SERVER ]);
|
||||
}));
|
||||
|
||||
// Test https://github.com/nodejs/node/issues/14734
|
||||
dns.resolve4(addresses.INET4_HOST, common.mustCall());
|
761
cli/tests/node_compat/test/internet/test-dns.js
Normal file
761
cli/tests/node_compat/test/internet/test-dns.js
Normal file
|
@ -0,0 +1,761 @@
|
|||
// 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
|
||||
|
||||
// Flags: --expose-internals
|
||||
// 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';
|
||||
|
||||
// TODO(cmorten): enable remaining tests once functionality is implemented.
|
||||
|
||||
const common = require('../common');
|
||||
const { addresses } = require('../common/internet');
|
||||
const { internalBinding } = require('internal/test/binding');
|
||||
// const { getSystemErrorName } = require('util');
|
||||
const assert = require('assert');
|
||||
const dns = require('dns');
|
||||
const net = require('net');
|
||||
const isIPv4 = net.isIPv4;
|
||||
const isIPv6 = net.isIPv6;
|
||||
const util = require('util');
|
||||
const dnsPromises = dns.promises;
|
||||
|
||||
let expected = 0;
|
||||
let completed = 0;
|
||||
let running = false;
|
||||
const queue = [];
|
||||
|
||||
|
||||
function TEST(f) {
|
||||
function next() {
|
||||
const f = queue.shift();
|
||||
if (f) {
|
||||
running = true;
|
||||
console.log(f.name);
|
||||
f(done);
|
||||
}
|
||||
}
|
||||
|
||||
function done() {
|
||||
running = false;
|
||||
completed++;
|
||||
process.nextTick(next);
|
||||
}
|
||||
|
||||
expected++;
|
||||
queue.push(f);
|
||||
|
||||
if (!running) {
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function checkWrap(req) {
|
||||
assert.strictEqual(typeof req, 'object');
|
||||
}
|
||||
|
||||
|
||||
// TEST(function test_reverse_bogus(done) {
|
||||
// dnsPromises.reverse('bogus ip')
|
||||
// .then(common.mustNotCall())
|
||||
// .catch(common.mustCall((err) => {
|
||||
// assert.strictEqual(err.code, 'EINVAL');
|
||||
// assert.strictEqual(getSystemErrorName(err.errno), 'EINVAL');
|
||||
// }));
|
||||
|
||||
// assert.throws(() => {
|
||||
// dns.reverse('bogus ip', common.mustNotCall());
|
||||
// }, /^Error: getHostByAddr EINVAL bogus ip$/);
|
||||
// done();
|
||||
// });
|
||||
|
||||
// TEST(async function test_resolve4_ttl(done) {
|
||||
// function validateResult(result) {
|
||||
// assert.ok(result.length > 0);
|
||||
|
||||
// for (const item of result) {
|
||||
// assert.strictEqual(typeof item, 'object');
|
||||
// assert.strictEqual(typeof item.ttl, 'number');
|
||||
// assert.strictEqual(typeof item.address, 'string');
|
||||
// assert.ok(item.ttl >= 0);
|
||||
// assert.ok(isIPv4(item.address));
|
||||
// }
|
||||
// }
|
||||
|
||||
// validateResult(await dnsPromises.resolve4(addresses.INET4_HOST, {
|
||||
// ttl: true
|
||||
// }));
|
||||
|
||||
// const req = dns.resolve4(addresses.INET4_HOST, {
|
||||
// ttl: true
|
||||
// }, function(err, result) {
|
||||
// assert.ifError(err);
|
||||
// validateResult(result);
|
||||
// done();
|
||||
// });
|
||||
|
||||
// checkWrap(req);
|
||||
// });
|
||||
|
||||
// TEST(async function test_resolve6_ttl(done) {
|
||||
// function validateResult(result) {
|
||||
// assert.ok(result.length > 0);
|
||||
|
||||
// for (const item of result) {
|
||||
// assert.strictEqual(typeof item, 'object');
|
||||
// assert.strictEqual(typeof item.ttl, 'number');
|
||||
// assert.strictEqual(typeof item.address, 'string');
|
||||
// assert.ok(item.ttl >= 0);
|
||||
// assert.ok(isIPv6(item.address));
|
||||
// }
|
||||
// }
|
||||
|
||||
// validateResult(await dnsPromises.resolve6(addresses.INET6_HOST, {
|
||||
// ttl: true
|
||||
// }));
|
||||
|
||||
// const req = dns.resolve6(addresses.INET6_HOST, {
|
||||
// ttl: true
|
||||
// }, function(err, result) {
|
||||
// assert.ifError(err);
|
||||
// validateResult(result);
|
||||
// done();
|
||||
// });
|
||||
|
||||
// checkWrap(req);
|
||||
// });
|
||||
|
||||
TEST(async function test_resolveMx(done) {
|
||||
function validateResult(result) {
|
||||
assert.ok(result.length > 0);
|
||||
|
||||
for (const item of result) {
|
||||
assert.strictEqual(typeof item, 'object');
|
||||
assert.ok(item.exchange);
|
||||
assert.strictEqual(typeof item.exchange, 'string');
|
||||
assert.strictEqual(typeof item.priority, 'number');
|
||||
}
|
||||
}
|
||||
|
||||
validateResult(await dnsPromises.resolveMx(addresses.MX_HOST));
|
||||
|
||||
const req = dns.resolveMx(addresses.MX_HOST, function(err, result) {
|
||||
assert.ifError(err);
|
||||
validateResult(result);
|
||||
done();
|
||||
});
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
TEST(function test_resolveMx_failure(done) {
|
||||
dnsPromises.resolveMx(addresses.NOT_FOUND)
|
||||
.then(common.mustNotCall())
|
||||
.catch(common.mustCall((err) => {
|
||||
assert.strictEqual(err.code, 'ENOTFOUND');
|
||||
}));
|
||||
|
||||
const req = dns.resolveMx(addresses.NOT_FOUND, function(err, result) {
|
||||
assert.ok(err instanceof Error);
|
||||
assert.strictEqual(err.code, 'ENOTFOUND');
|
||||
|
||||
assert.strictEqual(result, undefined);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
TEST(async function test_resolveNs(done) {
|
||||
function validateResult(result) {
|
||||
assert.ok(result.length > 0);
|
||||
|
||||
for (const item of result) {
|
||||
assert.ok(item);
|
||||
assert.strictEqual(typeof item, 'string');
|
||||
}
|
||||
}
|
||||
|
||||
validateResult(await dnsPromises.resolveNs(addresses.NS_HOST));
|
||||
|
||||
const req = dns.resolveNs(addresses.NS_HOST, function(err, names) {
|
||||
assert.ifError(err);
|
||||
validateResult(names);
|
||||
done();
|
||||
});
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
TEST(function test_resolveNs_failure(done) {
|
||||
dnsPromises.resolveNs(addresses.NOT_FOUND)
|
||||
.then(common.mustNotCall())
|
||||
.catch(common.mustCall((err) => {
|
||||
assert.strictEqual(err.code, 'ENOTFOUND');
|
||||
}));
|
||||
|
||||
const req = dns.resolveNs(addresses.NOT_FOUND, function(err, result) {
|
||||
assert.ok(err instanceof Error);
|
||||
assert.strictEqual(err.code, 'ENOTFOUND');
|
||||
|
||||
assert.strictEqual(result, undefined);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
TEST(async function test_resolveSrv(done) {
|
||||
function validateResult(result) {
|
||||
assert.ok(result.length > 0);
|
||||
|
||||
for (const item of result) {
|
||||
assert.strictEqual(typeof item, 'object');
|
||||
assert.ok(item.name);
|
||||
assert.strictEqual(typeof item.name, 'string');
|
||||
assert.strictEqual(typeof item.port, 'number');
|
||||
assert.strictEqual(typeof item.priority, 'number');
|
||||
assert.strictEqual(typeof item.weight, 'number');
|
||||
}
|
||||
}
|
||||
|
||||
validateResult(await dnsPromises.resolveSrv(addresses.SRV_HOST));
|
||||
|
||||
const req = dns.resolveSrv(addresses.SRV_HOST, function(err, result) {
|
||||
assert.ifError(err);
|
||||
validateResult(result);
|
||||
done();
|
||||
});
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
TEST(function test_resolveSrv_failure(done) {
|
||||
dnsPromises.resolveSrv(addresses.NOT_FOUND)
|
||||
.then(common.mustNotCall())
|
||||
.catch(common.mustCall((err) => {
|
||||
assert.strictEqual(err.code, 'ENOTFOUND');
|
||||
}));
|
||||
|
||||
const req = dns.resolveSrv(addresses.NOT_FOUND, function(err, result) {
|
||||
assert.ok(err instanceof Error);
|
||||
assert.strictEqual(err.code, 'ENOTFOUND');
|
||||
|
||||
assert.strictEqual(result, undefined);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
TEST(async function test_resolvePtr(done) {
|
||||
function validateResult(result) {
|
||||
assert.ok(result.length > 0);
|
||||
|
||||
for (const item of result) {
|
||||
assert.ok(item);
|
||||
assert.strictEqual(typeof item, 'string');
|
||||
}
|
||||
}
|
||||
|
||||
validateResult(await dnsPromises.resolvePtr(addresses.PTR_HOST));
|
||||
|
||||
const req = dns.resolvePtr(addresses.PTR_HOST, function(err, result) {
|
||||
assert.ifError(err);
|
||||
validateResult(result);
|
||||
done();
|
||||
});
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
TEST(function test_resolvePtr_failure(done) {
|
||||
dnsPromises.resolvePtr(addresses.NOT_FOUND)
|
||||
.then(common.mustNotCall())
|
||||
.catch(common.mustCall((err) => {
|
||||
assert.strictEqual(err.code, 'ENOTFOUND');
|
||||
}));
|
||||
|
||||
const req = dns.resolvePtr(addresses.NOT_FOUND, function(err, result) {
|
||||
assert.ok(err instanceof Error);
|
||||
assert.strictEqual(err.code, 'ENOTFOUND');
|
||||
|
||||
assert.strictEqual(result, undefined);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
TEST(async function test_resolveNaptr(done) {
|
||||
function validateResult(result) {
|
||||
assert.ok(result.length > 0);
|
||||
|
||||
for (const item of result) {
|
||||
assert.strictEqual(typeof item, 'object');
|
||||
assert.strictEqual(typeof item.flags, 'string');
|
||||
assert.strictEqual(typeof item.service, 'string');
|
||||
assert.strictEqual(typeof item.regexp, 'string');
|
||||
assert.strictEqual(typeof item.replacement, 'string');
|
||||
assert.strictEqual(typeof item.order, 'number');
|
||||
assert.strictEqual(typeof item.preference, 'number');
|
||||
}
|
||||
}
|
||||
|
||||
validateResult(await dnsPromises.resolveNaptr(addresses.NAPTR_HOST));
|
||||
|
||||
const req = dns.resolveNaptr(addresses.NAPTR_HOST, function(err, result) {
|
||||
assert.ifError(err);
|
||||
validateResult(result);
|
||||
done();
|
||||
});
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
TEST(function test_resolveNaptr_failure(done) {
|
||||
dnsPromises.resolveNaptr(addresses.NOT_FOUND)
|
||||
.then(common.mustNotCall())
|
||||
.catch(common.mustCall((err) => {
|
||||
assert.strictEqual(err.code, 'ENOTFOUND');
|
||||
}));
|
||||
|
||||
const req = dns.resolveNaptr(addresses.NOT_FOUND, function(err, result) {
|
||||
assert.ok(err instanceof Error);
|
||||
assert.strictEqual(err.code, 'ENOTFOUND');
|
||||
|
||||
assert.strictEqual(result, undefined);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
TEST(async function test_resolveSoa(done) {
|
||||
function validateResult(result) {
|
||||
assert.strictEqual(typeof result, 'object');
|
||||
assert.strictEqual(typeof result.nsname, 'string');
|
||||
assert.ok(result.nsname.length > 0);
|
||||
assert.strictEqual(typeof result.hostmaster, 'string');
|
||||
assert.ok(result.hostmaster.length > 0);
|
||||
assert.strictEqual(typeof result.serial, 'number');
|
||||
assert.ok((result.serial > 0) && (result.serial < 4294967295));
|
||||
assert.strictEqual(typeof result.refresh, 'number');
|
||||
assert.ok((result.refresh > 0) && (result.refresh < 2147483647));
|
||||
assert.strictEqual(typeof result.retry, 'number');
|
||||
assert.ok((result.retry > 0) && (result.retry < 2147483647));
|
||||
assert.strictEqual(typeof result.expire, 'number');
|
||||
assert.ok((result.expire > 0) && (result.expire < 2147483647));
|
||||
assert.strictEqual(typeof result.minttl, 'number');
|
||||
assert.ok((result.minttl >= 0) && (result.minttl < 2147483647));
|
||||
}
|
||||
|
||||
validateResult(await dnsPromises.resolveSoa(addresses.SOA_HOST));
|
||||
|
||||
const req = dns.resolveSoa(addresses.SOA_HOST, function(err, result) {
|
||||
assert.ifError(err);
|
||||
validateResult(result);
|
||||
done();
|
||||
});
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
TEST(function test_resolveSoa_failure(done) {
|
||||
dnsPromises.resolveSoa(addresses.NOT_FOUND)
|
||||
.then(common.mustNotCall())
|
||||
.catch(common.mustCall((err) => {
|
||||
assert.strictEqual(err.code, 'ENOTFOUND');
|
||||
}));
|
||||
|
||||
const req = dns.resolveSoa(addresses.NOT_FOUND, function(err, result) {
|
||||
assert.ok(err instanceof Error);
|
||||
assert.strictEqual(err.code, 'ENOTFOUND');
|
||||
|
||||
assert.strictEqual(result, undefined);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
TEST(async function test_resolveCaa(done) {
|
||||
function validateResult(result) {
|
||||
assert.ok(Array.isArray(result),
|
||||
`expected array, got ${util.inspect(result)}`);
|
||||
assert.strictEqual(result.length, 1);
|
||||
assert.strictEqual(typeof result[0].critical, 'number');
|
||||
assert.strictEqual(result[0].critical, 0);
|
||||
assert.strictEqual(result[0].issue, 'pki.goog');
|
||||
}
|
||||
|
||||
validateResult(await dnsPromises.resolveCaa(addresses.CAA_HOST));
|
||||
|
||||
const req = dns.resolveCaa(addresses.CAA_HOST, function(err, records) {
|
||||
assert.ifError(err);
|
||||
validateResult(records);
|
||||
done();
|
||||
});
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
TEST(function test_resolveCaa_failure(done) {
|
||||
dnsPromises.resolveTxt(addresses.NOT_FOUND)
|
||||
.then(common.mustNotCall())
|
||||
.catch(common.mustCall((err) => {
|
||||
assert.strictEqual(err.code, 'ENOTFOUND');
|
||||
}));
|
||||
|
||||
const req = dns.resolveCaa(addresses.NOT_FOUND, function(err, result) {
|
||||
assert.ok(err instanceof Error);
|
||||
assert.strictEqual(err.code, 'ENOTFOUND');
|
||||
|
||||
assert.strictEqual(result, undefined);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
TEST(async function test_resolveCname(done) {
|
||||
function validateResult(result) {
|
||||
assert.ok(result.length > 0);
|
||||
|
||||
for (const item of result) {
|
||||
assert.ok(item);
|
||||
assert.strictEqual(typeof item, 'string');
|
||||
}
|
||||
}
|
||||
|
||||
validateResult(await dnsPromises.resolveCname(addresses.CNAME_HOST));
|
||||
|
||||
const req = dns.resolveCname(addresses.CNAME_HOST, function(err, names) {
|
||||
assert.ifError(err);
|
||||
validateResult(names);
|
||||
done();
|
||||
});
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
TEST(function test_resolveCname_failure(done) {
|
||||
dnsPromises.resolveCname(addresses.NOT_FOUND)
|
||||
.then(common.mustNotCall())
|
||||
.catch(common.mustCall((err) => {
|
||||
assert.strictEqual(err.code, 'ENOTFOUND');
|
||||
}));
|
||||
|
||||
const req = dns.resolveCname(addresses.NOT_FOUND, function(err, result) {
|
||||
assert.ok(err instanceof Error);
|
||||
assert.strictEqual(err.code, 'ENOTFOUND');
|
||||
|
||||
assert.strictEqual(result, undefined);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
|
||||
TEST(async function test_resolveTxt(done) {
|
||||
function validateResult(result) {
|
||||
assert.ok(Array.isArray(result[0]));
|
||||
assert.strictEqual(result.length, 1);
|
||||
assert(result[0][0].startsWith('v=spf1'));
|
||||
}
|
||||
|
||||
validateResult(await dnsPromises.resolveTxt(addresses.TXT_HOST));
|
||||
|
||||
const req = dns.resolveTxt(addresses.TXT_HOST, function(err, records) {
|
||||
assert.ifError(err);
|
||||
validateResult(records);
|
||||
done();
|
||||
});
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
TEST(function test_resolveTxt_failure(done) {
|
||||
dnsPromises.resolveTxt(addresses.NOT_FOUND)
|
||||
.then(common.mustNotCall())
|
||||
.catch(common.mustCall((err) => {
|
||||
assert.strictEqual(err.code, 'ENOTFOUND');
|
||||
}));
|
||||
|
||||
const req = dns.resolveTxt(addresses.NOT_FOUND, function(err, result) {
|
||||
assert.ok(err instanceof Error);
|
||||
assert.strictEqual(err.code, 'ENOTFOUND');
|
||||
|
||||
assert.strictEqual(result, undefined);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
|
||||
TEST(function test_lookup_failure(done) {
|
||||
dnsPromises.lookup(addresses.NOT_FOUND, 4)
|
||||
.then(common.mustNotCall())
|
||||
.catch(common.expectsError({ code: dns.NOTFOUND }));
|
||||
|
||||
const req = dns.lookup(addresses.NOT_FOUND, 4, (err) => {
|
||||
assert.ok(err instanceof Error);
|
||||
assert.strictEqual(err.code, dns.NOTFOUND);
|
||||
assert.strictEqual(err.code, 'ENOTFOUND');
|
||||
assert.doesNotMatch(err.message, /ENOENT/);
|
||||
assert.ok(err.message.includes(addresses.NOT_FOUND));
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
|
||||
TEST(async function test_lookup_ip_all(done) {
|
||||
function validateResult(result) {
|
||||
assert.ok(Array.isArray(result));
|
||||
assert.ok(result.length > 0);
|
||||
assert.strictEqual(result[0].address, '127.0.0.1');
|
||||
assert.strictEqual(result[0].family, 4);
|
||||
}
|
||||
|
||||
validateResult(await dnsPromises.lookup('127.0.0.1', { all: true }));
|
||||
|
||||
const req = dns.lookup(
|
||||
'127.0.0.1',
|
||||
{ all: true },
|
||||
function(err, ips, family) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(family, undefined);
|
||||
validateResult(ips);
|
||||
done();
|
||||
}
|
||||
);
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
|
||||
TEST(function test_lookup_ip_all_promise(done) {
|
||||
const req = util.promisify(dns.lookup)('127.0.0.1', { all: true })
|
||||
.then(function(ips) {
|
||||
assert.ok(Array.isArray(ips));
|
||||
assert.ok(ips.length > 0);
|
||||
assert.strictEqual(ips[0].address, '127.0.0.1');
|
||||
assert.strictEqual(ips[0].family, 4);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
|
||||
TEST(function test_lookup_ip_promise(done) {
|
||||
util.promisify(dns.lookup)('127.0.0.1')
|
||||
.then(function({ address, family }) {
|
||||
assert.strictEqual(address, '127.0.0.1');
|
||||
assert.strictEqual(family, 4);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
TEST(async function test_lookup_null_all(done) {
|
||||
assert.deepStrictEqual(await dnsPromises.lookup(null, { all: true }), []);
|
||||
|
||||
const req = dns.lookup(null, { all: true }, (err, ips) => {
|
||||
assert.ifError(err);
|
||||
assert.ok(Array.isArray(ips));
|
||||
assert.strictEqual(ips.length, 0);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
|
||||
TEST(async function test_lookup_all_mixed(done) {
|
||||
function validateResult(result) {
|
||||
assert.ok(Array.isArray(result));
|
||||
assert.ok(result.length > 0);
|
||||
|
||||
result.forEach(function(ip) {
|
||||
if (isIPv4(ip.address))
|
||||
assert.strictEqual(ip.family, 4);
|
||||
else if (isIPv6(ip.address))
|
||||
assert.strictEqual(ip.family, 6);
|
||||
else
|
||||
assert.fail('unexpected IP address');
|
||||
});
|
||||
}
|
||||
|
||||
validateResult(await dnsPromises.lookup(addresses.INET_HOST, { all: true }));
|
||||
|
||||
const req = dns.lookup(addresses.INET_HOST, {
|
||||
all: true
|
||||
}, function(err, ips) {
|
||||
assert.ifError(err);
|
||||
validateResult(ips);
|
||||
done();
|
||||
});
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
|
||||
// TEST(function test_lookupservice_invalid(done) {
|
||||
// dnsPromises.lookupService('1.2.3.4', 80)
|
||||
// .then(common.mustNotCall())
|
||||
// .catch(common.expectsError({ code: 'ENOTFOUND' }));
|
||||
|
||||
// const req = dns.lookupService('1.2.3.4', 80, (err) => {
|
||||
// assert(err instanceof Error);
|
||||
// assert.strictEqual(err.code, 'ENOTFOUND');
|
||||
// assert.match(err.message, /1\.2\.3\.4/);
|
||||
|
||||
// done();
|
||||
// });
|
||||
|
||||
// checkWrap(req);
|
||||
// });
|
||||
|
||||
|
||||
// TEST(function test_reverse_failure(done) {
|
||||
// dnsPromises.reverse('203.0.113.0')
|
||||
// .then(common.mustNotCall())
|
||||
// .catch(common.expectsError({
|
||||
// code: 'ENOTFOUND',
|
||||
// hostname: '203.0.113.0'
|
||||
// }));
|
||||
|
||||
// // 203.0.113.0/24 are addresses reserved for (RFC) documentation use only
|
||||
// const req = dns.reverse('203.0.113.0', function(err) {
|
||||
// assert(err instanceof Error);
|
||||
// assert.strictEqual(err.code, 'ENOTFOUND'); // Silly error code...
|
||||
// assert.strictEqual(err.hostname, '203.0.113.0');
|
||||
// assert.match(err.message, /203\.0\.113\.0/);
|
||||
|
||||
// done();
|
||||
// });
|
||||
|
||||
// checkWrap(req);
|
||||
// });
|
||||
|
||||
|
||||
TEST(function test_lookup_failure(done) {
|
||||
dnsPromises.lookup(addresses.NOT_FOUND)
|
||||
.then(common.mustNotCall())
|
||||
.catch(common.expectsError({
|
||||
code: 'ENOTFOUND',
|
||||
hostname: addresses.NOT_FOUND
|
||||
}));
|
||||
|
||||
const req = dns.lookup(addresses.NOT_FOUND, (err) => {
|
||||
assert(err instanceof Error);
|
||||
assert.strictEqual(err.code, 'ENOTFOUND'); // Silly error code...
|
||||
assert.strictEqual(err.hostname, addresses.NOT_FOUND);
|
||||
assert.ok(err.message.includes(addresses.NOT_FOUND));
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
|
||||
TEST(function test_resolve_failure(done) {
|
||||
const req = dns.resolve4(addresses.NOT_FOUND, (err) => {
|
||||
assert(err instanceof Error);
|
||||
|
||||
switch (err.code) {
|
||||
case 'ENOTFOUND':
|
||||
case 'ESERVFAIL':
|
||||
break;
|
||||
default:
|
||||
assert.strictEqual(err.code, 'ENOTFOUND'); // Silly error code...
|
||||
break;
|
||||
}
|
||||
|
||||
assert.strictEqual(err.hostname, addresses.NOT_FOUND);
|
||||
assert.ok(err.message.includes(addresses.NOT_FOUND));
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
|
||||
let getaddrinfoCallbackCalled = false;
|
||||
|
||||
console.log(`looking up ${addresses.INET4_HOST}..`);
|
||||
|
||||
const cares = internalBinding('cares_wrap');
|
||||
const req = new cares.GetAddrInfoReqWrap();
|
||||
cares.getaddrinfo(req, addresses.INET4_HOST, 4,
|
||||
/* hints */ 0, /* verbatim */ true);
|
||||
|
||||
req.oncomplete = function(err, domains) {
|
||||
assert.strictEqual(err, 0);
|
||||
console.log(`${addresses.INET4_HOST} = ${domains}`);
|
||||
assert.ok(Array.isArray(domains));
|
||||
assert.ok(domains.length >= 1);
|
||||
assert.strictEqual(typeof domains[0], 'string');
|
||||
getaddrinfoCallbackCalled = true;
|
||||
};
|
||||
|
||||
process.on('exit', function() {
|
||||
console.log(`${completed} tests completed`);
|
||||
assert.strictEqual(running, false);
|
||||
assert.strictEqual(completed, expected);
|
||||
assert.ok(getaddrinfoCallbackCalled);
|
||||
});
|
||||
|
||||
// Should not throw.
|
||||
dns.lookup(addresses.INET6_HOST, 6, common.mustCall());
|
||||
dns.lookup(addresses.INET_HOST, {}, common.mustCall());
|
||||
// dns.lookupService('0.0.0.0', '0', common.mustCall());
|
||||
// dns.lookupService('0.0.0.0', 0, common.mustCall());
|
||||
(async function() {
|
||||
await dnsPromises.lookup(addresses.INET6_HOST, 6);
|
||||
await dnsPromises.lookup(addresses.INET_HOST, {});
|
||||
})().then(common.mustCall());
|
244
cli/tests/node_compat/test/parallel/test-assert-async.js
Normal file
244
cli/tests/node_compat/test/parallel/test-assert-async.js
Normal file
|
@ -0,0 +1,244 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
// Run all tests in parallel and check their outcome at the end.
|
||||
const promises = [];
|
||||
|
||||
// Thenable object without `catch` method,
|
||||
// shouldn't be considered as a valid Thenable
|
||||
const invalidThenable = {
|
||||
then: (fulfill, reject) => {
|
||||
fulfill();
|
||||
},
|
||||
};
|
||||
|
||||
// Function that returns a Thenable function,
|
||||
// a function with `catch` and `then` methods attached,
|
||||
// shouldn't be considered as a valid Thenable.
|
||||
const invalidThenableFunc = () => {
|
||||
function f() {}
|
||||
|
||||
f.then = (fulfill, reject) => {
|
||||
fulfill();
|
||||
};
|
||||
f.catch = () => {};
|
||||
|
||||
return f;
|
||||
};
|
||||
|
||||
// Test assert.rejects() and assert.doesNotReject() by checking their
|
||||
// expected output and by verifying that they do not work sync
|
||||
|
||||
// Check `assert.rejects`.
|
||||
{
|
||||
const rejectingFn = async () => assert.fail();
|
||||
const errObj = {
|
||||
code: 'ERR_ASSERTION',
|
||||
name: 'AssertionError',
|
||||
message: 'Failed'
|
||||
};
|
||||
|
||||
// `assert.rejects` accepts a function or a promise
|
||||
// or a thenable as first argument.
|
||||
promises.push(assert.rejects(rejectingFn, errObj));
|
||||
promises.push(assert.rejects(rejectingFn(), errObj));
|
||||
|
||||
const validRejectingThenable = {
|
||||
then: (fulfill, reject) => {
|
||||
reject({ code: 'FAIL' });
|
||||
},
|
||||
catch: () => {}
|
||||
};
|
||||
promises.push(assert.rejects(validRejectingThenable, { code: 'FAIL' }));
|
||||
|
||||
// `assert.rejects` should not accept thenables that
|
||||
// use a function as `obj` and that have no `catch` handler.
|
||||
promises.push(assert.rejects(
|
||||
assert.rejects(invalidThenable, {}),
|
||||
{
|
||||
code: 'ERR_INVALID_ARG_TYPE'
|
||||
})
|
||||
);
|
||||
promises.push(assert.rejects(
|
||||
assert.rejects(invalidThenableFunc, {}),
|
||||
{
|
||||
code: 'ERR_INVALID_RETURN_VALUE'
|
||||
})
|
||||
);
|
||||
|
||||
const err = new Error('foobar');
|
||||
const validate = () => { return 'baz'; };
|
||||
promises.push(assert.rejects(
|
||||
() => assert.rejects(Promise.reject(err), validate),
|
||||
{
|
||||
message: 'The "validate" validation function is expected to ' +
|
||||
"return \"true\". Received 'baz'\n\nCaught error:\n\n" +
|
||||
'Error: foobar',
|
||||
code: 'ERR_ASSERTION',
|
||||
actual: err,
|
||||
expected: validate,
|
||||
name: 'AssertionError',
|
||||
operator: 'rejects',
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
{
|
||||
const handler = (err) => {
|
||||
assert(err instanceof assert.AssertionError,
|
||||
`${err.name} is not instance of AssertionError`);
|
||||
assert.strictEqual(err.code, 'ERR_ASSERTION');
|
||||
assert.strictEqual(err.message,
|
||||
'Missing expected rejection (mustNotCall).');
|
||||
assert.strictEqual(err.operator, 'rejects');
|
||||
assert.ok(!err.stack.includes('at Function.rejects'));
|
||||
return true;
|
||||
};
|
||||
|
||||
let promise = assert.rejects(async () => {}, common.mustNotCall());
|
||||
promises.push(assert.rejects(promise, common.mustCall(handler)));
|
||||
|
||||
promise = assert.rejects(() => {}, common.mustNotCall());
|
||||
promises.push(assert.rejects(promise, {
|
||||
name: 'TypeError',
|
||||
code: 'ERR_INVALID_RETURN_VALUE',
|
||||
// FIXME(JakobJingleheimer): This should match on key words, like /Promise/ and /undefined/.
|
||||
message: 'Expected instance of Promise to be returned ' +
|
||||
'from the "promiseFn" function but got undefined.'
|
||||
}));
|
||||
|
||||
promise = assert.rejects(Promise.resolve(), common.mustNotCall());
|
||||
promises.push(assert.rejects(promise, common.mustCall(handler)));
|
||||
}
|
||||
|
||||
{
|
||||
const THROWN_ERROR = new Error();
|
||||
|
||||
promises.push(assert.rejects(() => {
|
||||
throw THROWN_ERROR;
|
||||
}, {}).catch(common.mustCall((err) => {
|
||||
assert.strictEqual(err, THROWN_ERROR);
|
||||
})));
|
||||
}
|
||||
|
||||
promises.push(assert.rejects(
|
||||
assert.rejects('fail', {}),
|
||||
{
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
message: 'The "promiseFn" argument must be of type function or an ' +
|
||||
"instance of Promise. Received type string ('fail')"
|
||||
}
|
||||
));
|
||||
|
||||
{
|
||||
const handler = (generated, actual, err) => {
|
||||
assert.strictEqual(err.generatedMessage, generated);
|
||||
assert.strictEqual(err.code, 'ERR_ASSERTION');
|
||||
assert.strictEqual(err.actual, actual);
|
||||
assert.strictEqual(err.operator, 'rejects');
|
||||
assert.match(err.stack, /rejects/);
|
||||
return true;
|
||||
};
|
||||
const err = new Error();
|
||||
promises.push(assert.rejects(
|
||||
assert.rejects(Promise.reject(null), { code: 'FOO' }),
|
||||
handler.bind(null, true, null)
|
||||
));
|
||||
promises.push(assert.rejects(
|
||||
assert.rejects(Promise.reject(5), { code: 'FOO' }, 'AAAAA'),
|
||||
handler.bind(null, false, 5)
|
||||
));
|
||||
promises.push(assert.rejects(
|
||||
assert.rejects(Promise.reject(err), { code: 'FOO' }, 'AAAAA'),
|
||||
handler.bind(null, false, err)
|
||||
));
|
||||
}
|
||||
|
||||
// Check `assert.doesNotReject`.
|
||||
{
|
||||
// `assert.doesNotReject` accepts a function or a promise
|
||||
// or a thenable as first argument.
|
||||
/* eslint-disable no-restricted-syntax */
|
||||
let promise = assert.doesNotReject(() => new Map(), common.mustNotCall());
|
||||
promises.push(assert.rejects(promise, {
|
||||
message: 'Expected instance of Promise to be returned ' +
|
||||
'from the "promiseFn" function but got an instance of Map.',
|
||||
code: 'ERR_INVALID_RETURN_VALUE',
|
||||
name: 'TypeError'
|
||||
}));
|
||||
promises.push(assert.doesNotReject(async () => {}));
|
||||
promises.push(assert.doesNotReject(Promise.resolve()));
|
||||
|
||||
// `assert.doesNotReject` should not accept thenables that
|
||||
// use a function as `obj` and that have no `catch` handler.
|
||||
const validFulfillingThenable = {
|
||||
then: (fulfill, reject) => {
|
||||
fulfill();
|
||||
},
|
||||
catch: () => {}
|
||||
};
|
||||
promises.push(assert.doesNotReject(validFulfillingThenable));
|
||||
promises.push(assert.rejects(
|
||||
assert.doesNotReject(invalidThenable),
|
||||
{
|
||||
code: 'ERR_INVALID_ARG_TYPE'
|
||||
})
|
||||
);
|
||||
promises.push(assert.rejects(
|
||||
assert.doesNotReject(invalidThenableFunc),
|
||||
{
|
||||
code: 'ERR_INVALID_RETURN_VALUE'
|
||||
})
|
||||
);
|
||||
|
||||
const handler1 = (err) => {
|
||||
assert(err instanceof assert.AssertionError,
|
||||
`${err.name} is not instance of AssertionError`);
|
||||
assert.strictEqual(err.code, 'ERR_ASSERTION');
|
||||
assert.strictEqual(err.message, 'Failed');
|
||||
return true;
|
||||
};
|
||||
const handler2 = (err) => {
|
||||
assert(err instanceof assert.AssertionError,
|
||||
`${err.name} is not instance of AssertionError`);
|
||||
assert.strictEqual(err.code, 'ERR_ASSERTION');
|
||||
assert.strictEqual(err.message,
|
||||
'Got unwanted rejection.\nActual message: "Failed"');
|
||||
assert.strictEqual(err.operator, 'doesNotReject');
|
||||
assert.ok(err.stack);
|
||||
assert.ok(!err.stack.includes('at Function.doesNotReject'));
|
||||
return true;
|
||||
};
|
||||
|
||||
const rejectingFn = async () => assert.fail();
|
||||
|
||||
promise = assert.doesNotReject(rejectingFn, common.mustCall(handler1));
|
||||
promises.push(assert.rejects(promise, common.mustCall(handler2)));
|
||||
|
||||
promise = assert.doesNotReject(rejectingFn(), common.mustCall(handler1));
|
||||
promises.push(assert.rejects(promise, common.mustCall(handler2)));
|
||||
|
||||
promise = assert.doesNotReject(() => assert.fail(), common.mustNotCall());
|
||||
promises.push(assert.rejects(promise, common.mustCall(handler1)));
|
||||
|
||||
promises.push(assert.rejects(
|
||||
assert.doesNotReject(123),
|
||||
{
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
message: 'The "promiseFn" argument must be of type ' +
|
||||
'function or an instance of Promise. Received type number (123)'
|
||||
}
|
||||
));
|
||||
/* eslint-enable no-restricted-syntax */
|
||||
}
|
||||
|
||||
// Make sure all async code gets properly executed.
|
||||
Promise.all(promises).then(common.mustCall());
|
1615
cli/tests/node_compat/test/parallel/test-assert.js
Normal file
1615
cli/tests/node_compat/test/parallel/test-assert.js
Normal file
File diff suppressed because it is too large
Load diff
40
cli/tests/node_compat/test/parallel/test-bad-unicode.js
Normal file
40
cli/tests/node_compat/test/parallel/test-bad-unicode.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// 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';
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
let exception = null;
|
||||
|
||||
try {
|
||||
eval('"\\uc/ef"');
|
||||
} catch (e) {
|
||||
exception = e;
|
||||
}
|
||||
|
||||
assert(exception instanceof SyntaxError);
|
1181
cli/tests/node_compat/test/parallel/test-buffer-alloc.js
Normal file
1181
cli/tests/node_compat/test/parallel/test-buffer-alloc.js
Normal file
File diff suppressed because it is too large
Load diff
162
cli/tests/node_compat/test/parallel/test-buffer-arraybuffer.js
Normal file
162
cli/tests/node_compat/test/parallel/test-buffer-arraybuffer.js
Normal file
|
@ -0,0 +1,162 @@
|
|||
// 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
|
||||
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
const LENGTH = 16;
|
||||
|
||||
const ab = new ArrayBuffer(LENGTH);
|
||||
const dv = new DataView(ab);
|
||||
const ui = new Uint8Array(ab);
|
||||
const buf = Buffer.from(ab);
|
||||
|
||||
|
||||
assert.ok(buf instanceof Buffer);
|
||||
assert.strictEqual(buf.parent, buf.buffer);
|
||||
assert.strictEqual(buf.buffer, ab);
|
||||
assert.strictEqual(buf.length, ab.byteLength);
|
||||
|
||||
|
||||
buf.fill(0xC);
|
||||
for (let i = 0; i < LENGTH; i++) {
|
||||
assert.strictEqual(ui[i], 0xC);
|
||||
ui[i] = 0xF;
|
||||
assert.strictEqual(buf[i], 0xF);
|
||||
}
|
||||
|
||||
buf.writeUInt32LE(0xF00, 0);
|
||||
buf.writeUInt32BE(0xB47, 4);
|
||||
buf.writeDoubleLE(3.1415, 8);
|
||||
|
||||
assert.strictEqual(dv.getUint32(0, true), 0xF00);
|
||||
assert.strictEqual(dv.getUint32(4), 0xB47);
|
||||
assert.strictEqual(dv.getFloat64(8, true), 3.1415);
|
||||
|
||||
|
||||
// Now test protecting users from doing stupid things
|
||||
|
||||
// TODO(Soremwar)
|
||||
// There is an inconsistency on feross implementation on how buffers are checked
|
||||
// Enable once it's sorted out
|
||||
// assert.throws(function() {
|
||||
// function AB() { }
|
||||
// Object.setPrototypeOf(AB, ArrayBuffer);
|
||||
// Object.setPrototypeOf(AB.prototype, ArrayBuffer.prototype);
|
||||
// Buffer.from(new AB());
|
||||
// }, {
|
||||
// code: 'ERR_INVALID_ARG_TYPE',
|
||||
// name: 'TypeError',
|
||||
// message: 'The first argument must be of type string or an instance of ' +
|
||||
// 'Buffer, ArrayBuffer, or Array or an Array-like Object. Received ' +
|
||||
// 'an instance of AB'
|
||||
// });
|
||||
|
||||
// Test the byteOffset and length arguments
|
||||
{
|
||||
const ab = new Uint8Array(5);
|
||||
ab[0] = 1;
|
||||
ab[1] = 2;
|
||||
ab[2] = 3;
|
||||
ab[3] = 4;
|
||||
ab[4] = 5;
|
||||
const buf = Buffer.from(ab.buffer, 1, 3);
|
||||
assert.strictEqual(buf.length, 3);
|
||||
assert.strictEqual(buf[0], 2);
|
||||
assert.strictEqual(buf[1], 3);
|
||||
assert.strictEqual(buf[2], 4);
|
||||
buf[0] = 9;
|
||||
assert.strictEqual(ab[1], 9);
|
||||
|
||||
assert.throws(() => Buffer.from(ab.buffer, 6), {
|
||||
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
|
||||
name: 'RangeError',
|
||||
message: '"offset" is outside of buffer bounds'
|
||||
});
|
||||
assert.throws(() => Buffer.from(ab.buffer, 3, 6), {
|
||||
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
|
||||
name: 'RangeError',
|
||||
message: '"length" is outside of buffer bounds'
|
||||
});
|
||||
}
|
||||
|
||||
// Test the deprecated Buffer() version also
|
||||
{
|
||||
const ab = new Uint8Array(5);
|
||||
ab[0] = 1;
|
||||
ab[1] = 2;
|
||||
ab[2] = 3;
|
||||
ab[3] = 4;
|
||||
ab[4] = 5;
|
||||
const buf = Buffer(ab.buffer, 1, 3);
|
||||
assert.strictEqual(buf.length, 3);
|
||||
assert.strictEqual(buf[0], 2);
|
||||
assert.strictEqual(buf[1], 3);
|
||||
assert.strictEqual(buf[2], 4);
|
||||
buf[0] = 9;
|
||||
assert.strictEqual(ab[1], 9);
|
||||
|
||||
assert.throws(() => Buffer(ab.buffer, 6), {
|
||||
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
|
||||
name: 'RangeError',
|
||||
message: '"offset" is outside of buffer bounds'
|
||||
});
|
||||
assert.throws(() => Buffer(ab.buffer, 3, 6), {
|
||||
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
|
||||
name: 'RangeError',
|
||||
message: '"length" is outside of buffer bounds'
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
// If byteOffset is not numeric, it defaults to 0.
|
||||
const ab = new ArrayBuffer(10);
|
||||
const expected = Buffer.from(ab, 0);
|
||||
assert.deepStrictEqual(Buffer.from(ab, 'fhqwhgads'), expected);
|
||||
assert.deepStrictEqual(Buffer.from(ab, NaN), expected);
|
||||
assert.deepStrictEqual(Buffer.from(ab, {}), expected);
|
||||
assert.deepStrictEqual(Buffer.from(ab, []), expected);
|
||||
|
||||
// If byteOffset can be converted to a number, it will be.
|
||||
assert.deepStrictEqual(Buffer.from(ab, [1]), Buffer.from(ab, 1));
|
||||
|
||||
// If byteOffset is Infinity, throw.
|
||||
assert.throws(() => {
|
||||
Buffer.from(ab, Infinity);
|
||||
}, {
|
||||
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
|
||||
name: 'RangeError',
|
||||
message: '"offset" is outside of buffer bounds'
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
// If length is not numeric, it defaults to 0.
|
||||
const ab = new ArrayBuffer(10);
|
||||
const expected = Buffer.from(ab, 0, 0);
|
||||
assert.deepStrictEqual(Buffer.from(ab, 0, 'fhqwhgads'), expected);
|
||||
assert.deepStrictEqual(Buffer.from(ab, 0, NaN), expected);
|
||||
assert.deepStrictEqual(Buffer.from(ab, 0, {}), expected);
|
||||
assert.deepStrictEqual(Buffer.from(ab, 0, []), expected);
|
||||
|
||||
// If length can be converted to a number, it will be.
|
||||
assert.deepStrictEqual(Buffer.from(ab, 0, [1]), Buffer.from(ab, 0, 1));
|
||||
|
||||
// If length is Infinity, throw.
|
||||
assert.throws(() => {
|
||||
Buffer.from(ab, 0, Infinity);
|
||||
}, {
|
||||
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
|
||||
name: 'RangeError',
|
||||
message: '"length" is outside of buffer bounds'
|
||||
});
|
||||
}
|
||||
|
||||
// Test an array like entry with the length set to NaN.
|
||||
assert.deepStrictEqual(Buffer.from({ length: NaN }), Buffer.alloc(0));
|
53
cli/tests/node_compat/test/parallel/test-buffer-ascii.js
Normal file
53
cli/tests/node_compat/test/parallel/test-buffer-ascii.js
Normal file
|
@ -0,0 +1,53 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// 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';
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
// ASCII conversion in node.js simply masks off the high bits,
|
||||
// it doesn't do transliteration.
|
||||
assert.strictEqual(Buffer.from('hérité').toString('ascii'), 'hC)ritC)');
|
||||
|
||||
// 71 characters, 78 bytes. The ’ character is a triple-byte sequence.
|
||||
const input = 'C’est, graphiquement, la réunion d’un accent aigu ' +
|
||||
'et d’un accent grave.';
|
||||
|
||||
const expected = 'Cb\u0000\u0019est, graphiquement, la rC)union ' +
|
||||
'db\u0000\u0019un accent aigu et db\u0000\u0019un ' +
|
||||
'accent grave.';
|
||||
|
||||
const buf = Buffer.from(input);
|
||||
|
||||
for (let i = 0; i < expected.length; ++i) {
|
||||
assert.strictEqual(buf.slice(i).toString('ascii'), expected.slice(i));
|
||||
|
||||
// Skip remainder of multi-byte sequence.
|
||||
if (input.charCodeAt(i) > 65535) ++i;
|
||||
if (input.charCodeAt(i) > 127) ++i;
|
||||
}
|
55
cli/tests/node_compat/test/parallel/test-buffer-badhex.js
Normal file
55
cli/tests/node_compat/test/parallel/test-buffer-badhex.js
Normal file
|
@ -0,0 +1,55 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
// Test hex strings and bad hex strings
|
||||
{
|
||||
const buf = Buffer.alloc(4);
|
||||
assert.strictEqual(buf.length, 4);
|
||||
assert.deepStrictEqual(buf, Buffer.from([0, 0, 0, 0]));
|
||||
assert.strictEqual(buf.write('abcdxx', 0, 'hex'), 2);
|
||||
assert.deepStrictEqual(buf, Buffer.from([0xab, 0xcd, 0x00, 0x00]));
|
||||
assert.strictEqual(buf.toString('hex'), 'abcd0000');
|
||||
assert.strictEqual(buf.write('abcdef01', 0, 'hex'), 4);
|
||||
assert.deepStrictEqual(buf, Buffer.from([0xab, 0xcd, 0xef, 0x01]));
|
||||
assert.strictEqual(buf.toString('hex'), 'abcdef01');
|
||||
|
||||
const copy = Buffer.from(buf.toString('hex'), 'hex');
|
||||
assert.strictEqual(buf.toString('hex'), copy.toString('hex'));
|
||||
}
|
||||
|
||||
{
|
||||
const buf = Buffer.alloc(5);
|
||||
assert.strictEqual(buf.write('abcdxx', 1, 'hex'), 2);
|
||||
assert.strictEqual(buf.toString('hex'), '00abcd0000');
|
||||
}
|
||||
|
||||
{
|
||||
const buf = Buffer.alloc(4);
|
||||
assert.deepStrictEqual(buf, Buffer.from([0, 0, 0, 0]));
|
||||
assert.strictEqual(buf.write('xxabcd', 0, 'hex'), 0);
|
||||
assert.deepStrictEqual(buf, Buffer.from([0, 0, 0, 0]));
|
||||
assert.strictEqual(buf.write('xxab', 1, 'hex'), 0);
|
||||
assert.deepStrictEqual(buf, Buffer.from([0, 0, 0, 0]));
|
||||
assert.strictEqual(buf.write('cdxxab', 0, 'hex'), 1);
|
||||
assert.deepStrictEqual(buf, Buffer.from([0xcd, 0, 0, 0]));
|
||||
}
|
||||
|
||||
{
|
||||
const buf = Buffer.alloc(256);
|
||||
for (let i = 0; i < 256; i++)
|
||||
buf[i] = i;
|
||||
|
||||
const hex = buf.toString('hex');
|
||||
assert.deepStrictEqual(Buffer.from(hex, 'hex'), buf);
|
||||
|
||||
const badHex = `${hex.slice(0, 256)}xx${hex.slice(256, 510)}`;
|
||||
assert.deepStrictEqual(Buffer.from(badHex, 'hex'), buf.slice(0, 128));
|
||||
}
|
62
cli/tests/node_compat/test/parallel/test-buffer-bigint64.js
Normal file
62
cli/tests/node_compat/test/parallel/test-buffer-bigint64.js
Normal file
|
@ -0,0 +1,62 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
const buf = Buffer.allocUnsafe(8);
|
||||
|
||||
['LE', 'BE'].forEach(function(endianness) {
|
||||
// Should allow simple BigInts to be written and read
|
||||
let val = 123456789n;
|
||||
buf[`writeBigInt64${endianness}`](val, 0);
|
||||
let rtn = buf[`readBigInt64${endianness}`](0);
|
||||
assert.strictEqual(val, rtn);
|
||||
|
||||
// Should allow INT64_MAX to be written and read
|
||||
val = 0x7fffffffffffffffn;
|
||||
buf[`writeBigInt64${endianness}`](val, 0);
|
||||
rtn = buf[`readBigInt64${endianness}`](0);
|
||||
assert.strictEqual(val, rtn);
|
||||
|
||||
// Should read and write a negative signed 64-bit integer
|
||||
val = -123456789n;
|
||||
buf[`writeBigInt64${endianness}`](val, 0);
|
||||
assert.strictEqual(val, buf[`readBigInt64${endianness}`](0));
|
||||
|
||||
// Should read and write an unsigned 64-bit integer
|
||||
val = 123456789n;
|
||||
buf[`writeBigUInt64${endianness}`](val, 0);
|
||||
assert.strictEqual(val, buf[`readBigUInt64${endianness}`](0));
|
||||
|
||||
// Should throw a RangeError upon INT64_MAX+1 being written
|
||||
assert.throws(function() {
|
||||
const val = 0x8000000000000000n;
|
||||
buf[`writeBigInt64${endianness}`](val, 0);
|
||||
}, RangeError);
|
||||
|
||||
// Should throw a RangeError upon UINT64_MAX+1 being written
|
||||
assert.throws(function() {
|
||||
const val = 0x10000000000000000n;
|
||||
buf[`writeBigUInt64${endianness}`](val, 0);
|
||||
}, {
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
message: 'The value of "value" is out of range. It must be ' +
|
||||
'>= 0n and < 2n ** 64n. Received 18_446_744_073_709_551_616n'
|
||||
});
|
||||
|
||||
// Should throw a TypeError upon invalid input
|
||||
assert.throws(function() {
|
||||
buf[`writeBigInt64${endianness}`]('bad', 0);
|
||||
}, TypeError);
|
||||
|
||||
// Should throw a TypeError upon invalid input
|
||||
assert.throws(function() {
|
||||
buf[`writeBigUInt64${endianness}`]('bad', 0);
|
||||
}, TypeError);
|
||||
});
|
142
cli/tests/node_compat/test/parallel/test-buffer-bytelength.js
Normal file
142
cli/tests/node_compat/test/parallel/test-buffer-bytelength.js
Normal file
|
@ -0,0 +1,142 @@
|
|||
// 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
|
||||
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const SlowBuffer = require('buffer').SlowBuffer;
|
||||
const vm = require('vm');
|
||||
|
||||
[
|
||||
[32, 'latin1'],
|
||||
[NaN, 'utf8'],
|
||||
[{}, 'latin1'],
|
||||
[],
|
||||
].forEach((args) => {
|
||||
assert.throws(
|
||||
() => Buffer.byteLength(...args),
|
||||
{
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
name: 'TypeError',
|
||||
message: 'The "string" argument must be of type string or an instance ' +
|
||||
'of Buffer or ArrayBuffer.' +
|
||||
common.invalidArgTypeHelper(args[0])
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
assert.strictEqual(Buffer.byteLength('', undefined, true), -1);
|
||||
|
||||
assert(ArrayBuffer.isView(new Buffer(10)));
|
||||
assert(ArrayBuffer.isView(new SlowBuffer(10)));
|
||||
assert(ArrayBuffer.isView(Buffer.alloc(10)));
|
||||
assert(ArrayBuffer.isView(Buffer.allocUnsafe(10)));
|
||||
assert(ArrayBuffer.isView(Buffer.allocUnsafeSlow(10)));
|
||||
assert(ArrayBuffer.isView(Buffer.from('')));
|
||||
|
||||
// buffer
|
||||
const incomplete = Buffer.from([0xe4, 0xb8, 0xad, 0xe6, 0x96]);
|
||||
assert.strictEqual(Buffer.byteLength(incomplete), 5);
|
||||
const ascii = Buffer.from('abc');
|
||||
assert.strictEqual(Buffer.byteLength(ascii), 3);
|
||||
|
||||
// ArrayBuffer
|
||||
const buffer = new ArrayBuffer(8);
|
||||
assert.strictEqual(Buffer.byteLength(buffer), 8);
|
||||
|
||||
// TypedArray
|
||||
const int8 = new Int8Array(8);
|
||||
assert.strictEqual(Buffer.byteLength(int8), 8);
|
||||
const uint8 = new Uint8Array(8);
|
||||
assert.strictEqual(Buffer.byteLength(uint8), 8);
|
||||
const uintc8 = new Uint8ClampedArray(2);
|
||||
assert.strictEqual(Buffer.byteLength(uintc8), 2);
|
||||
const int16 = new Int16Array(8);
|
||||
assert.strictEqual(Buffer.byteLength(int16), 16);
|
||||
const uint16 = new Uint16Array(8);
|
||||
assert.strictEqual(Buffer.byteLength(uint16), 16);
|
||||
const int32 = new Int32Array(8);
|
||||
assert.strictEqual(Buffer.byteLength(int32), 32);
|
||||
const uint32 = new Uint32Array(8);
|
||||
assert.strictEqual(Buffer.byteLength(uint32), 32);
|
||||
const float32 = new Float32Array(8);
|
||||
assert.strictEqual(Buffer.byteLength(float32), 32);
|
||||
const float64 = new Float64Array(8);
|
||||
assert.strictEqual(Buffer.byteLength(float64), 64);
|
||||
|
||||
// DataView
|
||||
const dv = new DataView(new ArrayBuffer(2));
|
||||
assert.strictEqual(Buffer.byteLength(dv), 2);
|
||||
|
||||
// Special case: zero length string
|
||||
assert.strictEqual(Buffer.byteLength('', 'ascii'), 0);
|
||||
assert.strictEqual(Buffer.byteLength('', 'HeX'), 0);
|
||||
|
||||
// utf8
|
||||
assert.strictEqual(Buffer.byteLength('∑éllö wørl∂!', 'utf-8'), 19);
|
||||
assert.strictEqual(Buffer.byteLength('κλμνξο', 'utf8'), 12);
|
||||
assert.strictEqual(Buffer.byteLength('挵挶挷挸挹', 'utf-8'), 15);
|
||||
assert.strictEqual(Buffer.byteLength('𠝹𠱓𠱸', 'UTF8'), 12);
|
||||
// Without an encoding, utf8 should be assumed
|
||||
assert.strictEqual(Buffer.byteLength('hey there'), 9);
|
||||
assert.strictEqual(Buffer.byteLength('𠱸挶νξ#xx :)'), 17);
|
||||
assert.strictEqual(Buffer.byteLength('hello world', ''), 11);
|
||||
// It should also be assumed with unrecognized encoding
|
||||
assert.strictEqual(Buffer.byteLength('hello world', 'abc'), 11);
|
||||
assert.strictEqual(Buffer.byteLength('ßœ∑≈', 'unkn0wn enc0ding'), 10);
|
||||
|
||||
// base64
|
||||
assert.strictEqual(Buffer.byteLength('aGVsbG8gd29ybGQ=', 'base64'), 11);
|
||||
assert.strictEqual(Buffer.byteLength('aGVsbG8gd29ybGQ=', 'BASE64'), 11);
|
||||
assert.strictEqual(Buffer.byteLength('bm9kZS5qcyByb2NrcyE=', 'base64'), 14);
|
||||
assert.strictEqual(Buffer.byteLength('aGkk', 'base64'), 3);
|
||||
assert.strictEqual(
|
||||
Buffer.byteLength('bHNrZGZsa3NqZmtsc2xrZmFqc2RsZmtqcw==', 'base64'), 25
|
||||
);
|
||||
assert.strictEqual(Buffer.byteLength('aGVsbG8gd29ybGQ', 'base64url'), 11);
|
||||
assert.strictEqual(Buffer.byteLength('aGVsbG8gd29ybGQ', 'BASE64URL'), 11);
|
||||
assert.strictEqual(Buffer.byteLength('bm9kZS5qcyByb2NrcyE', 'base64url'), 14);
|
||||
assert.strictEqual(Buffer.byteLength('aGkk', 'base64url'), 3);
|
||||
assert.strictEqual(
|
||||
Buffer.byteLength('bHNrZGZsa3NqZmtsc2xrZmFqc2RsZmtqcw', 'base64url'), 25
|
||||
);
|
||||
// special padding
|
||||
assert.strictEqual(Buffer.byteLength('aaa=', 'base64'), 2);
|
||||
assert.strictEqual(Buffer.byteLength('aaaa==', 'base64'), 3);
|
||||
assert.strictEqual(Buffer.byteLength('aaa=', 'base64url'), 2);
|
||||
assert.strictEqual(Buffer.byteLength('aaaa==', 'base64url'), 3);
|
||||
|
||||
assert.strictEqual(Buffer.byteLength('Il était tué'), 14);
|
||||
assert.strictEqual(Buffer.byteLength('Il était tué', 'utf8'), 14);
|
||||
|
||||
['ascii', 'latin1', 'binary']
|
||||
.reduce((es, e) => es.concat(e, e.toUpperCase()), [])
|
||||
.forEach((encoding) => {
|
||||
assert.strictEqual(Buffer.byteLength('Il était tué', encoding), 12);
|
||||
});
|
||||
|
||||
['ucs2', 'ucs-2', 'utf16le', 'utf-16le']
|
||||
.reduce((es, e) => es.concat(e, e.toUpperCase()), [])
|
||||
.forEach((encoding) => {
|
||||
assert.strictEqual(Buffer.byteLength('Il était tué', encoding), 24);
|
||||
});
|
||||
|
||||
// TODO(Soremwar)
|
||||
// Enable once vm module is available
|
||||
// // Test that ArrayBuffer from a different context is detected correctly
|
||||
// const arrayBuf = vm.runInNewContext('new ArrayBuffer()');
|
||||
// assert.strictEqual(Buffer.byteLength(arrayBuf), 0);
|
||||
|
||||
// Verify that invalid encodings are treated as utf8
|
||||
for (let i = 1; i < 10; i++) {
|
||||
const encoding = String(i).repeat(i);
|
||||
|
||||
assert.ok(!Buffer.isEncoding(encoding));
|
||||
assert.strictEqual(Buffer.byteLength('foo', encoding),
|
||||
Buffer.byteLength('foo', 'utf8'));
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
const a = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]);
|
||||
const b = Buffer.from([5, 6, 7, 8, 9, 0, 1, 2, 3, 4]);
|
||||
|
||||
assert.strictEqual(a.compare(b), -1);
|
||||
|
||||
// Equivalent to a.compare(b).
|
||||
assert.strictEqual(a.compare(b, 0), -1);
|
||||
assert.throws(() => a.compare(b, '0'), { code: 'ERR_INVALID_ARG_TYPE' });
|
||||
assert.strictEqual(a.compare(b, undefined), -1);
|
||||
|
||||
// Equivalent to a.compare(b).
|
||||
assert.strictEqual(a.compare(b, 0, undefined, 0), -1);
|
||||
|
||||
// Zero-length target, return 1
|
||||
assert.strictEqual(a.compare(b, 0, 0, 0), 1);
|
||||
assert.throws(
|
||||
() => a.compare(b, 0, '0', '0'),
|
||||
{ code: 'ERR_INVALID_ARG_TYPE' }
|
||||
);
|
||||
|
||||
// Equivalent to Buffer.compare(a, b.slice(6, 10))
|
||||
assert.strictEqual(a.compare(b, 6, 10), 1);
|
||||
|
||||
// Zero-length source, return -1
|
||||
assert.strictEqual(a.compare(b, 6, 10, 0, 0), -1);
|
||||
|
||||
// Zero-length source and target, return 0
|
||||
assert.strictEqual(a.compare(b, 0, 0, 0, 0), 0);
|
||||
assert.strictEqual(a.compare(b, 1, 1, 2, 2), 0);
|
||||
|
||||
// Equivalent to Buffer.compare(a.slice(4), b.slice(0, 5))
|
||||
assert.strictEqual(a.compare(b, 0, 5, 4), 1);
|
||||
|
||||
// Equivalent to Buffer.compare(a.slice(1), b.slice(5))
|
||||
assert.strictEqual(a.compare(b, 5, undefined, 1), 1);
|
||||
|
||||
// Equivalent to Buffer.compare(a.slice(2), b.slice(2, 4))
|
||||
assert.strictEqual(a.compare(b, 2, 4, 2), -1);
|
||||
|
||||
// Equivalent to Buffer.compare(a.slice(4), b.slice(0, 7))
|
||||
assert.strictEqual(a.compare(b, 0, 7, 4), -1);
|
||||
|
||||
// Equivalent to Buffer.compare(a.slice(4, 6), b.slice(0, 7));
|
||||
assert.strictEqual(a.compare(b, 0, 7, 4, 6), -1);
|
||||
|
||||
// Null is ambiguous.
|
||||
assert.throws(
|
||||
() => a.compare(b, 0, null),
|
||||
{ code: 'ERR_INVALID_ARG_TYPE' }
|
||||
);
|
||||
|
||||
// Values do not get coerced.
|
||||
assert.throws(
|
||||
() => a.compare(b, 0, { valueOf: () => 5 }),
|
||||
{ code: 'ERR_INVALID_ARG_TYPE' }
|
||||
);
|
||||
|
||||
// Infinity should not be coerced.
|
||||
assert.throws(
|
||||
() => a.compare(b, Infinity, -Infinity),
|
||||
{ code: 'ERR_OUT_OF_RANGE' }
|
||||
);
|
||||
|
||||
// Zero length target because default for targetEnd <= targetSource
|
||||
assert.strictEqual(a.compare(b, 0xff), 1);
|
||||
|
||||
assert.throws(
|
||||
() => a.compare(b, '0xff'),
|
||||
{ code: 'ERR_INVALID_ARG_TYPE' }
|
||||
);
|
||||
assert.throws(
|
||||
() => a.compare(b, 0, '0xff'),
|
||||
{ code: 'ERR_INVALID_ARG_TYPE' }
|
||||
);
|
||||
|
||||
const oor = { code: 'ERR_OUT_OF_RANGE' };
|
||||
|
||||
assert.throws(() => a.compare(b, 0, 100, 0), oor);
|
||||
assert.throws(() => a.compare(b, 0, 1, 0, 100), oor);
|
||||
assert.throws(() => a.compare(b, -1), oor);
|
||||
assert.throws(() => a.compare(b, 0, Infinity), oor);
|
||||
assert.throws(() => a.compare(b, 0, 1, -1), oor);
|
||||
assert.throws(() => a.compare(b, -Infinity, Infinity), oor);
|
||||
assert.throws(() => a.compare(), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
name: 'TypeError',
|
||||
message: 'The "target" argument must be an instance of ' +
|
||||
'Buffer or Uint8Array. Received undefined'
|
||||
});
|
107
cli/tests/node_compat/test/parallel/test-buffer-concat.js
Normal file
107
cli/tests/node_compat/test/parallel/test-buffer-concat.js
Normal file
|
@ -0,0 +1,107 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// 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';
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
const zero = [];
|
||||
const one = [ Buffer.from('asdf') ];
|
||||
const long = [];
|
||||
for (let i = 0; i < 10; i++) long.push(Buffer.from('asdf'));
|
||||
|
||||
const flatZero = Buffer.concat(zero);
|
||||
const flatOne = Buffer.concat(one);
|
||||
const flatLong = Buffer.concat(long);
|
||||
const flatLongLen = Buffer.concat(long, 40);
|
||||
|
||||
assert.strictEqual(flatZero.length, 0);
|
||||
assert.strictEqual(flatOne.toString(), 'asdf');
|
||||
|
||||
const check = 'asdf'.repeat(10);
|
||||
|
||||
// A special case where concat used to return the first item,
|
||||
// if the length is one. This check is to make sure that we don't do that.
|
||||
assert.notStrictEqual(flatOne, one[0]);
|
||||
assert.strictEqual(flatLong.toString(), check);
|
||||
assert.strictEqual(flatLongLen.toString(), check);
|
||||
|
||||
[undefined, null, Buffer.from('hello')].forEach((value) => {
|
||||
assert.throws(() => {
|
||||
Buffer.concat(value);
|
||||
}, {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
message: 'The "list" argument must be an instance of Array.' +
|
||||
`${common.invalidArgTypeHelper(value)}`
|
||||
});
|
||||
});
|
||||
|
||||
[[42], ['hello', Buffer.from('world')]].forEach((value) => {
|
||||
assert.throws(() => {
|
||||
Buffer.concat(value);
|
||||
}, {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
message: 'The "list[0]" argument must be an instance of Buffer ' +
|
||||
`or Uint8Array.${common.invalidArgTypeHelper(value[0])}`
|
||||
});
|
||||
});
|
||||
|
||||
assert.throws(() => {
|
||||
Buffer.concat([Buffer.from('hello'), 3]);
|
||||
}, {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
message: 'The "list[1]" argument must be an instance of Buffer ' +
|
||||
'or Uint8Array. Received type number (3)'
|
||||
});
|
||||
|
||||
// eslint-disable-next-line node-core/crypto-check
|
||||
const random10 = common.hasCrypto ?
|
||||
require('crypto').randomBytes(10) :
|
||||
Buffer.alloc(10, 1);
|
||||
const empty = Buffer.alloc(0);
|
||||
|
||||
assert.notDeepStrictEqual(random10, empty);
|
||||
assert.notDeepStrictEqual(random10, Buffer.alloc(10));
|
||||
|
||||
assert.deepStrictEqual(Buffer.concat([], 100), empty);
|
||||
assert.deepStrictEqual(Buffer.concat([random10], 0), empty);
|
||||
assert.deepStrictEqual(Buffer.concat([random10], 10), random10);
|
||||
assert.deepStrictEqual(Buffer.concat([random10, random10], 10), random10);
|
||||
assert.deepStrictEqual(Buffer.concat([empty, random10]), random10);
|
||||
assert.deepStrictEqual(Buffer.concat([random10, empty, empty]), random10);
|
||||
|
||||
// The tail should be zero-filled
|
||||
assert.deepStrictEqual(Buffer.concat([empty], 100), Buffer.alloc(100));
|
||||
assert.deepStrictEqual(Buffer.concat([empty], 4096), Buffer.alloc(4096));
|
||||
assert.deepStrictEqual(
|
||||
Buffer.concat([random10], 40),
|
||||
Buffer.concat([random10, Buffer.alloc(30)]));
|
||||
|
||||
assert.deepStrictEqual(Buffer.concat([new Uint8Array([0x41, 0x42]),
|
||||
new Uint8Array([0x43, 0x44])]),
|
||||
Buffer.from('ABCD'));
|
25
cli/tests/node_compat/test/parallel/test-buffer-constants.js
Normal file
25
cli/tests/node_compat/test/parallel/test-buffer-constants.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
const { kMaxLength, kStringMaxLength } = require('buffer');
|
||||
const { MAX_LENGTH, MAX_STRING_LENGTH } = require('buffer').constants;
|
||||
|
||||
assert.strictEqual(typeof MAX_LENGTH, 'number');
|
||||
assert.strictEqual(typeof MAX_STRING_LENGTH, 'number');
|
||||
assert(MAX_STRING_LENGTH <= MAX_LENGTH);
|
||||
assert.throws(() => ' '.repeat(MAX_STRING_LENGTH + 1),
|
||||
/^RangeError: Invalid string length$/);
|
||||
|
||||
' '.repeat(MAX_STRING_LENGTH); // Should not throw.
|
||||
|
||||
// Legacy values match:
|
||||
assert.strictEqual(kMaxLength, MAX_LENGTH);
|
||||
assert.strictEqual(kStringMaxLength, MAX_STRING_LENGTH);
|
236
cli/tests/node_compat/test/parallel/test-buffer-copy.js
Normal file
236
cli/tests/node_compat/test/parallel/test-buffer-copy.js
Normal file
|
@ -0,0 +1,236 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
const b = Buffer.allocUnsafe(1024);
|
||||
const c = Buffer.allocUnsafe(512);
|
||||
|
||||
let cntr = 0;
|
||||
|
||||
{
|
||||
// copy 512 bytes, from 0 to 512.
|
||||
b.fill(++cntr);
|
||||
c.fill(++cntr);
|
||||
const copied = b.copy(c, 0, 0, 512);
|
||||
assert.strictEqual(copied, 512);
|
||||
for (let i = 0; i < c.length; i++) {
|
||||
assert.strictEqual(c[i], b[i]);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// Current behavior is to coerce values to integers.
|
||||
b.fill(++cntr);
|
||||
c.fill(++cntr);
|
||||
const copied = b.copy(c, '0', '0', '512');
|
||||
assert.strictEqual(copied, 512);
|
||||
for (let i = 0; i < c.length; i++) {
|
||||
assert.strictEqual(c[i], b[i]);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// Floats will be converted to integers via `Math.floor`
|
||||
b.fill(++cntr);
|
||||
c.fill(++cntr);
|
||||
const copied = b.copy(c, 0, 0, 512.5);
|
||||
assert.strictEqual(copied, 512);
|
||||
for (let i = 0; i < c.length; i++) {
|
||||
assert.strictEqual(c[i], b[i]);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// Copy c into b, without specifying sourceEnd
|
||||
b.fill(++cntr);
|
||||
c.fill(++cntr);
|
||||
const copied = c.copy(b, 0, 0);
|
||||
assert.strictEqual(copied, c.length);
|
||||
for (let i = 0; i < c.length; i++) {
|
||||
assert.strictEqual(b[i], c[i]);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// Copy c into b, without specifying sourceStart
|
||||
b.fill(++cntr);
|
||||
c.fill(++cntr);
|
||||
const copied = c.copy(b, 0);
|
||||
assert.strictEqual(copied, c.length);
|
||||
for (let i = 0; i < c.length; i++) {
|
||||
assert.strictEqual(b[i], c[i]);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// Copied source range greater than source length
|
||||
b.fill(++cntr);
|
||||
c.fill(++cntr);
|
||||
const copied = c.copy(b, 0, 0, c.length + 1);
|
||||
assert.strictEqual(copied, c.length);
|
||||
for (let i = 0; i < c.length; i++) {
|
||||
assert.strictEqual(b[i], c[i]);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// Copy longer buffer b to shorter c without targetStart
|
||||
b.fill(++cntr);
|
||||
c.fill(++cntr);
|
||||
const copied = b.copy(c);
|
||||
assert.strictEqual(copied, c.length);
|
||||
for (let i = 0; i < c.length; i++) {
|
||||
assert.strictEqual(c[i], b[i]);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// Copy starting near end of b to c
|
||||
b.fill(++cntr);
|
||||
c.fill(++cntr);
|
||||
const copied = b.copy(c, 0, b.length - Math.floor(c.length / 2));
|
||||
assert.strictEqual(copied, Math.floor(c.length / 2));
|
||||
for (let i = 0; i < Math.floor(c.length / 2); i++) {
|
||||
assert.strictEqual(c[i], b[b.length - Math.floor(c.length / 2) + i]);
|
||||
}
|
||||
for (let i = Math.floor(c.length / 2) + 1; i < c.length; i++) {
|
||||
assert.strictEqual(c[c.length - 1], c[i]);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// Try to copy 513 bytes, and check we don't overrun c
|
||||
b.fill(++cntr);
|
||||
c.fill(++cntr);
|
||||
const copied = b.copy(c, 0, 0, 513);
|
||||
assert.strictEqual(copied, c.length);
|
||||
for (let i = 0; i < c.length; i++) {
|
||||
assert.strictEqual(c[i], b[i]);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// copy 768 bytes from b into b
|
||||
b.fill(++cntr);
|
||||
b.fill(++cntr, 256);
|
||||
const copied = b.copy(b, 0, 256, 1024);
|
||||
assert.strictEqual(copied, 768);
|
||||
for (let i = 0; i < b.length; i++) {
|
||||
assert.strictEqual(b[i], cntr);
|
||||
}
|
||||
}
|
||||
|
||||
// Copy string longer than buffer length (failure will segfault)
|
||||
const bb = Buffer.allocUnsafe(10);
|
||||
bb.fill('hello crazy world');
|
||||
|
||||
|
||||
// Try to copy from before the beginning of b. Should not throw.
|
||||
b.copy(c, 0, 100, 10);
|
||||
|
||||
// Throw with invalid source type
|
||||
assert.throws(
|
||||
() => Buffer.prototype.copy.call(0),
|
||||
{
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
name: 'TypeError',
|
||||
}
|
||||
);
|
||||
|
||||
// Copy throws at negative targetStart
|
||||
assert.throws(
|
||||
() => Buffer.allocUnsafe(5).copy(Buffer.allocUnsafe(5), -1, 0),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: 'The value of "targetStart" is out of range. ' +
|
||||
'It must be >= 0. Received -1'
|
||||
}
|
||||
);
|
||||
|
||||
// Copy throws at negative sourceStart
|
||||
assert.throws(
|
||||
() => Buffer.allocUnsafe(5).copy(Buffer.allocUnsafe(5), 0, -1),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: 'The value of "sourceStart" is out of range. ' +
|
||||
'It must be >= 0. Received -1'
|
||||
}
|
||||
);
|
||||
|
||||
{
|
||||
// Check sourceEnd resets to targetEnd if former is greater than the latter
|
||||
b.fill(++cntr);
|
||||
c.fill(++cntr);
|
||||
b.copy(c, 0, 0, 1025);
|
||||
for (let i = 0; i < c.length; i++) {
|
||||
assert.strictEqual(c[i], b[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Throw with negative sourceEnd
|
||||
assert.throws(
|
||||
() => b.copy(c, 0, 0, -1),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: 'The value of "sourceEnd" is out of range. ' +
|
||||
'It must be >= 0. Received -1'
|
||||
}
|
||||
);
|
||||
|
||||
// When sourceStart is greater than sourceEnd, zero copied
|
||||
assert.strictEqual(b.copy(c, 0, 100, 10), 0);
|
||||
|
||||
// When targetStart > targetLength, zero copied
|
||||
assert.strictEqual(b.copy(c, 512, 0, 10), 0);
|
||||
|
||||
// Test that the `target` can be a Uint8Array.
|
||||
{
|
||||
const d = new Uint8Array(c);
|
||||
// copy 512 bytes, from 0 to 512.
|
||||
b.fill(++cntr);
|
||||
d.fill(++cntr);
|
||||
const copied = b.copy(d, 0, 0, 512);
|
||||
assert.strictEqual(copied, 512);
|
||||
for (let i = 0; i < d.length; i++) {
|
||||
assert.strictEqual(d[i], b[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Test that the source can be a Uint8Array, too.
|
||||
{
|
||||
const e = new Uint8Array(b);
|
||||
// copy 512 bytes, from 0 to 512.
|
||||
e.fill(++cntr);
|
||||
c.fill(++cntr);
|
||||
const copied = Buffer.prototype.copy.call(e, c, 0, 0, 512);
|
||||
assert.strictEqual(copied, 512);
|
||||
for (let i = 0; i < c.length; i++) {
|
||||
assert.strictEqual(c[i], e[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// https://github.com/nodejs/node/issues/23668: Do not crash for invalid input.
|
||||
c.fill('c');
|
||||
b.copy(c, 'not a valid offset');
|
||||
// Make sure this acted like a regular copy with `0` offset.
|
||||
assert.deepStrictEqual(c, b.slice(0, c.length));
|
||||
|
||||
{
|
||||
c.fill('C');
|
||||
assert.throws(() => {
|
||||
b.copy(c, { [Symbol.toPrimitive]() { throw new Error('foo'); } });
|
||||
}, /foo/);
|
||||
// No copying took place:
|
||||
assert.deepStrictEqual(c.toString(), 'C'.repeat(c.length));
|
||||
}
|
32
cli/tests/node_compat/test/parallel/test-buffer-equals.js
Normal file
32
cli/tests/node_compat/test/parallel/test-buffer-equals.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
const b = Buffer.from('abcdf');
|
||||
const c = Buffer.from('abcdf');
|
||||
const d = Buffer.from('abcde');
|
||||
const e = Buffer.from('abcdef');
|
||||
|
||||
assert.ok(b.equals(c));
|
||||
assert.ok(!c.equals(d));
|
||||
assert.ok(!d.equals(e));
|
||||
assert.ok(d.equals(d));
|
||||
assert.ok(d.equals(new Uint8Array([0x61, 0x62, 0x63, 0x64, 0x65])));
|
||||
|
||||
assert.throws(
|
||||
() => Buffer.alloc(1).equals('abc'),
|
||||
{
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
name: 'TypeError',
|
||||
message: 'The "otherBuffer" argument must be an instance of ' +
|
||||
"Buffer or Uint8Array. Received type string ('abc')"
|
||||
}
|
||||
);
|
|
@ -0,0 +1,40 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
const SlowBuffer = require('buffer').SlowBuffer;
|
||||
|
||||
// Test failed or zero-sized Buffer allocations not affecting typed arrays.
|
||||
// This test exists because of a regression that occurred. Because Buffer
|
||||
// instances are allocated with the same underlying allocator as TypedArrays,
|
||||
// but Buffer's can optional be non-zero filled, there was a regression that
|
||||
// occurred when a Buffer allocated failed, the internal flag specifying
|
||||
// whether or not to zero-fill was not being reset, causing TypedArrays to
|
||||
// allocate incorrectly.
|
||||
const zeroArray = new Uint32Array(10).fill(0);
|
||||
const sizes = [1e10, 0, 0.1, -1, 'a', undefined, null, NaN];
|
||||
const allocators = [
|
||||
Buffer,
|
||||
SlowBuffer,
|
||||
Buffer.alloc,
|
||||
Buffer.allocUnsafe,
|
||||
Buffer.allocUnsafeSlow,
|
||||
];
|
||||
for (const allocator of allocators) {
|
||||
for (const size of sizes) {
|
||||
try {
|
||||
// Some of these allocations are known to fail. If they do,
|
||||
// Uint32Array should still produce a zeroed out result.
|
||||
allocator(size);
|
||||
} catch {
|
||||
assert.deepStrictEqual(zeroArray, new Uint32Array(10));
|
||||
}
|
||||
}
|
||||
}
|
61
cli/tests/node_compat/test/parallel/test-buffer-fakes.js
Normal file
61
cli/tests/node_compat/test/parallel/test-buffer-fakes.js
Normal file
|
@ -0,0 +1,61 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
function FakeBuffer() { }
|
||||
Object.setPrototypeOf(FakeBuffer, Buffer);
|
||||
Object.setPrototypeOf(FakeBuffer.prototype, Buffer.prototype);
|
||||
|
||||
const fb = new FakeBuffer();
|
||||
|
||||
assert.throws(function() {
|
||||
Buffer.from(fb);
|
||||
}, TypeError);
|
||||
|
||||
assert.throws(function() {
|
||||
+Buffer.prototype; // eslint-disable-line no-unused-expressions
|
||||
}, TypeError);
|
||||
|
||||
assert.throws(function() {
|
||||
Buffer.compare(fb, Buffer.alloc(0));
|
||||
}, TypeError);
|
||||
|
||||
assert.throws(function() {
|
||||
fb.write('foo');
|
||||
}, TypeError);
|
||||
|
||||
assert.throws(function() {
|
||||
Buffer.concat([fb, fb]);
|
||||
}, TypeError);
|
||||
|
||||
assert.throws(function() {
|
||||
fb.toString();
|
||||
}, TypeError);
|
||||
|
||||
assert.throws(function() {
|
||||
fb.equals(Buffer.alloc(0));
|
||||
}, TypeError);
|
||||
|
||||
assert.throws(function() {
|
||||
fb.indexOf(5);
|
||||
}, TypeError);
|
||||
|
||||
assert.throws(function() {
|
||||
fb.readFloatLE(0);
|
||||
}, TypeError);
|
||||
|
||||
assert.throws(function() {
|
||||
fb.writeFloatLE(0);
|
||||
}, TypeError);
|
||||
|
||||
assert.throws(function() {
|
||||
fb.fill(0);
|
||||
}, TypeError);
|
74
cli/tests/node_compat/test/parallel/test-buffer-from.js
Normal file
74
cli/tests/node_compat/test/parallel/test-buffer-from.js
Normal file
|
@ -0,0 +1,74 @@
|
|||
// 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
|
||||
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
const { deepStrictEqual, throws } = require('assert');
|
||||
const { runInNewContext } = require('vm');
|
||||
|
||||
const checkString = 'test';
|
||||
|
||||
const check = Buffer.from(checkString);
|
||||
|
||||
class MyString extends String {
|
||||
constructor() {
|
||||
super(checkString);
|
||||
}
|
||||
}
|
||||
|
||||
class MyPrimitive {
|
||||
[Symbol.toPrimitive]() {
|
||||
return checkString;
|
||||
}
|
||||
}
|
||||
|
||||
class MyBadPrimitive {
|
||||
[Symbol.toPrimitive]() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
deepStrictEqual(Buffer.from(new String(checkString)), check);
|
||||
deepStrictEqual(Buffer.from(new MyString()), check);
|
||||
deepStrictEqual(Buffer.from(new MyPrimitive()), check);
|
||||
|
||||
// TODO(Soremwar)
|
||||
// Enable once again when vm works correctly
|
||||
// deepStrictEqual(
|
||||
// Buffer.from(runInNewContext('new String(checkString)', { checkString })),
|
||||
// check
|
||||
// );
|
||||
|
||||
[
|
||||
{},
|
||||
new Boolean(true),
|
||||
{ valueOf() { return null; } },
|
||||
{ valueOf() { return undefined; } },
|
||||
{ valueOf: null },
|
||||
Object.create(null),
|
||||
new Number(true),
|
||||
new MyBadPrimitive(),
|
||||
Symbol(),
|
||||
5n,
|
||||
(one, two, three) => {},
|
||||
undefined,
|
||||
null,
|
||||
].forEach((input) => {
|
||||
const errObj = {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
name: 'TypeError',
|
||||
message: 'The first argument must be of type string or an instance of ' +
|
||||
'Buffer, ArrayBuffer, or Array or an Array-like Object.' +
|
||||
common.invalidArgTypeHelper(input)
|
||||
};
|
||||
throws(() => Buffer.from(input), errObj);
|
||||
throws(() => Buffer.from(input, 'hex'), errObj);
|
||||
});
|
||||
|
||||
Buffer.allocUnsafe(10); // Should not throw.
|
||||
Buffer.from('deadbeaf', 'hex'); // Should not throw.
|
317
cli/tests/node_compat/test/parallel/test-buffer-includes.js
Normal file
317
cli/tests/node_compat/test/parallel/test-buffer-includes.js
Normal file
|
@ -0,0 +1,317 @@
|
|||
// 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
|
||||
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
const b = Buffer.from('abcdef');
|
||||
const buf_a = Buffer.from('a');
|
||||
const buf_bc = Buffer.from('bc');
|
||||
const buf_f = Buffer.from('f');
|
||||
const buf_z = Buffer.from('z');
|
||||
const buf_empty = Buffer.from('');
|
||||
|
||||
assert(b.includes('a'));
|
||||
assert(!b.includes('a', 1));
|
||||
assert(!b.includes('a', -1));
|
||||
assert(!b.includes('a', -4));
|
||||
assert(b.includes('a', -b.length));
|
||||
assert(b.includes('a', NaN));
|
||||
assert(b.includes('a', -Infinity));
|
||||
assert(!b.includes('a', Infinity));
|
||||
assert(b.includes('bc'));
|
||||
assert(!b.includes('bc', 2));
|
||||
assert(!b.includes('bc', -1));
|
||||
assert(!b.includes('bc', -3));
|
||||
assert(b.includes('bc', -5));
|
||||
assert(b.includes('bc', NaN));
|
||||
assert(b.includes('bc', -Infinity));
|
||||
assert(!b.includes('bc', Infinity));
|
||||
assert(b.includes('f'), b.length - 1);
|
||||
assert(!b.includes('z'));
|
||||
assert(b.includes(''));
|
||||
assert(b.includes('', 1));
|
||||
assert(b.includes('', b.length + 1));
|
||||
assert(b.includes('', Infinity));
|
||||
assert(b.includes(buf_a));
|
||||
assert(!b.includes(buf_a, 1));
|
||||
assert(!b.includes(buf_a, -1));
|
||||
assert(!b.includes(buf_a, -4));
|
||||
assert(b.includes(buf_a, -b.length));
|
||||
assert(b.includes(buf_a, NaN));
|
||||
assert(b.includes(buf_a, -Infinity));
|
||||
assert(!b.includes(buf_a, Infinity));
|
||||
assert(b.includes(buf_bc));
|
||||
assert(!b.includes(buf_bc, 2));
|
||||
assert(!b.includes(buf_bc, -1));
|
||||
assert(!b.includes(buf_bc, -3));
|
||||
assert(b.includes(buf_bc, -5));
|
||||
assert(b.includes(buf_bc, NaN));
|
||||
assert(b.includes(buf_bc, -Infinity));
|
||||
assert(!b.includes(buf_bc, Infinity));
|
||||
assert(b.includes(buf_f), b.length - 1);
|
||||
assert(!b.includes(buf_z));
|
||||
assert(b.includes(buf_empty));
|
||||
assert(b.includes(buf_empty, 1));
|
||||
assert(b.includes(buf_empty, b.length + 1));
|
||||
assert(b.includes(buf_empty, Infinity));
|
||||
assert(b.includes(0x61));
|
||||
assert(!b.includes(0x61, 1));
|
||||
assert(!b.includes(0x61, -1));
|
||||
assert(!b.includes(0x61, -4));
|
||||
assert(b.includes(0x61, -b.length));
|
||||
assert(b.includes(0x61, NaN));
|
||||
assert(b.includes(0x61, -Infinity));
|
||||
assert(!b.includes(0x61, Infinity));
|
||||
assert(!b.includes(0x0));
|
||||
|
||||
// test offsets
|
||||
assert(b.includes('d', 2));
|
||||
assert(b.includes('f', 5));
|
||||
assert(b.includes('f', -1));
|
||||
assert(!b.includes('f', 6));
|
||||
|
||||
assert(b.includes(Buffer.from('d'), 2));
|
||||
assert(b.includes(Buffer.from('f'), 5));
|
||||
assert(b.includes(Buffer.from('f'), -1));
|
||||
assert(!b.includes(Buffer.from('f'), 6));
|
||||
|
||||
// TODO(Soremwar)
|
||||
// Enable again once encoding is taking into account when evaluating indexOf
|
||||
// assert(!Buffer.from('ff').includes(Buffer.from('f'), 1, 'ucs2'));
|
||||
|
||||
// test hex encoding
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('hex'), 'hex')
|
||||
.includes('64', 0, 'hex'),
|
||||
true
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('hex'), 'hex')
|
||||
.includes(Buffer.from('64', 'hex'), 0, 'hex'),
|
||||
true
|
||||
);
|
||||
|
||||
// Test base64 encoding
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('base64'), 'base64')
|
||||
.includes('ZA==', 0, 'base64'),
|
||||
true
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('base64'), 'base64')
|
||||
.includes(Buffer.from('ZA==', 'base64'), 0, 'base64'),
|
||||
true
|
||||
);
|
||||
|
||||
// test ascii encoding
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('ascii'), 'ascii')
|
||||
.includes('d', 0, 'ascii'),
|
||||
true
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('ascii'), 'ascii')
|
||||
.includes(Buffer.from('d', 'ascii'), 0, 'ascii'),
|
||||
true
|
||||
);
|
||||
|
||||
// Test latin1 encoding
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('latin1'), 'latin1')
|
||||
.includes('d', 0, 'latin1'),
|
||||
true
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('latin1'), 'latin1')
|
||||
.includes(Buffer.from('d', 'latin1'), 0, 'latin1'),
|
||||
true
|
||||
);
|
||||
|
||||
// Test binary encoding
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('binary'), 'binary')
|
||||
.includes('d', 0, 'binary'),
|
||||
true
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('binary'), 'binary')
|
||||
.includes(Buffer.from('d', 'binary'), 0, 'binary'),
|
||||
true
|
||||
);
|
||||
|
||||
|
||||
// test ucs2 encoding
|
||||
let twoByteString = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'ucs2');
|
||||
|
||||
assert(twoByteString.includes('\u0395', 4, 'ucs2'));
|
||||
assert(twoByteString.includes('\u03a3', -4, 'ucs2'));
|
||||
assert(twoByteString.includes('\u03a3', -6, 'ucs2'));
|
||||
assert(twoByteString.includes(
|
||||
Buffer.from('\u03a3', 'ucs2'), -6, 'ucs2'));
|
||||
assert(!twoByteString.includes('\u03a3', -2, 'ucs2'));
|
||||
|
||||
const mixedByteStringUcs2 =
|
||||
Buffer.from('\u039a\u0391abc\u03a3\u03a3\u0395', 'ucs2');
|
||||
assert(mixedByteStringUcs2.includes('bc', 0, 'ucs2'));
|
||||
assert(mixedByteStringUcs2.includes('\u03a3', 0, 'ucs2'));
|
||||
assert(!mixedByteStringUcs2.includes('\u0396', 0, 'ucs2'));
|
||||
|
||||
assert.ok(
|
||||
mixedByteStringUcs2.includes(Buffer.from('bc', 'ucs2'), 0, 'ucs2'));
|
||||
assert.ok(
|
||||
mixedByteStringUcs2.includes(Buffer.from('\u03a3', 'ucs2'), 0, 'ucs2'));
|
||||
assert.ok(
|
||||
!mixedByteStringUcs2.includes(Buffer.from('\u0396', 'ucs2'), 0, 'ucs2'));
|
||||
|
||||
twoByteString = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'ucs2');
|
||||
|
||||
// Test single char pattern
|
||||
assert(twoByteString.includes('\u039a', 0, 'ucs2'));
|
||||
assert(twoByteString.includes('\u0391', 0, 'ucs2'), 'Alpha');
|
||||
assert(twoByteString.includes('\u03a3', 0, 'ucs2'), 'First Sigma');
|
||||
assert(twoByteString.includes('\u03a3', 6, 'ucs2'), 'Second Sigma');
|
||||
assert(twoByteString.includes('\u0395', 0, 'ucs2'), 'Epsilon');
|
||||
assert(!twoByteString.includes('\u0392', 0, 'ucs2'), 'Not beta');
|
||||
|
||||
// Test multi-char pattern
|
||||
assert(twoByteString.includes('\u039a\u0391', 0, 'ucs2'), 'Lambda Alpha');
|
||||
assert(twoByteString.includes('\u0391\u03a3', 0, 'ucs2'), 'Alpha Sigma');
|
||||
assert(twoByteString.includes('\u03a3\u03a3', 0, 'ucs2'), 'Sigma Sigma');
|
||||
assert(twoByteString.includes('\u03a3\u0395', 0, 'ucs2'), 'Sigma Epsilon');
|
||||
|
||||
const mixedByteStringUtf8 = Buffer.from('\u039a\u0391abc\u03a3\u03a3\u0395');
|
||||
assert(mixedByteStringUtf8.includes('bc'));
|
||||
assert(mixedByteStringUtf8.includes('bc', 5));
|
||||
assert(mixedByteStringUtf8.includes('bc', -8));
|
||||
assert(mixedByteStringUtf8.includes('\u03a3'));
|
||||
assert(!mixedByteStringUtf8.includes('\u0396'));
|
||||
|
||||
|
||||
// Test complex string includes algorithms. Only trigger for long strings.
|
||||
// Long string that isn't a simple repeat of a shorter string.
|
||||
let longString = 'A';
|
||||
for (let i = 66; i < 76; i++) { // from 'B' to 'K'
|
||||
longString = longString + String.fromCharCode(i) + longString;
|
||||
}
|
||||
|
||||
const longBufferString = Buffer.from(longString);
|
||||
|
||||
// Pattern of 15 chars, repeated every 16 chars in long
|
||||
let pattern = 'ABACABADABACABA';
|
||||
for (let i = 0; i < longBufferString.length - pattern.length; i += 7) {
|
||||
const includes = longBufferString.includes(pattern, i);
|
||||
assert(includes, `Long ABACABA...-string at index ${i}`);
|
||||
}
|
||||
assert(longBufferString.includes('AJABACA'), 'Long AJABACA, First J');
|
||||
assert(longBufferString.includes('AJABACA', 511), 'Long AJABACA, Second J');
|
||||
|
||||
pattern = 'JABACABADABACABA';
|
||||
assert(longBufferString.includes(pattern), 'Long JABACABA..., First J');
|
||||
assert(longBufferString.includes(pattern, 512), 'Long JABACABA..., Second J');
|
||||
|
||||
// Search for a non-ASCII string in a pure ASCII string.
|
||||
const asciiString = Buffer.from(
|
||||
'arglebargleglopglyfarglebargleglopglyfarglebargleglopglyf');
|
||||
assert(!asciiString.includes('\x2061'));
|
||||
assert(asciiString.includes('leb', 0));
|
||||
|
||||
// Search in string containing many non-ASCII chars.
|
||||
const allCodePoints = [];
|
||||
for (let i = 0; i < 65534; i++) allCodePoints[i] = i;
|
||||
const allCharsString = String.fromCharCode.apply(String, allCodePoints) +
|
||||
String.fromCharCode(65534, 65535);
|
||||
const allCharsBufferUtf8 = Buffer.from(allCharsString);
|
||||
const allCharsBufferUcs2 = Buffer.from(allCharsString, 'ucs2');
|
||||
|
||||
// Search for string long enough to trigger complex search with ASCII pattern
|
||||
// and UC16 subject.
|
||||
assert(!allCharsBufferUtf8.includes('notfound'));
|
||||
assert(!allCharsBufferUcs2.includes('notfound'));
|
||||
|
||||
// Find substrings in Utf8.
|
||||
let lengths = [1, 3, 15]; // Single char, simple and complex.
|
||||
let indices = [0x5, 0x60, 0x400, 0x680, 0x7ee, 0xFF02, 0x16610, 0x2f77b];
|
||||
for (let lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) {
|
||||
for (let i = 0; i < indices.length; i++) {
|
||||
const index = indices[i];
|
||||
let length = lengths[lengthIndex];
|
||||
|
||||
if (index + length > 0x7F) {
|
||||
length = 2 * length;
|
||||
}
|
||||
|
||||
if (index + length > 0x7FF) {
|
||||
length = 3 * length;
|
||||
}
|
||||
|
||||
if (index + length > 0xFFFF) {
|
||||
length = 4 * length;
|
||||
}
|
||||
|
||||
const patternBufferUtf8 = allCharsBufferUtf8.slice(index, index + length);
|
||||
assert(index, allCharsBufferUtf8.includes(patternBufferUtf8));
|
||||
|
||||
const patternStringUtf8 = patternBufferUtf8.toString();
|
||||
assert(index, allCharsBufferUtf8.includes(patternStringUtf8));
|
||||
}
|
||||
}
|
||||
|
||||
// Find substrings in Usc2.
|
||||
lengths = [2, 4, 16]; // Single char, simple and complex.
|
||||
indices = [0x5, 0x65, 0x105, 0x205, 0x285, 0x2005, 0x2085, 0xfff0];
|
||||
for (let lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) {
|
||||
for (let i = 0; i < indices.length; i++) {
|
||||
const index = indices[i] * 2;
|
||||
const length = lengths[lengthIndex];
|
||||
|
||||
const patternBufferUcs2 =
|
||||
allCharsBufferUcs2.slice(index, index + length);
|
||||
assert.ok(
|
||||
allCharsBufferUcs2.includes(patternBufferUcs2, 0, 'ucs2'));
|
||||
|
||||
const patternStringUcs2 = patternBufferUcs2.toString('ucs2');
|
||||
assert.ok(
|
||||
allCharsBufferUcs2.includes(patternStringUcs2, 0, 'ucs2'));
|
||||
}
|
||||
}
|
||||
|
||||
[
|
||||
() => { },
|
||||
{},
|
||||
[],
|
||||
].forEach((val) => {
|
||||
assert.throws(
|
||||
() => b.includes(val),
|
||||
{
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
name: 'TypeError',
|
||||
message: 'The "value" argument must be one of type number or string ' +
|
||||
'or an instance of Buffer or Uint8Array.' +
|
||||
common.invalidArgTypeHelper(val)
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
// Test truncation of Number arguments to uint8
|
||||
// TODO(Soremwar)
|
||||
// Enable once multi byte number search is available
|
||||
// {
|
||||
// const buf = Buffer.from('this is a test');
|
||||
// assert.ok(buf.includes(0x6973));
|
||||
// assert.ok(buf.includes(0x697320));
|
||||
// assert.ok(buf.includes(0x69732069));
|
||||
// assert.ok(buf.includes(0x697374657374));
|
||||
// assert.ok(buf.includes(0x69737374));
|
||||
// assert.ok(buf.includes(0x69737465));
|
||||
// assert.ok(buf.includes(0x69737465));
|
||||
// assert.ok(buf.includes(-140));
|
||||
// assert.ok(buf.includes(-152));
|
||||
// assert.ok(!buf.includes(0xff));
|
||||
// assert.ok(!buf.includes(0xffff));
|
||||
// }
|
646
cli/tests/node_compat/test/parallel/test-buffer-indexof.js
Normal file
646
cli/tests/node_compat/test/parallel/test-buffer-indexof.js
Normal file
|
@ -0,0 +1,646 @@
|
|||
// 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
|
||||
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
const b = Buffer.from('abcdef');
|
||||
const buf_a = Buffer.from('a');
|
||||
const buf_bc = Buffer.from('bc');
|
||||
const buf_f = Buffer.from('f');
|
||||
const buf_z = Buffer.from('z');
|
||||
const buf_empty = Buffer.from('');
|
||||
|
||||
const s = 'abcdef';
|
||||
|
||||
assert.strictEqual(b.indexOf('a'), 0);
|
||||
assert.strictEqual(b.indexOf('a', 1), -1);
|
||||
assert.strictEqual(b.indexOf('a', -1), -1);
|
||||
assert.strictEqual(b.indexOf('a', -4), -1);
|
||||
assert.strictEqual(b.indexOf('a', -b.length), 0);
|
||||
assert.strictEqual(b.indexOf('a', NaN), 0);
|
||||
assert.strictEqual(b.indexOf('a', -Infinity), 0);
|
||||
assert.strictEqual(b.indexOf('a', Infinity), -1);
|
||||
assert.strictEqual(b.indexOf('bc'), 1);
|
||||
assert.strictEqual(b.indexOf('bc', 2), -1);
|
||||
assert.strictEqual(b.indexOf('bc', -1), -1);
|
||||
assert.strictEqual(b.indexOf('bc', -3), -1);
|
||||
assert.strictEqual(b.indexOf('bc', -5), 1);
|
||||
assert.strictEqual(b.indexOf('bc', NaN), 1);
|
||||
assert.strictEqual(b.indexOf('bc', -Infinity), 1);
|
||||
assert.strictEqual(b.indexOf('bc', Infinity), -1);
|
||||
assert.strictEqual(b.indexOf('f'), b.length - 1);
|
||||
assert.strictEqual(b.indexOf('z'), -1);
|
||||
assert.strictEqual(b.indexOf(''), 0);
|
||||
assert.strictEqual(b.indexOf('', 1), 1);
|
||||
assert.strictEqual(b.indexOf('', b.length + 1), b.length);
|
||||
assert.strictEqual(b.indexOf('', Infinity), b.length);
|
||||
assert.strictEqual(b.indexOf(buf_a), 0);
|
||||
assert.strictEqual(b.indexOf(buf_a, 1), -1);
|
||||
assert.strictEqual(b.indexOf(buf_a, -1), -1);
|
||||
assert.strictEqual(b.indexOf(buf_a, -4), -1);
|
||||
assert.strictEqual(b.indexOf(buf_a, -b.length), 0);
|
||||
assert.strictEqual(b.indexOf(buf_a, NaN), 0);
|
||||
assert.strictEqual(b.indexOf(buf_a, -Infinity), 0);
|
||||
assert.strictEqual(b.indexOf(buf_a, Infinity), -1);
|
||||
assert.strictEqual(b.indexOf(buf_bc), 1);
|
||||
assert.strictEqual(b.indexOf(buf_bc, 2), -1);
|
||||
assert.strictEqual(b.indexOf(buf_bc, -1), -1);
|
||||
assert.strictEqual(b.indexOf(buf_bc, -3), -1);
|
||||
assert.strictEqual(b.indexOf(buf_bc, -5), 1);
|
||||
assert.strictEqual(b.indexOf(buf_bc, NaN), 1);
|
||||
assert.strictEqual(b.indexOf(buf_bc, -Infinity), 1);
|
||||
assert.strictEqual(b.indexOf(buf_bc, Infinity), -1);
|
||||
assert.strictEqual(b.indexOf(buf_f), b.length - 1);
|
||||
assert.strictEqual(b.indexOf(buf_z), -1);
|
||||
assert.strictEqual(b.indexOf(buf_empty), 0);
|
||||
assert.strictEqual(b.indexOf(buf_empty, 1), 1);
|
||||
assert.strictEqual(b.indexOf(buf_empty, b.length + 1), b.length);
|
||||
assert.strictEqual(b.indexOf(buf_empty, Infinity), b.length);
|
||||
assert.strictEqual(b.indexOf(0x61), 0);
|
||||
assert.strictEqual(b.indexOf(0x61, 1), -1);
|
||||
assert.strictEqual(b.indexOf(0x61, -1), -1);
|
||||
assert.strictEqual(b.indexOf(0x61, -4), -1);
|
||||
assert.strictEqual(b.indexOf(0x61, -b.length), 0);
|
||||
assert.strictEqual(b.indexOf(0x61, NaN), 0);
|
||||
assert.strictEqual(b.indexOf(0x61, -Infinity), 0);
|
||||
assert.strictEqual(b.indexOf(0x61, Infinity), -1);
|
||||
assert.strictEqual(b.indexOf(0x0), -1);
|
||||
|
||||
// test offsets
|
||||
assert.strictEqual(b.indexOf('d', 2), 3);
|
||||
assert.strictEqual(b.indexOf('f', 5), 5);
|
||||
assert.strictEqual(b.indexOf('f', -1), 5);
|
||||
assert.strictEqual(b.indexOf('f', 6), -1);
|
||||
|
||||
assert.strictEqual(b.indexOf(Buffer.from('d'), 2), 3);
|
||||
assert.strictEqual(b.indexOf(Buffer.from('f'), 5), 5);
|
||||
assert.strictEqual(b.indexOf(Buffer.from('f'), -1), 5);
|
||||
assert.strictEqual(b.indexOf(Buffer.from('f'), 6), -1);
|
||||
|
||||
// TODO(Soremwar)
|
||||
// Enable again once encoding is taking into account when evaluating indexOf
|
||||
// assert.strictEqual(Buffer.from('ff').indexOf(Buffer.from('f'), 1, 'ucs2'), -1);
|
||||
|
||||
// Test invalid and uppercase encoding
|
||||
assert.strictEqual(b.indexOf('b', 'utf8'), 1);
|
||||
assert.strictEqual(b.indexOf('b', 'UTF8'), 1);
|
||||
assert.strictEqual(b.indexOf('62', 'HEX'), 1);
|
||||
assert.throws(() => b.indexOf('bad', 'enc'), /Unknown encoding: enc/);
|
||||
|
||||
// test hex encoding
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('hex'), 'hex')
|
||||
.indexOf('64', 0, 'hex'),
|
||||
3
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('hex'), 'hex')
|
||||
.indexOf(Buffer.from('64', 'hex'), 0, 'hex'),
|
||||
3
|
||||
);
|
||||
|
||||
// Test base64 encoding
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('base64'), 'base64')
|
||||
.indexOf('ZA==', 0, 'base64'),
|
||||
3
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('base64'), 'base64')
|
||||
.indexOf(Buffer.from('ZA==', 'base64'), 0, 'base64'),
|
||||
3
|
||||
);
|
||||
|
||||
// Test base64url encoding
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('base64url'), 'base64url')
|
||||
.indexOf('ZA==', 0, 'base64url'),
|
||||
3
|
||||
);
|
||||
|
||||
// test ascii encoding
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('ascii'), 'ascii')
|
||||
.indexOf('d', 0, 'ascii'),
|
||||
3
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('ascii'), 'ascii')
|
||||
.indexOf(Buffer.from('d', 'ascii'), 0, 'ascii'),
|
||||
3
|
||||
);
|
||||
|
||||
// Test latin1 encoding
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('latin1'), 'latin1')
|
||||
.indexOf('d', 0, 'latin1'),
|
||||
3
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('latin1'), 'latin1')
|
||||
.indexOf(Buffer.from('d', 'latin1'), 0, 'latin1'),
|
||||
3
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from('aa\u00e8aa', 'latin1')
|
||||
.indexOf('\u00e8', 'latin1'),
|
||||
2
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from('\u00e8', 'latin1')
|
||||
.indexOf('\u00e8', 'latin1'),
|
||||
0
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from('\u00e8', 'latin1')
|
||||
.indexOf(Buffer.from('\u00e8', 'latin1'), 'latin1'),
|
||||
0
|
||||
);
|
||||
|
||||
// Test binary encoding
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('binary'), 'binary')
|
||||
.indexOf('d', 0, 'binary'),
|
||||
3
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('binary'), 'binary')
|
||||
.indexOf(Buffer.from('d', 'binary'), 0, 'binary'),
|
||||
3
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from('aa\u00e8aa', 'binary')
|
||||
.indexOf('\u00e8', 'binary'),
|
||||
2
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from('\u00e8', 'binary')
|
||||
.indexOf('\u00e8', 'binary'),
|
||||
0
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from('\u00e8', 'binary')
|
||||
.indexOf(Buffer.from('\u00e8', 'binary'), 'binary'),
|
||||
0
|
||||
);
|
||||
|
||||
|
||||
// Test optional offset with passed encoding
|
||||
assert.strictEqual(Buffer.from('aaaa0').indexOf('30', 'hex'), 4);
|
||||
assert.strictEqual(Buffer.from('aaaa00a').indexOf('3030', 'hex'), 4);
|
||||
|
||||
{
|
||||
// Test usc2 and utf16le encoding
|
||||
['ucs2', 'utf16le'].forEach((encoding) => {
|
||||
const twoByteString = Buffer.from(
|
||||
'\u039a\u0391\u03a3\u03a3\u0395', encoding);
|
||||
|
||||
assert.strictEqual(twoByteString.indexOf('\u0395', 4, encoding), 8);
|
||||
assert.strictEqual(twoByteString.indexOf('\u03a3', -4, encoding), 6);
|
||||
assert.strictEqual(twoByteString.indexOf('\u03a3', -6, encoding), 4);
|
||||
assert.strictEqual(twoByteString.indexOf(
|
||||
Buffer.from('\u03a3', encoding), -6, encoding), 4);
|
||||
assert.strictEqual(-1, twoByteString.indexOf('\u03a3', -2, encoding));
|
||||
});
|
||||
}
|
||||
|
||||
const mixedByteStringUcs2 =
|
||||
Buffer.from('\u039a\u0391abc\u03a3\u03a3\u0395', 'ucs2');
|
||||
assert.strictEqual(mixedByteStringUcs2.indexOf('bc', 0, 'ucs2'), 6);
|
||||
assert.strictEqual(mixedByteStringUcs2.indexOf('\u03a3', 0, 'ucs2'), 10);
|
||||
assert.strictEqual(-1, mixedByteStringUcs2.indexOf('\u0396', 0, 'ucs2'));
|
||||
|
||||
assert.strictEqual(
|
||||
mixedByteStringUcs2.indexOf(Buffer.from('bc', 'ucs2'), 0, 'ucs2'), 6);
|
||||
assert.strictEqual(
|
||||
mixedByteStringUcs2.indexOf(Buffer.from('\u03a3', 'ucs2'), 0, 'ucs2'), 10);
|
||||
assert.strictEqual(
|
||||
-1, mixedByteStringUcs2.indexOf(Buffer.from('\u0396', 'ucs2'), 0, 'ucs2'));
|
||||
|
||||
{
|
||||
const twoByteString = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'ucs2');
|
||||
|
||||
// Test single char pattern
|
||||
assert.strictEqual(twoByteString.indexOf('\u039a', 0, 'ucs2'), 0);
|
||||
let index = twoByteString.indexOf('\u0391', 0, 'ucs2');
|
||||
assert.strictEqual(index, 2, `Alpha - at index ${index}`);
|
||||
index = twoByteString.indexOf('\u03a3', 0, 'ucs2');
|
||||
assert.strictEqual(index, 4, `First Sigma - at index ${index}`);
|
||||
index = twoByteString.indexOf('\u03a3', 6, 'ucs2');
|
||||
assert.strictEqual(index, 6, `Second Sigma - at index ${index}`);
|
||||
index = twoByteString.indexOf('\u0395', 0, 'ucs2');
|
||||
assert.strictEqual(index, 8, `Epsilon - at index ${index}`);
|
||||
index = twoByteString.indexOf('\u0392', 0, 'ucs2');
|
||||
assert.strictEqual(-1, index, `Not beta - at index ${index}`);
|
||||
|
||||
// Test multi-char pattern
|
||||
index = twoByteString.indexOf('\u039a\u0391', 0, 'ucs2');
|
||||
assert.strictEqual(index, 0, `Lambda Alpha - at index ${index}`);
|
||||
index = twoByteString.indexOf('\u0391\u03a3', 0, 'ucs2');
|
||||
assert.strictEqual(index, 2, `Alpha Sigma - at index ${index}`);
|
||||
index = twoByteString.indexOf('\u03a3\u03a3', 0, 'ucs2');
|
||||
assert.strictEqual(index, 4, `Sigma Sigma - at index ${index}`);
|
||||
index = twoByteString.indexOf('\u03a3\u0395', 0, 'ucs2');
|
||||
assert.strictEqual(index, 6, `Sigma Epsilon - at index ${index}`);
|
||||
}
|
||||
|
||||
const mixedByteStringUtf8 = Buffer.from('\u039a\u0391abc\u03a3\u03a3\u0395');
|
||||
assert.strictEqual(mixedByteStringUtf8.indexOf('bc'), 5);
|
||||
assert.strictEqual(mixedByteStringUtf8.indexOf('bc', 5), 5);
|
||||
assert.strictEqual(mixedByteStringUtf8.indexOf('bc', -8), 5);
|
||||
assert.strictEqual(mixedByteStringUtf8.indexOf('\u03a3'), 7);
|
||||
assert.strictEqual(mixedByteStringUtf8.indexOf('\u0396'), -1);
|
||||
|
||||
|
||||
// Test complex string indexOf algorithms. Only trigger for long strings.
|
||||
// Long string that isn't a simple repeat of a shorter string.
|
||||
let longString = 'A';
|
||||
for (let i = 66; i < 76; i++) { // from 'B' to 'K'
|
||||
longString = longString + String.fromCharCode(i) + longString;
|
||||
}
|
||||
|
||||
const longBufferString = Buffer.from(longString);
|
||||
|
||||
// Pattern of 15 chars, repeated every 16 chars in long
|
||||
let pattern = 'ABACABADABACABA';
|
||||
for (let i = 0; i < longBufferString.length - pattern.length; i += 7) {
|
||||
const index = longBufferString.indexOf(pattern, i);
|
||||
assert.strictEqual((i + 15) & ~0xf, index,
|
||||
`Long ABACABA...-string at index ${i}`);
|
||||
}
|
||||
|
||||
let index = longBufferString.indexOf('AJABACA');
|
||||
assert.strictEqual(index, 510, `Long AJABACA, First J - at index ${index}`);
|
||||
index = longBufferString.indexOf('AJABACA', 511);
|
||||
assert.strictEqual(index, 1534, `Long AJABACA, Second J - at index ${index}`);
|
||||
|
||||
pattern = 'JABACABADABACABA';
|
||||
index = longBufferString.indexOf(pattern);
|
||||
assert.strictEqual(index, 511, `Long JABACABA..., First J - at index ${index}`);
|
||||
index = longBufferString.indexOf(pattern, 512);
|
||||
assert.strictEqual(
|
||||
index, 1535, `Long JABACABA..., Second J - at index ${index}`);
|
||||
|
||||
// Search for a non-ASCII string in a pure ASCII string.
|
||||
const asciiString = Buffer.from(
|
||||
'arglebargleglopglyfarglebargleglopglyfarglebargleglopglyf');
|
||||
assert.strictEqual(-1, asciiString.indexOf('\x2061'));
|
||||
assert.strictEqual(asciiString.indexOf('leb', 0), 3);
|
||||
|
||||
// Search in string containing many non-ASCII chars.
|
||||
const allCodePoints = [];
|
||||
for (let i = 0; i < 65534; i++) allCodePoints[i] = i;
|
||||
const allCharsString = String.fromCharCode.apply(String, allCodePoints) +
|
||||
String.fromCharCode(65534, 65535);
|
||||
const allCharsBufferUtf8 = Buffer.from(allCharsString);
|
||||
const allCharsBufferUcs2 = Buffer.from(allCharsString, 'ucs2');
|
||||
|
||||
// Search for string long enough to trigger complex search with ASCII pattern
|
||||
// and UC16 subject.
|
||||
assert.strictEqual(-1, allCharsBufferUtf8.indexOf('notfound'));
|
||||
assert.strictEqual(-1, allCharsBufferUcs2.indexOf('notfound'));
|
||||
|
||||
// Needle is longer than haystack, but only because it's encoded as UTF-16
|
||||
assert.strictEqual(Buffer.from('aaaa').indexOf('a'.repeat(4), 'ucs2'), -1);
|
||||
|
||||
assert.strictEqual(Buffer.from('aaaa').indexOf('a'.repeat(4), 'utf8'), 0);
|
||||
assert.strictEqual(Buffer.from('aaaa').indexOf('你好', 'ucs2'), -1);
|
||||
|
||||
// Haystack has odd length, but the needle is UCS2.
|
||||
assert.strictEqual(Buffer.from('aaaaa').indexOf('b', 'ucs2'), -1);
|
||||
|
||||
{
|
||||
// Find substrings in Utf8.
|
||||
const lengths = [1, 3, 15]; // Single char, simple and complex.
|
||||
const indices = [0x5, 0x60, 0x400, 0x680, 0x7ee, 0xFF02, 0x16610, 0x2f77b];
|
||||
for (let lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) {
|
||||
for (let i = 0; i < indices.length; i++) {
|
||||
const index = indices[i];
|
||||
let length = lengths[lengthIndex];
|
||||
|
||||
if (index + length > 0x7F) {
|
||||
length = 2 * length;
|
||||
}
|
||||
|
||||
if (index + length > 0x7FF) {
|
||||
length = 3 * length;
|
||||
}
|
||||
|
||||
if (index + length > 0xFFFF) {
|
||||
length = 4 * length;
|
||||
}
|
||||
|
||||
const patternBufferUtf8 = allCharsBufferUtf8.slice(index, index + length);
|
||||
assert.strictEqual(index, allCharsBufferUtf8.indexOf(patternBufferUtf8));
|
||||
|
||||
const patternStringUtf8 = patternBufferUtf8.toString();
|
||||
assert.strictEqual(index, allCharsBufferUtf8.indexOf(patternStringUtf8));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(Soremwar)
|
||||
// Enable again once encoding is taking into account when evaluating indexOf
|
||||
// {
|
||||
// // Find substrings in Usc2.
|
||||
// const lengths = [2, 4, 16]; // Single char, simple and complex.
|
||||
// const indices = [0x5, 0x65, 0x105, 0x205, 0x285, 0x2005, 0x2085, 0xfff0];
|
||||
// for (let lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) {
|
||||
// for (let i = 0; i < indices.length; i++) {
|
||||
// const index = indices[i] * 2;
|
||||
// const length = lengths[lengthIndex];
|
||||
|
||||
// const patternBufferUcs2 =
|
||||
// allCharsBufferUcs2.slice(index, index + length);
|
||||
// assert.strictEqual(
|
||||
// index, allCharsBufferUcs2.indexOf(patternBufferUcs2, 0, 'ucs2'));
|
||||
|
||||
// const patternStringUcs2 = patternBufferUcs2.toString('ucs2');
|
||||
// assert.strictEqual(
|
||||
// index, allCharsBufferUcs2.indexOf(patternStringUcs2, 0, 'ucs2'));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
[
|
||||
() => {},
|
||||
{},
|
||||
[],
|
||||
].forEach((val) => {
|
||||
assert.throws(
|
||||
() => b.indexOf(val),
|
||||
{
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
name: 'TypeError',
|
||||
message: 'The "value" argument must be one of type number or string ' +
|
||||
'or an instance of Buffer or Uint8Array.' +
|
||||
common.invalidArgTypeHelper(val)
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
// Test weird offset arguments.
|
||||
// The following offsets coerce to NaN or 0, searching the whole Buffer
|
||||
assert.strictEqual(b.indexOf('b', undefined), 1);
|
||||
assert.strictEqual(b.indexOf('b', {}), 1);
|
||||
assert.strictEqual(b.indexOf('b', 0), 1);
|
||||
assert.strictEqual(b.indexOf('b', null), 1);
|
||||
assert.strictEqual(b.indexOf('b', []), 1);
|
||||
|
||||
// The following offset coerces to 2, in other words +[2] === 2
|
||||
assert.strictEqual(b.indexOf('b', [2]), -1);
|
||||
|
||||
// Behavior should match String.indexOf()
|
||||
assert.strictEqual(
|
||||
b.indexOf('b', undefined),
|
||||
s.indexOf('b', undefined));
|
||||
assert.strictEqual(
|
||||
b.indexOf('b', {}),
|
||||
s.indexOf('b', {}));
|
||||
assert.strictEqual(
|
||||
b.indexOf('b', 0),
|
||||
s.indexOf('b', 0));
|
||||
assert.strictEqual(
|
||||
b.indexOf('b', null),
|
||||
s.indexOf('b', null));
|
||||
assert.strictEqual(
|
||||
b.indexOf('b', []),
|
||||
s.indexOf('b', []));
|
||||
assert.strictEqual(
|
||||
b.indexOf('b', [2]),
|
||||
s.indexOf('b', [2]));
|
||||
|
||||
// All code for handling encodings is shared between Buffer.indexOf and
|
||||
// Buffer.lastIndexOf, so only testing the separate lastIndexOf semantics.
|
||||
|
||||
// Test lastIndexOf basic functionality; Buffer b contains 'abcdef'.
|
||||
// lastIndexOf string:
|
||||
assert.strictEqual(b.lastIndexOf('a'), 0);
|
||||
assert.strictEqual(b.lastIndexOf('a', 1), 0);
|
||||
assert.strictEqual(b.lastIndexOf('b', 1), 1);
|
||||
assert.strictEqual(b.lastIndexOf('c', 1), -1);
|
||||
assert.strictEqual(b.lastIndexOf('a', -1), 0);
|
||||
assert.strictEqual(b.lastIndexOf('a', -4), 0);
|
||||
assert.strictEqual(b.lastIndexOf('a', -b.length), 0);
|
||||
assert.strictEqual(b.lastIndexOf('a', -b.length - 1), -1);
|
||||
assert.strictEqual(b.lastIndexOf('a', NaN), 0);
|
||||
assert.strictEqual(b.lastIndexOf('a', -Infinity), -1);
|
||||
assert.strictEqual(b.lastIndexOf('a', Infinity), 0);
|
||||
// lastIndexOf Buffer:
|
||||
assert.strictEqual(b.lastIndexOf(buf_a), 0);
|
||||
assert.strictEqual(b.lastIndexOf(buf_a, 1), 0);
|
||||
assert.strictEqual(b.lastIndexOf(buf_a, -1), 0);
|
||||
assert.strictEqual(b.lastIndexOf(buf_a, -4), 0);
|
||||
assert.strictEqual(b.lastIndexOf(buf_a, -b.length), 0);
|
||||
assert.strictEqual(b.lastIndexOf(buf_a, -b.length - 1), -1);
|
||||
assert.strictEqual(b.lastIndexOf(buf_a, NaN), 0);
|
||||
assert.strictEqual(b.lastIndexOf(buf_a, -Infinity), -1);
|
||||
assert.strictEqual(b.lastIndexOf(buf_a, Infinity), 0);
|
||||
assert.strictEqual(b.lastIndexOf(buf_bc), 1);
|
||||
assert.strictEqual(b.lastIndexOf(buf_bc, 2), 1);
|
||||
assert.strictEqual(b.lastIndexOf(buf_bc, -1), 1);
|
||||
assert.strictEqual(b.lastIndexOf(buf_bc, -3), 1);
|
||||
assert.strictEqual(b.lastIndexOf(buf_bc, -5), 1);
|
||||
assert.strictEqual(b.lastIndexOf(buf_bc, -6), -1);
|
||||
assert.strictEqual(b.lastIndexOf(buf_bc, NaN), 1);
|
||||
assert.strictEqual(b.lastIndexOf(buf_bc, -Infinity), -1);
|
||||
assert.strictEqual(b.lastIndexOf(buf_bc, Infinity), 1);
|
||||
assert.strictEqual(b.lastIndexOf(buf_f), b.length - 1);
|
||||
assert.strictEqual(b.lastIndexOf(buf_z), -1);
|
||||
assert.strictEqual(b.lastIndexOf(buf_empty), b.length);
|
||||
assert.strictEqual(b.lastIndexOf(buf_empty, 1), 1);
|
||||
assert.strictEqual(b.lastIndexOf(buf_empty, b.length + 1), b.length);
|
||||
assert.strictEqual(b.lastIndexOf(buf_empty, Infinity), b.length);
|
||||
// lastIndexOf number:
|
||||
assert.strictEqual(b.lastIndexOf(0x61), 0);
|
||||
assert.strictEqual(b.lastIndexOf(0x61, 1), 0);
|
||||
assert.strictEqual(b.lastIndexOf(0x61, -1), 0);
|
||||
assert.strictEqual(b.lastIndexOf(0x61, -4), 0);
|
||||
assert.strictEqual(b.lastIndexOf(0x61, -b.length), 0);
|
||||
assert.strictEqual(b.lastIndexOf(0x61, -b.length - 1), -1);
|
||||
assert.strictEqual(b.lastIndexOf(0x61, NaN), 0);
|
||||
assert.strictEqual(b.lastIndexOf(0x61, -Infinity), -1);
|
||||
assert.strictEqual(b.lastIndexOf(0x61, Infinity), 0);
|
||||
assert.strictEqual(b.lastIndexOf(0x0), -1);
|
||||
|
||||
// Test weird offset arguments.
|
||||
// The following offsets coerce to NaN, searching the whole Buffer
|
||||
assert.strictEqual(b.lastIndexOf('b', undefined), 1);
|
||||
assert.strictEqual(b.lastIndexOf('b', {}), 1);
|
||||
|
||||
// The following offsets coerce to 0
|
||||
assert.strictEqual(b.lastIndexOf('b', 0), -1);
|
||||
assert.strictEqual(b.lastIndexOf('b', null), -1);
|
||||
assert.strictEqual(b.lastIndexOf('b', []), -1);
|
||||
|
||||
// The following offset coerces to 2, in other words +[2] === 2
|
||||
assert.strictEqual(b.lastIndexOf('b', [2]), 1);
|
||||
|
||||
// Behavior should match String.lastIndexOf()
|
||||
assert.strictEqual(
|
||||
b.lastIndexOf('b', undefined),
|
||||
s.lastIndexOf('b', undefined));
|
||||
assert.strictEqual(
|
||||
b.lastIndexOf('b', {}),
|
||||
s.lastIndexOf('b', {}));
|
||||
assert.strictEqual(
|
||||
b.lastIndexOf('b', 0),
|
||||
s.lastIndexOf('b', 0));
|
||||
assert.strictEqual(
|
||||
b.lastIndexOf('b', null),
|
||||
s.lastIndexOf('b', null));
|
||||
assert.strictEqual(
|
||||
b.lastIndexOf('b', []),
|
||||
s.lastIndexOf('b', []));
|
||||
assert.strictEqual(
|
||||
b.lastIndexOf('b', [2]),
|
||||
s.lastIndexOf('b', [2]));
|
||||
|
||||
// Test needles longer than the haystack.
|
||||
assert.strictEqual(b.lastIndexOf('aaaaaaaaaaaaaaa', 'ucs2'), -1);
|
||||
assert.strictEqual(b.lastIndexOf('aaaaaaaaaaaaaaa', 'utf8'), -1);
|
||||
assert.strictEqual(b.lastIndexOf('aaaaaaaaaaaaaaa', 'latin1'), -1);
|
||||
assert.strictEqual(b.lastIndexOf('aaaaaaaaaaaaaaa', 'binary'), -1);
|
||||
assert.strictEqual(b.lastIndexOf(Buffer.from('aaaaaaaaaaaaaaa')), -1);
|
||||
assert.strictEqual(b.lastIndexOf('aaaaaaaaaaaaaaa', 2, 'ucs2'), -1);
|
||||
assert.strictEqual(b.lastIndexOf('aaaaaaaaaaaaaaa', 3, 'utf8'), -1);
|
||||
assert.strictEqual(b.lastIndexOf('aaaaaaaaaaaaaaa', 5, 'latin1'), -1);
|
||||
assert.strictEqual(b.lastIndexOf('aaaaaaaaaaaaaaa', 5, 'binary'), -1);
|
||||
assert.strictEqual(b.lastIndexOf(Buffer.from('aaaaaaaaaaaaaaa'), 7), -1);
|
||||
|
||||
// 你好 expands to a total of 6 bytes using UTF-8 and 4 bytes using UTF-16
|
||||
assert.strictEqual(buf_bc.lastIndexOf('你好', 'ucs2'), -1);
|
||||
assert.strictEqual(buf_bc.lastIndexOf('你好', 'utf8'), -1);
|
||||
assert.strictEqual(buf_bc.lastIndexOf('你好', 'latin1'), -1);
|
||||
assert.strictEqual(buf_bc.lastIndexOf('你好', 'binary'), -1);
|
||||
assert.strictEqual(buf_bc.lastIndexOf(Buffer.from('你好')), -1);
|
||||
assert.strictEqual(buf_bc.lastIndexOf('你好', 2, 'ucs2'), -1);
|
||||
assert.strictEqual(buf_bc.lastIndexOf('你好', 3, 'utf8'), -1);
|
||||
assert.strictEqual(buf_bc.lastIndexOf('你好', 5, 'latin1'), -1);
|
||||
assert.strictEqual(buf_bc.lastIndexOf('你好', 5, 'binary'), -1);
|
||||
assert.strictEqual(buf_bc.lastIndexOf(Buffer.from('你好'), 7), -1);
|
||||
|
||||
// Test lastIndexOf on a longer buffer:
|
||||
const bufferString = Buffer.from('a man a plan a canal panama');
|
||||
assert.strictEqual(bufferString.lastIndexOf('canal'), 15);
|
||||
assert.strictEqual(bufferString.lastIndexOf('panama'), 21);
|
||||
assert.strictEqual(bufferString.lastIndexOf('a man a plan a canal panama'), 0);
|
||||
assert.strictEqual(-1, bufferString.lastIndexOf('a man a plan a canal mexico'));
|
||||
assert.strictEqual(-1, bufferString
|
||||
.lastIndexOf('a man a plan a canal mexico city'));
|
||||
assert.strictEqual(-1, bufferString.lastIndexOf(Buffer.from('a'.repeat(1000))));
|
||||
assert.strictEqual(bufferString.lastIndexOf('a man a plan', 4), 0);
|
||||
assert.strictEqual(bufferString.lastIndexOf('a '), 13);
|
||||
assert.strictEqual(bufferString.lastIndexOf('a ', 13), 13);
|
||||
assert.strictEqual(bufferString.lastIndexOf('a ', 12), 6);
|
||||
assert.strictEqual(bufferString.lastIndexOf('a ', 5), 0);
|
||||
assert.strictEqual(bufferString.lastIndexOf('a ', -1), 13);
|
||||
assert.strictEqual(bufferString.lastIndexOf('a ', -27), 0);
|
||||
assert.strictEqual(-1, bufferString.lastIndexOf('a ', -28));
|
||||
|
||||
// Test lastIndexOf for the case that the first character can be found,
|
||||
// but in a part of the buffer that does not make search to search
|
||||
// due do length constraints.
|
||||
const abInUCS2 = Buffer.from('ab', 'ucs2');
|
||||
assert.strictEqual(-1, Buffer.from('µaaaa¶bbbb', 'latin1').lastIndexOf('µ'));
|
||||
assert.strictEqual(-1, Buffer.from('µaaaa¶bbbb', 'binary').lastIndexOf('µ'));
|
||||
assert.strictEqual(-1, Buffer.from('bc').lastIndexOf('ab'));
|
||||
assert.strictEqual(-1, Buffer.from('abc').lastIndexOf('qa'));
|
||||
assert.strictEqual(-1, Buffer.from('abcdef').lastIndexOf('qabc'));
|
||||
assert.strictEqual(-1, Buffer.from('bc').lastIndexOf(Buffer.from('ab')));
|
||||
assert.strictEqual(-1, Buffer.from('bc', 'ucs2').lastIndexOf('ab', 'ucs2'));
|
||||
assert.strictEqual(-1, Buffer.from('bc', 'ucs2').lastIndexOf(abInUCS2));
|
||||
|
||||
assert.strictEqual(Buffer.from('abc').lastIndexOf('ab'), 0);
|
||||
assert.strictEqual(Buffer.from('abc').lastIndexOf('ab', 1), 0);
|
||||
assert.strictEqual(Buffer.from('abc').lastIndexOf('ab', 2), 0);
|
||||
assert.strictEqual(Buffer.from('abc').lastIndexOf('ab', 3), 0);
|
||||
|
||||
// The above tests test the LINEAR and SINGLE-CHAR strategies.
|
||||
// Now, we test the BOYER-MOORE-HORSPOOL strategy.
|
||||
// Test lastIndexOf on a long buffer w multiple matches:
|
||||
pattern = 'JABACABADABACABA';
|
||||
assert.strictEqual(longBufferString.lastIndexOf(pattern), 1535);
|
||||
assert.strictEqual(longBufferString.lastIndexOf(pattern, 1535), 1535);
|
||||
assert.strictEqual(longBufferString.lastIndexOf(pattern, 1534), 511);
|
||||
|
||||
// Finally, give it a really long input to trigger fallback from BMH to
|
||||
// regular BOYER-MOORE (which has better worst-case complexity).
|
||||
|
||||
// Generate a really long Thue-Morse sequence of 'yolo' and 'swag',
|
||||
// "yolo swag swag yolo swag yolo yolo swag" ..., goes on for about 5MB.
|
||||
// This is hard to search because it all looks similar, but never repeats.
|
||||
|
||||
// countBits returns the number of bits in the binary representation of n.
|
||||
function countBits(n) {
|
||||
let count;
|
||||
for (count = 0; n > 0; count++) {
|
||||
n = n & (n - 1); // remove top bit
|
||||
}
|
||||
return count;
|
||||
}
|
||||
const parts = [];
|
||||
for (let i = 0; i < 1000000; i++) {
|
||||
parts.push((countBits(i) % 2 === 0) ? 'yolo' : 'swag');
|
||||
}
|
||||
const reallyLong = Buffer.from(parts.join(' '));
|
||||
assert.strictEqual(reallyLong.slice(0, 19).toString(), 'yolo swag swag yolo');
|
||||
|
||||
// Expensive reverse searches. Stress test lastIndexOf:
|
||||
pattern = reallyLong.slice(0, 100000); // First 1/50th of the pattern.
|
||||
assert.strictEqual(reallyLong.lastIndexOf(pattern), 4751360);
|
||||
assert.strictEqual(reallyLong.lastIndexOf(pattern, 4000000), 3932160);
|
||||
assert.strictEqual(reallyLong.lastIndexOf(pattern, 3000000), 2949120);
|
||||
pattern = reallyLong.slice(100000, 200000); // Second 1/50th.
|
||||
assert.strictEqual(reallyLong.lastIndexOf(pattern), 4728480);
|
||||
pattern = reallyLong.slice(0, 1000000); // First 1/5th.
|
||||
assert.strictEqual(reallyLong.lastIndexOf(pattern), 3932160);
|
||||
pattern = reallyLong.slice(0, 2000000); // first 2/5ths.
|
||||
assert.strictEqual(reallyLong.lastIndexOf(pattern), 0);
|
||||
|
||||
// Test truncation of Number arguments to uint8
|
||||
// TODO(Soremwar)
|
||||
// Enable once multi byte number search is available
|
||||
// {
|
||||
// const buf = Buffer.from('this is a test');
|
||||
// assert.strictEqual(buf.indexOf(0x6973), 3);
|
||||
// assert.strictEqual(buf.indexOf(0x697320), 4);
|
||||
// assert.strictEqual(buf.indexOf(0x69732069), 2);
|
||||
// assert.strictEqual(buf.indexOf(0x697374657374), 0);
|
||||
// assert.strictEqual(buf.indexOf(0x69737374), 0);
|
||||
// assert.strictEqual(buf.indexOf(0x69737465), 11);
|
||||
// assert.strictEqual(buf.indexOf(0x69737465), 11);
|
||||
// assert.strictEqual(buf.indexOf(-140), 0);
|
||||
// assert.strictEqual(buf.indexOf(-152), 1);
|
||||
// assert.strictEqual(buf.indexOf(0xff), -1);
|
||||
// assert.strictEqual(buf.indexOf(0xffff), -1);
|
||||
// }
|
||||
|
||||
// Test that Uint8Array arguments are okay.
|
||||
{
|
||||
const needle = new Uint8Array([ 0x66, 0x6f, 0x6f ]);
|
||||
const haystack = Buffer.from('a foo b foo');
|
||||
assert.strictEqual(haystack.indexOf(needle), 2);
|
||||
assert.strictEqual(haystack.lastIndexOf(needle), haystack.length - 3);
|
||||
}
|
||||
|
||||
// Avoid abort because of invalid usage
|
||||
// see https://github.com/nodejs/node/issues/32753
|
||||
{
|
||||
assert.throws(() => {
|
||||
const buffer = require('buffer');
|
||||
new buffer.Buffer.prototype.lastIndexOf(1, 'str');
|
||||
}, {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
name: 'TypeError',
|
||||
message: 'The "buffer" argument must be an instance of Buffer, ' +
|
||||
'TypedArray, or DataView. ' +
|
||||
'Received an instance of lastIndexOf'
|
||||
});
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
|
||||
function T(n) {
|
||||
const ui8 = new Uint8Array(n);
|
||||
Object.setPrototypeOf(ui8, T.prototype);
|
||||
return ui8;
|
||||
}
|
||||
Object.setPrototypeOf(T.prototype, Buffer.prototype);
|
||||
Object.setPrototypeOf(T, Buffer);
|
||||
|
||||
T.prototype.sum = function sum() {
|
||||
let cntr = 0;
|
||||
for (let i = 0; i < this.length; i++)
|
||||
cntr += this[i];
|
||||
return cntr;
|
||||
};
|
||||
|
||||
|
||||
const vals = [new T(4), T(4)];
|
||||
|
||||
vals.forEach(function(t) {
|
||||
assert.strictEqual(t.constructor, T);
|
||||
assert.strictEqual(Object.getPrototypeOf(t), T.prototype);
|
||||
assert.strictEqual(Object.getPrototypeOf(Object.getPrototypeOf(t)),
|
||||
Buffer.prototype);
|
||||
|
||||
t.fill(5);
|
||||
let cntr = 0;
|
||||
for (let i = 0; i < t.length; i++)
|
||||
cntr += t[i];
|
||||
assert.strictEqual(cntr, t.length * 5);
|
||||
|
||||
// Check this does not throw
|
||||
t.toString();
|
||||
});
|
|
@ -0,0 +1,45 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
[
|
||||
'hex',
|
||||
'utf8',
|
||||
'utf-8',
|
||||
'ascii',
|
||||
'latin1',
|
||||
'binary',
|
||||
'base64',
|
||||
'base64url',
|
||||
'ucs2',
|
||||
'ucs-2',
|
||||
'utf16le',
|
||||
'utf-16le',
|
||||
].forEach((enc) => {
|
||||
assert.strictEqual(Buffer.isEncoding(enc), true);
|
||||
});
|
||||
|
||||
[
|
||||
'utf9',
|
||||
'utf-7',
|
||||
'Unicode-FTW',
|
||||
'new gnu gun',
|
||||
false,
|
||||
NaN,
|
||||
{},
|
||||
Infinity,
|
||||
[],
|
||||
1,
|
||||
0,
|
||||
-1,
|
||||
].forEach((enc) => {
|
||||
assert.strictEqual(Buffer.isEncoding(enc), false);
|
||||
});
|
69
cli/tests/node_compat/test/parallel/test-buffer-iterator.js
Normal file
69
cli/tests/node_compat/test/parallel/test-buffer-iterator.js
Normal file
|
@ -0,0 +1,69 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
const buffer = Buffer.from([1, 2, 3, 4, 5]);
|
||||
let arr;
|
||||
let b;
|
||||
|
||||
// Buffers should be iterable
|
||||
|
||||
arr = [];
|
||||
|
||||
for (b of buffer)
|
||||
arr.push(b);
|
||||
|
||||
assert.deepStrictEqual(arr, [1, 2, 3, 4, 5]);
|
||||
|
||||
|
||||
// Buffer iterators should be iterable
|
||||
|
||||
arr = [];
|
||||
|
||||
for (b of buffer[Symbol.iterator]())
|
||||
arr.push(b);
|
||||
|
||||
assert.deepStrictEqual(arr, [1, 2, 3, 4, 5]);
|
||||
|
||||
|
||||
// buffer#values() should return iterator for values
|
||||
|
||||
arr = [];
|
||||
|
||||
for (b of buffer.values())
|
||||
arr.push(b);
|
||||
|
||||
assert.deepStrictEqual(arr, [1, 2, 3, 4, 5]);
|
||||
|
||||
|
||||
// buffer#keys() should return iterator for keys
|
||||
|
||||
arr = [];
|
||||
|
||||
for (b of buffer.keys())
|
||||
arr.push(b);
|
||||
|
||||
assert.deepStrictEqual(arr, [0, 1, 2, 3, 4]);
|
||||
|
||||
|
||||
// buffer#entries() should return iterator for entries
|
||||
|
||||
arr = [];
|
||||
|
||||
for (b of buffer.entries())
|
||||
arr.push(b);
|
||||
|
||||
assert.deepStrictEqual(arr, [
|
||||
[0, 1],
|
||||
[1, 2],
|
||||
[2, 3],
|
||||
[3, 4],
|
||||
[4, 5],
|
||||
]);
|
18
cli/tests/node_compat/test/parallel/test-buffer-new.js
Normal file
18
cli/tests/node_compat/test/parallel/test-buffer-new.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
assert.throws(() => new Buffer(42, 'utf8'), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
name: 'TypeError',
|
||||
message: 'The "string" argument must be of type string. Received type ' +
|
||||
'number (42)'
|
||||
});
|
|
@ -0,0 +1,45 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
const { SlowBuffer } = require('buffer');
|
||||
|
||||
const msg = {
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
name: 'RangeError',
|
||||
message: /^The argument 'size' is invalid\. Received [^"]*$/
|
||||
};
|
||||
|
||||
// Test that negative Buffer length inputs throw errors.
|
||||
|
||||
assert.throws(() => Buffer(-Buffer.poolSize), msg);
|
||||
assert.throws(() => Buffer(-100), msg);
|
||||
assert.throws(() => Buffer(-1), msg);
|
||||
assert.throws(() => Buffer(NaN), msg);
|
||||
|
||||
assert.throws(() => Buffer.alloc(-Buffer.poolSize), msg);
|
||||
assert.throws(() => Buffer.alloc(-100), msg);
|
||||
assert.throws(() => Buffer.alloc(-1), msg);
|
||||
assert.throws(() => Buffer.alloc(NaN), msg);
|
||||
|
||||
assert.throws(() => Buffer.allocUnsafe(-Buffer.poolSize), msg);
|
||||
assert.throws(() => Buffer.allocUnsafe(-100), msg);
|
||||
assert.throws(() => Buffer.allocUnsafe(-1), msg);
|
||||
assert.throws(() => Buffer.allocUnsafe(NaN), msg);
|
||||
|
||||
assert.throws(() => Buffer.allocUnsafeSlow(-Buffer.poolSize), msg);
|
||||
assert.throws(() => Buffer.allocUnsafeSlow(-100), msg);
|
||||
assert.throws(() => Buffer.allocUnsafeSlow(-1), msg);
|
||||
assert.throws(() => Buffer.allocUnsafeSlow(NaN), msg);
|
||||
|
||||
assert.throws(() => SlowBuffer(-Buffer.poolSize), msg);
|
||||
assert.throws(() => SlowBuffer(-100), msg);
|
||||
assert.throws(() => SlowBuffer(-1), msg);
|
||||
assert.throws(() => SlowBuffer(NaN), msg);
|
|
@ -0,0 +1,20 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
// Flags: --no-warnings --pending-deprecation
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
|
||||
process.on('warning', common.mustNotCall('A warning should not be emitted'));
|
||||
|
||||
// With the --pending-deprecation flag, the deprecation warning for
|
||||
// new Buffer() should not be emitted when Uint8Array methods are called.
|
||||
|
||||
Buffer.from('abc').map((i) => i);
|
||||
Buffer.from('abc').filter((i) => i);
|
||||
Buffer.from('abc').slice(1, 2);
|
|
@ -0,0 +1,14 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
|
||||
process.on('warning', common.mustNotCall());
|
||||
|
||||
Buffer.of(0, 1);
|
|
@ -0,0 +1,37 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
require('../common');
|
||||
|
||||
const assert = require('assert');
|
||||
|
||||
const buffer = require('buffer');
|
||||
const SlowBuffer = buffer.SlowBuffer;
|
||||
|
||||
const kMaxLength = buffer.kMaxLength;
|
||||
const bufferMaxSizeMsg = {
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
name: 'RangeError',
|
||||
message: /^The argument 'size' is invalid\. Received [^"]*$/
|
||||
};
|
||||
|
||||
assert.throws(() => Buffer((-1 >>> 0) + 2), bufferMaxSizeMsg);
|
||||
assert.throws(() => SlowBuffer((-1 >>> 0) + 2), bufferMaxSizeMsg);
|
||||
assert.throws(() => Buffer.alloc((-1 >>> 0) + 2), bufferMaxSizeMsg);
|
||||
assert.throws(() => Buffer.allocUnsafe((-1 >>> 0) + 2), bufferMaxSizeMsg);
|
||||
assert.throws(() => Buffer.allocUnsafeSlow((-1 >>> 0) + 2), bufferMaxSizeMsg);
|
||||
|
||||
assert.throws(() => Buffer(kMaxLength + 1), bufferMaxSizeMsg);
|
||||
assert.throws(() => SlowBuffer(kMaxLength + 1), bufferMaxSizeMsg);
|
||||
assert.throws(() => Buffer.alloc(kMaxLength + 1), bufferMaxSizeMsg);
|
||||
assert.throws(() => Buffer.allocUnsafe(kMaxLength + 1), bufferMaxSizeMsg);
|
||||
assert.throws(() => Buffer.allocUnsafeSlow(kMaxLength + 1), bufferMaxSizeMsg);
|
||||
|
||||
// issue GH-4331
|
||||
assert.throws(() => Buffer.allocUnsafe(0x100000001), bufferMaxSizeMsg);
|
||||
assert.throws(() => Buffer.allocUnsafe(0xFFFFFFFFF), bufferMaxSizeMsg);
|
|
@ -0,0 +1,28 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
// Fix for https://github.com/nodejs/node/issues/8266
|
||||
//
|
||||
// Zero length Buffer objects should expose the `buffer` property of the
|
||||
// TypedArrays, via the `parent` property.
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
// If the length of the buffer object is zero
|
||||
assert((new Buffer(0)).parent instanceof ArrayBuffer);
|
||||
|
||||
// If the length of the buffer object is equal to the underlying ArrayBuffer
|
||||
assert((new Buffer(Buffer.poolSize)).parent instanceof ArrayBuffer);
|
||||
|
||||
// Same as the previous test, but with user created buffer
|
||||
const arrayBuffer = new ArrayBuffer(0);
|
||||
assert.strictEqual(new Buffer(arrayBuffer).parent, arrayBuffer);
|
||||
assert.strictEqual(new Buffer(arrayBuffer).buffer, arrayBuffer);
|
||||
assert.strictEqual(Buffer.from(arrayBuffer).parent, arrayBuffer);
|
||||
assert.strictEqual(Buffer.from(arrayBuffer).buffer, arrayBuffer);
|
113
cli/tests/node_compat/test/parallel/test-buffer-read.js
Normal file
113
cli/tests/node_compat/test/parallel/test-buffer-read.js
Normal file
|
@ -0,0 +1,113 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
// Testing basic buffer read functions
|
||||
const buf = Buffer.from([0xa4, 0xfd, 0x48, 0xea, 0xcf, 0xff, 0xd9, 0x01, 0xde]);
|
||||
|
||||
function read(buff, funx, args, expected) {
|
||||
assert.strictEqual(buff[funx](...args), expected);
|
||||
assert.throws(
|
||||
() => buff[funx](-1, args[1]),
|
||||
{ code: 'ERR_OUT_OF_RANGE' }
|
||||
);
|
||||
}
|
||||
|
||||
// Testing basic functionality of readDoubleBE() and readDoubleLE()
|
||||
read(buf, 'readDoubleBE', [1], -3.1827727774563287e+295);
|
||||
read(buf, 'readDoubleLE', [1], -6.966010051009108e+144);
|
||||
|
||||
// Testing basic functionality of readFloatBE() and readFloatLE()
|
||||
read(buf, 'readFloatBE', [1], -1.6691549692541768e+37);
|
||||
read(buf, 'readFloatLE', [1], -7861303808);
|
||||
|
||||
// Testing basic functionality of readInt8()
|
||||
read(buf, 'readInt8', [1], -3);
|
||||
|
||||
// Testing basic functionality of readInt16BE() and readInt16LE()
|
||||
read(buf, 'readInt16BE', [1], -696);
|
||||
read(buf, 'readInt16LE', [1], 0x48fd);
|
||||
|
||||
// Testing basic functionality of readInt32BE() and readInt32LE()
|
||||
read(buf, 'readInt32BE', [1], -45552945);
|
||||
read(buf, 'readInt32LE', [1], -806729475);
|
||||
|
||||
// Testing basic functionality of readIntBE() and readIntLE()
|
||||
read(buf, 'readIntBE', [1, 1], -3);
|
||||
read(buf, 'readIntLE', [2, 1], 0x48);
|
||||
|
||||
// Testing basic functionality of readUInt8()
|
||||
read(buf, 'readUInt8', [1], 0xfd);
|
||||
|
||||
// Testing basic functionality of readUInt16BE() and readUInt16LE()
|
||||
read(buf, 'readUInt16BE', [2], 0x48ea);
|
||||
read(buf, 'readUInt16LE', [2], 0xea48);
|
||||
|
||||
// Testing basic functionality of readUInt32BE() and readUInt32LE()
|
||||
read(buf, 'readUInt32BE', [1], 0xfd48eacf);
|
||||
read(buf, 'readUInt32LE', [1], 0xcfea48fd);
|
||||
|
||||
// Testing basic functionality of readUIntBE() and readUIntLE()
|
||||
read(buf, 'readUIntBE', [2, 2], 0x48ea);
|
||||
read(buf, 'readUIntLE', [2, 2], 0xea48);
|
||||
|
||||
// Error name and message
|
||||
const OOR_ERROR =
|
||||
{
|
||||
name: 'RangeError'
|
||||
};
|
||||
|
||||
const OOB_ERROR =
|
||||
{
|
||||
name: 'RangeError',
|
||||
message: 'Attempt to access memory outside buffer bounds'
|
||||
};
|
||||
|
||||
// Attempt to overflow buffers, similar to previous bug in array buffers
|
||||
assert.throws(
|
||||
() => Buffer.allocUnsafe(8).readFloatBE(0xffffffff), OOR_ERROR);
|
||||
|
||||
assert.throws(
|
||||
() => Buffer.allocUnsafe(8).readFloatLE(0xffffffff), OOR_ERROR);
|
||||
|
||||
// Ensure negative values can't get past offset
|
||||
assert.throws(
|
||||
() => Buffer.allocUnsafe(8).readFloatBE(-1), OOR_ERROR);
|
||||
assert.throws(
|
||||
() => Buffer.allocUnsafe(8).readFloatLE(-1), OOR_ERROR);
|
||||
|
||||
// Offset checks
|
||||
{
|
||||
const buf = Buffer.allocUnsafe(0);
|
||||
|
||||
assert.throws(
|
||||
() => buf.readUInt8(0), OOB_ERROR);
|
||||
assert.throws(
|
||||
() => buf.readInt8(0), OOB_ERROR);
|
||||
}
|
||||
|
||||
[16, 32].forEach((bit) => {
|
||||
const buf = Buffer.allocUnsafe(bit / 8 - 1);
|
||||
[`Int${bit}B`, `Int${bit}L`, `UInt${bit}B`, `UInt${bit}L`].forEach((fn) => {
|
||||
assert.throws(
|
||||
() => buf[`read${fn}E`](0), OOB_ERROR);
|
||||
});
|
||||
});
|
||||
|
||||
[16, 32].forEach((bits) => {
|
||||
const buf = Buffer.from([0xFF, 0xFF, 0xFF, 0xFF]);
|
||||
['LE', 'BE'].forEach((endian) => {
|
||||
assert.strictEqual(buf[`readUInt${bits}${endian}`](0),
|
||||
(0xFFFFFFFF >>> (32 - bits)));
|
||||
|
||||
assert.strictEqual(buf[`readInt${bits}${endian}`](0),
|
||||
(0xFFFFFFFF >> (32 - bits)));
|
||||
});
|
||||
});
|
151
cli/tests/node_compat/test/parallel/test-buffer-readdouble.js
Normal file
151
cli/tests/node_compat/test/parallel/test-buffer-readdouble.js
Normal file
|
@ -0,0 +1,151 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
// Test (64 bit) double
|
||||
const buffer = Buffer.allocUnsafe(8);
|
||||
|
||||
buffer[0] = 0x55;
|
||||
buffer[1] = 0x55;
|
||||
buffer[2] = 0x55;
|
||||
buffer[3] = 0x55;
|
||||
buffer[4] = 0x55;
|
||||
buffer[5] = 0x55;
|
||||
buffer[6] = 0xd5;
|
||||
buffer[7] = 0x3f;
|
||||
assert.strictEqual(buffer.readDoubleBE(0), 1.1945305291680097e+103);
|
||||
assert.strictEqual(buffer.readDoubleLE(0), 0.3333333333333333);
|
||||
|
||||
buffer[0] = 1;
|
||||
buffer[1] = 0;
|
||||
buffer[2] = 0;
|
||||
buffer[3] = 0;
|
||||
buffer[4] = 0;
|
||||
buffer[5] = 0;
|
||||
buffer[6] = 0xf0;
|
||||
buffer[7] = 0x3f;
|
||||
assert.strictEqual(buffer.readDoubleBE(0), 7.291122019655968e-304);
|
||||
assert.strictEqual(buffer.readDoubleLE(0), 1.0000000000000002);
|
||||
|
||||
buffer[0] = 2;
|
||||
assert.strictEqual(buffer.readDoubleBE(0), 4.778309726801735e-299);
|
||||
assert.strictEqual(buffer.readDoubleLE(0), 1.0000000000000004);
|
||||
|
||||
buffer[0] = 1;
|
||||
buffer[6] = 0;
|
||||
buffer[7] = 0;
|
||||
// eslint-disable-next-line no-loss-of-precision
|
||||
assert.strictEqual(buffer.readDoubleBE(0), 7.291122019556398e-304);
|
||||
assert.strictEqual(buffer.readDoubleLE(0), 5e-324);
|
||||
|
||||
buffer[0] = 0xff;
|
||||
buffer[1] = 0xff;
|
||||
buffer[2] = 0xff;
|
||||
buffer[3] = 0xff;
|
||||
buffer[4] = 0xff;
|
||||
buffer[5] = 0xff;
|
||||
buffer[6] = 0x0f;
|
||||
buffer[7] = 0x00;
|
||||
assert.ok(Number.isNaN(buffer.readDoubleBE(0)));
|
||||
assert.strictEqual(buffer.readDoubleLE(0), 2.225073858507201e-308);
|
||||
|
||||
buffer[6] = 0xef;
|
||||
buffer[7] = 0x7f;
|
||||
assert.ok(Number.isNaN(buffer.readDoubleBE(0)));
|
||||
assert.strictEqual(buffer.readDoubleLE(0), 1.7976931348623157e+308);
|
||||
|
||||
buffer[0] = 0;
|
||||
buffer[1] = 0;
|
||||
buffer[2] = 0;
|
||||
buffer[3] = 0;
|
||||
buffer[4] = 0;
|
||||
buffer[5] = 0;
|
||||
buffer[6] = 0xf0;
|
||||
buffer[7] = 0x3f;
|
||||
assert.strictEqual(buffer.readDoubleBE(0), 3.03865e-319);
|
||||
assert.strictEqual(buffer.readDoubleLE(0), 1);
|
||||
|
||||
buffer[6] = 0;
|
||||
buffer[7] = 0x40;
|
||||
assert.strictEqual(buffer.readDoubleBE(0), 3.16e-322);
|
||||
assert.strictEqual(buffer.readDoubleLE(0), 2);
|
||||
|
||||
buffer[7] = 0xc0;
|
||||
assert.strictEqual(buffer.readDoubleBE(0), 9.5e-322);
|
||||
assert.strictEqual(buffer.readDoubleLE(0), -2);
|
||||
|
||||
buffer[6] = 0x10;
|
||||
buffer[7] = 0;
|
||||
assert.strictEqual(buffer.readDoubleBE(0), 2.0237e-320);
|
||||
assert.strictEqual(buffer.readDoubleLE(0), 2.2250738585072014e-308);
|
||||
|
||||
buffer[6] = 0;
|
||||
assert.strictEqual(buffer.readDoubleBE(0), 0);
|
||||
assert.strictEqual(buffer.readDoubleLE(0), 0);
|
||||
assert.ok(1 / buffer.readDoubleLE(0) >= 0);
|
||||
|
||||
buffer[7] = 0x80;
|
||||
assert.strictEqual(buffer.readDoubleBE(0), 6.3e-322);
|
||||
assert.strictEqual(buffer.readDoubleLE(0), -0);
|
||||
assert.ok(1 / buffer.readDoubleLE(0) < 0);
|
||||
|
||||
buffer[6] = 0xf0;
|
||||
buffer[7] = 0x7f;
|
||||
assert.strictEqual(buffer.readDoubleBE(0), 3.0418e-319);
|
||||
assert.strictEqual(buffer.readDoubleLE(0), Infinity);
|
||||
|
||||
buffer[7] = 0xff;
|
||||
assert.strictEqual(buffer.readDoubleBE(0), 3.04814e-319);
|
||||
assert.strictEqual(buffer.readDoubleLE(0), -Infinity);
|
||||
|
||||
['readDoubleLE', 'readDoubleBE'].forEach((fn) => {
|
||||
|
||||
// Verify that default offset works fine.
|
||||
buffer[fn](undefined);
|
||||
buffer[fn]();
|
||||
|
||||
['', '0', null, {}, [], () => {}, true, false].forEach((off) => {
|
||||
assert.throws(
|
||||
() => buffer[fn](off),
|
||||
{ code: 'ERR_INVALID_ARG_TYPE' }
|
||||
);
|
||||
});
|
||||
|
||||
[Infinity, -1, 1].forEach((offset) => {
|
||||
assert.throws(
|
||||
() => buffer[fn](offset),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: 'The value of "offset" is out of range. ' +
|
||||
`It must be >= 0 and <= 0. Received ${offset}`
|
||||
});
|
||||
});
|
||||
|
||||
assert.throws(
|
||||
() => Buffer.alloc(1)[fn](1),
|
||||
{
|
||||
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
|
||||
name: 'RangeError',
|
||||
message: 'Attempt to access memory outside buffer bounds'
|
||||
});
|
||||
|
||||
[NaN, 1.01].forEach((offset) => {
|
||||
assert.throws(
|
||||
() => buffer[fn](offset),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: 'The value of "offset" is out of range. ' +
|
||||
`It must be an integer. Received ${offset}`
|
||||
});
|
||||
});
|
||||
});
|
113
cli/tests/node_compat/test/parallel/test-buffer-readfloat.js
Normal file
113
cli/tests/node_compat/test/parallel/test-buffer-readfloat.js
Normal file
|
@ -0,0 +1,113 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
// Test 32 bit float
|
||||
const buffer = Buffer.alloc(4);
|
||||
|
||||
buffer[0] = 0;
|
||||
buffer[1] = 0;
|
||||
buffer[2] = 0x80;
|
||||
buffer[3] = 0x3f;
|
||||
assert.strictEqual(buffer.readFloatBE(0), 4.600602988224807e-41);
|
||||
assert.strictEqual(buffer.readFloatLE(0), 1);
|
||||
|
||||
buffer[0] = 0;
|
||||
buffer[1] = 0;
|
||||
buffer[2] = 0;
|
||||
buffer[3] = 0xc0;
|
||||
assert.strictEqual(buffer.readFloatBE(0), 2.6904930515036488e-43);
|
||||
assert.strictEqual(buffer.readFloatLE(0), -2);
|
||||
|
||||
buffer[0] = 0xff;
|
||||
buffer[1] = 0xff;
|
||||
buffer[2] = 0x7f;
|
||||
buffer[3] = 0x7f;
|
||||
assert.ok(Number.isNaN(buffer.readFloatBE(0)));
|
||||
assert.strictEqual(buffer.readFloatLE(0), 3.4028234663852886e+38);
|
||||
|
||||
buffer[0] = 0xab;
|
||||
buffer[1] = 0xaa;
|
||||
buffer[2] = 0xaa;
|
||||
buffer[3] = 0x3e;
|
||||
assert.strictEqual(buffer.readFloatBE(0), -1.2126478207002966e-12);
|
||||
assert.strictEqual(buffer.readFloatLE(0), 0.3333333432674408);
|
||||
|
||||
buffer[0] = 0;
|
||||
buffer[1] = 0;
|
||||
buffer[2] = 0;
|
||||
buffer[3] = 0;
|
||||
assert.strictEqual(buffer.readFloatBE(0), 0);
|
||||
assert.strictEqual(buffer.readFloatLE(0), 0);
|
||||
assert.ok(1 / buffer.readFloatLE(0) >= 0);
|
||||
|
||||
buffer[3] = 0x80;
|
||||
assert.strictEqual(buffer.readFloatBE(0), 1.793662034335766e-43);
|
||||
assert.strictEqual(buffer.readFloatLE(0), -0);
|
||||
assert.ok(1 / buffer.readFloatLE(0) < 0);
|
||||
|
||||
buffer[0] = 0;
|
||||
buffer[1] = 0;
|
||||
buffer[2] = 0x80;
|
||||
buffer[3] = 0x7f;
|
||||
assert.strictEqual(buffer.readFloatBE(0), 4.609571298396486e-41);
|
||||
assert.strictEqual(buffer.readFloatLE(0), Infinity);
|
||||
|
||||
buffer[0] = 0;
|
||||
buffer[1] = 0;
|
||||
buffer[2] = 0x80;
|
||||
buffer[3] = 0xff;
|
||||
assert.strictEqual(buffer.readFloatBE(0), 4.627507918739843e-41);
|
||||
assert.strictEqual(buffer.readFloatLE(0), -Infinity);
|
||||
|
||||
['readFloatLE', 'readFloatBE'].forEach((fn) => {
|
||||
|
||||
// Verify that default offset works fine.
|
||||
buffer[fn](undefined);
|
||||
buffer[fn]();
|
||||
|
||||
['', '0', null, {}, [], () => {}, true, false].forEach((off) => {
|
||||
assert.throws(
|
||||
() => buffer[fn](off),
|
||||
{ code: 'ERR_INVALID_ARG_TYPE' }
|
||||
);
|
||||
});
|
||||
|
||||
[Infinity, -1, 1].forEach((offset) => {
|
||||
assert.throws(
|
||||
() => buffer[fn](offset),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: 'The value of "offset" is out of range. ' +
|
||||
`It must be >= 0 and <= 0. Received ${offset}`
|
||||
});
|
||||
});
|
||||
|
||||
assert.throws(
|
||||
() => Buffer.alloc(1)[fn](1),
|
||||
{
|
||||
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
|
||||
name: 'RangeError',
|
||||
message: 'Attempt to access memory outside buffer bounds'
|
||||
});
|
||||
|
||||
[NaN, 1.01].forEach((offset) => {
|
||||
assert.throws(
|
||||
() => buffer[fn](offset),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: 'The value of "offset" is out of range. ' +
|
||||
`It must be an integer. Received ${offset}`
|
||||
});
|
||||
});
|
||||
});
|
204
cli/tests/node_compat/test/parallel/test-buffer-readint.js
Normal file
204
cli/tests/node_compat/test/parallel/test-buffer-readint.js
Normal file
|
@ -0,0 +1,204 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
// Test OOB
|
||||
{
|
||||
const buffer = Buffer.alloc(4);
|
||||
|
||||
['Int8', 'Int16BE', 'Int16LE', 'Int32BE', 'Int32LE'].forEach((fn) => {
|
||||
|
||||
// Verify that default offset works fine.
|
||||
buffer[`read${fn}`](undefined);
|
||||
buffer[`read${fn}`]();
|
||||
|
||||
['', '0', null, {}, [], () => {}, true, false].forEach((o) => {
|
||||
assert.throws(
|
||||
() => buffer[`read${fn}`](o),
|
||||
{
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
name: 'TypeError'
|
||||
});
|
||||
});
|
||||
|
||||
[Infinity, -1, -4294967295].forEach((offset) => {
|
||||
assert.throws(
|
||||
() => buffer[`read${fn}`](offset),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError'
|
||||
});
|
||||
});
|
||||
|
||||
[NaN, 1.01].forEach((offset) => {
|
||||
assert.throws(
|
||||
() => buffer[`read${fn}`](offset),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: 'The value of "offset" is out of range. ' +
|
||||
`It must be an integer. Received ${offset}`
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Test 8 bit signed integers
|
||||
{
|
||||
const data = Buffer.from([0x23, 0xab, 0x7c, 0xef]);
|
||||
|
||||
assert.strictEqual(data.readInt8(0), 0x23);
|
||||
|
||||
data[0] = 0xff;
|
||||
assert.strictEqual(data.readInt8(0), -1);
|
||||
|
||||
data[0] = 0x87;
|
||||
assert.strictEqual(data.readInt8(0), -121);
|
||||
assert.strictEqual(data.readInt8(1), -85);
|
||||
assert.strictEqual(data.readInt8(2), 124);
|
||||
assert.strictEqual(data.readInt8(3), -17);
|
||||
}
|
||||
|
||||
// Test 16 bit integers
|
||||
{
|
||||
const buffer = Buffer.from([0x16, 0x79, 0x65, 0x6e, 0x69, 0x78]);
|
||||
|
||||
assert.strictEqual(buffer.readInt16BE(0), 0x1679);
|
||||
assert.strictEqual(buffer.readInt16LE(0), 0x7916);
|
||||
|
||||
buffer[0] = 0xff;
|
||||
buffer[1] = 0x80;
|
||||
assert.strictEqual(buffer.readInt16BE(0), -128);
|
||||
assert.strictEqual(buffer.readInt16LE(0), -32513);
|
||||
|
||||
buffer[0] = 0x77;
|
||||
buffer[1] = 0x65;
|
||||
assert.strictEqual(buffer.readInt16BE(0), 0x7765);
|
||||
assert.strictEqual(buffer.readInt16BE(1), 0x6565);
|
||||
assert.strictEqual(buffer.readInt16BE(2), 0x656e);
|
||||
assert.strictEqual(buffer.readInt16BE(3), 0x6e69);
|
||||
assert.strictEqual(buffer.readInt16BE(4), 0x6978);
|
||||
assert.strictEqual(buffer.readInt16LE(0), 0x6577);
|
||||
assert.strictEqual(buffer.readInt16LE(1), 0x6565);
|
||||
assert.strictEqual(buffer.readInt16LE(2), 0x6e65);
|
||||
assert.strictEqual(buffer.readInt16LE(3), 0x696e);
|
||||
assert.strictEqual(buffer.readInt16LE(4), 0x7869);
|
||||
}
|
||||
|
||||
// Test 32 bit integers
|
||||
{
|
||||
const buffer = Buffer.from([0x43, 0x53, 0x16, 0x79, 0x36, 0x17]);
|
||||
|
||||
assert.strictEqual(buffer.readInt32BE(0), 0x43531679);
|
||||
assert.strictEqual(buffer.readInt32LE(0), 0x79165343);
|
||||
|
||||
buffer[0] = 0xff;
|
||||
buffer[1] = 0xfe;
|
||||
buffer[2] = 0xef;
|
||||
buffer[3] = 0xfa;
|
||||
assert.strictEqual(buffer.readInt32BE(0), -69638);
|
||||
assert.strictEqual(buffer.readInt32LE(0), -84934913);
|
||||
|
||||
buffer[0] = 0x42;
|
||||
buffer[1] = 0xc3;
|
||||
buffer[2] = 0x95;
|
||||
buffer[3] = 0xa9;
|
||||
assert.strictEqual(buffer.readInt32BE(0), 0x42c395a9);
|
||||
assert.strictEqual(buffer.readInt32BE(1), -1013601994);
|
||||
assert.strictEqual(buffer.readInt32BE(2), -1784072681);
|
||||
assert.strictEqual(buffer.readInt32LE(0), -1449802942);
|
||||
assert.strictEqual(buffer.readInt32LE(1), 917083587);
|
||||
assert.strictEqual(buffer.readInt32LE(2), 389458325);
|
||||
}
|
||||
|
||||
// Test Int
|
||||
{
|
||||
const buffer = Buffer.from([0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]);
|
||||
|
||||
assert.strictEqual(buffer.readIntLE(0, 1), 0x01);
|
||||
assert.strictEqual(buffer.readIntBE(0, 1), 0x01);
|
||||
assert.strictEqual(buffer.readIntLE(0, 3), 0x030201);
|
||||
assert.strictEqual(buffer.readIntBE(0, 3), 0x010203);
|
||||
assert.strictEqual(buffer.readIntLE(0, 5), 0x0504030201);
|
||||
assert.strictEqual(buffer.readIntBE(0, 5), 0x0102030405);
|
||||
assert.strictEqual(buffer.readIntLE(0, 6), 0x060504030201);
|
||||
assert.strictEqual(buffer.readIntBE(0, 6), 0x010203040506);
|
||||
assert.strictEqual(buffer.readIntLE(1, 6), 0x070605040302);
|
||||
assert.strictEqual(buffer.readIntBE(1, 6), 0x020304050607);
|
||||
assert.strictEqual(buffer.readIntLE(2, 6), 0x080706050403);
|
||||
assert.strictEqual(buffer.readIntBE(2, 6), 0x030405060708);
|
||||
|
||||
// Check byteLength.
|
||||
['readIntBE', 'readIntLE'].forEach((fn) => {
|
||||
['', '0', null, {}, [], () => {}, true, false, undefined].forEach((len) => {
|
||||
assert.throws(
|
||||
() => buffer[fn](0, len),
|
||||
{ code: 'ERR_INVALID_ARG_TYPE' });
|
||||
});
|
||||
|
||||
[Infinity, -1].forEach((byteLength) => {
|
||||
assert.throws(
|
||||
() => buffer[fn](0, byteLength),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
message: 'The value of "byteLength" is out of range. ' +
|
||||
`It must be >= 1 and <= 6. Received ${byteLength}`
|
||||
});
|
||||
});
|
||||
|
||||
[NaN, 1.01].forEach((byteLength) => {
|
||||
assert.throws(
|
||||
() => buffer[fn](0, byteLength),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: 'The value of "byteLength" is out of range. ' +
|
||||
`It must be an integer. Received ${byteLength}`
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Test 1 to 6 bytes.
|
||||
for (let i = 1; i <= 6; i++) {
|
||||
['readIntBE', 'readIntLE'].forEach((fn) => {
|
||||
['', '0', null, {}, [], () => {}, true, false, undefined].forEach((o) => {
|
||||
assert.throws(
|
||||
() => buffer[fn](o, i),
|
||||
{
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
name: 'TypeError'
|
||||
});
|
||||
});
|
||||
|
||||
[Infinity, -1, -4294967295].forEach((offset) => {
|
||||
assert.throws(
|
||||
() => buffer[fn](offset, i),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: 'The value of "offset" is out of range. ' +
|
||||
`It must be >= 0 and <= ${8 - i}. Received ${offset}`
|
||||
});
|
||||
});
|
||||
|
||||
[NaN, 1.01].forEach((offset) => {
|
||||
assert.throws(
|
||||
() => buffer[fn](offset, i),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: 'The value of "offset" is out of range. ' +
|
||||
`It must be an integer. Received ${offset}`
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
172
cli/tests/node_compat/test/parallel/test-buffer-readuint.js
Normal file
172
cli/tests/node_compat/test/parallel/test-buffer-readuint.js
Normal file
|
@ -0,0 +1,172 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
// Test OOB
|
||||
{
|
||||
const buffer = Buffer.alloc(4);
|
||||
|
||||
['UInt8', 'UInt16BE', 'UInt16LE', 'UInt32BE', 'UInt32LE'].forEach((fn) => {
|
||||
|
||||
// Verify that default offset works fine.
|
||||
buffer[`read${fn}`](undefined);
|
||||
buffer[`read${fn}`]();
|
||||
|
||||
['', '0', null, {}, [], () => {}, true, false].forEach((o) => {
|
||||
assert.throws(
|
||||
() => buffer[`read${fn}`](o),
|
||||
{
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
name: 'TypeError'
|
||||
});
|
||||
});
|
||||
|
||||
[Infinity, -1, -4294967295].forEach((offset) => {
|
||||
assert.throws(
|
||||
() => buffer[`read${fn}`](offset),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError'
|
||||
});
|
||||
});
|
||||
|
||||
[NaN, 1.01].forEach((offset) => {
|
||||
assert.throws(
|
||||
() => buffer[`read${fn}`](offset),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: 'The value of "offset" is out of range. ' +
|
||||
`It must be an integer. Received ${offset}`
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Test 8 bit unsigned integers
|
||||
{
|
||||
const data = Buffer.from([0xff, 0x2a, 0x2a, 0x2a]);
|
||||
assert.strictEqual(data.readUInt8(0), 255);
|
||||
assert.strictEqual(data.readUInt8(1), 42);
|
||||
assert.strictEqual(data.readUInt8(2), 42);
|
||||
assert.strictEqual(data.readUInt8(3), 42);
|
||||
}
|
||||
|
||||
// Test 16 bit unsigned integers
|
||||
{
|
||||
const data = Buffer.from([0x00, 0x2a, 0x42, 0x3f]);
|
||||
assert.strictEqual(data.readUInt16BE(0), 0x2a);
|
||||
assert.strictEqual(data.readUInt16BE(1), 0x2a42);
|
||||
assert.strictEqual(data.readUInt16BE(2), 0x423f);
|
||||
assert.strictEqual(data.readUInt16LE(0), 0x2a00);
|
||||
assert.strictEqual(data.readUInt16LE(1), 0x422a);
|
||||
assert.strictEqual(data.readUInt16LE(2), 0x3f42);
|
||||
|
||||
data[0] = 0xfe;
|
||||
data[1] = 0xfe;
|
||||
assert.strictEqual(data.readUInt16BE(0), 0xfefe);
|
||||
assert.strictEqual(data.readUInt16LE(0), 0xfefe);
|
||||
}
|
||||
|
||||
// Test 32 bit unsigned integers
|
||||
{
|
||||
const data = Buffer.from([0x32, 0x65, 0x42, 0x56, 0x23, 0xff]);
|
||||
assert.strictEqual(data.readUInt32BE(0), 0x32654256);
|
||||
assert.strictEqual(data.readUInt32BE(1), 0x65425623);
|
||||
assert.strictEqual(data.readUInt32BE(2), 0x425623ff);
|
||||
assert.strictEqual(data.readUInt32LE(0), 0x56426532);
|
||||
assert.strictEqual(data.readUInt32LE(1), 0x23564265);
|
||||
assert.strictEqual(data.readUInt32LE(2), 0xff235642);
|
||||
}
|
||||
|
||||
// Test UInt
|
||||
{
|
||||
const buffer = Buffer.from([0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]);
|
||||
|
||||
assert.strictEqual(buffer.readUIntLE(0, 1), 0x01);
|
||||
assert.strictEqual(buffer.readUIntBE(0, 1), 0x01);
|
||||
assert.strictEqual(buffer.readUIntLE(0, 3), 0x030201);
|
||||
assert.strictEqual(buffer.readUIntBE(0, 3), 0x010203);
|
||||
assert.strictEqual(buffer.readUIntLE(0, 5), 0x0504030201);
|
||||
assert.strictEqual(buffer.readUIntBE(0, 5), 0x0102030405);
|
||||
assert.strictEqual(buffer.readUIntLE(0, 6), 0x060504030201);
|
||||
assert.strictEqual(buffer.readUIntBE(0, 6), 0x010203040506);
|
||||
assert.strictEqual(buffer.readUIntLE(1, 6), 0x070605040302);
|
||||
assert.strictEqual(buffer.readUIntBE(1, 6), 0x020304050607);
|
||||
assert.strictEqual(buffer.readUIntLE(2, 6), 0x080706050403);
|
||||
assert.strictEqual(buffer.readUIntBE(2, 6), 0x030405060708);
|
||||
|
||||
// Check byteLength.
|
||||
['readUIntBE', 'readUIntLE'].forEach((fn) => {
|
||||
['', '0', null, {}, [], () => {}, true, false, undefined].forEach((len) => {
|
||||
assert.throws(
|
||||
() => buffer[fn](0, len),
|
||||
{ code: 'ERR_INVALID_ARG_TYPE' });
|
||||
});
|
||||
|
||||
[Infinity, -1].forEach((byteLength) => {
|
||||
assert.throws(
|
||||
() => buffer[fn](0, byteLength),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
message: 'The value of "byteLength" is out of range. ' +
|
||||
`It must be >= 1 and <= 6. Received ${byteLength}`
|
||||
});
|
||||
});
|
||||
|
||||
[NaN, 1.01].forEach((byteLength) => {
|
||||
assert.throws(
|
||||
() => buffer[fn](0, byteLength),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: 'The value of "byteLength" is out of range. ' +
|
||||
`It must be an integer. Received ${byteLength}`
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Test 1 to 6 bytes.
|
||||
for (let i = 1; i <= 6; i++) {
|
||||
['readUIntBE', 'readUIntLE'].forEach((fn) => {
|
||||
['', '0', null, {}, [], () => {}, true, false, undefined].forEach((o) => {
|
||||
assert.throws(
|
||||
() => buffer[fn](o, i),
|
||||
{
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
name: 'TypeError'
|
||||
});
|
||||
});
|
||||
|
||||
[Infinity, -1, -4294967295].forEach((offset) => {
|
||||
assert.throws(
|
||||
() => buffer[fn](offset, i),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: 'The value of "offset" is out of range. ' +
|
||||
`It must be >= 0 and <= ${8 - i}. Received ${offset}`
|
||||
});
|
||||
});
|
||||
|
||||
[NaN, 1.01].forEach((offset) => {
|
||||
assert.throws(
|
||||
() => buffer[fn](offset, i),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: 'The value of "offset" is out of range. ' +
|
||||
`It must be an integer. Received ${offset}`
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
const safe = Buffer.alloc(10);
|
||||
|
||||
function isZeroFilled(buf) {
|
||||
for (let n = 0; n < buf.length; n++)
|
||||
if (buf[n] !== 0) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
assert(isZeroFilled(safe));
|
||||
|
||||
// Test that unsafe allocations doesn't affect subsequent safe allocations
|
||||
Buffer.allocUnsafe(10);
|
||||
assert(isZeroFilled(new Float64Array(10)));
|
||||
|
||||
new Buffer(10);
|
||||
assert(isZeroFilled(new Float64Array(10)));
|
||||
|
||||
Buffer.allocUnsafe(10);
|
||||
assert(isZeroFilled(Buffer.alloc(10)));
|
|
@ -0,0 +1,34 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
const sab = new SharedArrayBuffer(24);
|
||||
const arr1 = new Uint16Array(sab);
|
||||
const arr2 = new Uint16Array(12);
|
||||
arr2[0] = 5000;
|
||||
arr1[0] = 5000;
|
||||
arr1[1] = 4000;
|
||||
arr2[1] = 4000;
|
||||
|
||||
const arr_buf = Buffer.from(arr1.buffer);
|
||||
const ar_buf = Buffer.from(arr2.buffer);
|
||||
|
||||
assert.deepStrictEqual(arr_buf, ar_buf);
|
||||
|
||||
arr1[1] = 6000;
|
||||
arr2[1] = 6000;
|
||||
|
||||
assert.deepStrictEqual(arr_buf, ar_buf);
|
||||
|
||||
// Checks for calling Buffer.byteLength on a SharedArrayBuffer.
|
||||
assert.strictEqual(Buffer.byteLength(sab), sab.byteLength);
|
||||
|
||||
Buffer.from({ buffer: sab }); // Should not throw.
|
136
cli/tests/node_compat/test/parallel/test-buffer-slice.js
Normal file
136
cli/tests/node_compat/test/parallel/test-buffer-slice.js
Normal file
|
@ -0,0 +1,136 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// 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';
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
assert.strictEqual(Buffer.from('hello', 'utf8').slice(0, 0).length, 0);
|
||||
assert.strictEqual(Buffer('hello', 'utf8').slice(0, 0).length, 0);
|
||||
|
||||
const buf = Buffer.from('0123456789', 'utf8');
|
||||
const expectedSameBufs = [
|
||||
[buf.slice(-10, 10), Buffer.from('0123456789', 'utf8')],
|
||||
[buf.slice(-20, 10), Buffer.from('0123456789', 'utf8')],
|
||||
[buf.slice(-20, -10), Buffer.from('', 'utf8')],
|
||||
[buf.slice(), Buffer.from('0123456789', 'utf8')],
|
||||
[buf.slice(0), Buffer.from('0123456789', 'utf8')],
|
||||
[buf.slice(0, 0), Buffer.from('', 'utf8')],
|
||||
[buf.slice(undefined), Buffer.from('0123456789', 'utf8')],
|
||||
[buf.slice('foobar'), Buffer.from('0123456789', 'utf8')],
|
||||
[buf.slice(undefined, undefined), Buffer.from('0123456789', 'utf8')],
|
||||
[buf.slice(2), Buffer.from('23456789', 'utf8')],
|
||||
[buf.slice(5), Buffer.from('56789', 'utf8')],
|
||||
[buf.slice(10), Buffer.from('', 'utf8')],
|
||||
[buf.slice(5, 8), Buffer.from('567', 'utf8')],
|
||||
[buf.slice(8, -1), Buffer.from('8', 'utf8')],
|
||||
[buf.slice(-10), Buffer.from('0123456789', 'utf8')],
|
||||
[buf.slice(0, -9), Buffer.from('0', 'utf8')],
|
||||
[buf.slice(0, -10), Buffer.from('', 'utf8')],
|
||||
[buf.slice(0, -1), Buffer.from('012345678', 'utf8')],
|
||||
[buf.slice(2, -2), Buffer.from('234567', 'utf8')],
|
||||
[buf.slice(0, 65536), Buffer.from('0123456789', 'utf8')],
|
||||
[buf.slice(65536, 0), Buffer.from('', 'utf8')],
|
||||
[buf.slice(-5, -8), Buffer.from('', 'utf8')],
|
||||
[buf.slice(-5, -3), Buffer.from('56', 'utf8')],
|
||||
[buf.slice(-10, 10), Buffer.from('0123456789', 'utf8')],
|
||||
[buf.slice('0', '1'), Buffer.from('0', 'utf8')],
|
||||
[buf.slice('-5', '10'), Buffer.from('56789', 'utf8')],
|
||||
[buf.slice('-10', '10'), Buffer.from('0123456789', 'utf8')],
|
||||
[buf.slice('-10', '-5'), Buffer.from('01234', 'utf8')],
|
||||
[buf.slice('-10', '-0'), Buffer.from('', 'utf8')],
|
||||
[buf.slice('111'), Buffer.from('', 'utf8')],
|
||||
[buf.slice('0', '-111'), Buffer.from('', 'utf8')],
|
||||
];
|
||||
|
||||
for (let i = 0, s = buf.toString(); i < buf.length; ++i) {
|
||||
expectedSameBufs.push(
|
||||
[buf.slice(i), Buffer.from(s.slice(i))],
|
||||
[buf.slice(0, i), Buffer.from(s.slice(0, i))],
|
||||
[buf.slice(-i), Buffer.from(s.slice(-i))],
|
||||
[buf.slice(0, -i), Buffer.from(s.slice(0, -i))]
|
||||
);
|
||||
}
|
||||
|
||||
expectedSameBufs.forEach(([buf1, buf2]) => {
|
||||
assert.strictEqual(Buffer.compare(buf1, buf2), 0);
|
||||
});
|
||||
|
||||
const utf16Buf = Buffer.from('0123456789', 'utf16le');
|
||||
assert.deepStrictEqual(utf16Buf.slice(0, 6), Buffer.from('012', 'utf16le'));
|
||||
// Try to slice a zero length Buffer.
|
||||
// See https://github.com/joyent/node/issues/5881
|
||||
assert.strictEqual(Buffer.alloc(0).slice(0, 1).length, 0);
|
||||
|
||||
{
|
||||
// Single argument slice
|
||||
assert.strictEqual(Buffer.from('abcde', 'utf8').slice(1).toString('utf8'),
|
||||
'bcde');
|
||||
}
|
||||
|
||||
// slice(0,0).length === 0
|
||||
assert.strictEqual(Buffer.from('hello', 'utf8').slice(0, 0).length, 0);
|
||||
|
||||
{
|
||||
// Regression tests for https://github.com/nodejs/node/issues/9096
|
||||
const buf = Buffer.from('abcd', 'utf8');
|
||||
assert.strictEqual(buf.slice(buf.length / 3).toString('utf8'), 'bcd');
|
||||
assert.strictEqual(
|
||||
buf.slice(buf.length / 3, buf.length).toString(),
|
||||
'bcd'
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
const buf = Buffer.from('abcdefg', 'utf8');
|
||||
assert.strictEqual(buf.slice(-(-1 >>> 0) - 1).toString('utf8'),
|
||||
buf.toString('utf8'));
|
||||
}
|
||||
|
||||
{
|
||||
const buf = Buffer.from('abc', 'utf8');
|
||||
assert.strictEqual(buf.slice(-0.5).toString('utf8'), buf.toString('utf8'));
|
||||
}
|
||||
|
||||
{
|
||||
const buf = Buffer.from([
|
||||
1, 29, 0, 0, 1, 143, 216, 162, 92, 254, 248, 63, 0,
|
||||
0, 0, 18, 184, 6, 0, 175, 29, 0, 8, 11, 1, 0, 0,
|
||||
]);
|
||||
const chunk1 = Buffer.from([
|
||||
1, 29, 0, 0, 1, 143, 216, 162, 92, 254, 248, 63, 0,
|
||||
]);
|
||||
const chunk2 = Buffer.from([
|
||||
0, 0, 18, 184, 6, 0, 175, 29, 0, 8, 11, 1, 0, 0,
|
||||
]);
|
||||
const middle = buf.length / 2;
|
||||
|
||||
assert.deepStrictEqual(buf.slice(0, middle), chunk1);
|
||||
assert.deepStrictEqual(buf.slice(middle), chunk2);
|
||||
}
|
69
cli/tests/node_compat/test/parallel/test-buffer-slow.js
Normal file
69
cli/tests/node_compat/test/parallel/test-buffer-slow.js
Normal file
|
@ -0,0 +1,69 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
const buffer = require('buffer');
|
||||
const SlowBuffer = buffer.SlowBuffer;
|
||||
|
||||
const ones = [1, 1, 1, 1];
|
||||
|
||||
// Should create a Buffer
|
||||
let sb = SlowBuffer(4);
|
||||
assert(sb instanceof Buffer);
|
||||
assert.strictEqual(sb.length, 4);
|
||||
sb.fill(1);
|
||||
for (const [key, value] of sb.entries()) {
|
||||
assert.deepStrictEqual(value, ones[key]);
|
||||
}
|
||||
|
||||
// underlying ArrayBuffer should have the same length
|
||||
assert.strictEqual(sb.buffer.byteLength, 4);
|
||||
|
||||
// Should work without new
|
||||
sb = SlowBuffer(4);
|
||||
assert(sb instanceof Buffer);
|
||||
assert.strictEqual(sb.length, 4);
|
||||
sb.fill(1);
|
||||
for (const [key, value] of sb.entries()) {
|
||||
assert.deepStrictEqual(value, ones[key]);
|
||||
}
|
||||
|
||||
// Should work with edge cases
|
||||
assert.strictEqual(SlowBuffer(0).length, 0);
|
||||
try {
|
||||
assert.strictEqual(
|
||||
SlowBuffer(buffer.kMaxLength).length, buffer.kMaxLength);
|
||||
} catch (e) {
|
||||
// Don't match on message as it is from the JavaScript engine. V8 and
|
||||
// ChakraCore provide different messages.
|
||||
assert.strictEqual(e.name, 'RangeError');
|
||||
}
|
||||
|
||||
// Should throw with invalid length type
|
||||
const bufferInvalidTypeMsg = {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
name: 'TypeError',
|
||||
message: /^The "size" argument must be of type number/,
|
||||
};
|
||||
assert.throws(() => SlowBuffer(), bufferInvalidTypeMsg);
|
||||
assert.throws(() => SlowBuffer({}), bufferInvalidTypeMsg);
|
||||
assert.throws(() => SlowBuffer('6'), bufferInvalidTypeMsg);
|
||||
assert.throws(() => SlowBuffer(true), bufferInvalidTypeMsg);
|
||||
|
||||
// Should throw with invalid length value
|
||||
const bufferMaxSizeMsg = {
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
name: 'RangeError',
|
||||
message: /^The argument 'size' is invalid\. Received [^"]*$/
|
||||
};
|
||||
assert.throws(() => SlowBuffer(NaN), bufferMaxSizeMsg);
|
||||
assert.throws(() => SlowBuffer(Infinity), bufferMaxSizeMsg);
|
||||
assert.throws(() => SlowBuffer(-1), bufferMaxSizeMsg);
|
||||
assert.throws(() => SlowBuffer(buffer.kMaxLength + 1), bufferMaxSizeMsg);
|
159
cli/tests/node_compat/test/parallel/test-buffer-swap.js
Normal file
159
cli/tests/node_compat/test/parallel/test-buffer-swap.js
Normal file
|
@ -0,0 +1,159 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
// Test buffers small enough to use the JS implementation
|
||||
{
|
||||
const buf = Buffer.from([0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
|
||||
0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10]);
|
||||
|
||||
assert.strictEqual(buf, buf.swap16());
|
||||
assert.deepStrictEqual(buf, Buffer.from([0x02, 0x01, 0x04, 0x03, 0x06, 0x05,
|
||||
0x08, 0x07, 0x0a, 0x09, 0x0c, 0x0b,
|
||||
0x0e, 0x0d, 0x10, 0x0f]));
|
||||
buf.swap16(); // restore
|
||||
|
||||
assert.strictEqual(buf, buf.swap32());
|
||||
assert.deepStrictEqual(buf, Buffer.from([0x04, 0x03, 0x02, 0x01, 0x08, 0x07,
|
||||
0x06, 0x05, 0x0c, 0x0b, 0x0a, 0x09,
|
||||
0x10, 0x0f, 0x0e, 0x0d]));
|
||||
buf.swap32(); // restore
|
||||
|
||||
assert.strictEqual(buf, buf.swap64());
|
||||
assert.deepStrictEqual(buf, Buffer.from([0x08, 0x07, 0x06, 0x05, 0x04, 0x03,
|
||||
0x02, 0x01, 0x10, 0x0f, 0x0e, 0x0d,
|
||||
0x0c, 0x0b, 0x0a, 0x09]));
|
||||
}
|
||||
|
||||
// Operates in-place
|
||||
{
|
||||
const buf = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7]);
|
||||
buf.slice(1, 5).swap32();
|
||||
assert.deepStrictEqual(buf, Buffer.from([0x1, 0x5, 0x4, 0x3, 0x2, 0x6, 0x7]));
|
||||
buf.slice(1, 5).swap16();
|
||||
assert.deepStrictEqual(buf, Buffer.from([0x1, 0x4, 0x5, 0x2, 0x3, 0x6, 0x7]));
|
||||
|
||||
// Length assertions
|
||||
const re16 = /Buffer size must be a multiple of 16-bits/;
|
||||
const re32 = /Buffer size must be a multiple of 32-bits/;
|
||||
const re64 = /Buffer size must be a multiple of 64-bits/;
|
||||
|
||||
assert.throws(() => Buffer.from(buf).swap16(), re16);
|
||||
assert.throws(() => Buffer.alloc(1025).swap16(), re16);
|
||||
assert.throws(() => Buffer.from(buf).swap32(), re32);
|
||||
assert.throws(() => buf.slice(1, 3).swap32(), re32);
|
||||
assert.throws(() => Buffer.alloc(1025).swap32(), re32);
|
||||
assert.throws(() => buf.slice(1, 3).swap64(), re64);
|
||||
assert.throws(() => Buffer.alloc(1025).swap64(), re64);
|
||||
}
|
||||
|
||||
{
|
||||
const buf = Buffer.from([0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
|
||||
0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
|
||||
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
|
||||
0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10]);
|
||||
|
||||
buf.slice(2, 18).swap64();
|
||||
|
||||
assert.deepStrictEqual(buf, Buffer.from([0x01, 0x02, 0x0a, 0x09, 0x08, 0x07,
|
||||
0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
|
||||
0x10, 0x0f, 0x0e, 0x0d, 0x0c, 0x0b,
|
||||
0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
|
||||
0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
|
||||
0x0f, 0x10]));
|
||||
}
|
||||
|
||||
// Force use of native code (Buffer size above threshold limit for js impl)
|
||||
{
|
||||
const bufData = new Uint32Array(256).fill(0x04030201);
|
||||
const buf = Buffer.from(bufData.buffer, bufData.byteOffset);
|
||||
const otherBufData = new Uint32Array(256).fill(0x03040102);
|
||||
const otherBuf = Buffer.from(otherBufData.buffer, otherBufData.byteOffset);
|
||||
buf.swap16();
|
||||
assert.deepStrictEqual(buf, otherBuf);
|
||||
}
|
||||
|
||||
{
|
||||
const bufData = new Uint32Array(256).fill(0x04030201);
|
||||
const buf = Buffer.from(bufData.buffer);
|
||||
const otherBufData = new Uint32Array(256).fill(0x01020304);
|
||||
const otherBuf = Buffer.from(otherBufData.buffer, otherBufData.byteOffset);
|
||||
buf.swap32();
|
||||
assert.deepStrictEqual(buf, otherBuf);
|
||||
}
|
||||
|
||||
{
|
||||
const bufData = new Uint8Array(256 * 8);
|
||||
const otherBufData = new Uint8Array(256 * 8);
|
||||
for (let i = 0; i < bufData.length; i++) {
|
||||
bufData[i] = i % 8;
|
||||
otherBufData[otherBufData.length - i - 1] = i % 8;
|
||||
}
|
||||
const buf = Buffer.from(bufData.buffer, bufData.byteOffset);
|
||||
const otherBuf = Buffer.from(otherBufData.buffer, otherBufData.byteOffset);
|
||||
buf.swap64();
|
||||
assert.deepStrictEqual(buf, otherBuf);
|
||||
}
|
||||
|
||||
// Test native code with buffers that are not memory-aligned
|
||||
{
|
||||
const bufData = new Uint8Array(256 * 8);
|
||||
const otherBufData = new Uint8Array(256 * 8 - 2);
|
||||
for (let i = 0; i < bufData.length; i++) {
|
||||
bufData[i] = i % 2;
|
||||
}
|
||||
for (let i = 1; i < otherBufData.length; i++) {
|
||||
otherBufData[otherBufData.length - i] = (i + 1) % 2;
|
||||
}
|
||||
const buf = Buffer.from(bufData.buffer, bufData.byteOffset);
|
||||
// 0|1 0|1 0|1...
|
||||
const otherBuf = Buffer.from(otherBufData.buffer, otherBufData.byteOffset);
|
||||
// 0|0 1|0 1|0...
|
||||
|
||||
buf.slice(1, buf.length - 1).swap16();
|
||||
assert.deepStrictEqual(buf.slice(0, otherBuf.length), otherBuf);
|
||||
}
|
||||
|
||||
{
|
||||
const bufData = new Uint8Array(256 * 8);
|
||||
const otherBufData = new Uint8Array(256 * 8 - 4);
|
||||
for (let i = 0; i < bufData.length; i++) {
|
||||
bufData[i] = i % 4;
|
||||
}
|
||||
for (let i = 1; i < otherBufData.length; i++) {
|
||||
otherBufData[otherBufData.length - i] = (i + 1) % 4;
|
||||
}
|
||||
const buf = Buffer.from(bufData.buffer, bufData.byteOffset);
|
||||
// 0|1 2 3 0|1 2 3...
|
||||
const otherBuf = Buffer.from(otherBufData.buffer, otherBufData.byteOffset);
|
||||
// 0|0 3 2 1|0 3 2...
|
||||
|
||||
buf.slice(1, buf.length - 3).swap32();
|
||||
assert.deepStrictEqual(buf.slice(0, otherBuf.length), otherBuf);
|
||||
}
|
||||
|
||||
{
|
||||
const bufData = new Uint8Array(256 * 8);
|
||||
const otherBufData = new Uint8Array(256 * 8 - 8);
|
||||
for (let i = 0; i < bufData.length; i++) {
|
||||
bufData[i] = i % 8;
|
||||
}
|
||||
for (let i = 1; i < otherBufData.length; i++) {
|
||||
otherBufData[otherBufData.length - i] = (i + 1) % 8;
|
||||
}
|
||||
const buf = Buffer.from(bufData.buffer, bufData.byteOffset);
|
||||
// 0|1 2 3 4 5 6 7 0|1 2 3 4...
|
||||
const otherBuf = Buffer.from(otherBufData.buffer, otherBufData.byteOffset);
|
||||
// 0|0 7 6 5 4 3 2 1|0 7 6 5...
|
||||
|
||||
buf.slice(1, buf.length - 7).swap64();
|
||||
assert.deepStrictEqual(buf.slice(0, otherBuf.length), otherBuf);
|
||||
}
|
42
cli/tests/node_compat/test/parallel/test-buffer-tojson.js
Normal file
42
cli/tests/node_compat/test/parallel/test-buffer-tojson.js
Normal file
|
@ -0,0 +1,42 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
{
|
||||
assert.strictEqual(JSON.stringify(Buffer.alloc(0)),
|
||||
'{"type":"Buffer","data":[]}');
|
||||
assert.strictEqual(JSON.stringify(Buffer.from([1, 2, 3, 4])),
|
||||
'{"type":"Buffer","data":[1,2,3,4]}');
|
||||
}
|
||||
|
||||
// issue GH-7849
|
||||
{
|
||||
const buf = Buffer.from('test');
|
||||
const json = JSON.stringify(buf);
|
||||
const obj = JSON.parse(json);
|
||||
const copy = Buffer.from(obj);
|
||||
|
||||
assert.deepStrictEqual(buf, copy);
|
||||
}
|
||||
|
||||
// GH-5110
|
||||
{
|
||||
const buffer = Buffer.from('test');
|
||||
const string = JSON.stringify(buffer);
|
||||
|
||||
assert.strictEqual(string, '{"type":"Buffer","data":[116,101,115,116]}');
|
||||
|
||||
function receiver(key, value) {
|
||||
return value && value.type === 'Buffer' ? Buffer.from(value.data) : value;
|
||||
}
|
||||
|
||||
assert.deepStrictEqual(buffer, JSON.parse(string, receiver));
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
const rangeBuffer = Buffer.from('abc');
|
||||
|
||||
// If start >= buffer's length, empty string will be returned
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 3), '');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', +Infinity), '');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 3.14, 3), '');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 'Infinity', 3), '');
|
||||
|
||||
// If end <= 0, empty string will be returned
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 1, 0), '');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 1, -1.2), '');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 1, -100), '');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 1, -Infinity), '');
|
||||
|
||||
// If start < 0, start will be taken as zero
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', -1, 3), 'abc');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', -1.99, 3), 'abc');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', -Infinity, 3), 'abc');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', '-1', 3), 'abc');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', '-1.99', 3), 'abc');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', '-Infinity', 3), 'abc');
|
||||
|
||||
// If start is an invalid integer, start will be taken as zero
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 'node.js', 3), 'abc');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', {}, 3), 'abc');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', [], 3), 'abc');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', NaN, 3), 'abc');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', null, 3), 'abc');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', undefined, 3), 'abc');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', false, 3), 'abc');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', '', 3), 'abc');
|
||||
|
||||
// But, if start is an integer when coerced, then it will be coerced and used.
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', '-1', 3), 'abc');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', '1', 3), 'bc');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', '-Infinity', 3), 'abc');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', '3', 3), '');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', Number(3), 3), '');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', '3.14', 3), '');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', '1.99', 3), 'bc');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', '-1.99', 3), 'abc');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 1.99, 3), 'bc');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', true, 3), 'bc');
|
||||
|
||||
// If end > buffer's length, end will be taken as buffer's length
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 0, 5), 'abc');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 0, 6.99), 'abc');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 0, Infinity), 'abc');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 0, '5'), 'abc');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 0, '6.99'), 'abc');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 0, 'Infinity'), 'abc');
|
||||
|
||||
// If end is an invalid integer, end will be taken as buffer's length
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 0, 'node.js'), '');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 0, {}), '');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 0, NaN), '');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 0, undefined), 'abc');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 0), 'abc');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 0, null), '');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 0, []), '');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 0, false), '');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 0, ''), '');
|
||||
|
||||
// But, if end is an integer when coerced, then it will be coerced and used.
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 0, '-1'), '');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 0, '1'), 'a');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 0, '-Infinity'), '');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 0, '3'), 'abc');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 0, Number(3)), 'abc');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 0, '3.14'), 'abc');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 0, '1.99'), 'a');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 0, '-1.99'), '');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 0, 1.99), 'a');
|
||||
assert.strictEqual(rangeBuffer.toString('ascii', 0, true), 'a');
|
||||
|
||||
// Try toString() with an object as an encoding
|
||||
assert.strictEqual(rangeBuffer.toString({ toString: function() {
|
||||
return 'ascii';
|
||||
} }), 'abc');
|
||||
|
||||
// Try toString() with 0 and null as the encoding
|
||||
assert.throws(() => {
|
||||
rangeBuffer.toString(0, 1, 2);
|
||||
}, {
|
||||
code: 'ERR_UNKNOWN_ENCODING',
|
||||
name: 'TypeError',
|
||||
message: 'Unknown encoding: 0'
|
||||
});
|
||||
assert.throws(() => {
|
||||
rangeBuffer.toString(null, 1, 2);
|
||||
}, {
|
||||
code: 'ERR_UNKNOWN_ENCODING',
|
||||
name: 'TypeError',
|
||||
message: 'Unknown encoding: null'
|
||||
});
|
|
@ -0,0 +1,28 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
require('../common');
|
||||
|
||||
// This test ensures that Node.js throws a RangeError when trying to convert a
|
||||
// gigantic buffer into a string.
|
||||
// Regression test for https://github.com/nodejs/node/issues/649.
|
||||
|
||||
const assert = require('assert');
|
||||
const SlowBuffer = require('buffer').SlowBuffer;
|
||||
|
||||
const len = 1422561062959;
|
||||
const message = {
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
name: 'RangeError',
|
||||
message: /^The argument 'size' is invalid\. Received [^"]*$/
|
||||
};
|
||||
assert.throws(() => Buffer(len).toString('utf8'), message);
|
||||
assert.throws(() => SlowBuffer(len).toString('utf8'), message);
|
||||
assert.throws(() => Buffer.alloc(len).toString('utf8'), message);
|
||||
assert.throws(() => Buffer.allocUnsafe(len).toString('utf8'), message);
|
||||
assert.throws(() => Buffer.allocUnsafeSlow(len).toString('utf8'), message);
|
44
cli/tests/node_compat/test/parallel/test-buffer-tostring.js
Normal file
44
cli/tests/node_compat/test/parallel/test-buffer-tostring.js
Normal file
|
@ -0,0 +1,44 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
// utf8, ucs2, ascii, latin1, utf16le
|
||||
const encodings = ['utf8', 'utf-8', 'ucs2', 'ucs-2', 'ascii', 'latin1',
|
||||
'binary', 'utf16le', 'utf-16le'];
|
||||
|
||||
encodings
|
||||
.reduce((es, e) => es.concat(e, e.toUpperCase()), [])
|
||||
.forEach((encoding) => {
|
||||
assert.strictEqual(Buffer.from('foo', encoding).toString(encoding), 'foo');
|
||||
});
|
||||
|
||||
// base64
|
||||
['base64', 'BASE64'].forEach((encoding) => {
|
||||
assert.strictEqual(Buffer.from('Zm9v', encoding).toString(encoding), 'Zm9v');
|
||||
});
|
||||
|
||||
// hex
|
||||
['hex', 'HEX'].forEach((encoding) => {
|
||||
assert.strictEqual(Buffer.from('666f6f', encoding).toString(encoding),
|
||||
'666f6f');
|
||||
});
|
||||
|
||||
// Invalid encodings
|
||||
for (let i = 1; i < 10; i++) {
|
||||
const encoding = String(i).repeat(i);
|
||||
const error = common.expectsError({
|
||||
code: 'ERR_UNKNOWN_ENCODING',
|
||||
name: 'TypeError',
|
||||
message: `Unknown encoding: ${encoding}`
|
||||
});
|
||||
assert.ok(!Buffer.isEncoding(encoding));
|
||||
assert.throws(() => Buffer.from('foo').toString(encoding), error);
|
||||
}
|
115
cli/tests/node_compat/test/parallel/test-buffer-write.js
Normal file
115
cli/tests/node_compat/test/parallel/test-buffer-write.js
Normal file
|
@ -0,0 +1,115 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
[-1, 10].forEach((offset) => {
|
||||
assert.throws(
|
||||
() => Buffer.alloc(9).write('foo', offset),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: 'The value of "offset" is out of range. ' +
|
||||
`It must be >= 0 && <= 9. Received ${offset}`
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
const resultMap = new Map([
|
||||
['utf8', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])],
|
||||
['ucs2', Buffer.from([102, 0, 111, 0, 111, 0, 0, 0, 0])],
|
||||
['ascii', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])],
|
||||
['latin1', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])],
|
||||
['binary', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])],
|
||||
['utf16le', Buffer.from([102, 0, 111, 0, 111, 0, 0, 0, 0])],
|
||||
['base64', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])],
|
||||
['base64url', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])],
|
||||
['hex', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])],
|
||||
]);
|
||||
|
||||
// utf8, ucs2, ascii, latin1, utf16le
|
||||
const encodings = ['utf8', 'utf-8', 'ucs2', 'ucs-2', 'ascii', 'latin1',
|
||||
'binary', 'utf16le', 'utf-16le'];
|
||||
|
||||
encodings
|
||||
.reduce((es, e) => es.concat(e, e.toUpperCase()), [])
|
||||
.forEach((encoding) => {
|
||||
const buf = Buffer.alloc(9);
|
||||
const len = Buffer.byteLength('foo', encoding);
|
||||
assert.strictEqual(buf.write('foo', 0, len, encoding), len);
|
||||
|
||||
if (encoding.includes('-'))
|
||||
encoding = encoding.replace('-', '');
|
||||
|
||||
assert.deepStrictEqual(buf, resultMap.get(encoding.toLowerCase()));
|
||||
});
|
||||
|
||||
// base64
|
||||
['base64', 'BASE64', 'base64url', 'BASE64URL'].forEach((encoding) => {
|
||||
const buf = Buffer.alloc(9);
|
||||
const len = Buffer.byteLength('Zm9v', encoding);
|
||||
|
||||
assert.strictEqual(buf.write('Zm9v', 0, len, encoding), len);
|
||||
assert.deepStrictEqual(buf, resultMap.get(encoding.toLowerCase()));
|
||||
});
|
||||
|
||||
// hex
|
||||
['hex', 'HEX'].forEach((encoding) => {
|
||||
const buf = Buffer.alloc(9);
|
||||
const len = Buffer.byteLength('666f6f', encoding);
|
||||
|
||||
assert.strictEqual(buf.write('666f6f', 0, len, encoding), len);
|
||||
assert.deepStrictEqual(buf, resultMap.get(encoding.toLowerCase()));
|
||||
});
|
||||
|
||||
// Invalid encodings
|
||||
for (let i = 1; i < 10; i++) {
|
||||
const encoding = String(i).repeat(i);
|
||||
const error = common.expectsError({
|
||||
code: 'ERR_UNKNOWN_ENCODING',
|
||||
name: 'TypeError',
|
||||
message: `Unknown encoding: ${encoding}`
|
||||
});
|
||||
|
||||
assert.ok(!Buffer.isEncoding(encoding));
|
||||
assert.throws(() => Buffer.alloc(9).write('foo', encoding), error);
|
||||
}
|
||||
|
||||
// UCS-2 overflow CVE-2018-12115
|
||||
for (let i = 1; i < 4; i++) {
|
||||
// Allocate two Buffers sequentially off the pool. Run more than once in case
|
||||
// we hit the end of the pool and don't get sequential allocations
|
||||
const x = Buffer.allocUnsafe(4).fill(0);
|
||||
const y = Buffer.allocUnsafe(4).fill(1);
|
||||
// Should not write anything, pos 3 doesn't have enough room for a 16-bit char
|
||||
assert.strictEqual(x.write('ыыыыыы', 3, 'ucs2'), 0);
|
||||
// CVE-2018-12115 experienced via buffer overrun to next block in the pool
|
||||
assert.strictEqual(Buffer.compare(y, Buffer.alloc(4, 1)), 0);
|
||||
}
|
||||
|
||||
// Should not write any data when there is no space for 16-bit chars
|
||||
const z = Buffer.alloc(4, 0);
|
||||
assert.strictEqual(z.write('\u0001', 3, 'ucs2'), 0);
|
||||
assert.strictEqual(Buffer.compare(z, Buffer.alloc(4, 0)), 0);
|
||||
// Make sure longer strings are written up to the buffer end.
|
||||
assert.strictEqual(z.write('abcd', 2), 2);
|
||||
assert.deepStrictEqual([...z], [0, 0, 0x61, 0x62]);
|
||||
|
||||
// Large overrun could corrupt the process
|
||||
assert.strictEqual(Buffer.alloc(4)
|
||||
.write('ыыыыыы'.repeat(100), 3, 'utf16le'), 0);
|
||||
|
||||
{
|
||||
// .write() does not affect the byte after the written-to slice of the Buffer.
|
||||
// Refs: https://github.com/nodejs/node/issues/26422
|
||||
const buf = Buffer.alloc(8);
|
||||
assert.strictEqual(buf.write('ыы', 1, 'utf16le'), 4);
|
||||
assert.deepStrictEqual([...buf], [0, 0x4b, 0x04, 0x4b, 0x04, 0, 0, 0]);
|
||||
}
|
140
cli/tests/node_compat/test/parallel/test-buffer-writedouble.js
Normal file
140
cli/tests/node_compat/test/parallel/test-buffer-writedouble.js
Normal file
|
@ -0,0 +1,140 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
// Tests to verify doubles are correctly written
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
const buffer = Buffer.allocUnsafe(16);
|
||||
|
||||
buffer.writeDoubleBE(2.225073858507201e-308, 0);
|
||||
buffer.writeDoubleLE(2.225073858507201e-308, 8);
|
||||
assert.ok(buffer.equals(new Uint8Array([
|
||||
0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00,
|
||||
])));
|
||||
|
||||
buffer.writeDoubleBE(1.0000000000000004, 0);
|
||||
buffer.writeDoubleLE(1.0000000000000004, 8);
|
||||
assert.ok(buffer.equals(new Uint8Array([
|
||||
0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
|
||||
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f,
|
||||
])));
|
||||
|
||||
buffer.writeDoubleBE(-2, 0);
|
||||
buffer.writeDoubleLE(-2, 8);
|
||||
assert.ok(buffer.equals(new Uint8Array([
|
||||
0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,
|
||||
])));
|
||||
|
||||
buffer.writeDoubleBE(1.7976931348623157e+308, 0);
|
||||
buffer.writeDoubleLE(1.7976931348623157e+308, 8);
|
||||
assert.ok(buffer.equals(new Uint8Array([
|
||||
0x7f, 0xef, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xef, 0x7f,
|
||||
])));
|
||||
|
||||
buffer.writeDoubleBE(0 * -1, 0);
|
||||
buffer.writeDoubleLE(0 * -1, 8);
|
||||
assert.ok(buffer.equals(new Uint8Array([
|
||||
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
|
||||
])));
|
||||
|
||||
buffer.writeDoubleBE(Infinity, 0);
|
||||
buffer.writeDoubleLE(Infinity, 8);
|
||||
|
||||
assert.ok(buffer.equals(new Uint8Array([
|
||||
0x7F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x7F,
|
||||
])));
|
||||
|
||||
assert.strictEqual(buffer.readDoubleBE(0), Infinity);
|
||||
assert.strictEqual(buffer.readDoubleLE(8), Infinity);
|
||||
|
||||
buffer.writeDoubleBE(-Infinity, 0);
|
||||
buffer.writeDoubleLE(-Infinity, 8);
|
||||
|
||||
assert.ok(buffer.equals(new Uint8Array([
|
||||
0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF,
|
||||
])));
|
||||
|
||||
assert.strictEqual(buffer.readDoubleBE(0), -Infinity);
|
||||
assert.strictEqual(buffer.readDoubleLE(8), -Infinity);
|
||||
|
||||
buffer.writeDoubleBE(NaN, 0);
|
||||
buffer.writeDoubleLE(NaN, 8);
|
||||
|
||||
// JS only knows a single NaN but there exist two platform specific
|
||||
// implementations. Therefore, allow both quiet and signalling NaNs.
|
||||
if (buffer[1] === 0xF7) {
|
||||
assert.ok(buffer.equals(new Uint8Array([
|
||||
0x7F, 0xF7, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF7, 0x7F,
|
||||
])));
|
||||
} else {
|
||||
assert.ok(buffer.equals(new Uint8Array([
|
||||
0x7F, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x7F,
|
||||
])));
|
||||
}
|
||||
|
||||
assert.ok(Number.isNaN(buffer.readDoubleBE(0)));
|
||||
assert.ok(Number.isNaN(buffer.readDoubleLE(8)));
|
||||
|
||||
// OOB in writeDouble{LE,BE} should throw.
|
||||
{
|
||||
const small = Buffer.allocUnsafe(1);
|
||||
|
||||
['writeDoubleLE', 'writeDoubleBE'].forEach((fn) => {
|
||||
|
||||
// Verify that default offset works fine.
|
||||
buffer[fn](23, undefined);
|
||||
buffer[fn](23);
|
||||
|
||||
assert.throws(
|
||||
() => small[fn](11.11, 0),
|
||||
{
|
||||
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
|
||||
name: 'RangeError',
|
||||
message: 'Attempt to access memory outside buffer bounds'
|
||||
});
|
||||
|
||||
['', '0', null, {}, [], () => {}, true, false].forEach((off) => {
|
||||
assert.throws(
|
||||
() => small[fn](23, off),
|
||||
{ code: 'ERR_INVALID_ARG_TYPE' });
|
||||
});
|
||||
|
||||
[Infinity, -1, 9].forEach((offset) => {
|
||||
assert.throws(
|
||||
() => buffer[fn](23, offset),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: 'The value of "offset" is out of range. ' +
|
||||
`It must be >= 0 and <= 8. Received ${offset}`
|
||||
});
|
||||
});
|
||||
|
||||
[NaN, 1.01].forEach((offset) => {
|
||||
assert.throws(
|
||||
() => buffer[fn](42, offset),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: 'The value of "offset" is out of range. ' +
|
||||
`It must be an integer. Received ${offset}`
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
124
cli/tests/node_compat/test/parallel/test-buffer-writefloat.js
Normal file
124
cli/tests/node_compat/test/parallel/test-buffer-writefloat.js
Normal file
|
@ -0,0 +1,124 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
// Tests to verify floats are correctly written
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
const buffer = Buffer.allocUnsafe(8);
|
||||
|
||||
buffer.writeFloatBE(1, 0);
|
||||
buffer.writeFloatLE(1, 4);
|
||||
assert.ok(buffer.equals(
|
||||
new Uint8Array([ 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f ])));
|
||||
|
||||
buffer.writeFloatBE(1 / 3, 0);
|
||||
buffer.writeFloatLE(1 / 3, 4);
|
||||
assert.ok(buffer.equals(
|
||||
new Uint8Array([ 0x3e, 0xaa, 0xaa, 0xab, 0xab, 0xaa, 0xaa, 0x3e ])));
|
||||
|
||||
buffer.writeFloatBE(3.4028234663852886e+38, 0);
|
||||
buffer.writeFloatLE(3.4028234663852886e+38, 4);
|
||||
assert.ok(buffer.equals(
|
||||
new Uint8Array([ 0x7f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x7f ])));
|
||||
|
||||
buffer.writeFloatLE(1.1754943508222875e-38, 0);
|
||||
buffer.writeFloatBE(1.1754943508222875e-38, 4);
|
||||
assert.ok(buffer.equals(
|
||||
new Uint8Array([ 0x00, 0x00, 0x80, 0x00, 0x00, 0x80, 0x00, 0x00 ])));
|
||||
|
||||
buffer.writeFloatBE(0 * -1, 0);
|
||||
buffer.writeFloatLE(0 * -1, 4);
|
||||
assert.ok(buffer.equals(
|
||||
new Uint8Array([ 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 ])));
|
||||
|
||||
buffer.writeFloatBE(Infinity, 0);
|
||||
buffer.writeFloatLE(Infinity, 4);
|
||||
assert.ok(buffer.equals(
|
||||
new Uint8Array([ 0x7F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x7F ])));
|
||||
|
||||
assert.strictEqual(buffer.readFloatBE(0), Infinity);
|
||||
assert.strictEqual(buffer.readFloatLE(4), Infinity);
|
||||
|
||||
buffer.writeFloatBE(-Infinity, 0);
|
||||
buffer.writeFloatLE(-Infinity, 4);
|
||||
assert.ok(buffer.equals(
|
||||
new Uint8Array([ 0xFF, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF ])));
|
||||
|
||||
assert.strictEqual(buffer.readFloatBE(0), -Infinity);
|
||||
assert.strictEqual(buffer.readFloatLE(4), -Infinity);
|
||||
|
||||
buffer.writeFloatBE(NaN, 0);
|
||||
buffer.writeFloatLE(NaN, 4);
|
||||
|
||||
// JS only knows a single NaN but there exist two platform specific
|
||||
// implementations. Therefore, allow both quiet and signalling NaNs.
|
||||
if (buffer[1] === 0xBF) {
|
||||
assert.ok(
|
||||
buffer.equals(new Uint8Array(
|
||||
[ 0x7F, 0xBF, 0xFF, 0xFF, 0xFF, 0xFF, 0xBF, 0x7F ])));
|
||||
} else {
|
||||
assert.ok(
|
||||
buffer.equals(new Uint8Array(
|
||||
[ 0x7F, 0xC0, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x7F ])));
|
||||
}
|
||||
|
||||
assert.ok(Number.isNaN(buffer.readFloatBE(0)));
|
||||
assert.ok(Number.isNaN(buffer.readFloatLE(4)));
|
||||
|
||||
// OOB in writeFloat{LE,BE} should throw.
|
||||
{
|
||||
const small = Buffer.allocUnsafe(1);
|
||||
|
||||
['writeFloatLE', 'writeFloatBE'].forEach((fn) => {
|
||||
|
||||
// Verify that default offset works fine.
|
||||
buffer[fn](23, undefined);
|
||||
buffer[fn](23);
|
||||
|
||||
assert.throws(
|
||||
() => small[fn](11.11, 0),
|
||||
{
|
||||
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
|
||||
name: 'RangeError',
|
||||
message: 'Attempt to access memory outside buffer bounds'
|
||||
});
|
||||
|
||||
['', '0', null, {}, [], () => {}, true, false].forEach((off) => {
|
||||
assert.throws(
|
||||
() => small[fn](23, off),
|
||||
{ code: 'ERR_INVALID_ARG_TYPE' }
|
||||
);
|
||||
});
|
||||
|
||||
[Infinity, -1, 5].forEach((offset) => {
|
||||
assert.throws(
|
||||
() => buffer[fn](23, offset),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: 'The value of "offset" is out of range. ' +
|
||||
`It must be >= 0 and <= 4. Received ${offset}`
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
[NaN, 1.01].forEach((offset) => {
|
||||
assert.throws(
|
||||
() => buffer[fn](42, offset),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: 'The value of "offset" is out of range. ' +
|
||||
`It must be an integer. Received ${offset}`
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
277
cli/tests/node_compat/test/parallel/test-buffer-writeint.js
Normal file
277
cli/tests/node_compat/test/parallel/test-buffer-writeint.js
Normal file
|
@ -0,0 +1,277 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
// Tests to verify signed integers are correctly written
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
const errorOutOfBounds = {
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: new RegExp('^The value of "value" is out of range\\. ' +
|
||||
'It must be >= -\\d+ and <= \\d+\\. Received .+$')
|
||||
};
|
||||
|
||||
// Test 8 bit
|
||||
{
|
||||
const buffer = Buffer.alloc(2);
|
||||
|
||||
buffer.writeInt8(0x23, 0);
|
||||
buffer.writeInt8(-5, 1);
|
||||
assert.ok(buffer.equals(new Uint8Array([ 0x23, 0xfb ])));
|
||||
|
||||
/* Make sure we handle min/max correctly */
|
||||
buffer.writeInt8(0x7f, 0);
|
||||
buffer.writeInt8(-0x80, 1);
|
||||
assert.ok(buffer.equals(new Uint8Array([ 0x7f, 0x80 ])));
|
||||
|
||||
assert.throws(() => {
|
||||
buffer.writeInt8(0x7f + 1, 0);
|
||||
}, errorOutOfBounds);
|
||||
assert.throws(() => {
|
||||
buffer.writeInt8(-0x80 - 1, 0);
|
||||
}, errorOutOfBounds);
|
||||
|
||||
// Verify that default offset works fine.
|
||||
buffer.writeInt8(23, undefined);
|
||||
buffer.writeInt8(23);
|
||||
|
||||
['', '0', null, {}, [], () => {}, true, false].forEach((off) => {
|
||||
assert.throws(
|
||||
() => buffer.writeInt8(23, off),
|
||||
{ code: 'ERR_INVALID_ARG_TYPE' });
|
||||
});
|
||||
|
||||
[NaN, Infinity, -1, 1.01].forEach((off) => {
|
||||
assert.throws(
|
||||
() => buffer.writeInt8(23, off),
|
||||
{ code: 'ERR_OUT_OF_RANGE' });
|
||||
});
|
||||
}
|
||||
|
||||
// Test 16 bit
|
||||
{
|
||||
const buffer = Buffer.alloc(4);
|
||||
|
||||
buffer.writeInt16BE(0x0023, 0);
|
||||
buffer.writeInt16LE(0x0023, 2);
|
||||
assert.ok(buffer.equals(new Uint8Array([ 0x00, 0x23, 0x23, 0x00 ])));
|
||||
|
||||
buffer.writeInt16BE(-5, 0);
|
||||
buffer.writeInt16LE(-5, 2);
|
||||
assert.ok(buffer.equals(new Uint8Array([ 0xff, 0xfb, 0xfb, 0xff ])));
|
||||
|
||||
buffer.writeInt16BE(-1679, 0);
|
||||
buffer.writeInt16LE(-1679, 2);
|
||||
assert.ok(buffer.equals(new Uint8Array([ 0xf9, 0x71, 0x71, 0xf9 ])));
|
||||
|
||||
/* Make sure we handle min/max correctly */
|
||||
buffer.writeInt16BE(0x7fff, 0);
|
||||
buffer.writeInt16BE(-0x8000, 2);
|
||||
assert.ok(buffer.equals(new Uint8Array([ 0x7f, 0xff, 0x80, 0x00 ])));
|
||||
|
||||
buffer.writeInt16LE(0x7fff, 0);
|
||||
buffer.writeInt16LE(-0x8000, 2);
|
||||
assert.ok(buffer.equals(new Uint8Array([ 0xff, 0x7f, 0x00, 0x80 ])));
|
||||
|
||||
['writeInt16BE', 'writeInt16LE'].forEach((fn) => {
|
||||
|
||||
// Verify that default offset works fine.
|
||||
buffer[fn](23, undefined);
|
||||
buffer[fn](23);
|
||||
|
||||
assert.throws(() => {
|
||||
buffer[fn](0x7fff + 1, 0);
|
||||
}, errorOutOfBounds);
|
||||
assert.throws(() => {
|
||||
buffer[fn](-0x8000 - 1, 0);
|
||||
}, errorOutOfBounds);
|
||||
|
||||
['', '0', null, {}, [], () => {}, true, false].forEach((off) => {
|
||||
assert.throws(
|
||||
() => buffer[fn](23, off),
|
||||
{ code: 'ERR_INVALID_ARG_TYPE' });
|
||||
});
|
||||
|
||||
[NaN, Infinity, -1, 1.01].forEach((off) => {
|
||||
assert.throws(
|
||||
() => buffer[fn](23, off),
|
||||
{ code: 'ERR_OUT_OF_RANGE' });
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Test 32 bit
|
||||
{
|
||||
const buffer = Buffer.alloc(8);
|
||||
|
||||
buffer.writeInt32BE(0x23, 0);
|
||||
buffer.writeInt32LE(0x23, 4);
|
||||
assert.ok(buffer.equals(new Uint8Array([
|
||||
0x00, 0x00, 0x00, 0x23, 0x23, 0x00, 0x00, 0x00,
|
||||
])));
|
||||
|
||||
buffer.writeInt32BE(-5, 0);
|
||||
buffer.writeInt32LE(-5, 4);
|
||||
assert.ok(buffer.equals(new Uint8Array([
|
||||
0xff, 0xff, 0xff, 0xfb, 0xfb, 0xff, 0xff, 0xff,
|
||||
])));
|
||||
|
||||
buffer.writeInt32BE(-805306713, 0);
|
||||
buffer.writeInt32LE(-805306713, 4);
|
||||
assert.ok(buffer.equals(new Uint8Array([
|
||||
0xcf, 0xff, 0xfe, 0xa7, 0xa7, 0xfe, 0xff, 0xcf,
|
||||
])));
|
||||
|
||||
/* Make sure we handle min/max correctly */
|
||||
buffer.writeInt32BE(0x7fffffff, 0);
|
||||
buffer.writeInt32BE(-0x80000000, 4);
|
||||
assert.ok(buffer.equals(new Uint8Array([
|
||||
0x7f, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00,
|
||||
])));
|
||||
|
||||
buffer.writeInt32LE(0x7fffffff, 0);
|
||||
buffer.writeInt32LE(-0x80000000, 4);
|
||||
assert.ok(buffer.equals(new Uint8Array([
|
||||
0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x80,
|
||||
])));
|
||||
|
||||
['writeInt32BE', 'writeInt32LE'].forEach((fn) => {
|
||||
|
||||
// Verify that default offset works fine.
|
||||
buffer[fn](23, undefined);
|
||||
buffer[fn](23);
|
||||
|
||||
assert.throws(() => {
|
||||
buffer[fn](0x7fffffff + 1, 0);
|
||||
}, errorOutOfBounds);
|
||||
assert.throws(() => {
|
||||
buffer[fn](-0x80000000 - 1, 0);
|
||||
}, errorOutOfBounds);
|
||||
|
||||
['', '0', null, {}, [], () => {}, true, false].forEach((off) => {
|
||||
assert.throws(
|
||||
() => buffer[fn](23, off),
|
||||
{ code: 'ERR_INVALID_ARG_TYPE' });
|
||||
});
|
||||
|
||||
[NaN, Infinity, -1, 1.01].forEach((off) => {
|
||||
assert.throws(
|
||||
() => buffer[fn](23, off),
|
||||
{ code: 'ERR_OUT_OF_RANGE' });
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Test 48 bit
|
||||
{
|
||||
const value = 0x1234567890ab;
|
||||
const buffer = Buffer.allocUnsafe(6);
|
||||
buffer.writeIntBE(value, 0, 6);
|
||||
assert.ok(buffer.equals(new Uint8Array([
|
||||
0x12, 0x34, 0x56, 0x78, 0x90, 0xab,
|
||||
])));
|
||||
|
||||
buffer.writeIntLE(value, 0, 6);
|
||||
assert.ok(buffer.equals(new Uint8Array([
|
||||
0xab, 0x90, 0x78, 0x56, 0x34, 0x12,
|
||||
])));
|
||||
}
|
||||
|
||||
// Test Int
|
||||
{
|
||||
const data = Buffer.alloc(8);
|
||||
|
||||
// Check byteLength.
|
||||
['writeIntBE', 'writeIntLE'].forEach((fn) => {
|
||||
['', '0', null, {}, [], () => {}, true, false, undefined].forEach((bl) => {
|
||||
assert.throws(
|
||||
() => data[fn](23, 0, bl),
|
||||
{ code: 'ERR_INVALID_ARG_TYPE' });
|
||||
});
|
||||
|
||||
[Infinity, -1].forEach((byteLength) => {
|
||||
assert.throws(
|
||||
() => data[fn](23, 0, byteLength),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
message: 'The value of "byteLength" is out of range. ' +
|
||||
`It must be >= 1 and <= 6. Received ${byteLength}`
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
[NaN, 1.01].forEach((byteLength) => {
|
||||
assert.throws(
|
||||
() => data[fn](42, 0, byteLength),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: 'The value of "byteLength" is out of range. ' +
|
||||
`It must be an integer. Received ${byteLength}`
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Test 1 to 6 bytes.
|
||||
for (let i = 1; i <= 6; i++) {
|
||||
['writeIntBE', 'writeIntLE'].forEach((fn) => {
|
||||
const min = -(2 ** (i * 8 - 1));
|
||||
const max = 2 ** (i * 8 - 1) - 1;
|
||||
let range = `>= ${min} and <= ${max}`;
|
||||
if (i > 4) {
|
||||
range = `>= -(2 ** ${i * 8 - 1}) and < 2 ** ${i * 8 - 1}`;
|
||||
}
|
||||
[min - 1, max + 1].forEach((val) => {
|
||||
const received = i > 4 ?
|
||||
String(val).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1_') :
|
||||
val;
|
||||
assert.throws(() => {
|
||||
data[fn](val, 0, i);
|
||||
}, {
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: 'The value of "value" is out of range. ' +
|
||||
`It must be ${range}. Received ${received}`
|
||||
});
|
||||
});
|
||||
|
||||
['', '0', null, {}, [], () => {}, true, false, undefined].forEach((o) => {
|
||||
assert.throws(
|
||||
() => data[fn](min, o, i),
|
||||
{
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
name: 'TypeError'
|
||||
});
|
||||
});
|
||||
|
||||
[Infinity, -1, -4294967295].forEach((offset) => {
|
||||
assert.throws(
|
||||
() => data[fn](min, offset, i),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: 'The value of "offset" is out of range. ' +
|
||||
`It must be >= 0 and <= ${8 - i}. Received ${offset}`
|
||||
});
|
||||
});
|
||||
|
||||
[NaN, 1.01].forEach((offset) => {
|
||||
assert.throws(
|
||||
() => data[fn](max, offset, i),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: 'The value of "offset" is out of range. ' +
|
||||
`It must be an integer. Received ${offset}`
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
237
cli/tests/node_compat/test/parallel/test-buffer-writeuint.js
Normal file
237
cli/tests/node_compat/test/parallel/test-buffer-writeuint.js
Normal file
|
@ -0,0 +1,237 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
// We need to check the following things:
|
||||
// - We are correctly resolving big endian (doesn't mean anything for 8 bit)
|
||||
// - Correctly resolving little endian (doesn't mean anything for 8 bit)
|
||||
// - Correctly using the offsets
|
||||
// - Correctly interpreting values that are beyond the signed range as unsigned
|
||||
|
||||
{ // OOB
|
||||
const data = Buffer.alloc(8);
|
||||
['UInt8', 'UInt16BE', 'UInt16LE', 'UInt32BE', 'UInt32LE'].forEach((fn) => {
|
||||
|
||||
// Verify that default offset works fine.
|
||||
data[`write${fn}`](23, undefined);
|
||||
data[`write${fn}`](23);
|
||||
|
||||
['', '0', null, {}, [], () => {}, true, false].forEach((o) => {
|
||||
assert.throws(
|
||||
() => data[`write${fn}`](23, o),
|
||||
{ code: 'ERR_INVALID_ARG_TYPE' });
|
||||
});
|
||||
|
||||
[NaN, Infinity, -1, 1.01].forEach((o) => {
|
||||
assert.throws(
|
||||
() => data[`write${fn}`](23, o),
|
||||
{ code: 'ERR_OUT_OF_RANGE' });
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
{ // Test 8 bit
|
||||
const data = Buffer.alloc(4);
|
||||
|
||||
data.writeUInt8(23, 0);
|
||||
data.writeUInt8(23, 1);
|
||||
data.writeUInt8(23, 2);
|
||||
data.writeUInt8(23, 3);
|
||||
assert.ok(data.equals(new Uint8Array([23, 23, 23, 23])));
|
||||
|
||||
data.writeUInt8(23, 0);
|
||||
data.writeUInt8(23, 1);
|
||||
data.writeUInt8(23, 2);
|
||||
data.writeUInt8(23, 3);
|
||||
assert.ok(data.equals(new Uint8Array([23, 23, 23, 23])));
|
||||
|
||||
data.writeUInt8(255, 0);
|
||||
assert.strictEqual(data[0], 255);
|
||||
|
||||
data.writeUInt8(255, 0);
|
||||
assert.strictEqual(data[0], 255);
|
||||
}
|
||||
|
||||
// Test 16 bit
|
||||
{
|
||||
let value = 0x2343;
|
||||
const data = Buffer.alloc(4);
|
||||
|
||||
data.writeUInt16BE(value, 0);
|
||||
assert.ok(data.equals(new Uint8Array([0x23, 0x43, 0, 0])));
|
||||
|
||||
data.writeUInt16BE(value, 1);
|
||||
assert.ok(data.equals(new Uint8Array([0x23, 0x23, 0x43, 0])));
|
||||
|
||||
data.writeUInt16BE(value, 2);
|
||||
assert.ok(data.equals(new Uint8Array([0x23, 0x23, 0x23, 0x43])));
|
||||
|
||||
data.writeUInt16LE(value, 0);
|
||||
assert.ok(data.equals(new Uint8Array([0x43, 0x23, 0x23, 0x43])));
|
||||
|
||||
data.writeUInt16LE(value, 1);
|
||||
assert.ok(data.equals(new Uint8Array([0x43, 0x43, 0x23, 0x43])));
|
||||
|
||||
data.writeUInt16LE(value, 2);
|
||||
assert.ok(data.equals(new Uint8Array([0x43, 0x43, 0x43, 0x23])));
|
||||
|
||||
value = 0xff80;
|
||||
data.writeUInt16LE(value, 0);
|
||||
assert.ok(data.equals(new Uint8Array([0x80, 0xff, 0x43, 0x23])));
|
||||
|
||||
data.writeUInt16BE(value, 0);
|
||||
assert.ok(data.equals(new Uint8Array([0xff, 0x80, 0x43, 0x23])));
|
||||
|
||||
value = 0xfffff;
|
||||
['writeUInt16BE', 'writeUInt16LE'].forEach((fn) => {
|
||||
assert.throws(
|
||||
() => data[fn](value, 0),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
message: 'The value of "value" is out of range. ' +
|
||||
`It must be >= 0 and <= 65535. Received ${value}`
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// Test 32 bit
|
||||
{
|
||||
const data = Buffer.alloc(6);
|
||||
const value = 0xe7f90a6d;
|
||||
|
||||
data.writeUInt32BE(value, 0);
|
||||
assert.ok(data.equals(new Uint8Array([0xe7, 0xf9, 0x0a, 0x6d, 0, 0])));
|
||||
|
||||
data.writeUInt32BE(value, 1);
|
||||
assert.ok(data.equals(new Uint8Array([0xe7, 0xe7, 0xf9, 0x0a, 0x6d, 0])));
|
||||
|
||||
data.writeUInt32BE(value, 2);
|
||||
assert.ok(data.equals(new Uint8Array([0xe7, 0xe7, 0xe7, 0xf9, 0x0a, 0x6d])));
|
||||
|
||||
data.writeUInt32LE(value, 0);
|
||||
assert.ok(data.equals(new Uint8Array([0x6d, 0x0a, 0xf9, 0xe7, 0x0a, 0x6d])));
|
||||
|
||||
data.writeUInt32LE(value, 1);
|
||||
assert.ok(data.equals(new Uint8Array([0x6d, 0x6d, 0x0a, 0xf9, 0xe7, 0x6d])));
|
||||
|
||||
data.writeUInt32LE(value, 2);
|
||||
assert.ok(data.equals(new Uint8Array([0x6d, 0x6d, 0x6d, 0x0a, 0xf9, 0xe7])));
|
||||
}
|
||||
|
||||
// Test 48 bit
|
||||
{
|
||||
const value = 0x1234567890ab;
|
||||
const data = Buffer.allocUnsafe(6);
|
||||
data.writeUIntBE(value, 0, 6);
|
||||
assert.ok(data.equals(new Uint8Array([0x12, 0x34, 0x56, 0x78, 0x90, 0xab])));
|
||||
|
||||
data.writeUIntLE(value, 0, 6);
|
||||
assert.ok(data.equals(new Uint8Array([0xab, 0x90, 0x78, 0x56, 0x34, 0x12])));
|
||||
}
|
||||
|
||||
// Test UInt
|
||||
{
|
||||
const data = Buffer.alloc(8);
|
||||
let val = 0x100;
|
||||
|
||||
// Check byteLength.
|
||||
['writeUIntBE', 'writeUIntLE'].forEach((fn) => {
|
||||
['', '0', null, {}, [], () => {}, true, false, undefined].forEach((bl) => {
|
||||
assert.throws(
|
||||
() => data[fn](23, 0, bl),
|
||||
{ code: 'ERR_INVALID_ARG_TYPE' });
|
||||
});
|
||||
|
||||
[Infinity, -1].forEach((byteLength) => {
|
||||
assert.throws(
|
||||
() => data[fn](23, 0, byteLength),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
message: 'The value of "byteLength" is out of range. ' +
|
||||
`It must be >= 1 and <= 6. Received ${byteLength}`
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
[NaN, 1.01].forEach((byteLength) => {
|
||||
assert.throws(
|
||||
() => data[fn](42, 0, byteLength),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: 'The value of "byteLength" is out of range. ' +
|
||||
`It must be an integer. Received ${byteLength}`
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Test 1 to 6 bytes.
|
||||
for (let i = 1; i <= 6; i++) {
|
||||
const range = i < 5 ? `= ${val - 1}` : ` 2 ** ${i * 8}`;
|
||||
const received = i > 4 ?
|
||||
String(val).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1_') :
|
||||
val;
|
||||
['writeUIntBE', 'writeUIntLE'].forEach((fn) => {
|
||||
assert.throws(() => {
|
||||
data[fn](val, 0, i);
|
||||
}, {
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: 'The value of "value" is out of range. ' +
|
||||
`It must be >= 0 and <${range}. Received ${received}`
|
||||
});
|
||||
|
||||
['', '0', null, {}, [], () => {}, true, false].forEach((o) => {
|
||||
assert.throws(
|
||||
() => data[fn](23, o, i),
|
||||
{
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
name: 'TypeError'
|
||||
});
|
||||
});
|
||||
|
||||
[Infinity, -1, -4294967295].forEach((offset) => {
|
||||
assert.throws(
|
||||
() => data[fn](val - 1, offset, i),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: 'The value of "offset" is out of range. ' +
|
||||
`It must be >= 0 and <= ${8 - i}. Received ${offset}`
|
||||
});
|
||||
});
|
||||
|
||||
[NaN, 1.01].forEach((offset) => {
|
||||
assert.throws(
|
||||
() => data[fn](val - 1, offset, i),
|
||||
{
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
name: 'RangeError',
|
||||
message: 'The value of "offset" is out of range. ' +
|
||||
`It must be an integer. Received ${offset}`
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
val *= 0x100;
|
||||
}
|
||||
}
|
||||
|
||||
for (const fn of [
|
||||
'UInt8', 'UInt16LE', 'UInt16BE', 'UInt32LE', 'UInt32BE', 'UIntLE', 'UIntBE',
|
||||
'BigUInt64LE', 'BigUInt64BE',
|
||||
]) {
|
||||
const p = Buffer.prototype;
|
||||
const lowerFn = fn.replace(/UInt/, 'Uint');
|
||||
assert.strictEqual(p[`write${fn}`], p[`write${lowerFn}`]);
|
||||
assert.strictEqual(p[`read${fn}`], p[`read${lowerFn}`]);
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
// Flags: --zero-fill-buffers
|
||||
|
||||
// when using --zero-fill-buffers, every Buffer and SlowBuffer
|
||||
// instance must be zero filled upon creation
|
||||
|
||||
require('../common');
|
||||
const SlowBuffer = require('buffer').SlowBuffer;
|
||||
const assert = require('assert');
|
||||
|
||||
function isZeroFilled(buf) {
|
||||
for (const n of buf)
|
||||
if (n > 0) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// This can be somewhat unreliable because the
|
||||
// allocated memory might just already happen to
|
||||
// contain all zeroes. The test is run multiple
|
||||
// times to improve the reliability.
|
||||
for (let i = 0; i < 50; i++) {
|
||||
const bufs = [
|
||||
Buffer.alloc(20),
|
||||
Buffer.allocUnsafe(20),
|
||||
SlowBuffer(20),
|
||||
Buffer(20),
|
||||
new SlowBuffer(20),
|
||||
];
|
||||
for (const buf of bufs) {
|
||||
assert(isZeroFilled(buf));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
|
||||
function testUint8Array(ui) {
|
||||
const length = ui.length;
|
||||
for (let i = 0; i < length; i++)
|
||||
if (ui[i] !== 0) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
for (let i = 0; i < 100; i++) {
|
||||
Buffer.alloc(0);
|
||||
const ui = new Uint8Array(65);
|
||||
assert.ok(testUint8Array(ui), `Uint8Array is not zero-filled: ${ui}`);
|
||||
}
|
21
cli/tests/node_compat/test/parallel/test-buffer-zero-fill.js
Normal file
21
cli/tests/node_compat/test/parallel/test-buffer-zero-fill.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
// Tests deprecated Buffer API on purpose
|
||||
const buf1 = Buffer(100);
|
||||
const buf2 = new Buffer(100);
|
||||
|
||||
for (let n = 0; n < buf1.length; n++)
|
||||
assert.strictEqual(buf1[n], 0);
|
||||
|
||||
for (let n = 0; n < buf2.length; n++)
|
||||
assert.strictEqual(buf2[n], 0);
|
|
@ -0,0 +1,29 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
// Tests that a spawned child process can write to stdout without throwing.
|
||||
// See https://github.com/nodejs/node-v0.x-archive/issues/1899.
|
||||
|
||||
require('../common');
|
||||
const fixtures = require('../common/fixtures');
|
||||
const assert = require('assert');
|
||||
const spawn = require('child_process').spawn;
|
||||
|
||||
const child = spawn(process.argv[0], [
|
||||
fixtures.path('GH-1899-output.js'),
|
||||
]);
|
||||
let output = '';
|
||||
|
||||
child.stdout.on('data', function(data) {
|
||||
output += data;
|
||||
});
|
||||
|
||||
child.on('exit', function(code, signal) {
|
||||
assert.strictEqual(code, 0);
|
||||
assert.strictEqual(output, 'hello, world!\n');
|
||||
});
|
|
@ -0,0 +1,58 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// 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';
|
||||
const { isWindows } = require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
const spawn = require('child_process').spawn;
|
||||
const debug = require('util').debuglog('test');
|
||||
|
||||
process.env.HELLO = 'WORLD';
|
||||
|
||||
let child;
|
||||
if (isWindows) {
|
||||
child = spawn('cmd.exe', ['/c', 'set'], {});
|
||||
} else {
|
||||
child = spawn('/usr/bin/env', [], {});
|
||||
}
|
||||
|
||||
let response = '';
|
||||
|
||||
child.stdout.setEncoding('utf8');
|
||||
|
||||
child.stdout.on('data', function(chunk) {
|
||||
debug(`stdout: ${chunk}`);
|
||||
response += chunk;
|
||||
});
|
||||
|
||||
process.on('exit', function() {
|
||||
assert.ok(response.includes('HELLO=WORLD'),
|
||||
'spawn did not use process.env as default ' +
|
||||
`(process.env.HELLO = ${process.env.HELLO})`);
|
||||
});
|
|
@ -0,0 +1,129 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// 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';
|
||||
const {
|
||||
isWindows,
|
||||
mustCall,
|
||||
mustCallAtLeast,
|
||||
} = require('../common');
|
||||
const assert = require('assert');
|
||||
const os = require('os');
|
||||
const spawn = require('child_process').spawn;
|
||||
const debug = require('util').debuglog('test');
|
||||
|
||||
// We're trying to reproduce:
|
||||
// $ echo "hello\nnode\nand\nworld" | grep o | sed s/o/a/
|
||||
|
||||
let grep, sed, echo;
|
||||
|
||||
if (isWindows) {
|
||||
grep = spawn('grep', ['--binary', 'o']);
|
||||
sed = spawn('sed', ['--binary', 's/o/O/']);
|
||||
echo = spawn('cmd.exe',
|
||||
['/c', 'echo', 'hello&&', 'echo',
|
||||
'node&&', 'echo', 'and&&', 'echo', 'world']);
|
||||
} else {
|
||||
grep = spawn('grep', ['o']);
|
||||
sed = spawn('sed', ['s/o/O/']);
|
||||
echo = spawn('echo', ['hello\nnode\nand\nworld\n']);
|
||||
}
|
||||
|
||||
// If the spawn function leaks file descriptors to subprocesses, grep and sed
|
||||
// hang.
|
||||
// This happens when calling pipe(2) and then forgetting to set the
|
||||
// FD_CLOEXEC flag on the resulting file descriptors.
|
||||
//
|
||||
// This test checks child processes exit, meaning they don't hang like
|
||||
// explained above.
|
||||
|
||||
|
||||
// pipe echo | grep
|
||||
echo.stdout.on('data', mustCallAtLeast((data) => {
|
||||
debug(`grep stdin write ${data.length}`);
|
||||
if (!grep.stdin.write(data)) {
|
||||
echo.stdout.pause();
|
||||
}
|
||||
}));
|
||||
|
||||
// TODO(@jasnell): This does not appear to ever be
|
||||
// emitted. It's not clear if it is necessary.
|
||||
grep.stdin.on('drain', (data) => {
|
||||
echo.stdout.resume();
|
||||
});
|
||||
|
||||
// Propagate end from echo to grep
|
||||
echo.stdout.on('end', mustCall((code) => {
|
||||
grep.stdin.end();
|
||||
}));
|
||||
|
||||
echo.on('exit', mustCall(() => {
|
||||
debug('echo exit');
|
||||
}));
|
||||
|
||||
grep.on('exit', mustCall(() => {
|
||||
debug('grep exit');
|
||||
}));
|
||||
|
||||
sed.on('exit', mustCall(() => {
|
||||
debug('sed exit');
|
||||
}));
|
||||
|
||||
|
||||
// pipe grep | sed
|
||||
grep.stdout.on('data', mustCallAtLeast((data) => {
|
||||
debug(`grep stdout ${data.length}`);
|
||||
if (!sed.stdin.write(data)) {
|
||||
grep.stdout.pause();
|
||||
}
|
||||
}));
|
||||
|
||||
// TODO(@jasnell): This does not appear to ever be
|
||||
// emitted. It's not clear if it is necessary.
|
||||
sed.stdin.on('drain', (data) => {
|
||||
grep.stdout.resume();
|
||||
});
|
||||
|
||||
// Propagate end from grep to sed
|
||||
grep.stdout.on('end', mustCall((code) => {
|
||||
debug('grep stdout end');
|
||||
sed.stdin.end();
|
||||
}));
|
||||
|
||||
|
||||
let result = '';
|
||||
|
||||
// print sed's output
|
||||
sed.stdout.on('data', mustCallAtLeast((data) => {
|
||||
result += data.toString('utf8', 0, data.length);
|
||||
debug(data);
|
||||
}));
|
||||
|
||||
sed.stdout.on('end', mustCall((code) => {
|
||||
assert.strictEqual(result, `hellO${os.EOL}nOde${os.EOL}wOrld${os.EOL}`);
|
||||
}));
|
|
@ -0,0 +1,54 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.8.0
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
// TODO(PolarETech): The "eval" subcommand passed to execPromisifed() should be the "-e" option.
|
||||
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const exec = require('child_process').exec;
|
||||
const { promisify } = require('util');
|
||||
|
||||
const execPromisifed = promisify(exec);
|
||||
const invalidArgTypeError = {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
name: 'TypeError'
|
||||
};
|
||||
|
||||
const waitCommand = common.isLinux ?
|
||||
'sleep 2m' :
|
||||
`${process.execPath} eval "setInterval(()=>{}, 99)"`;
|
||||
|
||||
{
|
||||
const ac = new AbortController();
|
||||
const signal = ac.signal;
|
||||
const promise = execPromisifed(waitCommand, { signal });
|
||||
assert.rejects(promise, /AbortError/, 'post aborted sync signal failed')
|
||||
.then(common.mustCall());
|
||||
ac.abort();
|
||||
}
|
||||
|
||||
{
|
||||
assert.throws(() => {
|
||||
execPromisifed(waitCommand, { signal: {} });
|
||||
}, invalidArgTypeError);
|
||||
}
|
||||
|
||||
{
|
||||
function signal() {}
|
||||
assert.throws(() => {
|
||||
execPromisifed(waitCommand, { signal });
|
||||
}, invalidArgTypeError);
|
||||
}
|
||||
|
||||
{
|
||||
const signal = AbortSignal.abort(); // Abort in advance
|
||||
const promise = execPromisifed(waitCommand, { signal });
|
||||
|
||||
assert.rejects(promise, /AbortError/, 'pre aborted signal failed')
|
||||
.then(common.mustCall());
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// 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';
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const exec = require('child_process').exec;
|
||||
|
||||
let pwdcommand, dir;
|
||||
|
||||
if (common.isWindows) {
|
||||
pwdcommand = 'echo %cd%';
|
||||
dir = 'c:\\windows';
|
||||
} else {
|
||||
pwdcommand = 'pwd';
|
||||
dir = '/dev';
|
||||
}
|
||||
|
||||
exec(pwdcommand, { cwd: dir }, common.mustSucceed((stdout, stderr) => {
|
||||
assert(stdout.startsWith(dir));
|
||||
}));
|
|
@ -0,0 +1,59 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.8.0
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
// TODO(PolarETech): The process.argv[3] check should be argv[2], and the
|
||||
// command passed to exec() should not need to include "run", "-A",
|
||||
// and "require.ts".
|
||||
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
const stdoutData = 'foo';
|
||||
const stderrData = 'bar';
|
||||
|
||||
if (process.argv[3] === 'child') {
|
||||
// The following console calls are part of the test.
|
||||
console.log(stdoutData);
|
||||
console.error(stderrData);
|
||||
} else {
|
||||
const assert = require('assert');
|
||||
const cp = require('child_process');
|
||||
const expectedStdout = `${stdoutData}\n`;
|
||||
const expectedStderr = `${stderrData}\n`;
|
||||
function run(options, callback) {
|
||||
const cmd = `"${process.execPath}" run -A require.ts "${__filename}" child`;
|
||||
|
||||
cp.exec(cmd, options, common.mustSucceed((stdout, stderr) => {
|
||||
callback(stdout, stderr);
|
||||
}));
|
||||
}
|
||||
|
||||
// Test default encoding, which should be utf8.
|
||||
run({}, (stdout, stderr) => {
|
||||
assert.strictEqual(typeof stdout, 'string');
|
||||
assert.strictEqual(typeof stderr, 'string');
|
||||
assert.strictEqual(stdout, expectedStdout);
|
||||
assert.strictEqual(stderr, expectedStderr);
|
||||
});
|
||||
|
||||
// Test explicit utf8 encoding.
|
||||
run({ encoding: 'utf8' }, (stdout, stderr) => {
|
||||
assert.strictEqual(typeof stdout, 'string');
|
||||
assert.strictEqual(typeof stderr, 'string');
|
||||
assert.strictEqual(stdout, expectedStdout);
|
||||
assert.strictEqual(stderr, expectedStderr);
|
||||
});
|
||||
|
||||
// Test cases that result in buffer encodings.
|
||||
[undefined, null, 'buffer', 'invalid'].forEach((encoding) => {
|
||||
run({ encoding }, (stdout, stderr) => {
|
||||
assert(stdout instanceof Buffer);
|
||||
assert(stdout instanceof Buffer);
|
||||
assert.strictEqual(stdout.toString(), expectedStdout);
|
||||
assert.strictEqual(stderr.toString(), expectedStderr);
|
||||
});
|
||||
});
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// 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';
|
||||
const { isWindows } = require('../common');
|
||||
const assert = require('assert');
|
||||
const exec = require('child_process').exec;
|
||||
const debug = require('util').debuglog('test');
|
||||
|
||||
let success_count = 0;
|
||||
let error_count = 0;
|
||||
let response = '';
|
||||
let child;
|
||||
|
||||
function after(err, stdout, stderr) {
|
||||
if (err) {
|
||||
error_count++;
|
||||
debug(`error!: ${err.code}`);
|
||||
debug(`stdout: ${JSON.stringify(stdout)}`);
|
||||
debug(`stderr: ${JSON.stringify(stderr)}`);
|
||||
assert.strictEqual(err.killed, false);
|
||||
} else {
|
||||
success_count++;
|
||||
assert.notStrictEqual(stdout, '');
|
||||
}
|
||||
}
|
||||
|
||||
if (!isWindows) {
|
||||
child = exec('/usr/bin/env', { env: { 'HELLO': 'WORLD' } }, after);
|
||||
} else {
|
||||
child = exec('set',
|
||||
{ env: { ...process.env, 'HELLO': 'WORLD' } },
|
||||
after);
|
||||
}
|
||||
|
||||
child.stdout.setEncoding('utf8');
|
||||
child.stdout.on('data', function(chunk) {
|
||||
response += chunk;
|
||||
});
|
||||
|
||||
process.on('exit', function() {
|
||||
debug('response: ', response);
|
||||
assert.strictEqual(success_count, 1);
|
||||
assert.strictEqual(error_count, 0);
|
||||
assert.ok(response.includes('HELLO=WORLD'));
|
||||
});
|
|
@ -0,0 +1,51 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// 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';
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const child_process = require('child_process');
|
||||
|
||||
function test(fn, code, expectPidType = 'number') {
|
||||
const child = fn('does-not-exist', common.mustCall(function(err) {
|
||||
assert.strictEqual(err.code, code);
|
||||
assert(err.cmd.includes('does-not-exist'));
|
||||
}));
|
||||
|
||||
assert.strictEqual(typeof child.pid, expectPidType);
|
||||
}
|
||||
|
||||
// With `shell: true`, expect pid (of the shell)
|
||||
if (common.isWindows) {
|
||||
test(child_process.exec, 1, 'number'); // Exit code of cmd.exe
|
||||
} else {
|
||||
test(child_process.exec, 127, 'number'); // Exit code of /bin/sh
|
||||
}
|
||||
|
||||
// With `shell: false`, expect no pid
|
||||
test(child_process.execFile, 'ENOENT', 'undefined');
|
|
@ -0,0 +1,42 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.8.0
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
// TODO(PolarETech): The process.argv[3] check should be argv[2], and the
|
||||
// command passed to exec() should not need to include "run", "-A",
|
||||
// and "require.ts".
|
||||
|
||||
'use strict';
|
||||
// Flags: --expose-internals
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const cp = require('child_process');
|
||||
|
||||
if (process.argv[3] === 'child') {
|
||||
// Since maxBuffer is 0, this should trigger an error.
|
||||
console.log('foo');
|
||||
} else {
|
||||
const internalCp = require('internal/child_process');
|
||||
|
||||
// Monkey patch ChildProcess#kill() to kill the process and then throw.
|
||||
const kill = internalCp.ChildProcess.prototype.kill;
|
||||
|
||||
internalCp.ChildProcess.prototype.kill = function() {
|
||||
kill.apply(this, arguments);
|
||||
throw new Error('mock error');
|
||||
};
|
||||
|
||||
const cmd = `"${process.execPath}" run -A require.ts "${__filename}" child`;
|
||||
const options = { maxBuffer: 0, killSignal: 'SIGKILL' };
|
||||
|
||||
const child = cp.exec(cmd, options, common.mustCall((err, stdout, stderr) => {
|
||||
// Verify that if ChildProcess#kill() throws, the error is reported.
|
||||
assert.strictEqual(err.message, 'mock error', err);
|
||||
assert.strictEqual(stdout, '');
|
||||
assert.strictEqual(stderr, '');
|
||||
assert.strictEqual(child.killed, true);
|
||||
}));
|
||||
}
|
|
@ -0,0 +1,161 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.8.0
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
// TODO(PolarETech): The "eval" subcommand passed to exec() should be the "-e" option.
|
||||
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const cp = require('child_process');
|
||||
|
||||
function runChecks(err, stdio, streamName, expected) {
|
||||
assert.strictEqual(err.message, `${streamName} maxBuffer length exceeded`);
|
||||
assert(err instanceof RangeError);
|
||||
assert.strictEqual(err.code, 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER');
|
||||
assert.deepStrictEqual(stdio[streamName], expected);
|
||||
}
|
||||
|
||||
// default value
|
||||
{
|
||||
const cmd =
|
||||
`"${process.execPath}" eval "console.log('a'.repeat(1024 * 1024))"`;
|
||||
|
||||
cp.exec(cmd, common.mustCall((err) => {
|
||||
assert(err instanceof RangeError);
|
||||
assert.strictEqual(err.message, 'stdout maxBuffer length exceeded');
|
||||
assert.strictEqual(err.code, 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER');
|
||||
}));
|
||||
}
|
||||
|
||||
// default value
|
||||
{
|
||||
const cmd =
|
||||
`${process.execPath} eval "console.log('a'.repeat(1024 * 1024 - 1))"`;
|
||||
|
||||
cp.exec(cmd, common.mustSucceed((stdout, stderr) => {
|
||||
assert.strictEqual(stdout.trim(), 'a'.repeat(1024 * 1024 - 1));
|
||||
assert.strictEqual(stderr, '');
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
const cmd = `"${process.execPath}" eval "console.log('hello world');"`;
|
||||
const options = { maxBuffer: Infinity };
|
||||
|
||||
cp.exec(cmd, options, common.mustSucceed((stdout, stderr) => {
|
||||
assert.strictEqual(stdout.trim(), 'hello world');
|
||||
assert.strictEqual(stderr, '');
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
const cmd = 'echo hello world';
|
||||
|
||||
cp.exec(
|
||||
cmd,
|
||||
{ maxBuffer: 5 },
|
||||
common.mustCall((err, stdout, stderr) => {
|
||||
runChecks(err, { stdout, stderr }, 'stdout', 'hello');
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// default value
|
||||
{
|
||||
const cmd =
|
||||
`"${process.execPath}" eval "console.log('a'.repeat(1024 * 1024))"`;
|
||||
|
||||
cp.exec(
|
||||
cmd,
|
||||
common.mustCall((err, stdout, stderr) => {
|
||||
runChecks(
|
||||
err,
|
||||
{ stdout, stderr },
|
||||
'stdout',
|
||||
'a'.repeat(1024 * 1024)
|
||||
);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// default value
|
||||
{
|
||||
const cmd =
|
||||
`"${process.execPath}" eval "console.log('a'.repeat(1024 * 1024 - 1))"`;
|
||||
|
||||
cp.exec(cmd, common.mustSucceed((stdout, stderr) => {
|
||||
assert.strictEqual(stdout.trim(), 'a'.repeat(1024 * 1024 - 1));
|
||||
assert.strictEqual(stderr, '');
|
||||
}));
|
||||
}
|
||||
|
||||
const unicode = '中文测试'; // length = 4, byte length = 12
|
||||
|
||||
{
|
||||
const cmd = `"${process.execPath}" eval "console.log('${unicode}');"`;
|
||||
|
||||
cp.exec(
|
||||
cmd,
|
||||
{ maxBuffer: 10 },
|
||||
common.mustCall((err, stdout, stderr) => {
|
||||
runChecks(err, { stdout, stderr }, 'stdout', '中文测试\n');
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
const cmd = `"${process.execPath}" eval "console.error('${unicode}');"`;
|
||||
|
||||
cp.exec(
|
||||
cmd,
|
||||
{ maxBuffer: 3 },
|
||||
common.mustCall((err, stdout, stderr) => {
|
||||
runChecks(err, { stdout, stderr }, 'stderr', '中文测');
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
const cmd = `"${process.execPath}" eval "console.log('${unicode}');"`;
|
||||
|
||||
const child = cp.exec(
|
||||
cmd,
|
||||
{ encoding: null, maxBuffer: 10 },
|
||||
common.mustCall((err, stdout, stderr) => {
|
||||
runChecks(err, { stdout, stderr }, 'stdout', '中文测试\n');
|
||||
})
|
||||
);
|
||||
|
||||
child.stdout.setEncoding('utf-8');
|
||||
}
|
||||
|
||||
{
|
||||
const cmd = `"${process.execPath}" eval "console.error('${unicode}');"`;
|
||||
|
||||
const child = cp.exec(
|
||||
cmd,
|
||||
{ encoding: null, maxBuffer: 3 },
|
||||
common.mustCall((err, stdout, stderr) => {
|
||||
runChecks(err, { stdout, stderr }, 'stderr', '中文测');
|
||||
})
|
||||
);
|
||||
|
||||
child.stderr.setEncoding('utf-8');
|
||||
}
|
||||
|
||||
{
|
||||
const cmd = `"${process.execPath}" eval "console.error('${unicode}');"`;
|
||||
|
||||
cp.exec(
|
||||
cmd,
|
||||
{ encoding: null, maxBuffer: 5 },
|
||||
common.mustCall((err, stdout, stderr) => {
|
||||
const buf = Buffer.from(unicode).slice(0, 5);
|
||||
runChecks(err, { stdout, stderr }, 'stderr', buf);
|
||||
})
|
||||
);
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.8.0
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
// TODO(PolarETech): The process.argv[3] check should be argv[2], and the
|
||||
// command passed to exec() should not need to include "run", "-A",
|
||||
// and "require.ts".
|
||||
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const cp = require('child_process');
|
||||
const stdoutData = 'foo';
|
||||
const stderrData = 'bar';
|
||||
const expectedStdout = `${stdoutData}\n`;
|
||||
const expectedStderr = `${stderrData}\n`;
|
||||
|
||||
if (process.argv[3] === 'child') {
|
||||
// The following console calls are part of the test.
|
||||
console.log(stdoutData);
|
||||
console.error(stderrData);
|
||||
} else {
|
||||
const cmd = `"${process.execPath}" run -A require.ts "${__filename}" child`;
|
||||
const child = cp.exec(cmd, common.mustSucceed((stdout, stderr) => {
|
||||
assert.strictEqual(stdout, expectedStdout);
|
||||
assert.strictEqual(stderr, expectedStderr);
|
||||
}));
|
||||
child.stdout.setEncoding('utf-8');
|
||||
child.stderr.setEncoding('utf-8');
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
'use strict';
|
||||
// Refs: https://github.com/nodejs/node/issues/7342
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const exec = require('child_process').exec;
|
||||
|
||||
const command = common.isWindows ? 'dir' : 'ls';
|
||||
|
||||
exec(command).stdout.on('data', common.mustCallAtLeast());
|
||||
|
||||
exec('fhqwhgads').stderr.on('data', common.mustCallAtLeast((data) => {
|
||||
assert.strictEqual(typeof data, 'string');
|
||||
}));
|
|
@ -0,0 +1,61 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
// TODO(PolarETech): The process.argv[3] check should be argv[2], and the
|
||||
// command passed to exec() should not need to include "run", "-A",
|
||||
// and "require.ts".
|
||||
|
||||
'use strict';
|
||||
|
||||
// Test exec() with a timeout that expires.
|
||||
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const cp = require('child_process');
|
||||
|
||||
const {
|
||||
cleanupStaleProcess,
|
||||
logAfterTime,
|
||||
kExpiringChildRunTime,
|
||||
kExpiringParentTimer
|
||||
} = require('../common/child_process');
|
||||
|
||||
if (process.argv[3] === 'child') {
|
||||
logAfterTime(kExpiringChildRunTime);
|
||||
return;
|
||||
}
|
||||
|
||||
const cmd = `"${process.execPath}" run -A require.ts "${__filename}" child`;
|
||||
|
||||
cp.exec(cmd, {
|
||||
timeout: kExpiringParentTimer,
|
||||
}, common.mustCall((err, stdout, stderr) => {
|
||||
console.log('[stdout]', stdout.trim());
|
||||
console.log('[stderr]', stderr.trim());
|
||||
|
||||
let sigterm = 'SIGTERM';
|
||||
assert.strictEqual(err.killed, true);
|
||||
// TODO OpenBSD returns a null signal and 143 for code
|
||||
if (common.isOpenBSD) {
|
||||
assert.strictEqual(err.code, 143);
|
||||
sigterm = null;
|
||||
} else {
|
||||
assert.strictEqual(err.code, null);
|
||||
}
|
||||
// At least starting with Darwin Kernel Version 16.4.0, sending a SIGTERM to a
|
||||
// process that is still starting up kills it with SIGKILL instead of SIGTERM.
|
||||
// See: https://github.com/libuv/libuv/issues/1226
|
||||
if (common.isOSX)
|
||||
assert.ok(err.signal === 'SIGTERM' || err.signal === 'SIGKILL');
|
||||
else
|
||||
assert.strictEqual(err.signal, sigterm);
|
||||
assert.strictEqual(err.cmd, cmd);
|
||||
assert.strictEqual(stdout.trim(), '');
|
||||
assert.strictEqual(stderr.trim(), '');
|
||||
}));
|
||||
|
||||
cleanupStaleProcess(__filename);
|
|
@ -0,0 +1,50 @@
|
|||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||
// Taken from Node 18.12.1
|
||||
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
||||
|
||||
// TODO(PolarETech): The process.argv[3] check should be argv[2], and the
|
||||
// command passed to exec() should not need to include "run", "-A",
|
||||
// and "require.ts".
|
||||
|
||||
'use strict';
|
||||
|
||||
// Test exec() with both a timeout and a killSignal.
|
||||
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const cp = require('child_process');
|
||||
|
||||
const {
|
||||
cleanupStaleProcess,
|
||||
logInTimeout,
|
||||
kExpiringChildRunTime,
|
||||
kExpiringParentTimer,
|
||||
} = require('../common/child_process');
|
||||
|
||||
if (process.argv[3] === 'child') {
|
||||
logInTimeout(kExpiringChildRunTime);
|
||||
return;
|
||||
}
|
||||
|
||||
const cmd = `"${process.execPath}" run -A require.ts "${__filename}" child`;
|
||||
|
||||
// Test with a different kill signal.
|
||||
cp.exec(cmd, {
|
||||
timeout: kExpiringParentTimer,
|
||||
killSignal: 'SIGKILL'
|
||||
}, common.mustCall((err, stdout, stderr) => {
|
||||
console.log('[stdout]', stdout.trim());
|
||||
console.log('[stderr]', stderr.trim());
|
||||
|
||||
assert.strictEqual(err.killed, true);
|
||||
assert.strictEqual(err.code, null);
|
||||
assert.strictEqual(err.signal, 'SIGKILL');
|
||||
assert.strictEqual(err.cmd, cmd);
|
||||
assert.strictEqual(stdout.trim(), '');
|
||||
assert.strictEqual(stderr.trim(), '');
|
||||
}));
|
||||
|
||||
cleanupStaleProcess(__filename);
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue