Guido van Rossum | 0874f7f | 1997-10-27 22:15:06 +0000 | [diff] [blame] | 1 | # Tests for the 'tokenize' module. |
Tim Peters | 3b5de4d | 2003-02-19 02:44:12 +0000 | [diff] [blame] | 2 | # Large bits stolen from test_grammar.py. |
Guido van Rossum | 0874f7f | 1997-10-27 22:15:06 +0000 | [diff] [blame] | 3 | |
| 4 | # Comments |
| 5 | "#" |
| 6 | #' |
| 7 | #" |
| 8 | #\ |
| 9 | # |
| 10 | # abc |
| 11 | '''# |
| 12 | #''' |
| 13 | |
| 14 | x = 1 # |
| 15 | |
| 16 | # Balancing continuation |
| 17 | |
| 18 | a = (3, 4, |
| 19 | 5, 6) |
| 20 | y = [3, 4, |
| 21 | 5] |
| 22 | z = {'a':5, |
| 23 | 'b':6} |
Brett Cannon | 0b70cca | 2006-08-25 02:59:59 +0000 | [diff] [blame] | 24 | x = (len(repr(y)) + 5*x - a[ |
Guido van Rossum | 0874f7f | 1997-10-27 22:15:06 +0000 | [diff] [blame] | 25 | 3 ] |
| 26 | - x + len({ |
| 27 | } |
| 28 | ) |
| 29 | ) |
| 30 | |
| 31 | # Backslash means line continuation: |
| 32 | x = 1 \ |
| 33 | + 1 |
| 34 | |
| 35 | # Backslash does not means continuation in comments :\ |
| 36 | x = 0 |
| 37 | |
| 38 | # Ordinary integers |
Guido van Rossum | b053cd8 | 2006-08-24 03:53:23 +0000 | [diff] [blame] | 39 | 0xff != 255 |
Guido van Rossum | cd16bf6 | 2007-06-13 18:07:49 +0000 | [diff] [blame] | 40 | 0o377 != 255 |
| 41 | 2147483647 != 0o17777777777 |
| 42 | -2147483647-1 != 0o20000000000 |
| 43 | 0o37777777777 != -1 |
| 44 | 0xffffffff != -1; 0o37777777777 != -1; -0o1234567 == 0O001234567; 0b10101 == 0B00010101 |
Guido van Rossum | 0874f7f | 1997-10-27 22:15:06 +0000 | [diff] [blame] | 45 | |
| 46 | # Long integers |
Guido van Rossum | cd16bf6 | 2007-06-13 18:07:49 +0000 | [diff] [blame] | 47 | x = 0 |
| 48 | x = 0 |
| 49 | x = 0xffffffffffffffff |
| 50 | x = 0xffffffffffffffff |
| 51 | x = 0o77777777777777777 |
| 52 | x = 0B11101010111111111 |
| 53 | x = 123456789012345678901234567890 |
| 54 | x = 123456789012345678901234567890 |
Guido van Rossum | 0874f7f | 1997-10-27 22:15:06 +0000 | [diff] [blame] | 55 | |
| 56 | # Floating-point numbers |
| 57 | x = 3.14 |
| 58 | x = 314. |
| 59 | x = 0.314 |
| 60 | # XXX x = 000.314 |
| 61 | x = .314 |
| 62 | x = 3e14 |
| 63 | x = 3E14 |
| 64 | x = 3e-14 |
| 65 | x = 3e+14 |
| 66 | x = 3.e14 |
| 67 | x = .3e14 |
| 68 | x = 3.1e4 |
| 69 | |
| 70 | # String literals |
| 71 | x = ''; y = ""; |
| 72 | x = '\''; y = "'"; |
| 73 | x = '"'; y = "\""; |
| 74 | x = "doesn't \"shrink\" does it" |
| 75 | y = 'doesn\'t "shrink" does it' |
| 76 | x = "does \"shrink\" doesn't it" |
| 77 | y = 'does "shrink" doesn\'t it' |
| 78 | x = """ |
| 79 | The "quick" |
| 80 | brown fox |
| 81 | jumps over |
| 82 | the 'lazy' dog. |
| 83 | """ |
| 84 | y = '\nThe "quick"\nbrown fox\njumps over\nthe \'lazy\' dog.\n' |
| 85 | y = ''' |
| 86 | The "quick" |
| 87 | brown fox |
| 88 | jumps over |
| 89 | the 'lazy' dog. |
| 90 | '''; |
| 91 | y = "\n\ |
| 92 | The \"quick\"\n\ |
| 93 | brown fox\n\ |
| 94 | jumps over\n\ |
| 95 | the 'lazy' dog.\n\ |
| 96 | "; |
| 97 | y = '\n\ |
| 98 | The \"quick\"\n\ |
| 99 | brown fox\n\ |
| 100 | jumps over\n\ |
| 101 | the \'lazy\' dog.\n\ |
| 102 | '; |
| 103 | x = r'\\' + R'\\' |
| 104 | x = r'\'' + '' |
| 105 | y = r''' |
| 106 | foo bar \\ |
| 107 | baz''' + R''' |
| 108 | foo''' |
| 109 | y = r"""foo |
| 110 | bar \\ baz |
| 111 | """ + R'''spam |
| 112 | ''' |
Guido van Rossum | 4fe72f9 | 2007-11-12 17:40:10 +0000 | [diff] [blame] | 113 | x = b'abc' + B'ABC' |
| 114 | y = b"abc" + B"ABC" |
| 115 | x = br'abc' + Br'ABC' + bR'ABC' + BR'ABC' |
| 116 | y = br"abc" + Br"ABC" + bR"ABC" + BR"ABC" |
| 117 | x = br'\\' + BR'\\' |
| 118 | x = br'\'' + '' |
| 119 | y = br''' |
Ka-Ping Yee | 1ff08b1 | 2001-01-15 22:04:30 +0000 | [diff] [blame] | 120 | foo bar \\ |
Guido van Rossum | 4fe72f9 | 2007-11-12 17:40:10 +0000 | [diff] [blame] | 121 | baz''' + BR''' |
Ka-Ping Yee | 1ff08b1 | 2001-01-15 22:04:30 +0000 | [diff] [blame] | 122 | foo''' |
Guido van Rossum | 4fe72f9 | 2007-11-12 17:40:10 +0000 | [diff] [blame] | 123 | y = Br"""foo |
Ka-Ping Yee | 1ff08b1 | 2001-01-15 22:04:30 +0000 | [diff] [blame] | 124 | bar \\ baz |
Guido van Rossum | 4fe72f9 | 2007-11-12 17:40:10 +0000 | [diff] [blame] | 125 | """ + bR'''spam |
Ka-Ping Yee | 1ff08b1 | 2001-01-15 22:04:30 +0000 | [diff] [blame] | 126 | ''' |
Guido van Rossum | 0874f7f | 1997-10-27 22:15:06 +0000 | [diff] [blame] | 127 | |
| 128 | # Indentation |
| 129 | if 1: |
| 130 | x = 2 |
| 131 | if 1: |
Tim Peters | 3b5de4d | 2003-02-19 02:44:12 +0000 | [diff] [blame] | 132 | x = 2 |
Guido van Rossum | 0874f7f | 1997-10-27 22:15:06 +0000 | [diff] [blame] | 133 | if 1: |
| 134 | while 0: |
Tim Peters | 3b5de4d | 2003-02-19 02:44:12 +0000 | [diff] [blame] | 135 | if 0: |
| 136 | x = 2 |
| 137 | x = 2 |
Guido van Rossum | 0874f7f | 1997-10-27 22:15:06 +0000 | [diff] [blame] | 138 | if 0: |
Tim Peters | 3b5de4d | 2003-02-19 02:44:12 +0000 | [diff] [blame] | 139 | if 2: |
| 140 | while 0: |
| 141 | if 1: |
| 142 | x = 2 |
Guido van Rossum | 0874f7f | 1997-10-27 22:15:06 +0000 | [diff] [blame] | 143 | |
| 144 | # Operators |
| 145 | |
| 146 | def d22(a, b, c=1, d=2): pass |
Jeremy Hylton | a4553c0 | 2001-04-13 14:36:51 +0000 | [diff] [blame] | 147 | def d01v(a=1, *restt, **restd): pass |
Guido van Rossum | 0874f7f | 1997-10-27 22:15:06 +0000 | [diff] [blame] | 148 | |
Guido van Rossum | b053cd8 | 2006-08-24 03:53:23 +0000 | [diff] [blame] | 149 | (x, y) != ({'a':1}, {'b':2}) |
Guido van Rossum | 0874f7f | 1997-10-27 22:15:06 +0000 | [diff] [blame] | 150 | |
| 151 | # comparison |
Guido van Rossum | b053cd8 | 2006-08-24 03:53:23 +0000 | [diff] [blame] | 152 | if 1 < 1 > 1 == 1 >= 1 <= 1 != 1 != 1 in 1 not in 1 is 1 is not 1: pass |
Guido van Rossum | 0874f7f | 1997-10-27 22:15:06 +0000 | [diff] [blame] | 153 | |
| 154 | # binary |
| 155 | x = 1 & 1 |
| 156 | x = 1 ^ 1 |
| 157 | x = 1 | 1 |
| 158 | |
| 159 | # shift |
| 160 | x = 1 << 1 >> 1 |
| 161 | |
| 162 | # additive |
| 163 | x = 1 - 1 + 1 - 1 + 1 |
| 164 | |
| 165 | # multiplicative |
| 166 | x = 1 / 1 * 1 % 1 |
| 167 | |
| 168 | # unary |
| 169 | x = ~1 ^ 1 & 1 | 1 & 1 ^ -1 |
| 170 | x = -1*1/1 + 1*1 - ---1*1 |
| 171 | |
| 172 | # selector |
| 173 | import sys, time |
| 174 | x = sys.modules['time'].time() |
Tim Peters | 3b5de4d | 2003-02-19 02:44:12 +0000 | [diff] [blame] | 175 | |
Anthony Baxter | c2a5a63 | 2004-08-02 06:10:11 +0000 | [diff] [blame] | 176 | @staticmethod |
| 177 | def foo(): pass |
| 178 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 179 | @staticmethod |
| 180 | def foo(x:1)->1: pass |
| 181 | |