Package org.moxie.maxml

Examples of org.moxie.maxml.MaxmlParser


  String references3 = "project.version.r1: {\n version: 1\n  }\nproject.version.r2: {\n  version: 2\n  }\nversions: &'project.version.r'[1..2]";

  @SuppressWarnings("rawtypes")
  @Test
  public void testValueParsing() throws Exception {
    MaxmlParser parser = new MaxmlParser();
    // strings
    assertEquals("string", parser.parseValue("string"));
    assertEquals("string", parser.parseValue("'string'"));
    assertEquals("string", parser.parseValue("\"string\""));
    assertEquals("Moxie\nis a\nJava Project Build Toolkit\n", Maxml.parse(blockTest).get("description"));
    assertEquals("Moxie\n is a\n  Java Project Build Toolkit", Maxml.parse(blockTest2).get("description"));
    assertEquals("Moxie\n is a\n  Java Project Build Toolkit\n", Maxml.parse(blockTest3).get("description"));
    assertEquals("[blue, purple, green, red, yellow, orange, magenta]", Maxml.parse(references).get("all").toString());
    assertEquals("yellow", Maxml.parse(references).get("mycolor").toString());
    assertEquals("[blue, purple, green, red, yellow, orange, magenta]", Maxml.parse(references2).get("all").toString());
    assertEquals("yellow", Maxml.parse(references2).get("mycolor").toString());
    assertEquals("[{version=1}, {version=2}]", Maxml.parse(references3).get("versions").toString());

    // numerics
    assertEquals(101, parser.parseValue("101"));
    assertEquals(8, parser.parseValue("0x8"));
    assertEquals(8, parser.parseValue("010"));
    assertEquals(3405691582L, parser.parseValue("0xcafebabe"));
    assertEquals(3405691582L, parser.parseValue("#cafebabe"));
    assertEquals(1101, parser.parseValue("1,101"));
    assertEquals(1101202, parser.parseValue("1,101,202"));
    assertEquals(4000000000L, parser.parseValue("4000000000"));
    assertEquals(4000000000L, parser.parseValue("4,000,000,000"));
    assertEquals(2.3f, parser.parseValue("2.3"));
    assertEquals(6.0E23f, parser.parseValue("6.0E+23"));
    assertEquals(6.0E56d, parser.parseValue("6.0E+56"));

    // booleans
    assertEquals(true, parser.parseValue("true"));
    assertEquals(true, parser.parseValue("yes"));
    assertEquals(true, parser.parseValue("on"));

    assertEquals(false, parser.parseValue("false"));
    assertEquals(false, parser.parseValue("no"));
    assertEquals(false, parser.parseValue("off"));

    // null
    assertNull(parser.parseValue("~"));

    // inline lists
    assertEquals("[a, b, c]", parser.parseValue("[a, b, c]").toString());
    assertEquals("[a, b, c]", parser.parseValue("['a', 'b', 'c']")
        .toString());
    assertEquals("[a, b, c]", parser.parseValue("[\"a\", \"b\", \"c\"]")
        .toString());
    assertEquals(3, ((List) parser.parseValue("[a, b, c]")).size());

    assertEquals(3,
        ((List) parser.parseValue("[a, \"b, or beta\", c]")).size());
   
    // inline map
    assertEquals(7, ((MaxmlMap) parser.parseValue(inlineMap)).size());
    assertEquals(4, ((MaxmlMap) parser.parseValue(inlineMap2)).size());   
    assertEquals("[org.moxie]", ((MaxmlMap) parser.parseValue(inlineMap2)).getList("affinity", null).toString());
   
    // dates
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    assertEquals("2003-07-04",
        df.format(((Date) parser.parseValue("2003-07-04"))));

    df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    assertEquals("2003-07-04T15:15:15Z",
        df.format(((Date) parser.parseValue("2003-07-04T15:15:15Z"))));

    df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
    df.setTimeZone(TimeZone.getTimeZone("America/New_York"));
    assertEquals("2003-07-04T15:15:15-0400", df.format(((Date) parser
        .parseValue("2003-07-04T15:15:15-0400"))));
  }
View Full Code Here

TOP

Related Classes of org.moxie.maxml.MaxmlParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.