11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci// From: https://github.com/w3c/web-platform-tests/blob/7f567fa29c/encoding/textdecoder-ignorebom.html 41cb0ef41Sopenharmony_ci// This is the part that can be run without ICU 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_cirequire('../common'); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst assert = require('assert'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst cases = [ 111cb0ef41Sopenharmony_ci { 121cb0ef41Sopenharmony_ci encoding: 'utf-8', 131cb0ef41Sopenharmony_ci bytes: [0xEF, 0xBB, 0xBF, 0x61, 0x62, 0x63] 141cb0ef41Sopenharmony_ci }, 151cb0ef41Sopenharmony_ci { 161cb0ef41Sopenharmony_ci encoding: 'utf-16le', 171cb0ef41Sopenharmony_ci bytes: [0xFF, 0xFE, 0x61, 0x00, 0x62, 0x00, 0x63, 0x00] 181cb0ef41Sopenharmony_ci }, 191cb0ef41Sopenharmony_ci]; 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_cicases.forEach((testCase) => { 221cb0ef41Sopenharmony_ci const BOM = '\uFEFF'; 231cb0ef41Sopenharmony_ci let decoder = new TextDecoder(testCase.encoding, { ignoreBOM: true }); 241cb0ef41Sopenharmony_ci const bytes = new Uint8Array(testCase.bytes); 251cb0ef41Sopenharmony_ci assert.strictEqual(decoder.decode(bytes), `${BOM}abc`); 261cb0ef41Sopenharmony_ci decoder = new TextDecoder(testCase.encoding, { ignoreBOM: false }); 271cb0ef41Sopenharmony_ci assert.strictEqual(decoder.decode(bytes), 'abc'); 281cb0ef41Sopenharmony_ci decoder = new TextDecoder(testCase.encoding); 291cb0ef41Sopenharmony_ci assert.strictEqual(decoder.decode(bytes), 'abc'); 301cb0ef41Sopenharmony_ci}); 31