• 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>t008lexer</title>
6
7<!-- ANTLR includes -->
8<script type="text/javascript" src="../../lib/antlr3-all.js"></script>
9<script type="text/javascript" src="t008lexer.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, t008lexer, {
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("ffaf"),
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(), 'fa');
42
43        token = lexer.nextToken();
44        assertEquals(token.getType(), lexer.FOO);
45        assertEquals(token.getStartIndex(), 3);
46        assertEquals(token.getStopIndex(), 3);
47        assertEquals(token.getText(), 'f');
48
49       token = lexer.nextToken();
50        assertEquals(token.getType(), lexer.EOF);
51    }
52
53    function testMalformedInput() {
54        var stream = new org.antlr.runtime.ANTLRStringStream('fafb'),
55            lexer = new TLexer(stream),
56            token;
57
58        lexer.nextToken();
59        lexer.nextToken();
60        try {
61            token = lexer.nextToken();
62            fail("nextToken should have thrown error on invalid input");
63        } catch (e) {
64            assertEquals(e.getUnexpectedType(), 'b');
65            assertEquals(e.charPositionInLine, 3);
66            assertEquals(e.line, 1);
67        }
68    }
69</script>
70
71</head>
72<body>
73    <h1>t008lexer</h1>
74</body>
75