diff options
author | Jesse Luehrs <doy@tozt.net> | 2013-02-26 19:34:11 -0600 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2013-02-26 19:34:11 -0600 |
commit | d2130f483f7afc263cc6949d0694efdc189e44ec (patch) | |
tree | 29b9279085c99aff29cb440a805205c3eba5a590 /src/main | |
parent | 16a2a08c20f902057788d05b8149af7244eec55d (diff) | |
download | scala-test-more-d2130f483f7afc263cc6949d0694efdc189e44ec.tar.gz scala-test-more-d2130f483f7afc263cc6949d0694efdc189e44ec.zip |
more refactoring
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/scala/org/perl8/test/tap/Consumer.scala | 102 |
1 files changed, 52 insertions, 50 deletions
diff --git a/src/main/scala/org/perl8/test/tap/Consumer.scala b/src/main/scala/org/perl8/test/tap/Consumer.scala index fefa078..8d9eaab 100644 --- a/src/main/scala/org/perl8/test/tap/Consumer.scala +++ b/src/main/scala/org/perl8/test/tap/Consumer.scala @@ -78,68 +78,70 @@ class Consumer (cb: TAPEvent => Unit) { ) } - private def subtest: Parser[TAPResult] = Parser { in => - if (in.atEnd) { - Failure("Subtest expected, but end of input found", in) - } - else { - val oldIndent = expectedIndent - val newIndent = in.first.indent + private def subtest: Parser[TAPResult] = LineParser("subtest") { in => + val oldIndent = expectedIndent + val newIndent = in.first.indent - try { - expectedIndent = newIndent - tap(in) - } - finally { - expectedIndent = oldIndent - } + try { + expectedIndent = newIndent + tap(in) + } + finally { + expectedIndent = oldIndent } } - private def planLine: Parser[PlanLine] = Parser { in => - if (in.atEnd) { - Failure("Plan line expected, but end of input found", in) + private def planLine: Parser[PlanLine] = LineParser("plan") { in => + val line = in.first + if (line.indent == expectedIndent) { + line match { + case p: PlanLine => + Success(p, in.rest) + case _ => + Failure("Plan line expected, but '" + line + "' found", in) + } } else { - val line = in.first - if (line.indent == expectedIndent) { - line match { - case p: PlanLine => - Success(p, in.rest) - case _ => - Failure("Plan line expected, but '" + line + "' found", in) - } - } - else { - Failure( - "Plan line expected, but " + - "'" + line + "' has incorrect indentation", - in - ) - } + Failure( + "Plan line expected, but " + + "'" + line + "' has incorrect indentation", + in + ) } } - private def resultLine: Parser[ResultLine] = Parser { in => - if (in.atEnd) { - Failure("Result line expected, but end of input found", in) + private def resultLine: Parser[ResultLine] = LineParser("result") { in => + val line = in.first + if (line.indent == expectedIndent) { + line match { + case p: ResultLine => + Success(p, in.rest) + case _ => + Failure("Result line expected, but '" + line + "' found", in) + } } else { - val line = in.first - if (line.indent == expectedIndent) { - line match { - case p: ResultLine => - Success(p, in.rest) - case _ => - Failure("Result line expected, but '" + line + "' found", in) + Failure( + "Result line expected, but " + + "'" + line + "' has incorrect indentation", + in + ) + } + } + + private def LineParser[T] ( + lineType: String + )( + body: Input => ParseResult[T] + ): Parser[T] = { + new Parser[T] { + def apply (in: Input): ParseResult[T] = { + if (in.atEnd) { + Failure(lineType + " line expected, but end of input found", in) + } + else { + body(in) } - } - else { - Failure( - "Result line expected, but " + - "'" + line + "' has incorrect indentation", - in - ) } } } |