Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: convert test_encoding_binding.cc to a JS test #56791

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 6 additions & 23 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -402,26 +402,8 @@
],
'node_cctest_sources': [
'src/node_snapshot_stub.cc',
'test/cctest/node_test_fixture.cc',
'test/cctest/node_test_fixture.h',
'test/cctest/test_aliased_buffer.cc',
'test/cctest/test_base64.cc',
'test/cctest/test_base_object_ptr.cc',
'test/cctest/test_cppgc.cc',
'test/cctest/test_node_postmortem_metadata.cc',
'test/cctest/test_node_task_runner.cc',
'test/cctest/test_environment.cc',
'test/cctest/test_linked_binding.cc',
'test/cctest/test_node_api.cc',
'test/cctest/test_path.cc',
'test/cctest/test_per_process.cc',
'test/cctest/test_platform.cc',
'test/cctest/test_report.cc',
'test/cctest/test_json_utils.cc',
'test/cctest/test_sockaddr.cc',
'test/cctest/test_traced_value.cc',
'test/cctest/test_util.cc',
'test/cctest/test_dataqueue.cc',
'<!@(<(python) tools/search_files.py . test/cctest cc)',
'<!@(<(python) tools/search_files.py . test/cctest h)',
],
'node_cctest_openssl_sources': [
'test/cctest/test_crypto_clienthello.cc',
Expand Down Expand Up @@ -1204,13 +1186,13 @@
'dependencies': [
'deps/ncrypto/ncrypto.gyp:ncrypto',
],
'sources': [ '<@(node_cctest_openssl_sources)' ],
}, {
'sources!': [ '<@(node_cctest_openssl_sources)' ],
}],
['v8_enable_inspector==1', {
'defines': [
'HAVE_INSPECTOR=1',
],
'sources': [ '<@(node_cctest_inspector_sources)' ],
'include_dirs': [
# TODO(legendecas): make node_inspector.gypi a dependable target.
'<(SHARED_INTERMEDIATE_DIR)', # for inspector
Expand All @@ -1222,7 +1204,8 @@
}, {
'defines': [
'HAVE_INSPECTOR=0',
]
],
'sources!': [ '<@(node_cctest_inspector_sources)' ],
}],
['OS=="solaris"', {
'ldflags': [ '-I<(SHARED_INTERMEDIATE_DIR)' ]
Expand Down
176 changes: 0 additions & 176 deletions test/cctest/test_encoding_binding.cc

This file was deleted.

48 changes: 48 additions & 0 deletions test/parallel/test-internal-encoding-binding.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Flags: --expose-internals

'use strict';

require('../common');

const assert = require('node:assert');
const { internalBinding } = require('internal/test/binding');
const binding = internalBinding('encoding_binding');

{
// Valid input
const buf = Uint8Array.from([0xC1, 0xE9, 0xF3]);
assert.strictEqual(binding.decodeLatin1(buf, false, false), 'Áéó');
}

{
// Empty input
const buf = Uint8Array.from([]);
assert.strictEqual(binding.decodeLatin1(buf, false, false), '');
}

{
// Invalid input, but Latin1 has no invalid chars and should never throw.
const buf = new TextEncoder().encode('Invalid Latin1 🧑‍🧑‍🧒‍🧒');
assert.strictEqual(
binding.decodeLatin1(buf, false, false),
'Invalid Latin1 ð\x9F§\x91â\x80\x8Dð\x9F§\x91â\x80\x8Dð\x9F§\x92â\x80\x8Dð\x9F§\x92'
);
}

{
// IgnoreBOM with BOM
const buf = Uint8Array.from([0xFE, 0xFF, 0xC1, 0xE9, 0xF3]);
assert.strictEqual(binding.decodeLatin1(buf, true, false), 'þÿÁéó');
}

{
// Fatal and InvalidInput, but Latin1 has no invalid chars and should never throw.
const buf = Uint8Array.from([0xFF, 0xFF, 0xFF]);
assert.strictEqual(binding.decodeLatin1(buf, false, true), 'ÿÿÿ');
}

{
// IgnoreBOM and Fatal, but Latin1 has no invalid chars and should never throw.
const buf = Uint8Array.from([0xFE, 0xFF, 0xC1, 0xE9, 0xF3]);
assert.strictEqual(binding.decodeLatin1(buf, true, true), 'þÿÁéó');
}
3 changes: 3 additions & 0 deletions tools/search_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
try:
files = SearchFiles(*sys.argv[2:])
files = [ os.path.relpath(x, sys.argv[1]) for x in files ]
# Apply the same transform in SearchFiles after relpath
if sys.platform == 'win32':
files = [ x.replace('\\', '/') for x in files ]
print('\n'.join(files))
except Exception as e:
print(str(e))
Expand Down
Loading