Example #1
0
 @Test
 public void issue31() {
   StringWriter sw = new StringWriter();
   Printer p = Printers.newPrinter(sw);
   assertEquals("\"'\"", Printers.printString("\'"));
   assertEquals("\"'\"", Printers.printString("'"));
 }
Example #2
0
 @Test
 public void testPrettyPrinting() {
   Map<Integer, String> m = new HashMap();
   m.put(3, "Three");
   m.put(4, "Four");
   List<?> list = Arrays.asList(new HashSet(Arrays.asList(1, 2)), m);
   String s = Printers.printString(Printers.prettyPrinterProtocol(), list);
   assertEquals("[\n  #{\n    1\n    2\n  }\n  {\n    3 \"Three\"\n    4 \"Four\"\n  }\n]", s);
 }
Example #3
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 #4
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));
  }