Esempio n. 1
0
 @Test
 public void sequenceOfTokens() throws IOException {
   String txt =
       "; comment\n"
           + "\t\n"
           + "true false nil \\#{:keyword  [1 2N 3.0 4.0M]}symbol\n"
           + "\\newline \"some text\"\\x ; another comment\n"
           + "() #{-42}";
   Parseable pbr = Parsers.newParseable(txt);
   Object[] expected = {
     true,
     false,
     Token.NIL,
     '#',
     Token.BEGIN_MAP,
     key("keyword"),
     Token.BEGIN_VECTOR,
     1L,
     BigInteger.valueOf(2),
     3.0d,
     new BigDecimal("4.0"),
     Token.END_VECTOR,
     Token.END_MAP_OR_SET,
     sym("symbol"),
     '\n',
     "some text",
     'x',
     Token.BEGIN_LIST,
     Token.END_LIST,
     Token.BEGIN_SET,
     -42L,
     Token.END_MAP_OR_SET,
     Token.END_OF_INPUT
   };
   Scanner s = scanner();
   for (Object o : expected) {
     assertEquals(o, s.nextToken(pbr));
   }
 }
Esempio n. 2
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));
  }
Esempio n. 3
0
 static Scanner scanner() {
   return new ScannerImpl(Parsers.defaultConfiguration());
 }
Esempio n. 4
0
 static Object scan(String input) {
   Parseable pbr = Parsers.newParseable(input);
   return scanner().nextToken(pbr);
 }