Skip to content

Commit

Permalink
Improvre error-reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
Kota Mizushima committed Sep 9, 2018
1 parent 46894de commit 7b19f7f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/main/scala/com/github/kmizu/scomb/SCombinator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ abstract class SCombinator[R] {self =>
val substring = current(index)
literal.findPrefixOf(substring) match {
case Some(prefix) => Success(prefix, index + prefix.length)
case None => Failure(s"expected:`${literal}`", index)
case None => Failure(s"expected:`${literal}` actual: `${current(index)(0)}`", index)
}
}
}
Expand All @@ -477,7 +477,7 @@ abstract class SCombinator[R] {self =>
} else if(current(index).startsWith(literal)) {
Success(literal, index + literal.length)
} else {
Failure(s"expected:`${literal}`", index)
Failure(s"expected:`${literal}` actual:`${current(index)(0)}`", index)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/com/github/kmizu/scomb/JsonSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class JsonSpec extends FunSpec with DiagrammedAssertions {
it("cannot parse incorrect array") {
val failure = parse("[1, 2, ]").asInstanceOf[Result.Failure]
assert(Location(1, 6) == failure.location)
assert("""expected:`]` in <rbracket>""" == failure.message)
assert("""expected:`]` actual:`,` in <rbracket>""" == failure.message)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class RegularExpressionSpec extends FunSpec with DiagrammedAssertions {
input = "(1|9)*"
assert(parse(input) == Result.Success(Repeat(Choice(Value('1'), Value('9')))))
input = "*"
assert(parse(input) == Result.Failure(Location(1, 1), "expected:`\\`"))
assert(parse(input) == Result.Failure(Location(1, 1), "expected:`\\` actual:`*`"))
}
}
}

0 comments on commit 7b19f7f

Please sign in to comment.