Permalink
Browse files

- use parsing utils in tests

- added another test to ExampleTests
  • Loading branch information...
1 parent 7075d6d commit e606f42daa177514616b760ef9c49c9cbe331909 @renggli renggli committed Apr 15, 2012
Showing with 14 additions and 5 deletions.
  1. +3 −5 test/org/petitparser/Assertions.java
  2. +11 −0 test/org/petitparser/ExampleTest.java
@@ -5,8 +5,8 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import static org.petitparser.Parsing.parse;
-import org.petitparser.context.Context;
import org.petitparser.context.ParseError;
import org.petitparser.context.Result;
import org.petitparser.parser.Parser;
@@ -19,8 +19,7 @@
public static <T> void assertSuccess(Parser parser, String input,
T expected, int position) {
- Context context = new Context(input);
- Result result = parser.parse(context);
+ Result result = parse(parser, input);
assertNotNull(result.toString());
assertTrue("Expected parse success", result.isSuccess());
assertEquals("Position", position, result.getPosition());
@@ -44,8 +43,7 @@
public static <T> void assertFailure(Parser parser, String input,
int position, String message) {
- Context context = new Context(input);
- Result result = parser.parse(context);
+ Result result = parse(parser, input);
assertNotNull(result.toString());
assertTrue("Expected parse failure", result.isFailure());
assertEquals("Position", position, result.getPosition());
@@ -32,6 +32,11 @@
.seq(whitespace().plus().flatten()).seq(IDENTIFIER.or(NUMBER).or(STRING))
.map(Functions.lastOfList());
+ private static Parser JAVADOC = string("/**")
+ .seq(string("*/").negate().star())
+ .seq(string("*/"))
+ .flatten();
+
@Test
public void testIdentitiferSuccess() {
assertSuccess(IDENTIFIER, "a", "a");
@@ -135,4 +140,10 @@ public void testReturnFailure() {
assertFailure(RETURN, "return $", 8, "\" expected");
}
+ @Test
+ public void testJavaDoc() {
+ assertSuccess(JAVADOC, "/** foo */", "/** foo */");
+ assertSuccess(JAVADOC, "/** * * */", "/** * * */");
+ }
+
}

0 comments on commit e606f42

Please sign in to comment.