• 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>t003lexer</title>
6
7<!-- ANTLR includes -->
8<script type="text/javascript" src="../../lib/antlr3-all.js"></script>
9<script type="text/javascript" src="t003lexer.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, t003lexer, {
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("0fooze1"),
28            lexer = new TLexer(stream),
29            token;
30
31        token = lexer.nextToken();
32        assertEquals(token.getType(), lexer.ZERO);
33
34        token = lexer.nextToken();
35        assertEquals(token.getType(), lexer.FOOZE);
36
37        token = lexer.nextToken();
38        assertEquals(token.getType(), lexer.ONE);
39
40        token = lexer.nextToken();
41        assertEquals(token.getType(), lexer.EOF);
42    }
43
44    function testMalformedInput() {
45        var stream = new org.antlr.runtime.ANTLRStringStream('2'),
46            lexer = new TLexer(stream),
47            token;
48
49        try {
50            token = lexer.nextToken();
51            fail("nextToken should have thrown error on invalid input");
52        } catch (e) {
53            assertEquals(e.getUnexpectedType(), '2');
54        }
55    }
56</script>
57
58</head>
59<body>
60    <h1>t003lexer</h1>
61</body>
62</html>
63