Back to index

python3.2  3.2.2
Public Member Functions
py2_test_grammar.TokenTests Class Reference

List of all members.

Public Member Functions

def testBackslash
def testPlainIntegers
def testLongIntegers
def testFloats
def testStringLiterals

Detailed Description

Definition at line 17 of file py2_test_grammar.py.


Member Function Documentation

Definition at line 19 of file py2_test_grammar.py.

00019 
00020     def testBackslash(self):
00021         # Backslash means line continuation:
00022         x = 1 \
00023         + 1
00024         self.assertEquals(x, 2, 'backslash for line continuation')
00025 
00026         # Backslash does not means continuation in comments :\
00027         x = 0
00028         self.assertEquals(x, 0, 'backslash ending comment')

Definition at line 69 of file py2_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 py2_test_grammar.py.

00059 
00060     def testLongIntegers(self):
00061         x = 0L
00062         x = 0l
00063         x = 0xffffffffffffffffL
00064         x = 0xffffffffffffffffl
00065         x = 077777777777777777L
00066         x = 077777777777777777l
00067         x = 123456789012345678901234567890L
00068         x = 123456789012345678901234567890l

Definition at line 29 of file py2_test_grammar.py.

00029 
00030     def testPlainIntegers(self):
00031         self.assertEquals(0xff, 255)
00032         self.assertEquals(0377, 255)
00033         self.assertEquals(2147483647, 017777777777)
00034         # "0x" is not a valid literal
00035         self.assertRaises(SyntaxError, eval, "0x")
00036         from sys import maxint
00037         if maxint == 2147483647:
00038             self.assertEquals(-2147483647-1, -020000000000)
00039             # XXX -2147483648
00040             self.assert_(037777777777 > 0)
00041             self.assert_(0xffffffff > 0)
00042             for s in '2147483648', '040000000000', '0x100000000':
00043                 try:
00044                     x = eval(s)
00045                 except OverflowError:
00046                     self.fail("OverflowError on huge integer literal %r" % s)
00047         elif maxint == 9223372036854775807:
00048             self.assertEquals(-9223372036854775807-1, -01000000000000000000000)
00049             self.assert_(01777777777777777777777 > 0)
00050             self.assert_(0xffffffffffffffff > 0)
00051             for s in '9223372036854775808', '02000000000000000000000', \
00052                      '0x10000000000000000':
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 maxint value %r' % maxint)

Here is the call graph for this function:

Definition at line 83 of file py2_test_grammar.py.

00083 
00084     def testStringLiterals(self):
00085         x = ''; y = ""; self.assert_(len(x) == 0 and x == y)
00086         x = '\''; y = "'"; self.assert_(len(x) == 1 and x == y and ord(x) == 39)
00087         x = '"'; y = "\""; self.assert_(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.assert_(len(x) == 24 and x == y)
00091         x = "does \"shrink\" doesn't it"
00092         y = 'does "shrink" doesn\'t it'
00093         self.assert_(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.assertEquals(x, y)
00102         y = '''
00103 The "quick"
00104 brown fox
00105 jumps over
00106 the 'lazy' dog.
00107 '''
00108         self.assertEquals(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.assertEquals(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.assertEquals(x, y)
00123 

Here is the call graph for this function:


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