private void verifyAssembly(String templateName) throws Exception { StringWriter output = new StringWriter(); assembler.assemble( createClassPathUrl("templates/" + templateName + ".xhtml"), namespace, output); String expectedOutput = loadText(createClassPathUrl("solutions/" + templateName + ".html")); assertEquals(expectedOutput, output.toString()); }
@Test public void testCons1() { lwriter.writeCons(new Cons("", new Symbol("find-buffer-file-type-coding-system"))); assertEquals("(\"\" . find-buffer-file-type-coding-system)", output.toString()); reset(); lwriter.writeUnknown(new Cons("", new Symbol("find-buffer-file-type-coding-system"))); assertEquals("(\"\" . find-buffer-file-type-coding-system)", output.toString()); }
@Test public void testDouble1() { lwriter.writeDouble(10.1d); assertEquals("10.1", output.toString()); reset(); lwriter.writeUnknown(10.1d); assertEquals("10.1", output.toString()); }
@Test public void testInt1() { lwriter.writeInt(1010); assertEquals("1010", output.toString()); reset(); lwriter.writeUnknown(1010); assertEquals("1010", output.toString()); }
@Test public void testForm1() { List l = Arrays.asList(new Symbol("message"), "Hello %s", new Symbol("user-full-name")); lwriter.writeForm(l); assertEquals("(message \"Hello %s\" user-full-name)", output.toString()); reset(); lwriter.writeUnknown(l); assertEquals("'(message \"Hello %s\" user-full-name)", output.toString()); }
@Test public void testMinimalTemplate() throws Exception { final String INPUT = "<html xmlns=\"http://www.w3.org/1999/xhtml\"/>"; final String EXPECTED_OUTPUT = "<!DOCTYPE html>\n" + "<html xmlns=\"http://www.w3.org/1999/xhtml\"/>"; StringWriter output = new StringWriter(); assembler.assemble(createLiteralUrl(INPUT), output); assertEquals(EXPECTED_OUTPUT, output.toString()); }
@Test public void testChars() { lwriter.writeChar('a'); assertEquals("?a", output.toString()); reset(); lwriter.writeChar('?'); assertEquals("?\\?", output.toString()); reset(); lwriter.writeChar('\\'); assertEquals("?\\\\", output.toString()); }
@Test public void testMapAlist() { Map<Object, Object> m = new LinkedHashMap<>(); m.put("foo", new Symbol("bar")); m.put("baz", new Symbol("quux")); lwriter.writeAlist(m); assertEquals("'((\"foo\" . bar) (\"baz\" . quux))", output.toString()); reset(); lwriter.writeUnknown(m); assertEquals("'((\"foo\" . bar) (\"baz\" . quux))", output.toString()); }
@Test public void testQuoted1() { List l = new ArrayList(); l.add(new Symbol("apply")); l.add(new Quoted(new Symbol("+"))); l.add(1); l.add(2); List inner = new ArrayList(); inner.add(3); inner.add(4); l.add(new Quoted(inner)); lwriter.writeForm(l); assertEquals("(apply '+ 1 2 '(3 4))", output.toString()); reset(); lwriter.writeUnknown(l); assertEquals("'(apply '+ 1 2 '(3 4))", output.toString()); }
/** * Generates an <add><doc>... XML String with options on the add. * * @param doc the Document to add * @param args 0th and Even numbered args are param names, Odds are param values. * @see #add * @see #doc */ public String add(Doc doc, String... args) { try { StringWriter r = new StringWriter(); // this is anoying if (null == args || 0 == args.length) { r.write("<add>"); r.write(doc.xml); r.write("</add>"); } else { XML.writeUnescapedXML(r, "add", doc.xml, (Object[]) args); } return r.getBuffer().toString(); } catch (IOException e) { throw new RuntimeException("this should never happen with a StringWriter", e); } }
@Test public void testWriteJdeeJuciInvokeElispForm() { List eval = new ArrayList(); eval.add(new Symbol("jdee-juci-invoke-elisp")); List form = new ArrayList(); form.add(new Symbol("message")); form.addAll(Arrays.asList("hello %s", "nick")); eval.add(form); lwriter.writeForm(eval); assertEquals("(jdee-juci-invoke-elisp '(message \"hello %s\" \"nick\"))", output.toString()); }