diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /testing/web-platform/tests/encoding/textdecoder-byte-order-marks.any.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/encoding/textdecoder-byte-order-marks.any.js')
-rw-r--r-- | testing/web-platform/tests/encoding/textdecoder-byte-order-marks.any.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/testing/web-platform/tests/encoding/textdecoder-byte-order-marks.any.js b/testing/web-platform/tests/encoding/textdecoder-byte-order-marks.any.js new file mode 100644 index 0000000000..9ef0d73141 --- /dev/null +++ b/testing/web-platform/tests/encoding/textdecoder-byte-order-marks.any.js @@ -0,0 +1,42 @@ +// META: title=Encoding API: Byte-order marks + +var testCases = [ + { + encoding: 'utf-8', + bom: [0xEF, 0xBB, 0xBF], + bytes: [0x7A, 0xC2, 0xA2, 0xE6, 0xB0, 0xB4, 0xF0, 0x9D, 0x84, 0x9E, 0xF4, 0x8F, 0xBF, 0xBD] + }, + { + encoding: 'utf-16le', + bom: [0xff, 0xfe], + bytes: [0x7A, 0x00, 0xA2, 0x00, 0x34, 0x6C, 0x34, 0xD8, 0x1E, 0xDD, 0xFF, 0xDB, 0xFD, 0xDF] + }, + { + encoding: 'utf-16be', + bom: [0xfe, 0xff], + bytes: [0x00, 0x7A, 0x00, 0xA2, 0x6C, 0x34, 0xD8, 0x34, 0xDD, 0x1E, 0xDB, 0xFF, 0xDF, 0xFD] + } +]; + +var string = 'z\xA2\u6C34\uD834\uDD1E\uDBFF\uDFFD'; // z, cent, CJK water, G-Clef, Private-use character + +testCases.forEach(function(t) { + test(function() { + + var decoder = new TextDecoder(t.encoding); + assert_equals(decoder.decode(new Uint8Array(t.bytes)), string, + 'Sequence without BOM should decode successfully'); + + assert_equals(decoder.decode(new Uint8Array(t.bom.concat(t.bytes))), string, + 'Sequence with BOM should decode successfully (with no BOM present in output)'); + + testCases.forEach(function(o) { + if (o === t) + return; + + assert_not_equals(decoder.decode(new Uint8Array(o.bom.concat(t.bytes))), string, + 'Mismatching BOM should not be ignored - treated as garbage bytes.'); + }); + + }, 'Byte-order marks: ' + t.encoding); +}); |