Home | History | Annotate | Download | only in functional
      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>t009lexer</title>
      6 
      7 <!-- ANTLR includes -->
      8 <script type="text/javascript" src="../../lib/antlr3-all.js"></script>
      9 <script type="text/javascript" src="t009lexer.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, t009lexer, {
     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("085"),
     28             lexer = new TLexer(stream),
     29             token;
     30 
     31         token = lexer.nextToken();
     32         assertEquals(token.getType(), lexer.DIGIT);
     33         assertEquals(token.getStartIndex(), 0);
     34         assertEquals(token.getStopIndex(), 0);
     35         assertEquals(token.getText(), "0");
     36 
     37         token = lexer.nextToken();
     38         assertEquals(token.getType(), lexer.DIGIT);
     39         assertEquals(token.getStartIndex(), 1);
     40         assertEquals(token.getStopIndex(), 1);
     41         assertEquals(token.getText(), '8');
     42 
     43         token = lexer.nextToken();
     44         assertEquals(token.getType(), lexer.DIGIT);
     45         assertEquals(token.getStartIndex(), 2);
     46         assertEquals(token.getStopIndex(), 2);
     47         assertEquals(token.getText(), '5');
     48 
     49        token = lexer.nextToken();
     50         assertEquals(token.getType(), lexer.EOF);
     51     }
     52 
     53     function testMalformedInput() {
     54         var stream = new org.antlr.runtime.ANTLRStringStream('2a'),
     55             lexer = new TLexer(stream),
     56             token;
     57 
     58         lexer.nextToken();
     59         try {
     60             token = lexer.nextToken();
     61             fail("nextToken should have thrown error on invalid input");
     62         } catch (e) {
     63             assertEquals(e.a, '0');
     64             assertEquals(e.b, '9');
     65             assertEquals(e.getUnexpectedType(), 'a');
     66             assertEquals(e.charPositionInLine, 1);
     67             assertEquals(e.line, 1);
     68         }
     69     }
     70 </script>
     71 
     72 </head>
     73 <body>
     74     <h1>t009lexer</h1>
     75 </body>
     76