summaryrefslogtreecommitdiffstatshomepage
path: root/tests/basics/lexer.py
blob: 244de8cb98cb5872e64892afa1ef5a2e88613abf (plain) (blame)
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
# test the lexer

# __debug__ is a special symbol
print(type(__debug__))

# short input
exec("")
exec("\n")
exec("\n\n")
exec("\r")
exec("\r\r")
exec("\t")
exec("\r\n")
exec("\nprint(1)")
exec("\rprint(2)")
exec("\r\nprint(3)")
exec("\n5")
exec("\r6")
exec("\r\n7")
print(eval("1"))
print(eval("12"))
print(eval("123"))
print(eval("1\n"))
print(eval("12\n"))
print(eval("123\n"))
print(eval("1\r"))
print(eval("12\r"))
print(eval("123\r"))

# line continuation
print(eval("'123' \\\r '456'"))
print(eval("'123' \\\n '456'"))
print(eval("'123' \\\r\n '456'"))
print(eval("'123'\\\r'456'"))
print(eval("'123'\\\n'456'"))
print(eval("'123'\\\r\n'456'"))

# backslash used to escape a line-break in a string
print('a\
b')

# lots of indentation
def a(x):
 if x:
  if x:
   if x:
    if x:
     if x:
      if x:
       if x:
        if x:
         if x:
          if x:
           if x:
            if x:
             if x:
              if x:
               if x:
                print(x)
a(1)

# badly formed hex escape sequences
try:
    exec(r"'\x0'")
except SyntaxError:
    print("SyntaxError")
try:
    exec(r"b'\x0'")
except SyntaxError:
    print("SyntaxError")
try:
    exec(r"'\u000'")
except SyntaxError:
    print("SyntaxError")
try:
    exec(r"'\U0000000'")
except SyntaxError:
    print("SyntaxError")