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>t004lexer</title>
6
7<!-- ANTLR includes -->
8<script type="text/javascript" src="../../lib/antlr3-all.js"></script>
9<script type="text/javascript" src="t004lexer.js"></script>
10
11<!-- JsUnit include -->
12<script type="text/javascript" src="../jsunit/app/jsUnitCore.js"></script>
13
14<!-- Test Code -->
15<script type="text/javascript">
16    function TLexer() {
17        TLexer.superclass.constructor.apply(this, arguments);
18    }
19    org.antlr.lang.extend(TLexer, t004lexer, {
20        reportError: function(re) {
21            /* don't recover, just crash */
22            throw re;
23        }
24    });
25
26    function testValid() {
27        var stream = new org.antlr.runtime.ANTLRStringStream("ffofoofooo"),
28            lexer = new TLexer(stream),
29            token;
30
31        token = lexer.nextToken();
32        assertEquals(token.getType(), lexer.FOO);
33        assertEquals(token.getStartIndex(), 0);
34        assertEquals(token.getStopIndex(), 0);
35        assertEquals(token.getText(), "f");
36
37        token = lexer.nextToken();
38        assertEquals(token.getType(), lexer.FOO);
39        assertEquals(token.getStartIndex(), 1);
40        assertEquals(token.getStopIndex(), 2);
41        assertEquals(token.getText(), 'fo');
42
43        token = lexer.nextToken();
44        assertEquals(token.getType(), lexer.FOO);
45        assertEquals(token.getStartIndex(), 3);
46        assertEquals(token.getStopIndex(), 5);
47        assertEquals(token.getText(), 'foo');
48
49        token = lexer.nextToken();
50        assertEquals(token.getType(), lexer.FOO);
51        assertEquals(token.getStartIndex(), 6);
52        assertEquals(token.getStopIndex(), 9);
53        assertEquals(token.getText(), 'fooo');
54
55        token = lexer.nextToken();
56        assertEquals(token.getType(), lexer.EOF);
57    }
58
59    function testMalformedInput() {
60        var stream = new org.antlr.runtime.ANTLRStringStream('2'),
61            lexer = new TLexer(stream),
62            token;
63
64        try {
65            token = lexer.nextToken();
66            fail("nextToken should have thrown error on invalid input");
67        } catch (e) {
68            assertEquals(e.expecting, 'f');
69            assertEquals(e.getUnexpectedType(), '2');
70        }
71    }
72</script>
73
74</head>
75<body>
76    <h1>t004lexer</h1>
77</body>
78</html>
79