node/test/parallel/test-internal-encoding-binding.js
2025-12-04 14:23:01 +00:00

54 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Flags: --expose-internals
'use strict';
require('../common');
const assert = require('node:assert');
const { internalBinding } = require('internal/test/binding');
const binding = internalBinding('encoding_binding');
// Windows-1252 specific tests
{
// Test Windows-1252 special characters in 128-159 range
// These differ from Latin-1
assert.strictEqual(binding.decodeWindows1252(Uint8Array.of(0x80), false, false), '€');
assert.strictEqual(binding.decodeWindows1252(Uint8Array.of(0x82), false, false), '');
assert.strictEqual(binding.decodeWindows1252(Uint8Array.of(0x83), false, false), 'ƒ');
assert.strictEqual(binding.decodeWindows1252(Uint8Array.of(0x9F), false, false), 'Ÿ');
}
{
// Test Windows-1252 characters outside 128-159 range (same as Latin-1)
const buf = Uint8Array.from([0xC1, 0xE9, 0xF3]);
assert.strictEqual(binding.decodeWindows1252(buf, false, false), 'Áéó');
}
{
// Empty input
const buf = Uint8Array.from([]);
assert.strictEqual(binding.decodeWindows1252(buf, false, false), '');
}
// Windows-1252 specific tests
{
// Test Windows-1252 special characters in 128-159 range
// These differ from Latin-1
assert.strictEqual(binding.decodeWindows1252(Uint8Array.of(0x80), false, false), '€');
assert.strictEqual(binding.decodeWindows1252(Uint8Array.of(0x82), false, false), '');
assert.strictEqual(binding.decodeWindows1252(Uint8Array.of(0x83), false, false), 'ƒ');
assert.strictEqual(binding.decodeWindows1252(Uint8Array.of(0x9F), false, false), 'Ÿ');
}
{
// Test Windows-1252 characters outside 128-159 range (same as Latin-1)
const buf = Uint8Array.from([0xC1, 0xE9, 0xF3]);
assert.strictEqual(binding.decodeWindows1252(buf, false, false), 'Áéó');
}
{
// Empty input
const buf = Uint8Array.from([]);
assert.strictEqual(binding.decodeWindows1252(buf, false, false), '');
}