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