Exemple #1
0
  public void testParsePipe() throws Exception {
    assertEquals(Operator.EDIT, Parser.parseOperator(Parser.tokenize("|")));
    assertEquals(Operator.TRANSLATE, Parser.parseOperator(Parser.tokenize(">")));

    assertParseOperatorFails("a", "Invalid operator \"Token[a], line 1\"");
    assertParseOperatorFails("-", "Invalid operator \"Token['-'], line 1\"");
  }
Exemple #2
0
 public void assertParseOperatorFails(String input, String errorMessage) {
   try {
     Parser.parseOperator(Parser.tokenize(input));
     fail();
   } catch (Parser.ParseError e) {
     assertEquals("Cannot parse: " + errorMessage, e.getMessage());
   }
 }
Exemple #3
0
 public void assertParseTermFails(String input, String errorMessage) {
   try {
     Term r = Parser.parseTerm(Parser.tokenize(input));
     fail(
         String.format(
             "Successfully parsed invalid string: %s into %s and %s",
             input, r.identifier, r.options.toString()));
   } catch (Parser.ParseError e) {
     assertEquals("Cannot parse: " + errorMessage, e.getMessage());
   }
 }
Exemple #4
0
 public void assertParseTermCompletely(
     String input, String identifier, ImmutableMap<String, String> options)
     throws Parser.ParseError {
   Term r = Parser.parseTermCompletely(input);
   assertEquals(identifier, r.identifier);
   assertEquals(options, r.options);
 }
Exemple #5
0
 void assertOptionsFail(String s) {
   try {
     Parser.parseOption(tokenize(s));
     fail("Successfully parsed invalid string: " + s);
   } catch (Parser.ParseError e) {
   }
 }
Exemple #6
0
 public void assertOptionsResult(String s, ImmutableMap<String, String> expected) {
   try {
     Map<String, String> actual = Parser.parseOptions(tokenize(s));
     assertEquals(expected, actual);
   } catch (Parser.ParseError e) {
     fail(String.format("Could not parse %s: %s", s, e));
   }
 }
Exemple #7
0
 public void assertOperationListRoundTrip(String expected, String input) throws Exception {
   List<Operation> terms = Parser.parseOperationList(tokenize(input));
   StringBuilder r = new StringBuilder();
   for (Operation op : terms) {
     r.append(op.operator);
     r.append(op.term);
   }
   assertEquals(expected, r.toString());
 }
Exemple #8
0
  public void testParseOption() throws Exception {
    Parser.ParseOptionResult r;

    r = Parser.parseOption(tokenize("key=value baz"));
    assertEquals("key", r.key);
    assertEquals("value", r.value);
    r = Parser.parseOption(tokenize("key    = value baz"));
    assertEquals("key", r.key);
    assertEquals("value", r.value);
    r = Parser.parseOption(tokenize("\"key\" = \"value\" baz"));
    assertEquals("key", r.key);
    assertEquals("value", r.value);

    assertOptionFail("key=");
    assertOptionFail("=value");
    assertOptionFail("key");
    assertOptionFail("key value");
    assertOptionFail(" = ");
  }
Exemple #9
0
  public void testParseRepositoryExpression() throws Exception {
    testParseRepoExHelper("internal", new RepositoryExpression(new Term("internal", EMPTY_MAP)));

    testParseRepoExHelper(
        "internal(revision=1)", new RepositoryExpression("internal").atRevision("1"));

    testParseRepoExHelper(
        "file(path=\"/tmp\",projectSpace=internal)",
        new RepositoryExpression("file")
            .withOption("path", "/tmp")
            .withOption("projectSpace", "internal"));

    try {
      Parser.parseRepositoryExpression("internal(revision=1)>public");
      fail("Expression w/ translation should have failed parsing as RepositoryExpression.");
    } catch (ParseError expected) {
    }
  }
Exemple #10
0
 private void testParseRepoExHelper(String exString, RepositoryExpression ex) throws Exception {
   assertEquals(exString, ex.toString());
   assertEquals(ex, Parser.parseRepositoryExpression(exString));
 }