blob: 35ab934ab373d202e666b3147b9046d416b4d6b3 [file] [log] [blame]
Brett Cannone3944a52009-04-01 05:08:41 +00001import __future__
2import unittest
Pablo Galindoc5fc1562020-04-22 23:29:27 +01003import sys
Victor Stinner1def7752020-04-23 03:03:24 +02004from test import support
Brett Cannone3944a52009-04-01 05:08:41 +00005
Pablo Galindoc5fc1562020-04-22 23:29:27 +01006
Victor Stinner1def7752020-04-23 03:03:24 +02007@support.skip_if_new_parser("Not supported by pegen yet")
Brett Cannone3944a52009-04-01 05:08:41 +00008class FLUFLTests(unittest.TestCase):
9
10 def test_barry_as_bdfl(self):
Serhiy Storchakaaba24ff2018-07-23 23:41:11 +030011 code = "from __future__ import barry_as_FLUFL\n2 {0} 3"
Brett Cannone3944a52009-04-01 05:08:41 +000012 compile(code.format('<>'), '<BDFL test>', 'exec',
13 __future__.CO_FUTURE_BARRY_AS_BDFL)
Serhiy Storchakaaba24ff2018-07-23 23:41:11 +030014 with self.assertRaises(SyntaxError) as cm:
15 compile(code.format('!='), '<FLUFL test>', 'exec',
16 __future__.CO_FUTURE_BARRY_AS_BDFL)
17 self.assertRegex(str(cm.exception),
18 "with Barry as BDFL, use '<>' instead of '!='")
19 self.assertEqual(cm.exception.text, '2 != 3\n')
20 self.assertEqual(cm.exception.filename, '<FLUFL test>')
21 self.assertEqual(cm.exception.lineno, 2)
22 self.assertEqual(cm.exception.offset, 4)
Brett Cannone3944a52009-04-01 05:08:41 +000023
24 def test_guido_as_bdfl(self):
25 code = '2 {0} 3'
26 compile(code.format('!='), '<BDFL test>', 'exec')
Serhiy Storchakaaba24ff2018-07-23 23:41:11 +030027 with self.assertRaises(SyntaxError) as cm:
28 compile(code.format('<>'), '<FLUFL test>', 'exec')
29 self.assertRegex(str(cm.exception), "invalid syntax")
30 self.assertEqual(cm.exception.text, '2 <> 3\n')
31 self.assertEqual(cm.exception.filename, '<FLUFL test>')
32 self.assertEqual(cm.exception.lineno, 1)
33 self.assertEqual(cm.exception.offset, 4)
Brett Cannone3944a52009-04-01 05:08:41 +000034
35
Brett Cannone3944a52009-04-01 05:08:41 +000036if __name__ == '__main__':
Zachary Ware38c707e2015-04-13 15:00:43 -050037 unittest.main()