Skip to content

Commit 9fe4d5f

Browse files
committed
Add test that reveals a bug
1 parent 6302a56 commit 9fe4d5f

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

tests/src/Main.gren

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,49 @@ main =
7272
P.run parser "2+2"
7373
|> Expect.equal (Ok 4)
7474
]
75-
, describe "chompUntil"
76-
[ test "Simple case" <| \{} ->
75+
, describe "Chomping"
76+
[ test "chompIf" <| \{} ->
77+
let
78+
chomper =
79+
P.succeed {}
80+
|> P.skip (P.chompIf Char.isAlpha)
81+
|> P.skip (P.chompIf Char.isAlpha)
82+
|> P.skip (P.chompIf Char.isAlpha)
83+
|> P.getChompedString
84+
in
85+
P.run chomper "abc test"
86+
|> Expect.equal (Ok "abc")
87+
, test "chompIf failure" <| \{} ->
88+
let
89+
chomper =
90+
P.succeed {}
91+
|> P.skip (P.chompIf Char.isAlpha)
92+
|> P.skip (P.chompIf Char.isAlpha)
93+
|> P.skip (P.chompIf Char.isAlpha)
94+
|> P.getChompedString
95+
in
96+
P.run chomper "a2c test"
97+
|> Expect.err
98+
, test "chompIf unicode" <| \{} ->
99+
let
100+
chomper =
101+
P.succeed {}
102+
|> P.skip (P.chompIf (\_ -> True))
103+
|> P.skip (P.chompIf (\_ -> True))
104+
|> P.skip (P.chompIf (\_ -> True))
105+
|> P.getChompedString
106+
in
107+
P.run chomper "a𤭢c test"
108+
|> Expect.equal (Ok "a𤭢c")
109+
, test "chompUntil" <| \{} ->
77110
let
78111
chomper =
79112
P.succeed (\value { row, col } -> { value = value, row = row, column = col })
80113
|> P.keep (P.getChompedString (P.chompUntil "bar"))
81114
|> P.keep P.getPosition
82115
in
116+
-- A little bit more complicated than it needs to be, in order to check
117+
-- parser state
83118
P.run chomper "foobar"
84119
|> Expect.equal (Ok { value = "foobar", row = 1, column = 7 })
85120
]

0 commit comments

Comments
 (0)