예제 #1
0
    def test_get_word(self):
        inp = StringIO('ab1')
        compiler.init(inp=inp, out=self.stdout, err=self.stderr)
        self.assertEqual(compiler.get_word(), 'a')
        self.assertEqual(compiler.get_word(), 'b')

        with self.assertRaises(SystemExit):
            compiler.get_word()
        self.assertEqual(self.stderr.getvalue(), "\n'Word' expected.\n")
예제 #2
0
 def test_match(self):
     inp = StringIO('mo')
     compiler.init(inp=inp, out=self.stdout, err=self.stderr)
     self.assertEqual(compiler.Peek, 'm')
     compiler.match('m')
     self.assertEqual(compiler.Peek, 'o')
     with self.assertRaises(SystemExit):
         compiler.match('n')
     self.assertEqual(self.stderr.getvalue(), "\n'n' expected.\n")
예제 #3
0
    def test_get_number(self):
        inp = StringIO('12z')
        compiler.init(inp=inp, out=self.stdout, err=self.stderr)
        self.assertEqual(compiler.get_number(), '1')
        self.assertEqual(compiler.get_number(), '2')

        with self.assertRaises(SystemExit):
            compiler.get_number()
        self.assertEqual(self.stderr.getvalue(), "\n'Number' expected.\n")
예제 #4
0
 def test_emitln(self):
     compiler.init(inp=StringIO(), out=self.stdout, err=self.stderr)
     compiler.emitln('123')
     self.assertEqual(self.stdout.getvalue(), "123\n")
예제 #5
0
 def test_emit(self):
     compiler.init(inp=StringIO(), out=self.stdout, err=self.stderr)
     compiler.emit('abc')
     self.assertEqual(self.stdout.getvalue(), 'abc')
예제 #6
0
 def test_get_char(self):
     inp = StringIO('abc')
     compiler.init(inp=inp, out=self.stdout, err=self.stderr)
     self.assertEqual(compiler.get_char(), 'a')
     self.assertEqual(compiler.get_char(), 'b')
     self.assertEqual(compiler.get_char(), 'c')
예제 #7
0
 def test_expected(self):
     compiler.init(inp=StringIO(), out=self.stdout, err=self.stderr)
     with self.assertRaises(SystemExit):
         compiler.expected('better')
     self.assertEqual(self.stderr.getvalue(), "\n'better' expected.\n")
예제 #8
0
 def test_error(self):
     compiler.init(inp=StringIO(), out=self.stdout, err=self.stderr)
     compiler.error('whoops')
     self.assertEqual(self.stderr.getvalue(), "\nwhoops\n")
     self.assertEqual(self.stdout.getvalue(), "")
예제 #9
0
 def test_abort(self):
     compiler.init(inp=StringIO(), out=self.stdout, err=self.stderr)
     with self.assertRaises(SystemExit):
         compiler.abort('hello')
     self.assertEqual(self.stderr.getvalue(), "\nhello\n")
     self.assertEqual(self.stdout.getvalue(), "")
예제 #10
0
 def assertExpr(self, text, result):
     want = "Result: %d" % int(result)
     compiler.init(inp=StringIO(text), out=self.stdout, err=self.stderr)
     compiler.compile()
     output = self.stdout.getvalue().split("\n")[-2]
     self.assertEqual(output, want)
예제 #11
0
 def test_read_at_eof(self):
     compiler.init(StringIO('ab'))
     self.assertEqual(compiler.get_char(), 'a')
     self.assertEqual(compiler.get_char(), 'b')
     self.assertIsNone(compiler.get_char())