예제 #1
0
    def test_parser_comparison(self):
        """Test that parser can parse comparison."""
        ast = ""

        p = parser.ParserForNarratr()
        with open('sampleprograms/3_comparison.ntr') as f:
            ast = str(p.parse(f.read()))
예제 #2
0
    def test_parser_andor(self):
        """Test that parser can parse and/or."""
        ast = ""

        p = parser.ParserForNarratr()
        with open('sampleprograms/3_andor.ntr') as f:
            ast = str(p.parse(f.read()))
예제 #3
0
    def test_parser_while(self):
        """Test that parser can parse while."""
        ast = ""

        p = parser.ParserForNarratr()
        with open('sampleprograms/4_while.ntr') as f:
            ast = str(p.parse(f.read()))
예제 #4
0
    def test_parser_moves(self):
        """Test that parser can parse moves."""
        ast = ""

        p = parser.ParserForNarratr()
        with open('sampleprograms/5_moves.ntr') as f:
            ast = str(p.parse(f.read()))
예제 #5
0
    def test_parser_unmatched_braces(self):
        """Test that parser has error when parsing unmatched_braces."""
        ast = ""

        p = parser.ParserForNarratr()
        with open('sampleprograms/6_unmatched_braces.ntr') as f:
            self.assertRaises(SystemExit, lambda: p.parse(f.read()))
예제 #6
0
    def test_parser_elseif(self):
        """Test that parser can parse else/if."""
        ast = ""

        p = parser.ParserForNarratr()
        with open('sampleprograms/4_elseif.ntr') as f:
            ast = str(p.parse(f.read()))
예제 #7
0
    def test_parser_rogue_semicolon(self):
        """Test that parser has error when parsing rogue_semicolon."""
        ast = ""

        p = parser.ParserForNarratr()
        with open('sampleprograms/6_rogue_semicolon.ntr') as f:
            self.assertRaises(SystemExit, lambda: p.parse(f.read()))
예제 #8
0
    def test_parser_scene_name_conflict(self):
        """Test that parser has error when parsing scene_name_conflict."""
        ast = ""

        p = parser.ParserForNarratr()
        with open('sampleprograms/6_scene_name_conflict.ntr') as f:
            self.assertRaises(SystemExit, lambda: p.parse(f.read()))
예제 #9
0
    def test_parser_multiple_cleanups(self):
        """Test that parser has error when parsing multiple_cleanups."""
        ast = ""

        p = parser.ParserForNarratr()
        with open('sampleprograms/6_multiple_cleanups.ntr') as f:
            self.assertRaises(SystemExit, lambda: p.parse(f.read()))
예제 #10
0
    def test_parser_different_order(self):
        """Test that parser has error when parsing different_order."""
        ast = ""

        p = parser.ParserForNarratr()
        with open('sampleprograms/6_different_order.ntr') as f:
            self.assertRaises(SystemExit, lambda: p.parse(f.read()))
예제 #11
0
    def test_parser_misspelled_start(self):
        """Test that parser has error when parsing misspelled_start."""
        ast = ""

        p = parser.ParserForNarratr()
        with open('sampleprograms/6_misspelled_start.ntr') as f:
            self.assertRaises(SystemExit, lambda: p.parse(f.read()))
예제 #12
0
    def test_parser_helloworld(self):
        """Test that parser can parse Hello World."""
        ast = ""

        p = parser.ParserForNarratr()
        with open('sampleprograms/0_helloworld.ntr') as f:
            ast = str(p.parse(f.read()))
예제 #13
0
    def test_parser_costantsliterals(self):

        """Test that parser can parse constants, literals."""
        ast = ""

        p = parser.ParserForNarratr()
        with open('sampleprograms/1_constantsliterals.ntr') as f:
            ast = str(p.parse(f.read()))
예제 #14
0
def test_nonexistent_start_scene_error():

    """Test that a nonexistent start scene causes an error."""
    p = parser.ParserForNarratr()
    with open('sampleprograms/6_nonexistent_start_scene.ntr') as f:
        ast = p.parse(f.read())
    symtab = p.symtab
    c = codegen.CodeGen()
    assert_raises(SystemExit, lambda: c.process(ast, symtab))
예제 #15
0
def check_expected_output(fname, output):

    """Run each compiled program and check for output correctness."""
    p = parser.ParserForNarratr()
    try:
        with open(fname) as f:
            ast = p.parse(f.read())
        symtab = p.symtab
        c = codegen.CodeGen()
        c.process(ast, symtab)
        c.construct('temp.py')
    except:
        e = sys.exc_info()[0]
        assert_equal(0, 1, ("Exception: " + str(e)))
    else:
        proc = subprocess.Popen(['python', 'temp.py'],
                                stdout=subprocess.PIPE, stdin=subprocess.PIPE)
        proc.stdin.write('hello')
        p_output = proc.communicate()[0]
        expected_output = output
        assert_equal(p_output, expected_output,
                     fname + " printed:\n" + p_output +
                     "instead of:\n" + expected_output)