summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/encoding/textdecoder-eof.any.js
blob: e41e326aace2440f9f46969bbce6d82c1e582507 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
test(() => {
  // Truncated sequences
  assert_equals(new TextDecoder().decode(new Uint8Array([0xF0])), "\uFFFD");
  assert_equals(new TextDecoder().decode(new Uint8Array([0xF0, 0x9F])), "\uFFFD");
  assert_equals(new TextDecoder().decode(new Uint8Array([0xF0, 0x9F, 0x92])), "\uFFFD");

  // Errors near end-of-queue
  assert_equals(new TextDecoder().decode(new Uint8Array([0xF0, 0x9F, 0x41])), "\uFFFDA");
  assert_equals(new TextDecoder().decode(new Uint8Array([0xF0, 0x41, 0x42])), "\uFFFDAB");
  assert_equals(new TextDecoder().decode(new Uint8Array([0xF0, 0x41, 0xF0])), "\uFFFDA\uFFFD");
  assert_equals(new TextDecoder().decode(new Uint8Array([0xF0, 0x8F, 0x92])), "\uFFFD\uFFFD\uFFFD");
}, "TextDecoder end-of-queue handling");

test(() => {
  const decoder = new TextDecoder();
  decoder.decode(new Uint8Array([0xF0]), { stream: true });
  assert_equals(decoder.decode(), "\uFFFD");

  decoder.decode(new Uint8Array([0xF0]), { stream: true });
  decoder.decode(new Uint8Array([0x9F]), { stream: true });
  assert_equals(decoder.decode(), "\uFFFD");

  decoder.decode(new Uint8Array([0xF0, 0x9F]), { stream: true });
  assert_equals(decoder.decode(new Uint8Array([0x92])), "\uFFFD");

  assert_equals(decoder.decode(new Uint8Array([0xF0, 0x9F]), { stream: true }), "");
  assert_equals(decoder.decode(new Uint8Array([0x41]), { stream: true }), "\uFFFDA");
  assert_equals(decoder.decode(), "");

  assert_equals(decoder.decode(new Uint8Array([0xF0, 0x41, 0x42]), { stream: true }), "\uFFFDAB");
  assert_equals(decoder.decode(), "");

  assert_equals(decoder.decode(new Uint8Array([0xF0, 0x41, 0xF0]), { stream: true }), "\uFFFDA");
  assert_equals(decoder.decode(), "\uFFFD");

  assert_equals(decoder.decode(new Uint8Array([0xF0]), { stream: true }), "");
  assert_equals(decoder.decode(new Uint8Array([0x8F]), { stream: true }), "\uFFFD\uFFFD");
  assert_equals(decoder.decode(new Uint8Array([0x92]), { stream: true }), "\uFFFD");
  assert_equals(decoder.decode(), "");
}, "TextDecoder end-of-queue handling using stream: true");