tokenize_tests.txt 2.7 KB

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