summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/harness/wptrunner/wptmanifest/tests/test_serializer.py
blob: ec4d6e2d7373d480141f2430b021e568dd922c4a (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

import unittest

from cStringIO import StringIO

from .. import parser, serializer


class TokenizerTest(unittest.TestCase):
    def setUp(self):
        self.serializer = serializer.ManifestSerializer()
        self.parser = parser.Parser()

    def serialize(self, input_str):
        return self.serializer.serialize(self.parser.parse(input_str))

    def compare(self, input_str, expected=None):
        if expected is None:
            expected = input_str
        expected = expected.encode("utf8")
        actual = self.serialize(input_str)
        self.assertEquals(actual, expected)

    def test_0(self):
        self.compare("""key: value
[Heading 1]
  other_key: other_value
""")

    def test_1(self):
        self.compare("""key: value
[Heading 1]
  other_key:
    if a or b: other_value
""")

    def test_2(self):
        self.compare("""key: value
[Heading 1]
  other_key:
    if a or b: other_value
    fallback_value
""")

    def test_3(self):
        self.compare("""key: value
[Heading 1]
  other_key:
    if a == 1: other_value
    fallback_value
""")

    def test_4(self):
        self.compare("""key: value
[Heading 1]
  other_key:
    if a == "1": other_value
    fallback_value
""")

    def test_5(self):
        self.compare("""key: value
[Heading 1]
  other_key:
    if a == "abc"[1]: other_value
    fallback_value
""")

    def test_6(self):
        self.compare("""key: value
[Heading 1]
  other_key:
    if a == "abc"[c]: other_value
    fallback_value
""")

    def test_7(self):
        self.compare("""key: value
[Heading 1]
  other_key:
    if (a or b) and c: other_value
    fallback_value
""",
"""key: value
[Heading 1]
  other_key:
    if a or b and c: other_value
    fallback_value
""")

    def test_8(self):
        self.compare("""key: value
[Heading 1]
  other_key:
    if a or (b and c): other_value
    fallback_value
""")

    def test_9(self):
        self.compare("""key: value
[Heading 1]
  other_key:
    if not (a and b): other_value
    fallback_value
""")

    def test_10(self):
        self.compare("""key: value
[Heading 1]
  some_key: some_value

[Heading 2]
  other_key: other_value
""")

    def test_11(self):
        self.compare("""key:
  if not a and b and c and d: true
""")

    def test_12(self):
        self.compare("""[Heading 1]
  key: [a:1, b:2]
""")

    def test_13(self):
        self.compare("""key: [a:1, "b:#"]
""")

    def test_14(self):
        self.compare("""key: [","]
""")

    def test_15(self):
        self.compare("""key: ,
""")

    def test_16(self):
        self.compare("""key: ["]", b]
""")

    def test_17(self):
        self.compare("""key: ]
""")

    def test_18(self):
        self.compare("""key: \]
        """, """key: ]
""")

    def test_escape_0(self):
        self.compare(r"""k\t\:y: \a\b\f\n\r\t\v""",
                     r"""k\t\:y: \x07\x08\x0c\n\r\t\x0b
""")

    def test_escape_1(self):
        self.compare(r"""k\x00: \x12A\x45""",
                     r"""k\x00: \x12AE
""")

    def test_escape_2(self):
        self.compare(r"""k\u0045y: \u1234A\uABc6""",
                     u"""kEy: \u1234A\uabc6
""")

    def test_escape_3(self):
        self.compare(r"""k\u0045y: \u1234A\uABc6""",
                     u"""kEy: \u1234A\uabc6
""")

    def test_escape_4(self):
        self.compare(r"""key: '\u1234A\uABc6'""",
                     u"""key: \u1234A\uabc6
""")

    def test_escape_5(self):
        self.compare(r"""key: [\u1234A\uABc6]""",
                     u"""key: [\u1234A\uabc6]
""")

    def test_escape_6(self):
        self.compare(r"""key: [\u1234A\uABc6\,]""",
                     u"""key: ["\u1234A\uabc6,"]
""")

    def test_escape_7(self):
        self.compare(r"""key: [\,\]\#]""",
                     r"""key: [",]#"]
""")

    def test_escape_8(self):
        self.compare(r"""key: \#""",
                     r"""key: "#"
""")

    def test_escape_9(self):
        self.compare(r"""key: \U10FFFFabc""",
                     u"""key: \U0010FFFFabc
""")

    def test_escape_10(self):
        self.compare(r"""key: \u10FFab""",
                     u"""key: \u10FFab
""")

    def test_escape_11(self):
        self.compare(r"""key: \\ab
""")

    def test_atom_1(self):
            self.compare(r"""key: @True
""")

    def test_atom_2(self):
            self.compare(r"""key: @False
""")

    def test_atom_3(self):
            self.compare(r"""key: @Reset
""")

    def test_atom_4(self):
        self.compare(r"""key: [a, @Reset, b]
""")