1'use strict'; 2 3// From: https://github.com/w3c/web-platform-tests/blob/7f567fa29c/encoding/textdecoder-ignorebom.html 4// This is the part that can be run without ICU 5 6require('../common'); 7 8const assert = require('assert'); 9 10const cases = [ 11 { 12 encoding: 'utf-8', 13 bytes: [0xEF, 0xBB, 0xBF, 0x61, 0x62, 0x63] 14 }, 15 { 16 encoding: 'utf-16le', 17 bytes: [0xFF, 0xFE, 0x61, 0x00, 0x62, 0x00, 0x63, 0x00] 18 }, 19]; 20 21cases.forEach((testCase) => { 22 const BOM = '\uFEFF'; 23 let decoder = new TextDecoder(testCase.encoding, { ignoreBOM: true }); 24 const bytes = new Uint8Array(testCase.bytes); 25 assert.strictEqual(decoder.decode(bytes), `${BOM}abc`); 26 decoder = new TextDecoder(testCase.encoding, { ignoreBOM: false }); 27 assert.strictEqual(decoder.decode(bytes), 'abc'); 28 decoder = new TextDecoder(testCase.encoding); 29 assert.strictEqual(decoder.decode(bytes), 'abc'); 30}); 31