blob: 0ff54aa227e37c63bd4e6275a32b8cbe451602e3 [file] [log] [blame]
Brett Cannone3944a52009-04-01 05:08:41 +00001import __future__
2import unittest
Victor Stinner1def7752020-04-23 03:03:24 +02003from test import support
Brett Cannone3944a52009-04-01 05:08:41 +00004
Pablo Galindoc5fc1562020-04-22 23:29:27 +01005
Brett Cannone3944a52009-04-01 05:08:41 +00006class FLUFLTests(unittest.TestCase):
7
8 def test_barry_as_bdfl(self):
Serhiy Storchakaaba24ff2018-07-23 23:41:11 +03009 code = "from __future__ import barry_as_FLUFL\n2 {0} 3"
Brett Cannone3944a52009-04-01 05:08:41 +000010 compile(code.format('<>'), '<BDFL test>', 'exec',
11 __future__.CO_FUTURE_BARRY_AS_BDFL)
Serhiy Storchakaaba24ff2018-07-23 23:41:11 +030012 with self.assertRaises(SyntaxError) as cm:
13 compile(code.format('!='), '<FLUFL test>', 'exec',
14 __future__.CO_FUTURE_BARRY_AS_BDFL)
15 self.assertRegex(str(cm.exception),
16 "with Barry as BDFL, use '<>' instead of '!='")
Pablo Galindo2b74c832020-04-27 18:02:07 +010017 self.assertIn('2 != 3', cm.exception.text)
Serhiy Storchakaaba24ff2018-07-23 23:41:11 +030018 self.assertEqual(cm.exception.filename, '<FLUFL test>')
Pablo Galindo2b74c832020-04-27 18:02:07 +010019
20 self.assertTrue(cm.exception.lineno, 2)
21 # The old parser reports the end of the token and the new
22 # parser reports the start of the token
Pablo Galindo1ed83ad2020-06-11 17:30:46 +010023 self.assertEqual(cm.exception.offset, 3)
Brett Cannone3944a52009-04-01 05:08:41 +000024
25 def test_guido_as_bdfl(self):
26 code = '2 {0} 3'
27 compile(code.format('!='), '<BDFL test>', 'exec')
Serhiy Storchakaaba24ff2018-07-23 23:41:11 +030028 with self.assertRaises(SyntaxError) as cm:
29 compile(code.format('<>'), '<FLUFL test>', 'exec')
30 self.assertRegex(str(cm.exception), "invalid syntax")
Pablo Galindo2b74c832020-04-27 18:02:07 +010031 self.assertIn('2 <> 3', cm.exception.text)
Serhiy Storchakaaba24ff2018-07-23 23:41:11 +030032 self.assertEqual(cm.exception.filename, '<FLUFL test>')
33 self.assertEqual(cm.exception.lineno, 1)
Pablo Galindo2b74c832020-04-27 18:02:07 +010034 # The old parser reports the end of the token and the new
35 # parser reports the start of the token
Pablo Galindo1ed83ad2020-06-11 17:30:46 +010036 self.assertEqual(cm.exception.offset, 3)
Brett Cannone3944a52009-04-01 05:08:41 +000037
38
Brett Cannone3944a52009-04-01 05:08:41 +000039if __name__ == '__main__':
Zachary Ware38c707e2015-04-13 15:00:43 -050040 unittest.main()