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>t022scopes</title> 6 7 <!-- ANTLR includes --> 8 <script type="text/javascript" src="../../lib/antlr3-all.js"></script> 9 <script type="text/javascript" src="t022scopesLexer.js"></script> 10 <script type="text/javascript" src="t022scopesParser.js"></script> 11 12 13 <!-- JsUnit include --> 14 <script type="text/javascript" src="../jsunit/app/jsUnitCore.js"></script> 15 16 <!-- Test Code --> 17 <script type="text/javascript"> 18 var TParser = function() { 19 TParser.superclass.constructor.apply(this, arguments); 20 } 21 org.antlr.lang.extend(TParser, t022scopesParser, { 22 emitErrorMessage: function(msg) {}, 23 reportError: function(e) { throw e; } 24 }); 25 26 27 function testa1() { 28 var cstream = new org.antlr.runtime.ANTLRStringStream("foobar"), 29 lexer = new t022scopesLexer(cstream), 30 tstream = new org.antlr.runtime.CommonTokenStream(lexer), 31 parser = new TParser(tstream); 32 33 // just make sure we don't get any errors 34 parser.a(); 35 } 36 37 function testb1() { 38 var cstream = new org.antlr.runtime.ANTLRStringStream("foobar"), 39 lexer = new t022scopesLexer(cstream), 40 tstream = new org.antlr.runtime.CommonTokenStream(lexer), 41 parser = new TParser(tstream); 42 43 try { 44 parser.b(false); 45 fail("above should have throw error"); 46 } catch(e) { 47 assert(org.antlr.lang.isValue(e)); 48 } 49 } 50 51 function testb2() { 52 var cstream = new org.antlr.runtime.ANTLRStringStream("foobar"), 53 lexer = new t022scopesLexer(cstream), 54 tstream = new org.antlr.runtime.CommonTokenStream(lexer), 55 parser = new TParser(tstream); 56 57 parser.b(true); 58 } 59 60 function testc1() { 61 var xinput = [ 62 "{", 63 " int i;", 64 " int j;", 65 " i = 0;", 66 "}" 67 ].join("\n"); 68 69 var cstream = new org.antlr.runtime.ANTLRStringStream(xinput), 70 lexer = new t022scopesLexer(cstream), 71 tstream = new org.antlr.runtime.CommonTokenStream(lexer), 72 parser = new TParser(tstream), 73 i; 74 75 var symbols = parser.c(); 76 assert(symbols.i); 77 assert(symbols.j); 78 } 79 80 function testc2() { 81 var xinput = [ 82 "{", 83 " int i;", 84 " int j;", 85 " i = 0;", 86 " x = 4;", 87 "}" 88 ].join("\n"); 89 90 var cstream = new org.antlr.runtime.ANTLRStringStream(xinput), 91 lexer = new t022scopesLexer(cstream), 92 tstream = new org.antlr.runtime.CommonTokenStream(lexer), 93 parser = new TParser(tstream), 94 i; 95 96 try { 97 parser.c(); 98 fail("shouldn't get here"); 99 } catch(e) { 100 assertEquals(e.message, "x"); 101 } 102 } 103 104 function testd1() { 105 var xinput = [ 106 "{", 107 " int i;", 108 " int j;", 109 " i = 0;", 110 " {", 111 " int i;", 112 " int x;", 113 " x = 5;", 114 " }", 115 "}" 116 ].join("\n"); 117 118 var cstream = new org.antlr.runtime.ANTLRStringStream(xinput), 119 lexer = new t022scopesLexer(cstream), 120 tstream = new org.antlr.runtime.CommonTokenStream(lexer), 121 parser = new TParser(tstream), 122 i; 123 124 var symbols = parser.d(); 125 assert(symbols.i); 126 assert(symbols.j); 127 } 128 129 function teste1() { 130 var xinput = "{ { { { 12 } } } }"; 131 var cstream = new org.antlr.runtime.ANTLRStringStream(xinput), 132 lexer = new t022scopesLexer(cstream), 133 tstream = new org.antlr.runtime.CommonTokenStream(lexer), 134 parser = new TParser(tstream); 135 136 var res = parser.e(); 137 assertEquals(res, 12); 138 } 139 140 function testf1() { 141 var xinput = "{ { { { 12 } } } }"; 142 var cstream = new org.antlr.runtime.ANTLRStringStream(xinput), 143 lexer = new t022scopesLexer(cstream), 144 tstream = new org.antlr.runtime.CommonTokenStream(lexer), 145 parser = new TParser(tstream); 146 147 var res = parser.f(); 148 assertUndefined(res); 149 } 150 151 function testf2() { 152 var xinput = "{ { 12 } }"; 153 var cstream = new org.antlr.runtime.ANTLRStringStream(xinput), 154 lexer = new t022scopesLexer(cstream), 155 tstream = new org.antlr.runtime.CommonTokenStream(lexer), 156 parser = new TParser(tstream); 157 158 var res = parser.f(); 159 assertUndefined(res); 160 } 161 </script> 162 163 </head> 164 <body> 165 <h1>t022scopes</h1> 166 </body> 167 </html> 168