summaryrefslogtreecommitdiffstats
path: root/layout/style/test/test_css_escape_api.html
blob: 00ec240c70d71113103ce4bdc43566ab631482cd (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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=955860
-->
<head>
  <meta charset="utf-8">
  <title>Test for Bug 955860</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  <script type="application/javascript">
  </script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=955860">Mozilla Bug 955860</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script>
// Tests taken from:
// https://github.com/mathiasbynens/CSS.escape/blob/master/tests/tests.js

SimpleTest.doesThrow(() => CSS.escape(), 'undefined');

is(CSS.escape('\0'), '\uFFFD', "escaping for 0 char (1)");
is(CSS.escape('a\0'), 'a\uFFFD', "escaping for 0 char (2)");
is(CSS.escape('\0b'), '\uFFFDb', "escaping for 0 char (3)");
is(CSS.escape('a\0b'), 'a\uFFFDb', "escaping for 0 char (4)");

is(CSS.escape('\uFFFD'), '\uFFFD', "escaping for replacement char (1)");
is(CSS.escape('a\uFFFD'), 'a\uFFFD', "escaping replacement char (2)");
is(CSS.escape('\uFFFDb'), '\uFFFDb', "escaping replacement char (3)");
is(CSS.escape('a\uFFFDb'), 'a\uFFFDb', "escaping replacement char (4)");

is(CSS.escape(true), 'true', "escapingFailed Character : true(bool)");
is(CSS.escape(false), 'false', "escapingFailed Character : false(bool)");
is(CSS.escape(null), 'null', "escapingFailed Character : null");
is(CSS.escape(''), '', "escapingFailed Character : '' ");

is(CSS.escape('\x01\x02\x1E\x1F'), '\\1 \\2 \\1e \\1f ',"escapingFailed Char: \\x01\\x02\\x1E\\x1F");

is(CSS.escape('0a'), '\\30 a', "escapingFailed Char: 0a");
is(CSS.escape('1a'), '\\31 a', "escapingFailed Char: 1a");
is(CSS.escape('2a'), '\\32 a', "escapingFailed Char: 2a");
is(CSS.escape('3a'), '\\33 a', "escapingFailed Char: 3a");
is(CSS.escape('4a'), '\\34 a', "escapingFailed Char: 4a");
is(CSS.escape('5a'), '\\35 a', "escapingFailed Char: 5a");
is(CSS.escape('6a'), '\\36 a', "escapingFailed Char: 6a");
is(CSS.escape('7a'), '\\37 a', "escapingFailed Char: 7a");
is(CSS.escape('8a'), '\\38 a', "escapingFailed Char: 8a");
is(CSS.escape('9a'), '\\39 a', "escapingFailed Char: 9a");

is(CSS.escape('a0b'), 'a0b', "escapingFailed Char: a0b");
is(CSS.escape('a1b'), 'a1b', "escapingFailed Char: a1b");
is(CSS.escape('a2b'), 'a2b', "escapingFailed Char: a2b");
is(CSS.escape('a3b'), 'a3b', "escapingFailed Char: a3b");
is(CSS.escape('a4b'), 'a4b', "escapingFailed Char: a4b");
is(CSS.escape('a5b'), 'a5b', "escapingFailed Char: a5b");
is(CSS.escape('a6b'), 'a6b', "escapingFailed Char: a6b");
is(CSS.escape('a7b'), 'a7b', "escapingFailed Char: a7b");
is(CSS.escape('a8b'), 'a8b', "escapingFailed Char: a8b");
is(CSS.escape('a9b'), 'a9b', "escapingFailed Char: a9b");

is(CSS.escape('-0a'), '-\\30 a', "escapingFailed Char: -0a");
is(CSS.escape('-1a'), '-\\31 a', "escapingFailed Char: -1a");
is(CSS.escape('-2a'), '-\\32 a', "escapingFailed Char: -2a");
is(CSS.escape('-3a'), '-\\33 a', "escapingFailed Char: -3a");
is(CSS.escape('-4a'), '-\\34 a', "escapingFailed Char: -4a");
is(CSS.escape('-5a'), '-\\35 a', "escapingFailed Char: -5a");
is(CSS.escape('-6a'), '-\\36 a', "escapingFailed Char: -6a");
is(CSS.escape('-7a'), '-\\37 a', "escapingFailed Char: -7a");
is(CSS.escape('-8a'), '-\\38 a', "escapingFailed Char: -8a");
is(CSS.escape('-9a'), '-\\39 a', "escapingFailed Char: -9a");

is(CSS.escape('--a'), '--a', 'Should not need to escape leading "--"');

is(CSS.escape('\x80\x2D\x5F\xA9'), '\\80 \x2D\x5F\xA9', "escapingFailed Char: \\x80\\x2D\\x5F\\xA9");
is(CSS.escape('\xA0\xA1\xA2'), '\xA0\xA1\xA2', "escapingFailed Char: \\xA0\\xA1\\xA2");
is(CSS.escape('a0123456789b'), 'a0123456789b', "escapingFailed Char: a0123465789");
is(CSS.escape('abcdefghijklmnopqrstuvwxyz'), 'abcdefghijklmnopqrstuvwxyz', "escapingFailed Char: abcdefghijklmnopqrstuvwxyz");
is(CSS.escape('ABCDEFGHIJKLMNOPQRSTUVWXYZ'), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', "escapingFailed Char: ABCDEFGHIJKLMNOPQRSTUVWXYZBCDEFGHIJKLMNOPQRSTUVWXYZ");

is(CSS.escape('\x20\x21\x78\x79'), '\\ \\!xy', "escapingFailed Char: \\x20\\x21\\x78\\x79");

// astral symbol (U+1D306 TETRAGRAM FOR CENTRE)
is(CSS.escape('\uD834\uDF06'), '\uD834\uDF06', "escapingFailed Char:\\uD834\\uDF06");
// lone surrogates
is(CSS.escape('\uDF06'), '\uDF06', "escapingFailed Char: \\uDF06");
is(CSS.escape('\uD834'), '\uD834', "escapingFailed Char: \\uD834");
</script>
</pre>
</body>
</html>