• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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>t014parser</title>
6
7<!-- ANTLR includes -->
8<script type="text/javascript" src="../../lib/antlr3-all.js"></script>
9<script type="text/javascript" src="t014parserLexer.js"></script>
10<script type="text/javascript" src="t014parserParser.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    function testValid() {
19        var cstream = new org.antlr.runtime.ANTLRStringStream("var foobar; gnarz(); var blupp; flupp ( ) ;"),
20            lexer = new t014parserLexer(cstream),
21            tstream = new org.antlr.runtime.CommonTokenStream(lexer),
22            parser = new t014parserParser(tstream),
23            i,
24            expected = [
25                ["decl", "foobar"],
26                ["call", "gnarz"],
27                ["decl", "blupp"],
28                ["call", "flupp"]
29            ];
30
31        parser.document();
32        assertEquals(0, parser.reportedErrors.length);
33        for (i=0; i<parser.events.length; i++) {
34            assertEquals(parser.events[i][0], expected[i][0]);
35            assertEquals(parser.events[i][1], expected[i][1]);
36        }
37    }
38
39    function testMalformedInput1() {
40        var cstream = new org.antlr.runtime.ANTLRStringStream("var; foo();"),
41            lexer = new t014parserLexer(cstream),
42            tstream = new org.antlr.runtime.CommonTokenStream(lexer),
43            parser = new t014parserParser(tstream);
44
45        parser.document();
46        assertEquals(parser.reportedErrors.length, 1);
47        assertEquals(parser.reportedErrors[0].indexOf("line 1:3"), 0);
48        assertEquals(parser.events.length, 0);
49    }
50
51    function testMalformedInput2() {
52        var cstream = new org.antlr.runtime.ANTLRStringStream("var foobar(); gnarz();"),
53            lexer = new t014parserLexer(cstream),
54            tstream = new org.antlr.runtime.CommonTokenStream(lexer),
55            parser = new t014parserParser(tstream),
56            expected = [["call", "gnarz"]];
57
58        parser.document();
59        assertEquals(parser.reportedErrors.length, 1);
60        assertEquals(parser.reportedErrors[0].indexOf("line 1:10"), 0);
61        var i;
62        assertEquals(parser.events.length, expected.length);
63        for (i=0; i<expected.length; i++) {
64            assertEquals(parser.events[i][0], expected[i][0]);
65            assertEquals(parser.events[i][1], expected[i][1]);
66        }
67    }
68
69    function testMalformedInput3() {
70        var cstream = new org.antlr.runtime.ANTLRStringStream("gnarz(; flupp();"),
71            lexer = new t014parserLexer(cstream),
72            tstream = new org.antlr.runtime.CommonTokenStream(lexer),
73            parser = new t014parserParser(tstream),
74            expected = [["call","gnarz"],["call","flupp"]];
75
76        parser.document();
77        assertEquals(parser.reportedErrors.length, 1);
78        assertEquals(parser.reportedErrors[0].indexOf("line 1:6"), 0);
79        var i;
80        assertEquals(parser.events.length, expected.length);
81        for (i=0; i<expected.length; i++) {
82            assertEquals(parser.events[i][0], expected[i][0]);
83            assertEquals(parser.events[i][1], expected[i][1]);
84        }
85    }
86</script>
87
88</head>
89<body>
90    <h1>t014parser</h1>
91</body>
92