File tree Expand file tree Collapse file tree 6 files changed +121
-2
lines changed
Expand file tree Collapse file tree 6 files changed +121
-2
lines changed Original file line number Diff line number Diff line change 1+ # literals
2+ print (b'123' )
3+ print (br'123' )
4+ print (rb'123' )
5+ print (b'\u1234' )
6+
7+ # construction
18print (bytes ())
9+ print (bytes (b'abc' ))
210
311a = b"123"
412print (a )
Original file line number Diff line number Diff line change 1+ # test the lexer
2+
3+ # __debug__ is a special symbol
4+ print (type (__debug__ ))
5+
6+ # short input
7+ exec ("" )
8+ exec ("\n " )
9+ exec ("\n \n " )
10+ exec ("\r " )
11+ exec ("\r \r " )
12+ print (eval ("1" ))
13+ print (eval ("12" ))
14+ print (eval ("123" ))
15+ print (eval ("1\n " ))
16+ print (eval ("12\n " ))
17+ print (eval ("123\n " ))
18+ print (eval ("1\r " ))
19+ print (eval ("12\r " ))
20+ print (eval ("123\r " ))
21+
22+ # lots of indentation
23+ def a (x ):
24+ if x :
25+ if x :
26+ if x :
27+ if x :
28+ if x :
29+ if x :
30+ if x :
31+ if x :
32+ if x :
33+ if x :
34+ if x :
35+ if x :
36+ if x :
37+ if x :
38+ if x :
39+ print (x )
40+ a (1 )
Original file line number Diff line number Diff line change 11# basic strings
22
3+ # literals
4+ print ('abc' )
5+ print (r'abc' )
6+ print (u'abc' )
7+ print (repr ('\a \b \t \n \v \f \r ' ))
8+ print ('\z' ) # unrecognised escape char
9+
10+ # construction
311print (str ())
12+ print (str ('abc' ))
413
14+ # inplace addition
515x = 'abc'
616print (x )
7-
817x += 'def'
918print (x )
1019
20+ # binary ops
1121print ('123' + "456" )
12-
1322print ('123' * 5 )
1423
24+ # subscription
1525print ('abc' [1 ])
1626print ('abc' [- 1 ])
1727try :
Original file line number Diff line number Diff line change @@ -4,9 +4,28 @@ def test_syntax(code):
44 try :
55 exec (code )
66 print ("no SyntaxError" )
7+ except IndentationError :
8+ print ("IndentationError" )
79 except SyntaxError :
810 print ("SyntaxError" )
911
12+ # non-newline after line-continuation character (lexer error)
13+ test_syntax ("a \\ a\n " )
14+
15+ # dedent mismatch (lexer error)
16+ test_syntax ("def f():\n a\n a\n " )
17+
18+ # unclosed string (lexer error)
19+ test_syntax ("'abc" )
20+
21+ # invalid (lexer error)
22+ test_syntax ("!" )
23+ test_syntax ("$" )
24+ test_syntax ("`" )
25+
26+ # bad indentation (lexer error)
27+ test_syntax (" a\n " )
28+
1029# can't assign to literals
1130test_syntax ("1 = 2" )
1231test_syntax ("'' = 1" )
Original file line number Diff line number Diff line change 2525print (1j * 2 )
2626print (1j * 2j )
2727print (1j / 2 )
28+ print ((1j / 2j ).real )
2829print (1j / (1 + 2j ))
30+ ans = 0j ** 0 ; print ("%.5g %.5g" % (ans .real , ans .imag ))
31+ ans = 0j ** 0j ; print ("%.5g %.5g" % (ans .real , ans .imag ))
2932ans = 1j ** 2.5 ; print ("%.5g %.5g" % (ans .real , ans .imag ))
3033ans = 1j ** 2.5j ; print ("%.5g %.5g" % (ans .real , ans .imag ))
3134
35+ # comparison
36+ print (1j == 1 )
37+ print (1j == 1j )
38+
3239# builtin abs
3340print (abs (1j ))
3441print ("%.5g" % abs (1j + 2 ))
4451 1j + []
4552except TypeError :
4653 print ("TypeError" )
54+
55+ # unsupported unary op
56+ try :
57+ ~ (1j )
58+ except TypeError :
59+ print ("TypeError" )
60+
61+ # unsupported binary op
62+ try :
63+ 1j // 2
64+ except TypeError :
65+ print ("TypeError" )
66+
67+ # unsupported binary op
68+ try :
69+ 1j < 2j
70+ except TypeError :
71+ print ("TypeError" )
72+
73+ # zero division
74+ try :
75+ 1j / 0
76+ except ZeroDivisionError :
77+ print ("ZeroDivisionError" )
78+
79+ # zero division via power
80+ try :
81+ 0j ** 1j
82+ except ZeroDivisionError :
83+ print ("ZeroDivisionError" )
Original file line number Diff line number Diff line change 11# test basic float capabilities
22
3+ # literals
4+ print (.12 )
5+ print (1. )
6+ print (1.2 )
7+
38# float construction
49print (float (1.2 ))
510
You can’t perform that action at this time.
0 commit comments