Home | History | Annotate | Download | only in test
      1 # Tests for the 'tokenize' module.
      2 # Large bits stolen from test_grammar.py. 
      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}
     24 x = (len(repr(y)) + 5*x - a[
     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
     39 0xff != 255
     40 0o377 != 255
     41 2147483647   != 0o17777777777
     42 -2147483647-1 != 0o20000000000
     43 0o37777777777 != -1
     44 0xffffffff != -1; 0o37777777777 != -1; -0o1234567 == 0O001234567; 0b10101 == 0B00010101
     45 
     46 # Long integers
     47 x = 0
     48 x = 0
     49 x = 0xffffffffffffffff
     50 x = 0xffffffffffffffff
     51 x = 0o77777777777777777
     52 x = 0B11101010111111111
     53 x = 123456789012345678901234567890
     54 x = 123456789012345678901234567890
     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 '''
    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 = rb'abc' + rB'ABC' + Rb'ABC' + RB'ABC'
    118 y = rb"abc" + rB"ABC" + Rb"ABC" + RB"ABC"
    119 x = br'\\' + BR'\\'
    120 x = rb'\\' + RB'\\'
    121 x = br'\'' + ''
    122 x = rb'\'' + ''
    123 y = br'''
    124 foo bar \\
    125 baz''' + BR'''
    126 foo'''
    127 y = Br"""foo
    128 bar \\ baz
    129 """ + bR'''spam
    130 '''
    131 y = rB"""foo
    132 bar \\ baz
    133 """ + Rb'''spam
    134 '''
    135 
    136 # Indentation
    137 if 1:
    138     x = 2
    139 if 1:
    140         x = 2
    141 if 1:
    142     while 0:
    143      if 0:
    144            x = 2
    145      x = 2
    146 if 0:
    147   if 2:
    148    while 0:
    149         if 1:
    150           x = 2
    151 
    152 # Operators
    153 
    154 def d22(a, b, c=1, d=2): pass
    155 def d01v(a=1, *restt, **restd): pass
    156 
    157 (x, y) != ({'a':1}, {'b':2})
    158 
    159 # comparison
    160 if 1 < 1 > 1 == 1 >= 1 <= 1 != 1 != 1 in 1 not in 1 is 1 is not 1: pass
    161 
    162 # binary
    163 x = 1 & 1
    164 x = 1 ^ 1
    165 x = 1 | 1
    166 
    167 # shift
    168 x = 1 << 1 >> 1
    169 
    170 # additive
    171 x = 1 - 1 + 1 - 1 + 1
    172 
    173 # multiplicative
    174 x = 1 / 1 * 1 % 1
    175 
    176 # unary
    177 x = ~1 ^ 1 & 1 | 1 & 1 ^ -1
    178 x = -1*1/1 + 1*1 - ---1*1
    179 
    180 # selector
    181 import sys, time
    182 x = sys.modules['time'].time()
    183 
    184 @staticmethod
    185 def foo(): pass
    186 
    187 @staticmethod
    188 def foo(x:1)->1: pass
    189 
    190