Back to index

python3.2  3.2.2
Public Member Functions
test.test_grammar.TokenTests Class Reference

List of all members.

Public Member Functions

def testBackslash
def testPlainIntegers
def testLongIntegers
def testFloats
def testStringLiterals
def testEllipsis

Detailed Description

Definition at line 11 of file test_grammar.py.


Member Function Documentation

Definition at line 13 of file test_grammar.py.

00013 
00014     def testBackslash(self):
00015         # Backslash means line continuation:
00016         x = 1 \
00017         + 1
00018         self.assertEqual(x, 2, 'backslash for line continuation')
00019 
00020         # Backslash does not means continuation in comments :\
00021         x = 0
00022         self.assertEqual(x, 0, 'backslash ending comment')

Here is the call graph for this function:

Definition at line 123 of file test_grammar.py.

00123 
00124     def testEllipsis(self):
00125         x = ...
00126         self.assertTrue(x is Ellipsis)
00127         self.assertRaises(SyntaxError, eval, ".. .")

Here is the call graph for this function:

Definition at line 69 of file test_grammar.py.

00069 
00070     def testFloats(self):
00071         x = 3.14
00072         x = 314.
00073         x = 0.314
00074         # XXX x = 000.314
00075         x = .314
00076         x = 3e14
00077         x = 3E14
00078         x = 3e-14
00079         x = 3e+14
00080         x = 3.e14
00081         x = .3e14
00082         x = 3.1e4

Definition at line 59 of file test_grammar.py.

00059 
00060     def testLongIntegers(self):
00061         x = 0
00062         x = 0xffffffffffffffff
00063         x = 0Xffffffffffffffff
00064         x = 0o77777777777777777
00065         x = 0O77777777777777777
00066         x = 123456789012345678901234567890
00067         x = 0b100000000000000000000000000000000000000000000000000000000000000000000
00068         x = 0B111111111111111111111111111111111111111111111111111111111111111111111

Definition at line 23 of file test_grammar.py.

00023 
00024     def testPlainIntegers(self):
00025         self.assertEqual(type(000), type(0))
00026         self.assertEqual(0xff, 255)
00027         self.assertEqual(0o377, 255)
00028         self.assertEqual(2147483647, 0o17777777777)
00029         self.assertEqual(0b1001, 9)
00030         # "0x" is not a valid literal
00031         self.assertRaises(SyntaxError, eval, "0x")
00032         from sys import maxsize
00033         if maxsize == 2147483647:
00034             self.assertEqual(-2147483647-1, -0o20000000000)
00035             # XXX -2147483648
00036             self.assertTrue(0o37777777777 > 0)
00037             self.assertTrue(0xffffffff > 0)
00038             self.assertTrue(0b1111111111111111111111111111111 > 0)
00039             for s in ('2147483648', '0o40000000000', '0x100000000',
00040                       '0b10000000000000000000000000000000'):
00041                 try:
00042                     x = eval(s)
00043                 except OverflowError:
00044                     self.fail("OverflowError on huge integer literal %r" % s)
00045         elif maxsize == 9223372036854775807:
00046             self.assertEqual(-9223372036854775807-1, -0o1000000000000000000000)
00047             self.assertTrue(0o1777777777777777777777 > 0)
00048             self.assertTrue(0xffffffffffffffff > 0)
00049             self.assertTrue(0b11111111111111111111111111111111111111111111111111111111111111 > 0)
00050             for s in '9223372036854775808', '0o2000000000000000000000', \
00051                      '0x10000000000000000', \
00052                      '0b100000000000000000000000000000000000000000000000000000000000000':
00053                 try:
00054                     x = eval(s)
00055                 except OverflowError:
00056                     self.fail("OverflowError on huge integer literal %r" % s)
00057         else:
00058             self.fail('Weird maxsize value %r' % maxsize)

Here is the call graph for this function:

Definition at line 83 of file test_grammar.py.

00083 
00084     def testStringLiterals(self):
00085         x = ''; y = ""; self.assertTrue(len(x) == 0 and x == y)
00086         x = '\''; y = "'"; self.assertTrue(len(x) == 1 and x == y and ord(x) == 39)
00087         x = '"'; y = "\""; self.assertTrue(len(x) == 1 and x == y and ord(x) == 34)
00088         x = "doesn't \"shrink\" does it"
00089         y = 'doesn\'t "shrink" does it'
00090         self.assertTrue(len(x) == 24 and x == y)
00091         x = "does \"shrink\" doesn't it"
00092         y = 'does "shrink" doesn\'t it'
00093         self.assertTrue(len(x) == 24 and x == y)
00094         x = """
00095 The "quick"
00096 brown fox
00097 jumps over
00098 the 'lazy' dog.
00099 """
00100         y = '\nThe "quick"\nbrown fox\njumps over\nthe \'lazy\' dog.\n'
00101         self.assertEqual(x, y)
00102         y = '''
00103 The "quick"
00104 brown fox
00105 jumps over
00106 the 'lazy' dog.
00107 '''
00108         self.assertEqual(x, y)
00109         y = "\n\
00110 The \"quick\"\n\
00111 brown fox\n\
00112 jumps over\n\
00113 the 'lazy' dog.\n\
00114 "
00115         self.assertEqual(x, y)
00116         y = '\n\
00117 The \"quick\"\n\
00118 brown fox\n\
00119 jumps over\n\
00120 the \'lazy\' dog.\n\
00121 '
00122         self.assertEqual(x, y)

Here is the call graph for this function:


The documentation for this class was generated from the following file: