Example #1
0
  @Test
  public void testDefaultPrinter() {
    StringWriter sw = new StringWriter();
    Printer p = Printers.newPrinter(sw);

    ArrayList<Object> al = new ArrayList<Object>();
    al.add(1);
    al.add(2);
    p.printValue(al);
    assertEquals("[1 2]", sw.toString());
  }
Example #2
0
 @Test
 public void testLoosePrinter() {
   StringWriter sw = new StringWriter();
   Printer p = LoosePrinter.newLoosePrinter(sw);
   ArrayList<Object> al = new ArrayList<Object>();
   al.add(Keyword.newKeyword("test"));
   al.add("test");
   al.add(Keyword.newKeyword("value"));
   Map map = new HashMap();
   map.put(Keyword.newKeyword("name"), "Test");
   al.add(map);
   p.printValue(al);
   assertEquals("[:test \"test\" :value {:name \"Test\"}]", sw.toString());
 }
Example #3
0
  void assertRoundTrip(String ednText) {
    Parser parser;
    Parseable pbr;
    pbr = Parsers.newParseable(ednText);
    parser = Parsers.newParser(Parsers.defaultConfiguration());
    Object originalParsedValue = parser.nextValue(pbr);

    StringWriter sw = new StringWriter();
    Printer ew = Printers.newPrinter(Printers.defaultPrinterProtocol(), sw);
    ew.printValue(originalParsedValue);
    ew.close();

    pbr = Parsers.newParseable(sw.toString());
    parser = Parsers.newParser(Parsers.defaultConfiguration());
    Object secondGenerationParsedValue = parser.nextValue(pbr);
    assertEquals(
        "'" + ednText + "' => '" + sw.toString() + "' did not round-trip.",
        originalParsedValue,
        secondGenerationParsedValue);
    assertEquals(Parser.END_OF_INPUT, parser.nextValue(pbr));
  }