()
| 460 | } |
| 461 | |
| 462 | public static void test1() throws IOException |
| 463 | { // test rig |
| 464 | String templates = "method(type,name,locals,args,stats) ::= <<\n"+"public <type> <name>(<args:{a| int <a>}; separator=\", \">) {\n"+" <if(locals)>int locals[<locals>];<endif>\n"+" <stats;separator=\"\\n\">\n"+"}\n"+">>\n"+"assign(a,b) ::= \"<a> = <b>;\"\n"+"return(x) ::= <<return <x>;>>\n"+"paren(x) ::= \"(<x>)\"\n"; |
| 465 | String tmpdir = System.getProperty("java.io.tmpdir"); |
| 466 | writeFile(tmpdir, "t.stg", templates); |
| 467 | STGroup group = new STGroupFile(tmpdir+"/"+"t.stg"); |
| 468 | ST st = group.getInstanceOf("method"); |
| 469 | st.impl.dump(); |
| 470 | st.add("type", "float"); |
| 471 | st.add("name", "foo"); |
| 472 | st.add("locals", 3); |
| 473 | st.add("args", new String[] {"x", |
| 474 | "y", |
| 475 | "z"}); |
| 476 | ST s1 = group.getInstanceOf("assign"); |
| 477 | ST paren = group.getInstanceOf("paren"); |
| 478 | paren.add("x", "x"); |
| 479 | s1.add("a", paren); |
| 480 | s1.add("b", "y"); |
| 481 | ST s2 = group.getInstanceOf("assign"); |
| 482 | s2.add("a", "y"); |
| 483 | s2.add("b", "z"); |
| 484 | ST s3 = group.getInstanceOf("return"); |
| 485 | s3.add("x", "3.14159"); |
| 486 | st.add("stats", s1); |
| 487 | st.add("stats", s2); |
| 488 | st.add("stats", s3); |
| 489 | STViz viz = st.inspect(); |
| 490 | System.out.println(st.render()); // should not mess up ST event lists |
| 491 | } |
| 492 | |
| 493 | public static void test2() throws IOException |
| 494 | { // test rig |
no test coverage detected