-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtests.py
9025 lines (7518 loc) · 243 KB
/
tests.py
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
def to_string(x):
if x.__class__.__name__ == 'bytes':
return x.decode('utf-8')
return x
import unittest, regex, os
from __init__ import oprex, OprexSyntaxError
class TestErrorHandling(unittest.TestCase):
def given(self, oprex_source, expect_error):
oprex_source = to_string(oprex_source)
expect_error = to_string(expect_error)
if expect_error:
expect_error = '\n' + expect_error
try:
oprex(oprex_source)
except Exception as err:
got_error = str(err)
else:
got_error = ''
if got_error != expect_error:
msg = 'For input: %s\n----------------------------- Got Error: -----------------------------%s\n\n-------------------------- Expected Error: ---------------------------%s'
raise AssertionError(msg % (
oprex_source or '(empty string)',
got_error or '\n(no error)',
expect_error or '\n(no error)',
))
def test_white_guards(self):
self.given('one-liner input',
expect_error=b'Line 1: First line must be blank, not: one-liner input')
self.given(b'''something in the first line
''',
expect_error=b'Line 1: First line must be blank, not: something in the first line')
self.given(b'''
something in the last line''',
expect_error=b'Line 2: Last line must be blank, not: something in the last line')
def test_unknown_symbol(self):
self.given(b'''
`@$%^&;{}[]\\
''',
expect_error=b'Line 2: Syntax error at or near: `@$%^&;{}[]\\')
def test_unexpected_token(self):
self.given(b'''
/to/be/?
''',
expect_error=b'''Line 2: Unexpected QUESTMARK
/to/be/?
^''')
self.given(b'''
root
branch
''',
expect_error=b'''Line 3: Unexpected NEWLINE
branch
^''')
self.given(b'''
root
root = '/'
root2
''',
expect_error=b'''Line 4: Unexpected VARNAME
root2
^''')
self.given(b'''
root
root = '/'\nroot2
''',
expect_error=b'Line 4: Unexpected VARNAME\nroot2\n^')
self.given(b'''
*) /warming/and/warming/
''',
expect_error=b'Line 2: Unexpected GLOBALMARK\n*) /warming/and/warming/\n^')
self.given(b'''
/greeting/world/
greeting = 'hello'
world = 'world'
''',
expect_error="Line 4: 'world' is defined but not used (by its parent expression)")
def test_indentation_error(self):
self.given(b'''
/greeting/world/
greeting = 'hello'
world = 'world'
''',
expect_error="Line 4: 'world' is defined but not used (by its parent expression)")
self.given(b'''
root
branch
misaligned
''',
expect_error=b'Line 4: Indentation error')
self.given(b'''
root
branch
hyperroot
''',
expect_error=b'Line 4: Indentation error')
def test_correct_error_line_numbering(self):
self.given(b'''
/greeting/world/
greeting = 'hello'
world = 'world'
''',
expect_error="Line 5: 'world' is defined but not used (by its parent expression)")
self.given(b'''
/greeting/world/
greeting = 'hello'
world = 'world'
''',
expect_error="Line 8: 'world' is defined but not used (by its parent expression)")
self.given(b'''
/greeting/world/
greeting = 'hello'
world = 'world'
''',
expect_error=b'Line 6: Indentation error')
self.given(b'''
warming
*) warming = 'global'
''',
expect_error="Line 5: The GLOBALMARK *) must be put at the line's beginning")
def test_mixed_indentation(self):
self.given(b'''
\tthis_line_mixes_tab_and_spaces_for_indentation
''',
expect_error=b'Line 2: Cannot mix space and tab for indentation')
self.given(b'''
/tabs/vs/spaces/
\t\ttabs = 'this line is tabs-indented'
spaces = 'this line is spaces-indented'
''',
expect_error=b'Line 3: Inconsistent indentation character')
def test_undefined_variable(self):
self.given(b'''
bigfoot
''',
expect_error="Line 2: 'bigfoot' is not defined")
self.given(b'''
/horses/and/unicorns/
horses = 'Thoroughbreds'
and = ' and '
''',
expect_error="Line 2: 'unicorns' is not defined")
self.given(b'''
/unicorns/and/horses/
horses = 'Thoroughbreds'
and = ' and '
''',
expect_error="Line 2: 'unicorns' is not defined")
def test_illegal_variable_name(self):
self.given(b'''
101dalmatians
101dalmatians = 101 of 'dalmatians'
''',
expect_error=b'''Line 2: Unexpected VARNAME
101dalmatians
^''')
self.given(b'''
/101dalmatians/
101dalmatians = 101 of 'dalmatians'
''',
expect_error=b'''Line 2: Unexpected NUMBER
/101dalmatians/
^''')
self.given(b'''
_
''',
expect_error=b'''Line 2: Unexpected NEWLINE
_
^''')
self.given(b'''
/_/
''',
expect_error=b'''Line 2: Unexpected UNDERSCORE
/_/
^''')
self.given(b'''
underscore
_ = '_'
''',
expect_error=b'''Line 3: Unexpected UNDERSCORE
_ = '_'
^''')
self.given(b'''
<<|
|_
''',
expect_error=b'''Line 3: Unexpected NEWLINE
|_
^''')
self.given(b'''
@|
|/_/
''',
expect_error=b'''Line 3: Unexpected UNDERSCORE
|/_/
^''')
self.given(b'''
<@>
_
''',
expect_error=b'''Line 3: Unexpected UNDERSCORE
_
^''')
self.given(b'''
<@>
|_|
''',
expect_error=b'''Line 3: Unexpected UNDERSCORE
|_|
^''')
def test_duplicate_variable(self):
self.given(u'''
dejavu
dejavu = 'Déjà vu'
dejavu = 'Déjà vu'
''',
expect_error="Line 4: Names must be unique within a scope, 'dejavu' is already defined (previous definition at line 3)")
self.given(u'''
dejavu
dejavu = dejavu = 'Déjà vu'
''',
expect_error="Line 3: Names must be unique within a scope, 'dejavu' is already declared (previous declaration at line 3)")
self.given(u'''
dejavu
dejavu = 'Déjà vu'
dejavu = dejavu
''',
expect_error="Line 4: Names must be unique within a scope, 'dejavu' is already defined (previous definition at line 3)")
self.given(u'''
/de/jade/
de = 'de'
jade = /ja/de/
ja = 'JA'
de = 'DE'
''',
expect_error="Line 6: Names must be unique within a scope, 'de' is already defined (previous definition at line 3)")
self.given(u'''
/deja/de/
deja = /de/ja/
de = 'de' -- different scope
ja = 'JA'
de = 'DE' -- different scope, so should be no error
''',
expect_error=b'')
self.given(u'''
chicken
chicken = /egg/hatches/
egg = /chicken/lays/
chicken = /velociraptor/evolves/
''',
expect_error="Line 5: Names must be unique within a scope, 'chicken' is already declared (previous declaration at line 3)")
self.given(b'''
/subject/predicate/object/
subject = /article/adjective/noun/
*) article = 'the'
*) adjective = /speed/color/
speed = 'quick'
color = 'brown'
*) noun = 'fox'
predicate = /verb/adverb/
verb = 'jumps'
adverb = 'over'
object = /article/adjective/noun/
article = 'an'
''',
expect_error="Line 13: Names must be unique within a scope, 'article' is already defined (previous definition at line 4)")
def test_unused_variable(self):
self.given(b'''
/alice/bob/
alice = 'alice'
bob = 'bob'
trudy = 'trudy'
''',
expect_error="Line 5: 'trudy' is defined but not used (by its parent expression)")
self.given(b'''
/alice/bob/
alice = 'alice'
bob = robert
robert = 'bob'
doe = 'doe'
''',
expect_error="Line 6: 'doe' is defined but not used (by its parent expression)")
self.given(b'''
non-vowel
vowel: a i u e o
''',
expect_error=b'') # vowel should be counted as used
def test_invalid_atomizer(self):
self.given(b'''
@alpha -- atomizer only applicable to chained lookup
''',
expect_error=b'''Line 2: Unexpected VARNAME
@alpha -- atomizer only applicable to chained lookup
^''')
def test_unclosed_literal(self):
self.given(b'''
mcd
mcd = 'McDonald's
''',
expect_error=b'''Line 3: Unexpected VARNAME
mcd = 'McDonald's
^''')
self.given(b'''
"she said \\"Hi\\"
''',
expect_error=b'Line 2: Syntax error at or near: "she said \\"Hi\\"')
self.given(b'''
quotes_mismatch
quotes_mismatch = "'
''',
expect_error="""Line 3: Syntax error at or near: "'""")
def test_invalid_string_escape(self):
self.given(b'''
'\N{KABAYAN}'
''',
expect_error="Line 2: undefined character name 'KABAYAN'")
self.given(u'''
'\N{APOSTROPHE}'
''',
expect_error="Line 2: Syntax error at or near: '")
def test_invalid_global_mark(self):
self.given(b'''
*)
''',
expect_error="Line 2: The GLOBALMARK *) must be put at the line's beginning")
self.given(b'''
*)
''',
expect_error=b'Line 2: Syntax error: *)')
self.given(b'''
*)\t
''',
expect_error=b'Line 2: Unexpected GLOBALMARK\n*) \n^')
self.given(b'''
*)warming
''',
expect_error=b'Line 2: Syntax error: *)')
self.given(b'''
*) warming
''',
expect_error=b'Line 2: Unexpected GLOBALMARK\n*) warming\n^')
self.given(b'''
warming
*)warming = 'global'
''',
expect_error="Line 3: The GLOBALMARK *) must be put at the line's beginning")
self.given(b'''
warming
*) warming = 'global'
''',
expect_error="Line 3: The GLOBALMARK *) must be put at the line's beginning")
self.given(b'''
warming
warming*) = 'global'
''',
expect_error="Line 3: Syntax error at or near: *) = 'global'")
self.given(b'''
warming
warming = global *)
''',
expect_error="Line 3: Syntax error: warming = global *)")
self.given(b'''
warming
warming = *) 'global'
''',
expect_error="Line 3: Syntax error: warming = *) 'global'")
self.given(b'''
warming
warming *) = 'global'
''',
expect_error="Line 3: Syntax error: warming *) = 'global'")
self.given(b'''
warming
*) *) warming = 'global'
''',
expect_error=b'Line 3: Syntax error: *) *) ')
self.given(b'''
warming
*) warming*) = 'global'
''',
expect_error="Line 3: Syntax error at or near: *) = 'global'")
self.given(b'''
warming
*) warming = global *)
''',
expect_error="Line 3: Syntax error: *) warming = global *)")
self.given(b'''
warming
warming = 'global'
*)
''',
expect_error="Line 4: Unexpected NEWLINE\n*) \n ^")
self.given(b'''
warming
warming = 'global'
*)
''',
expect_error="Line 4: Syntax error: *)")
self.given(b'''
warming
warming = 'global'
*) junk
''',
expect_error="Line 4: Unexpected NEWLINE\n*) junk\n ^")
self.given(b'''
warming
warming = 'global'
*) *)junk
''',
expect_error="Line 4: Syntax error: *) *)")
self.given(b'''
warming
warming = 'global'
*) *)
''',
expect_error="Line 4: Syntax error: *) *)")
self.given(b'''
warming
warming = 'global'
*) *)
''',
expect_error="Line 4: Syntax error: *) *)")
def test_global_aliasing(self):
self.given(b'''
/oneoneone/oneone/one/
oneoneone = /satu/uno/ichi/
satu = '1'
*) uno = ichi = satu
oneone = /uno/ichi/
one = ichi
ichi: 1
''',
expect_error="Line 8: Names must be unique within a scope, 'ichi' is already defined (previous definition at line 5)")
self.given(b'''
/oneoneone/oneone/one/
oneoneone = /satu/uno/ichi/
satu = '1'
*) uno = ichi = satu
oneone = /uno/ichi/
one = uno
uno: 1
''',
expect_error="Line 8: Names must be unique within a scope, 'uno' is already defined (previous definition at line 5)")
self.given(b'''
/oneoneone/oneone/one/
oneoneone = /satu/uno/ichi/
satu = '1'
*) uno = ichi = satu
oneone = /uno/ichi/
one = satu
''',
expect_error="Line 7: 'satu' is not defined")
self.given(b'''
/oneoneone/oneone/one/
oneoneone = /satu/uno/ichi/
*) satu = '1'
uno = ichi = satu
one = satu
oneone = /uno/ichi/
''',
expect_error="Line 7: 'uno' is not defined")
def test_invalid_charclass(self):
self.given(b'''
empty_charclass
empty_charclass:
''',
expect_error=b'''Line 3: Unexpected NEWLINE
empty_charclass:
^''')
self.given(b'''
noSpaceAfterColon
noSpaceAfterColon:n o
''',
expect_error=b'''Line 3: Unexpected CHAR
noSpaceAfterColon:n o
^''')
self.given(b'''
diphtong
diphtong: ae au
''',
expect_error="Line 3: Cannot include 'ae': not defined")
self.given(b'''
miscolon
miscolon: /colon/should/be/equal/sign/
''',
expect_error=b'Line 3: /colon compiles to \p{colon} which is rejected by the regex engine with error message: unknown property at position 10')
self.given(b'''
miscolon
miscolon: /alphabetic/colon/should/be/equal/sign/
''',
expect_error=b'Line 3: /colon compiles to \p{colon} which is rejected by the regex engine with error message: unknown property at position 10')
self.given(b'''
miscolon
miscolon: 'colon should be equal sign'
''',
expect_error=b'''Line 3: Unexpected CHAR
miscolon: 'colon should be equal sign'
^''')
self.given(b'''
/A/a/
A: a: A a
''',
expect_error=b'''Line 3: Unexpected CHAR
A: a: A a
^''')
self.given(b'''
/A/a/
A: a = A a
''',
expect_error="Line 2: 'a' is not defined")
self.given(b'''
/A/a/
A: a = A
''',
expect_error="Line 2: 'a' is not defined")
self.given(b'''
/shouldBeColon/
shouldBeColon = A a
''',
expect_error=b'''Line 3: Unexpected VARNAME
shouldBeColon = A a
^''')
self.given(b'''
mixedAssignment
mixedAssignment : = x
''',
expect_error=b'''Line 3: Unexpected COLON
mixedAssignment : = x
^''')
self.given(b'''
mixedAssignment
mixedAssignment := x
''',
expect_error=b'''Line 3: Unexpected COLON
mixedAssignment := x
^''')
self.given(b'''
mixedAssignment
mixedAssignment:= x
''',
expect_error=b'''Line 3: Unexpected CHAR
mixedAssignment:= x
^''')
self.given(b'''
mixedAssignment
mixedAssignment=: x
''',
expect_error=b'''Line 3: Unexpected COLON
mixedAssignment=: x
^''')
self.given(b'''
mixedAssignment
mixedAssignment =: x
''',
expect_error=b'''Line 3: Unexpected COLON
mixedAssignment =: x
^''')
self.given(b'''
x
x: /IsAwesome
''',
expect_error=b'Line 3: /IsAwesome compiles to \p{IsAwesome} which is rejected by the regex engine with error message: unknown property at position 14')
self.given(b'''
x
x: :KABAYAN_SABA_KOTA
''',
expect_error=b'Line 3: :KABAYAN_SABA_KOTA compiles to \N{KABAYAN SABA KOTA} which is rejected by the regex engine with error message: undefined character name at position 22')
self.given(br'''
x
x: \N{KABAYAN}
''',
expect_error=b'Line 3: \N{KABAYAN} compiles to \N{KABAYAN} which is rejected by the regex engine with error message: undefined character name at position 12')
self.given(br'''
x
x: \o
''',
expect_error=b'Line 3: Bad escape sequence: \o')
self.given(br'''
x
x: \w
''',
expect_error=b'Line 3: Bad escape sequence: \w')
self.given(br'''
x
x: \'
''',
expect_error="Line 3: Bad escape sequence: \\'")
self.given(br'''
x
x: \"
''',
expect_error=b'Line 3: Bad escape sequence: \\"')
self.given(br'''
x
x: \ron
''',
expect_error=br'Line 3: Bad escape sequence: \ron')
self.given(br'''
x
x: \u123
''',
expect_error=b'Line 3: Bad escape sequence: \u123')
self.given(br'''
x
x: \U1234
''',
expect_error=b'Line 3: Bad escape sequence: \U1234')
self.given(br'''
x
x: \u12345
''',
expect_error=b'Line 3: Bad escape sequence: \u12345')
def test_invalid_char(self):
self.given(b'''
x
x: u1234
''',
expect_error="Line 3: Cannot include 'u1234': not defined")
self.given(b'''
x
x: \uab
''',
expect_error=b'Line 3: Bad escape sequence: \uab')
self.given(b'''
x
x: \u123z
''',
expect_error=b'Line 3: Bad escape sequence: \u123z')
self.given(b'''
x
x: \U1234567z
''',
expect_error=b'Line 3: Bad escape sequence: \U1234567z')
self.given(b'''
x
x: \U123456789
''',
expect_error=b'Line 3: Bad escape sequence: \U123456789')
self.given(b'''
x
x: \U
''',
expect_error=b'Line 3: Bad escape sequence: \U')
self.given(b'''
x
x: :YET_ANOTHER_CHARACTER_THAT_SHOULD_NOT_BE_IN_UNICODE
''',
expect_error=b'Line 3: :YET_ANOTHER_CHARACTER_THAT_SHOULD_NOT_BE_IN_UNICODE compiles to \N{YET ANOTHER CHARACTER THAT SHOULD NOT BE IN UNICODE} which is rejected by the regex engine with error message: undefined character name at position 56')
# unicode character name should be in uppercase
self.given(b'''
x
x: check-mark
''',
expect_error=b'''Line 3: Unexpected CHAR
x: check-mark
^''')
self.given(b'''
x
x: @omic
''',
expect_error=b'''Line 3: Unexpected CHAR
x: @omic
^''')
self.given(b'''
x
x: awe$ome
''',
expect_error=b'''Line 3: Unexpected CHAR
x: awe$ome
^''')
def test_invalid_range(self):
self.given(b'''
x
x: ..
''',
expect_error=b'''Line 3: Unexpected DOT
x: ..
^''')
self.given(b'''
x
x: ...,
''',
expect_error=b'''Line 3: Unexpected DOT
x: ...,
^''')
self.given(b'''
x
x: ,...
''',
expect_error=b'''Line 3: Unexpected DOT
x: ,...
^''')
self.given(b'''
x
x: ;..,
''',
expect_error=b'Line 3: ;.., compiles to [;-,] which is rejected by the regex engine with error message: bad character range at position 4')
self.given(b'''
x
x: x....
''',
expect_error=b'''Line 3: Unexpected DOT
x: x....
^''')
self.given(b'''
x
x: infinity..
''',
expect_error=b'''Line 3: Unexpected NEWLINE
x: infinity..
^''')
self.given(b'''
x
x: ..bigbang
''',
expect_error=b'''Line 3: Unexpected DOT
x: ..bigbang
^''')
self.given(b'''
x
x: bigcrunch..bigbang
''',
expect_error=b'Line 3: Invalid character range: bigcrunch..bigbang')
self.given(b'''
x
x: A...Z
''',
expect_error=b'''Line 3: Unexpected DOT
x: A...Z
^''')
self.given(b'''
x
x: 1..2..3
''',
expect_error=b'''Line 3: Unexpected DOT
x: 1..2..3
^''')
self.given(b'''
x
x: /IsAlphabetic..Z
''',
expect_error=b'Line 3: Invalid character range: /IsAlphabetic..Z')
self.given(b'''
x
x: +alpha..Z
''',
expect_error=b'Line 3: Invalid character range: +alpha..Z')
self.given(b'''
aB
aB: a..B
''',
expect_error=b'Line 3: a..B compiles to [a-B] which is rejected by the regex engine with error message: bad character range at position 4')
self.given(br'''
BA
BA: \u0042..A
''',
expect_error=b'Line 3: \u0042..A compiles to [\u0042-A] which is rejected by the regex engine with error message: bad character range at position 9')
self.given(br'''
BA
BA: \U00000042..\u0041
''',
expect_error=b'Line 3: \U00000042..\u0041 compiles to [\U00000042-\u0041] which is rejected by the regex engine with error message: bad character range at position 18')
self.given(br'''
BA
BA: \x42..\U00000041
''',
expect_error=br'Line 3: \x42..\U00000041 compiles to [\x42-\U00000041] which is rejected by the regex engine with error message: bad character range at position 16')
self.given(br'''
BA
BA: \102..\x41
''',
expect_error=br'Line 3: \102..\x41 compiles to [\102-\x41] which is rejected by the regex engine with error message: bad character range at position 10')
self.given(br'''
BA
BA: \N{LATIN CAPITAL LETTER B}..\101
''',
expect_error=br'Line 3: \N{LATIN CAPITAL LETTER B}..\101 compiles to [\N{LATIN CAPITAL LETTER B}-\101] which is rejected by the regex engine with error message: bad character range at position 32')
self.given(b'''
BA
BA: :LATIN_CAPITAL_LETTER_B..\N{LATIN CAPITAL LETTER A}
''',
expect_error=b'Line 3: :LATIN_CAPITAL_LETTER_B..\N{LATIN CAPITAL LETTER A} compiles to [\N{LATIN CAPITAL LETTER B}-\N{LATIN CAPITAL LETTER A}] which is rejected by the regex engine with error message: bad character range at position 54')
self.given(b'''
BA
BA: \N{LATIN CAPITAL LETTER B}..:LATIN_CAPITAL_LETTER_A
''',
expect_error=b'Line 3: \N{LATIN CAPITAL LETTER B}..:LATIN_CAPITAL_LETTER_A compiles to [\N{LATIN CAPITAL LETTER B}-\N{LATIN CAPITAL LETTER A}] which is rejected by the regex engine with error message: bad character range at position 54')
self.given(br'''
aZ
aZ: \N{LATIN SMALL LETTER A}..:LATIN_CAPITAL_LETTER_Z
''',
expect_error=b'Line 3: \N{LATIN SMALL LETTER A}..:LATIN_CAPITAL_LETTER_Z compiles to [\N{LATIN SMALL LETTER A}-\N{LATIN CAPITAL LETTER Z}] which is rejected by the regex engine with error message: bad character range at position 52')
def test_invalid_charclass_include(self):
self.given(b'''
x
x: +1
''',
expect_error="Line 3: Cannot include '1': not defined")
self.given(b'''
x
x: +7even
''',
expect_error="Line 3: Cannot include '7even': not defined")
self.given(b'''
x
x: +7even
7even: 7
''',
expect_error=b'''Line 4: Unexpected NUMBER
7even: 7
^''')
self.given(b'''
x
x: +bang!
''',
expect_error=b'''Line 3: Unexpected CHAR
x: +bang!
^''')
self.given(b'''
x
x: ++
''',
expect_error=b'''Line 3: Unexpected CHAR
x: ++
^''')
self.given(b'''
x
x: +!awe+some
''',
expect_error=b'''Line 3: Unexpected CHAR