|
2 | 2 | Tests for the tokenize module. |
3 | 3 |
|
4 | 4 | The tests can be really simple. Given a small fragment of source |
5 | | -code, print out a table with tokens. The ENDMARK is omitted for |
| 5 | +code, print out a table with tokens. The ENDMARKER is omitted for |
6 | 6 | brevity. |
7 | 7 |
|
8 | 8 | >>> dump_tokens("1 + 1") |
@@ -1180,15 +1180,30 @@ def test_pathological_trailing_whitespace(self): |
1180 | 1180 | class UntokenizeTest(TestCase): |
1181 | 1181 |
|
1182 | 1182 | def test_bad_input_order(self): |
| 1183 | + # raise if previous row |
1183 | 1184 | u = Untokenizer() |
1184 | 1185 | u.prev_row = 2 |
1185 | 1186 | u.prev_col = 2 |
1186 | 1187 | with self.assertRaises(ValueError) as cm: |
1187 | 1188 | u.add_whitespace((1,3)) |
1188 | 1189 | self.assertEqual(cm.exception.args[0], |
1189 | 1190 | 'start (1,3) precedes previous end (2,2)') |
| 1191 | + # raise if previous column in row |
1190 | 1192 | self.assertRaises(ValueError, u.add_whitespace, (2,1)) |
1191 | 1193 |
|
| 1194 | + def test_backslash_continuation(self): |
| 1195 | + # The problem is that <whitespace>\<newline> leaves no token |
| 1196 | + u = Untokenizer() |
| 1197 | + u.prev_row = 1 |
| 1198 | + u.prev_col = 1 |
| 1199 | + u.tokens = [] |
| 1200 | + u.add_whitespace((2, 0)) |
| 1201 | + self.assertEqual(u.tokens, ['\\\n']) |
| 1202 | + u.prev_row = 2 |
| 1203 | + u.add_whitespace((4, 4)) |
| 1204 | + self.assertEqual(u.tokens, ['\\\n', '\\\n\\\n', ' ']) |
| 1205 | + self.assertTrue(roundtrip('a\n b\n c\n \\\n c\n')) |
| 1206 | + |
1192 | 1207 | def test_iter_compat(self): |
1193 | 1208 | u = Untokenizer() |
1194 | 1209 | token = (NAME, 'Hello') |
|
0 commit comments