summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/encoding/textdecoder-labels.any.js
blob: efc4ae2d2ea586cf15d2e89369c9bb337b765cfa (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
// META: title=Encoding API: Encoding labels
// META: script=resources/encodings.js
// META: timeout=long

var whitespace = [' ', '\t', '\n', '\f', '\r'];
encodings_table.forEach(function(section) {
  section.encodings.filter(function(encoding) {
    return encoding.name !== 'replacement';
  }).forEach(function(encoding) {
    encoding.labels.forEach(function(label) {
      const textDecoderName = encoding.name.toLowerCase(); // ASCII names only, so safe
      test(function(t) {
        assert_equals(
          new TextDecoder(label).encoding, textDecoderName,
          'label for encoding should match');
        assert_equals(
          new TextDecoder(label.toUpperCase()).encoding, textDecoderName,
          'label matching should be case-insensitive');
        whitespace.forEach(function(ws) {
          assert_equals(
            new TextDecoder(ws + label).encoding, textDecoderName,
            'label for encoding with leading whitespace should match');
          assert_equals(
            new TextDecoder(label + ws).encoding, textDecoderName,
            'label for encoding with trailing whitespace should match');
          assert_equals(
            new TextDecoder(ws + label + ws).encoding, textDecoderName,
            'label for encoding with surrounding whitespace should match');
        });
      }, label + ' => ' + encoding.name);
    });
  });
});