@Override public Node invert(Node node, String text, AtomicInteger position) { int start = position.get(); List<Node> nodes = new ArrayList<>(); Node invert; while ((invert = mustache.invert(new Node(), text, position)) != null) { nodes.add(invert); } node.put(name, list(nodes)); return matchAppended(node, text, position, start); } }
@Test public void testCollectPoints() throws Exception { MustacheFactory dmf = new DefaultMustacheFactory(); Mustache compile = dmf.compile(new StringReader("{{#page}}This is a {{test}}{{/page}}"), UUID.randomUUID().toString()); Node node = compile.invert("This is a good day"); assertNotNull(node); }
@Test public void testNoNode() throws Exception { MustacheFactory dmf = new DefaultMustacheFactory(); Mustache compile = dmf.compile(new StringReader("Using cluster file [^\\n]+\nHello World"), UUID.randomUUID().toString()); Node node = compile.invert("Using cluster file `/etc/foundationdb/fdb.cluster'.\nHello World"); assertNotNull(node); } }
@Test public void testToJson4() throws IOException { DefaultMustacheFactory dmf = new DefaultMustacheFactory(); Mustache compile = dmf.compile("fdbcli2.mustache"); Path file = getPath("src/test/resources/fdbcli3.txt"); String txt = new String(Files.readAllBytes(file), "UTF-8"); System.out.println("Input text:["); System.out.print(txt); System.out.println("]"); Node invert = compile.invert(txt); output(invert); }
@Test public void testParser() throws IOException { DefaultMustacheFactory dmf = new DefaultMustacheFactory(); Mustache compile = dmf.compile("fdbcli.mustache"); Path file = getPath("src/test/resources/fdbcli.txt"); String txt = new String(Files.readAllBytes(file), "UTF-8"); Node invert = compile.invert(txt); System.out.println(invert); }
@Test public void testToJson5() throws IOException { DefaultMustacheFactory dmf = new DefaultMustacheFactory(); Mustache compile = dmf.compile("fdbcli3.mustache"); Path file = getPath("src/test/resources/fdbcli.txt"); String txt = new String(Files.readAllBytes(file), "UTF-8"); Node invert = compile.invert(txt); output(invert); }
@Test public void testToJson() throws IOException { DefaultMustacheFactory dmf = new DefaultMustacheFactory(); Mustache compile = dmf.compile("fdbcli.mustache"); Path file = getPath("src/test/resources/fdbcli.txt"); String txt = new String(Files.readAllBytes(file), "UTF-8"); Node invert = compile.invert(txt); output(invert); }
@Test public void testToJson3() throws IOException { DefaultMustacheFactory dmf = new DefaultMustacheFactory(); Mustache compile = dmf.compile("psauxwww.mustache"); Path file = getPath("src/test/resources/psauxwww.txt"); String txt = new String(Files.readAllBytes(file), "UTF-8"); Node invert = compile.invert(txt); output(invert); }
@Test public void testDiskstats() throws IOException { DefaultMustacheFactory dmf = new DefaultMustacheFactory(); Mustache m = dmf.compile(new StringReader("{{#disk}}\n" + "\\s+[0-9]+\\s+[0-9]+\\s+{{tag_device}} {{reads}} {{reads_merged}} {{sectors_read}} {{read_time}} {{writes}} {{writes_merged}} {{sectors_written}} {{write_time}} {{ios}} {{io_time}} {{weighted_io_time}}\n" + "{{/disk}}"), "diskstats"); String txt = " 220 100 xvdb 3140 43 23896 216 57698654 45893891 1261011016 12232816 0 10994276 12222124\n" + " 220 100 xvdk 2417241 93 19338786 1287328 284969078 116717514 10144866416 1520589288 0 329180460 1521686240\n"; Node invert = m.invert(txt); output(invert); }
@Test public void testToJson2() throws IOException { DefaultMustacheFactory dmf = new DefaultMustacheFactory(); Mustache compile = dmf.compile("fdbcli2.mustache"); Path file = getPath("src/test/resources/fdbcli2.txt"); String txt = new String(Files.readAllBytes(file), "UTF-8"); Node invert = compile.invert(txt); output(invert); }
@Test public void testSimple() throws IOException { DefaultMustacheFactory dmf = new DefaultMustacheFactory(); Mustache test = dmf.compile(new StringReader("test {{value}} test"), "test"); Node invert = test.invert("test value test"); Node node = new Node(); node.put("value", value("value")); assertEquals(node, invert); }
@Test public void testIterable() throws IOException { DefaultMustacheFactory dmf = new DefaultMustacheFactory(); Mustache test = dmf.compile(new StringReader("{{#values}}\ntest: {{value}}\n{{/values}}"), "test"); Node invert = test.invert("test: sam\ntest: fred\n"); Node node = new Node(); Node sam = new Node(); sam.put("value", value("sam")); Node fred = new Node(); fred.put("value", value("fred")); node.put("values", list(asList(sam, fred))); assertEquals(node, invert); StringWriter sw = new StringWriter(); test.execute(sw, invert).close(); System.out.println(sw); }
@Override public Node invert(Node node, String text, AtomicInteger position) { int start = position.get(); List<Node> nodes = new ArrayList<>(); Node invert; while ((invert = mustache.invert(new Node(), text, position)) != null) { nodes.add(invert); } node.put(name, list(nodes)); return matchAppended(node, text, position, start); } }
@Override public Node invert(Node node, String text, AtomicInteger position) { int start = position.get(); List<Node> nodes = new ArrayList<>(); Node invert; while ((invert = mustache.invert(new Node(), text, position)) != null) { nodes.add(invert); } node.put(name, list(nodes)); return matchAppended(node, text, position, start); } }