1*16467b97STreehugger Robot<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2*16467b97STreehugger Robot<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 3*16467b97STreehugger Robot<head> 4*16467b97STreehugger Robot<meta http-equiv="content-type" content="text/html;charset=utf-8" /> 5*16467b97STreehugger Robot<title>t017parser</title> 6*16467b97STreehugger Robot 7*16467b97STreehugger Robot<!-- ANTLR includes --> 8*16467b97STreehugger Robot<script type="text/javascript" src="../../lib/antlr3-all.js"></script> 9*16467b97STreehugger Robot<script type="text/javascript" src="t017parserLexer.js"></script> 10*16467b97STreehugger Robot<script type="text/javascript" src="t017parserParser.js"></script> 11*16467b97STreehugger Robot 12*16467b97STreehugger Robot 13*16467b97STreehugger Robot<!-- JsUnit include --> 14*16467b97STreehugger Robot<script type="text/javascript" src="../jsunit/app/jsUnitCore.js"></script> 15*16467b97STreehugger Robot 16*16467b97STreehugger Robot<!-- Test Code --> 17*16467b97STreehugger Robot<script type="text/javascript"> 18*16467b97STreehugger Robot TestParser = function() { 19*16467b97STreehugger Robot TestParser.superclass.constructor.apply(this, arguments); 20*16467b97STreehugger Robot this.reportedErrors = []; 21*16467b97STreehugger Robot }; 22*16467b97STreehugger Robot org.antlr.lang.extend(TestParser, t017parserParser, { 23*16467b97STreehugger Robot emitErrorMessage: function(msg) { 24*16467b97STreehugger Robot this.reportedErrors.push(msg); 25*16467b97STreehugger Robot } 26*16467b97STreehugger Robot }); 27*16467b97STreehugger Robot 28*16467b97STreehugger Robot function testValid() { 29*16467b97STreehugger Robot var cstream = new org.antlr.runtime.ANTLRStringStream("int foo;"), 30*16467b97STreehugger Robot lexer = new t017parserLexer(cstream), 31*16467b97STreehugger Robot tstream = new org.antlr.runtime.CommonTokenStream(lexer), 32*16467b97STreehugger Robot parser = new TestParser(tstream); 33*16467b97STreehugger Robot 34*16467b97STreehugger Robot parser.program(); 35*16467b97STreehugger Robot assertEquals(parser.reportedErrors.length, 0); 36*16467b97STreehugger Robot } 37*16467b97STreehugger Robot 38*16467b97STreehugger Robot function testMalformedInput1() { 39*16467b97STreehugger Robot var cstream = new org.antlr.runtime.ANTLRStringStream("int foo() { 1+2 }"); 40*16467b97STreehugger Robot lexer = new t017parserLexer(cstream), 41*16467b97STreehugger Robot tstream = new org.antlr.runtime.CommonTokenStream(lexer), 42*16467b97STreehugger Robot parser = new TestParser(tstream); 43*16467b97STreehugger Robot 44*16467b97STreehugger Robot parser.program(); 45*16467b97STreehugger Robot assertEquals(parser.reportedErrors.length, 1); 46*16467b97STreehugger Robot assertEquals(parser.reportedErrors[0].indexOf("line 1:16"), 0); 47*16467b97STreehugger Robot } 48*16467b97STreehugger Robot 49*16467b97STreehugger Robot function testMalformedInput2() { 50*16467b97STreehugger Robot var cstream = new org.antlr.runtime.ANTLRStringStream("int foo() { 1+; 1+2 }"), 51*16467b97STreehugger Robot lexer = new t017parserLexer(cstream), 52*16467b97STreehugger Robot tstream = new org.antlr.runtime.CommonTokenStream(lexer), 53*16467b97STreehugger Robot parser = new TestParser(tstream); 54*16467b97STreehugger Robot 55*16467b97STreehugger Robot parser.program(); 56*16467b97STreehugger Robot assertEquals(parser.reportedErrors.length, 2); 57*16467b97STreehugger Robot assertEquals(parser.reportedErrors[0].indexOf("line 1:14"), 0); 58*16467b97STreehugger Robot assertEquals(parser.reportedErrors[1].indexOf("line 1:20"), 0); 59*16467b97STreehugger Robot } 60*16467b97STreehugger Robot 61*16467b97STreehugger Robot 62*16467b97STreehugger Robot</script> 63*16467b97STreehugger Robot 64*16467b97STreehugger Robot</head> 65*16467b97STreehugger Robot<body> 66*16467b97STreehugger Robot <h1>t017parser</h1> 67*16467b97STreehugger Robot</body> 68*16467b97STreehugger Robot</html> 69