-
Notifications
You must be signed in to change notification settings - Fork 30.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: convert test_encoding_binding.cc to a JS test
The cctest file `test_encoding_binding.cc` is never tested and it is not a valid test. Binding functions should never be tested with V8 API circumvented. A binding function should only be tested with JS calls. PR-URL: #56791 Refs: #55275 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Daniel Lemire <daniel@lemire.me> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
- Loading branch information
1 parent
1b2a966
commit 3c105b6
Showing
2 changed files
with
48 additions
and
176 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), 'þÿÁéó'); | ||
} |