1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3<head>
4<meta http-equiv="content-type" content="text/html;charset=utf-8" />
5<title>t017parser</title>
6
7<!-- ANTLR includes -->
8<script type="text/javascript" src="../../lib/antlr3-all.js"></script>
9<script type="text/javascript" src="t017parserLexer.js"></script>
10<script type="text/javascript" src="t017parserParser.js"></script>
11
12
13<!-- JsUnit include -->
14<script type="text/javascript" src="../jsunit/app/jsUnitCore.js"></script>
15
16<!-- Test Code -->
17<script type="text/javascript">
18    TestParser = function() {
19        TestParser.superclass.constructor.apply(this, arguments);
20        this.reportedErrors = [];
21    };
22    org.antlr.lang.extend(TestParser, t017parserParser, {
23        emitErrorMessage: function(msg) {
24            this.reportedErrors.push(msg);
25        }
26    });
27
28    function testValid() {
29        var cstream = new org.antlr.runtime.ANTLRStringStream("int foo;"),
30            lexer = new t017parserLexer(cstream),
31            tstream = new org.antlr.runtime.CommonTokenStream(lexer),
32            parser = new TestParser(tstream);
33
34        parser.program();
35        assertEquals(parser.reportedErrors.length, 0);
36    }
37
38    function testMalformedInput1() {
39        var cstream = new org.antlr.runtime.ANTLRStringStream("int foo() { 1+2 }");
40            lexer = new t017parserLexer(cstream),
41            tstream = new org.antlr.runtime.CommonTokenStream(lexer),
42            parser = new TestParser(tstream);
43
44        parser.program();
45        assertEquals(parser.reportedErrors.length, 1);
46        assertEquals(parser.reportedErrors[0].indexOf("line 1:16"), 0);
47    }
48
49    function testMalformedInput2() {
50        var cstream = new org.antlr.runtime.ANTLRStringStream("int foo() { 1+; 1+2 }"),
51            lexer = new t017parserLexer(cstream),
52            tstream = new org.antlr.runtime.CommonTokenStream(lexer),
53            parser = new TestParser(tstream);
54
55        parser.program();
56        assertEquals(parser.reportedErrors.length, 2);
57        assertEquals(parser.reportedErrors[0].indexOf("line 1:14"), 0);
58        assertEquals(parser.reportedErrors[1].indexOf("line 1:20"), 0);
59    }
60
61
62</script>
63
64</head>
65<body>
66    <h1>t017parser</h1>
67</body>
68</html>
69