This repository has been archived by the owner on Jan 5, 2023. It is now read-only.
forked from j-mie6/parsley
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ErrorMessageTests.scala
95 lines (89 loc) · 3.08 KB
/
ErrorMessageTests.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package org.http4s
import parsley.Combinator.eof
import parsley.Parsley._
import parsley.{Failure, Parsley, runParser}
import parsley.Implicits.{charLift, stringLift}
class ErrorMessageTests extends ParsleyTest
{
//TODO Bind tests
lazy val r: Parsley[List[String]] = "correct error message" <::> (r </> Nil)
"?" should "affect base error messages" in
{
runParser('a' ? "ay!", "b") should be (Failure("(line 1, column 1):\n unexpected \"b\"\n expected ay!"))
}
it should "work across a recursion boundary" in
{
runParser(r ? "nothing but this :)", "") should be
{
Failure("(line 1, column 1):\n unexpected end of input\n expected nothing but this :)")
}
runParser(r ? "nothing but this :)", "correct error messagec") should be
{
Failure("(line 1, column 23):\n unexpected end of input\n expected nothing but this :)")
}
}
"fail" should "yield a raw message" in
{
runParser(Parsley.fail("hi"), "b") should be
{
Failure("(line 1, column 1):\n hi")
}
}
it should "produce an expected message under influence of ?, along with original message" in
{
runParser('a' <|> (Parsley.fail("oops") ? "hi"), "b") should be
{
Failure("(line 1, column 1):\n unexpected \"b\"\n expected \"a\" or hi\n oops")
}
}
"unexpected" should "yield changes to unexpected messages" in
{
runParser(unexpected("bee"), "b")
}
it should "produce expected message under influence of ?, along with original message" in
{
runParser('a' <|> unexpected("bee") ? "something less cute", "b")
}
"empty" should "produce unknown error messages" in
{
runParser(Parsley.empty, "b") should be
{
Failure("(line 1, column 1):\n unknown parse error")
}
}
it should "produce no unknown message under influence of ?" in
{
runParser(Parsley.empty ? "something, at least", "b") should be
{
Failure("(line 1, column 1):\n expected something, at least")
}
}
it should "not produce an error message at the end of <|> chain" in
{
runParser('a' <|> Parsley.empty, "b") should be
{
Failure("(line 1, column 1):\n unexpected \"b\"\n expected \"a\"")
}
}
it should "produce an expected error under influence of ? in <|> chain" in
{
runParser('a' <|> Parsley.empty ? "something, at least", "b") should be
{
Failure("(line 1, column 1):\n unexpected \"b\"\n expected \"a\" or something, at least")
}
}
"eof" should "produce unexpected end of input" in
{
runParser(eof, "a") should be
{
Failure("(line 1, column 1):\n unexpected \"a\"\n expected end of input")
}
}
it should "change message under influence of ?" in
{
runParser(eof ? "something more", "a") should be
{
Failure("(line 1, column 1):\n unexpected \"a\"\n expected something more")
}
}
}