@@ -304,62 +304,6 @@ int taxed_value() {
304304 assertEquals(getContents(root, "simple2.txt"), sw.toString());
305305 }
306306
307- public void testEscaped() throws MustacheException, IOException {
308- MustacheBuilder c = init();
309- Mustache m = c.parseFile("escaped.html");
310- StringWriter sw = new StringWriter();
311- FutureWriter writer = new FutureWriter(sw);
312- m.execute(writer, new Scope(new Object() {
313- String title = "Bear > Shark";
314- String entities = """;
315- }));
316- writer.flush();
317- assertEquals(getContents(root, "escaped.txt"), sw.toString());
318- }
319-
320- public void testUnescaped() throws MustacheException, IOException {
321- MustacheBuilder c = new MustacheBuilder(root);
322- Mustache m = c.parseFile("unescaped.html");
323- StringWriter sw = new StringWriter();
324- FutureWriter writer = new FutureWriter(sw);
325- m.execute(writer, new Scope(new Object() {
326- String title() {
327- return "Bear > Shark";
328- }
329- }));
330- writer.flush();
331- assertEquals(getContents(root, "unescaped.txt"), sw.toString());
332- }
333-
334- public void testInverted() throws MustacheException, IOException {
335- MustacheBuilder c = init();
336- Mustache m = c.parseFile("inverted_section.html");
337- StringWriter sw = new StringWriter();
338- FutureWriter writer = new FutureWriter(sw);
339- m.execute(writer, new Scope(new Object() {
340- String name() {
341- return "Bear > Shark";
342- }
343-
344- ArrayList repo = new ArrayList();
345- }));
346- writer.flush();
347- assertEquals(getContents(root, "inverted_section.txt"), sw.toString());
348- }
349-
350- public void testComments() throws MustacheException, IOException {
351- MustacheBuilder c = init();
352- Mustache m = c.parseFile("comments.html");
353- StringWriter sw = new StringWriter();
354- FutureWriter writer = new FutureWriter(sw);
355- m.execute(writer, new Scope(new Object() {
356- String title() {
357- return "A Comedy of Errors";
358- }
359- }));
360- writer.flush();
361- assertEquals(getContents(root, "comments.txt"), sw.toString());
362- }
363307 */
364308 public void testPartial () throws MustacheException , IOException {
365309 MustacheCompiler c = init ();
@@ -373,74 +317,47 @@ public void testPartial() throws MustacheException, IOException {
373317 m .execute (sw , scope );
374318 assertEquals (getContents (root , "template_partial.txt" ), sw .toString ());
375319 }
376- /*
377- public static class PartialChanged extends Mustache {
378- static AtomicBoolean executed = new AtomicBoolean(false);
379- protected Mustache compilePartial(String name) throws MustacheException {
380- executed.set(true);
381- return super.compilePartial(name);
382- }
383- }
384-
385- public void testPartialOverride() throws MustacheException, IOException {
386- MustacheBuilder c = init();
387- c.setSuperclass(PartialChanged.class.getName());
388- Mustache m = c.parseFile("template_partial.html");
320+
321+ public void testComplex () throws MustacheException , IOException {
322+ MustacheCompiler c = init ();
323+ Mustache m = c .compile ("complex.html" );
389324 StringWriter sw = new StringWriter ();
390- FutureWriter writer = new FutureWriter(sw);
391- Scope scope = new Scope();
392- scope.put("title", "Welcome");
393- scope.put("template_partial_2", new Object() {
394- String again = "Goodbye";
395- });
396- m.execute(writer, scope);
397- writer.flush();
398- assertEquals(getContents(root, "template_partial.txt"), sw.toString());
399- assertTrue(PartialChanged.executed.get());
325+ m .execute (sw , new ComplexObject ());
326+ assertEquals (getContents (root , "complex.txt" ), sw .toString ());
400327 }
401328
402- public void testComplex() throws MustacheException, IOException {
403- Scope scope = new Scope(new Object() {
404- String header = "Colors";
405- List item = Arrays.asList(
406- new Object() {
407- String name = "red";
408- boolean current = true;
409- String url = "#Red";
410- },
411- new Object() {
412- String name = "green";
413- boolean current = false;
414- String url = "#Green";
415- },
416- new Object() {
417- String name = "blue";
418- boolean current = false;
419- String url = "#Blue";
420- }
421- );
329+ private static class ComplexObject {
330+ String header = "Colors" ;
331+ List <Color > item = Arrays .asList (
332+ new Color ("red" , true , "#Red" ),
333+ new Color ("green" , false , "#Green" ),
334+ new Color ("blue" , false , "#Blue" )
335+ );
422336
423- boolean link(Scope s ) {
424- return !((Boolean) s.get("current")) ;
425- }
337+ boolean list ( ) {
338+ return item . size () != 0 ;
339+ }
426340
427- boolean list(Scope s ) {
428- return ((List) s.get(" item")) .size() ! = 0;
429- }
341+ boolean empty ( ) {
342+ return item .size () = = 0 ;
343+ }
430344
431- boolean empty(Scope s) {
432- return ((List) s.get("item")).size() == 0;
345+ private static class Color {
346+ boolean link () {
347+ return !current ;
433348 }
434- });
435- MustacheBuilder c = new MustacheBuilder(root);
436- Mustache m = c.parseFile("complex.html");
437- StringWriter sw = new StringWriter();
438- FutureWriter writer = new FutureWriter(sw);
439- m.execute(writer, scope);
440- writer.flush();
441- assertEquals(getContents(root, "complex.txt"), sw.toString());
349+ Color (String name , boolean current , String url ) {
350+ this .name = name ;
351+ this .current = current ;
352+ this .url = url ;
353+ }
354+ String name ;
355+ boolean current ;
356+ String url ;
357+ }
442358 }
443359
360+ /*
444361 @SuppressWarnings("serial")
445362 public void testCurrentElementInArray() throws IOException, MustacheException {
446363
@@ -467,40 +384,34 @@ public void testCurrentElementInArray() throws IOException, MustacheException {
467384 assertEquals("\n\n", sw.toString());
468385
469386 }
470-
387+ */
471388 public void testReadme () throws MustacheException , IOException {
472- MustacheBuilder c = init();
473- Mustache m = c.parseFile ("items.html");
389+ MustacheCompiler c = init ();
390+ Mustache m = c .compile ("items.html" );
474391 StringWriter sw = new StringWriter ();
475- FutureWriter writer = new FutureWriter(sw);
476392 long start = System .currentTimeMillis ();
477- m.execute(writer, new Scope(new Context()));
478- writer.flush();
393+ m .execute (sw , new Context ());
479394 long diff = System .currentTimeMillis () - start ;
480395 assertEquals (getContents (root , "items.txt" ), sw .toString ());
481396 }
482397
483398 public void testReadme2 () throws MustacheException , IOException {
484- MustacheBuilder c = init();
485- Mustache m = c.parseFile ("items2.html");
399+ MustacheCompiler c = init ();
400+ Mustache m = c .compile ("items2.html" );
486401 StringWriter sw = new StringWriter ();
487- FutureWriter writer = new FutureWriter(sw);
488402 long start = System .currentTimeMillis ();
489- m.execute(writer, new Scope(new Context()));
490- writer.flush();
403+ m .execute (sw , new Context ());
491404 long diff = System .currentTimeMillis () - start ;
492405 assertEquals (getContents (root , "items.txt" ), sw .toString ());
493406 assertTrue ("Should be a little bit more than 1 second: " + diff , diff > 999 && diff < 2000 );
494407 }
495408
496409 public void testReadme3 () throws MustacheException , IOException {
497- MustacheBuilder c = init();
498- Mustache m = c.parseFile ("items3.html");
410+ MustacheCompiler c = init ();
411+ Mustache m = c .compile ("items3.html" );
499412 StringWriter sw = new StringWriter ();
500- FutureWriter writer = new FutureWriter(sw);
501413 long start = System .currentTimeMillis ();
502- m.execute(writer, new Scope(new Context()));
503- writer.flush();
414+ m .execute (sw , new Context ());
504415 long diff = System .currentTimeMillis () - start ;
505416 assertEquals (getContents (root , "items3.txt" ), sw .toString ());
506417 assertTrue ("Should be a little bit more than 1 second: " + diff , diff > 999 && diff < 2000 );
@@ -545,7 +456,7 @@ public void run() {
545456 }
546457 }
547458 }
548- */
459+
549460 private MustacheCompiler init () {
550461 DefaultCodeFactory cf = new DefaultCodeFactory (root );
551462 return new MustacheCompiler (cf );
0 commit comments