11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci// From: https://github.com/w3c/web-platform-tests/blob/fa9436d12c/encoding/textdecoder-streaming.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 string =
111cb0ef41Sopenharmony_ci  '\x00123ABCabc\x80\xFF\u0100\u1000\uFFFD\uD800\uDC00\uDBFF\uDFFF';
121cb0ef41Sopenharmony_ciconst octets = {
131cb0ef41Sopenharmony_ci  'utf-8': [
141cb0ef41Sopenharmony_ci    0x00, 0x31, 0x32, 0x33, 0x41, 0x42, 0x43, 0x61, 0x62, 0x63, 0xc2, 0x80,
151cb0ef41Sopenharmony_ci    0xc3, 0xbf, 0xc4, 0x80, 0xe1, 0x80, 0x80, 0xef, 0xbf, 0xbd, 0xf0, 0x90,
161cb0ef41Sopenharmony_ci    0x80, 0x80, 0xf4, 0x8f, 0xbf, 0xbf],
171cb0ef41Sopenharmony_ci  'utf-16le': [
181cb0ef41Sopenharmony_ci    0x00, 0x00, 0x31, 0x00, 0x32, 0x00, 0x33, 0x00, 0x41, 0x00, 0x42, 0x00,
191cb0ef41Sopenharmony_ci    0x43, 0x00, 0x61, 0x00, 0x62, 0x00, 0x63, 0x00, 0x80, 0x00, 0xFF, 0x00,
201cb0ef41Sopenharmony_ci    0x00, 0x01, 0x00, 0x10, 0xFD, 0xFF, 0x00, 0xD8, 0x00, 0xDC, 0xFF, 0xDB,
211cb0ef41Sopenharmony_ci    0xFF, 0xDF]
221cb0ef41Sopenharmony_ci};
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ciObject.keys(octets).forEach((encoding) => {
251cb0ef41Sopenharmony_ci  for (let len = 1; len <= 5; ++len) {
261cb0ef41Sopenharmony_ci    const encoded = octets[encoding];
271cb0ef41Sopenharmony_ci    const decoder = new TextDecoder(encoding);
281cb0ef41Sopenharmony_ci    let out = '';
291cb0ef41Sopenharmony_ci    for (let i = 0; i < encoded.length; i += len) {
301cb0ef41Sopenharmony_ci      const sub = [];
311cb0ef41Sopenharmony_ci      for (let j = i; j < encoded.length && j < i + len; ++j)
321cb0ef41Sopenharmony_ci        sub.push(encoded[j]);
331cb0ef41Sopenharmony_ci      out += decoder.decode(new Uint8Array(sub), { stream: true });
341cb0ef41Sopenharmony_ci    }
351cb0ef41Sopenharmony_ci    out += decoder.decode();
361cb0ef41Sopenharmony_ci    assert.strictEqual(out, string);
371cb0ef41Sopenharmony_ci  }
381cb0ef41Sopenharmony_ci});
39