summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/cssom/escape.html
blob: 895da59c49c0495514f0002fa6c340059c1d3123 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<!doctype html>
<meta charset=utf-8>
<title>CSS#escape</title>
<link rel=help href=https://drafts.csswg.org/cssom-1/#the-css.escape()-method>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id=log></div>
<script>
test(function() {
  assert_equals(CSS.escape.length, 1);
  assert_throws_js(TypeError, function() { CSS.escape(); });
}, "Number of arguments");

test(function() {
  assert_equals(CSS.escape(true), 'true');
  assert_equals(CSS.escape(false), 'false');
  assert_equals(CSS.escape(null), 'null');
  assert_equals(CSS.escape(''), '');
}, "String conversion");

test(function() {
  assert_equals(CSS.escape('\0'), '\uFFFD');
  assert_equals(CSS.escape('a\0'), 'a\uFFFD');
  assert_equals(CSS.escape('\0b'), '\uFFFDb');
  assert_equals(CSS.escape('a\0b'), 'a\uFFFDb');
}, "Null bytes");

test(function() {
  assert_equals(CSS.escape('\uFFFD'), '\uFFFD');
  assert_equals(CSS.escape('a\uFFFD'), 'a\uFFFD');
  assert_equals(CSS.escape('\uFFFDb'), '\uFFFDb');
  assert_equals(CSS.escape('a\uFFFDb'), 'a\uFFFDb');
}, "Replacement character");

test(function() {
  assert_equals(CSS.escape('0a'), '\\30 a');
  assert_equals(CSS.escape('1a'), '\\31 a');
  assert_equals(CSS.escape('2a'), '\\32 a');
  assert_equals(CSS.escape('3a'), '\\33 a');
  assert_equals(CSS.escape('4a'), '\\34 a');
  assert_equals(CSS.escape('5a'), '\\35 a');
  assert_equals(CSS.escape('6a'), '\\36 a');
  assert_equals(CSS.escape('7a'), '\\37 a');
  assert_equals(CSS.escape('8a'), '\\38 a');
  assert_equals(CSS.escape('9a'), '\\39 a');
}, "Number prefix");

test(function() {
  assert_equals(CSS.escape('a0b'), 'a0b');
  assert_equals(CSS.escape('a1b'), 'a1b');
  assert_equals(CSS.escape('a2b'), 'a2b');
  assert_equals(CSS.escape('a3b'), 'a3b');
  assert_equals(CSS.escape('a4b'), 'a4b');
  assert_equals(CSS.escape('a5b'), 'a5b');
  assert_equals(CSS.escape('a6b'), 'a6b');
  assert_equals(CSS.escape('a7b'), 'a7b');
  assert_equals(CSS.escape('a8b'), 'a8b');
  assert_equals(CSS.escape('a9b'), 'a9b');
}, "Letter number prefix");

test(function() {
  assert_equals(CSS.escape('-0a'), '-\\30 a');
  assert_equals(CSS.escape('-1a'), '-\\31 a');
  assert_equals(CSS.escape('-2a'), '-\\32 a');
  assert_equals(CSS.escape('-3a'), '-\\33 a');
  assert_equals(CSS.escape('-4a'), '-\\34 a');
  assert_equals(CSS.escape('-5a'), '-\\35 a');
  assert_equals(CSS.escape('-6a'), '-\\36 a');
  assert_equals(CSS.escape('-7a'), '-\\37 a');
  assert_equals(CSS.escape('-8a'), '-\\38 a');
  assert_equals(CSS.escape('-9a'), '-\\39 a');
}, "Dash number prefix");

test(function() {
  assert_equals(CSS.escape('--a'), '--a');
}, "Double dash prefix");

test(function() {
  assert_equals(CSS.escape('\x01\x02\x1E\x1F'), '\\1 \\2 \\1e \\1f ');

  assert_equals(CSS.escape('\x80\x2D\x5F\xA9'), '\x80\x2D\x5F\xA9');
  assert_equals(CSS.escape('\x7F\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F'), '\\7f \x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F');
  assert_equals(CSS.escape('\xA0\xA1\xA2'), '\xA0\xA1\xA2');
  assert_equals(CSS.escape('a0123456789b'), 'a0123456789b');
  assert_equals(CSS.escape('abcdefghijklmnopqrstuvwxyz'), 'abcdefghijklmnopqrstuvwxyz');
  assert_equals(CSS.escape('ABCDEFGHIJKLMNOPQRSTUVWXYZ'), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ');

  assert_equals(CSS.escape("hello\\world"), "hello\\\\world", "Backslashes get backslash-escaped");
  assert_equals(CSS.escape("hello\u{1234}world"), "hello\u{1234}world", "Code points greater than U+0080 are preserved");
  assert_equals(CSS.escape("-"), "\\-", "CSS.escape: Single dash escaped");

  assert_equals(CSS.escape('\x20\x21\x78\x79'), '\\ \\!xy');
}, "Various tests");

test(function() {
  // astral symbol (U+1D306 TETRAGRAM FOR CENTRE)
  assert_equals(CSS.escape('\uD834\uDF06'), '\uD834\uDF06');
  // lone surrogates
  assert_equals(CSS.escape('\uDF06'), '\uDF06');
  assert_equals(CSS.escape('\uD834'), '\uD834');
}, "Surrogates");
</script>