• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// META: title=Encoding API: Encoding labels
2// META: script=resources/encodings.js
3
4var whitespace = [' ', '\t', '\n', '\f', '\r'];
5encodings_table.forEach(function(section) {
6  section.encodings.filter(function(encoding) {
7    return encoding.name !== 'replacement';
8  }).forEach(function(encoding) {
9    encoding.labels.forEach(function(label) {
10      const textDecoderName = encoding.name.toLowerCase(); // ASCII names only, so safe
11      test(function(t) {
12        assert_equals(
13          new TextDecoder(label).encoding, textDecoderName,
14          'label for encoding should match');
15        assert_equals(
16          new TextDecoder(label.toUpperCase()).encoding, textDecoderName,
17          'label matching should be case-insensitive');
18        whitespace.forEach(function(ws) {
19          assert_equals(
20            new TextDecoder(ws + label).encoding, textDecoderName,
21            'label for encoding with leading whitespace should match');
22          assert_equals(
23            new TextDecoder(label + ws).encoding, textDecoderName,
24            'label for encoding with trailing whitespace should match');
25          assert_equals(
26            new TextDecoder(ws + label + ws).encoding, textDecoderName,
27            'label for encoding with surrounding whitespace should match');
28        });
29      }, label + ' => ' + encoding.name);
30    });
31  });
32});
33