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>t005lexer</title> 6 7<!-- ANTLR includes --> 8<script type="text/javascript" src="../../lib/antlr3-all.js"></script> 9<script type="text/javascript" src="t005lexer.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, t005lexer, { 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("fofoofooo"), 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(), 1); 35 assertEquals(token.getText(), "fo"); 36 37 token = lexer.nextToken(); 38 assertEquals(token.getType(), lexer.FOO); 39 assertEquals(token.getStartIndex(), 2); 40 assertEquals(token.getStopIndex(), 4); 41 assertEquals(token.getText(), 'foo'); 42 43 token = lexer.nextToken(); 44 assertEquals(token.getType(), lexer.FOO); 45 assertEquals(token.getStartIndex(), 5); 46 assertEquals(token.getStopIndex(), 8); 47 assertEquals(token.getText(), 'fooo'); 48 49 token = lexer.nextToken(); 50 assertEquals(token.getType(), lexer.EOF); 51 } 52 53 function testMalformedInput1() { 54 var stream = new org.antlr.runtime.ANTLRStringStream('2'), 55 lexer = new TLexer(stream), 56 token; 57 58 try { 59 token = lexer.nextToken(); 60 fail("nextToken should have thrown error on invalid input"); 61 } catch (e) { 62 assertEquals(e.expecting, 'f'); 63 assertEquals(e.getUnexpectedType(), '2'); 64 } 65 } 66 67 function testMalformedInput2() { 68 var stream = new org.antlr.runtime.ANTLRStringStream('f'), 69 lexer = new TLexer(stream), 70 token; 71 72 try { 73 token = lexer.nextToken(); 74 fail("nextToken should have thrown error on invalid input"); 75 } catch (e) { 76 assertEquals(e.getUnexpectedType(), lexer.EOF); 77 } 78 } 79</script> 80 81</head> 82<body> 83 <h1>t005lexer</h1> 84</body> 85</html> 86