Skip to content

Commit

Permalink
Merge pull request #130 from inhabitedtype/count_while-bug
Browse files Browse the repository at this point in the history
count_while-bug: fix bug in count_while and count_while1
  • Loading branch information
seliopou authored Jan 22, 2018
2 parents c72d2ea + 90fcadb commit 88d5127
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/angstrom.ml
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ let rec count_while ~init ~f ~with_buffer =
let succ' input' pos' more' =
(count_while ~init:init' ~f ~with_buffer).run input' pos' more' fail succ
and fail' input' pos' more' =
succ input' pos' more' (Input.apply input' pos' init' ~f:with_buffer)
succ input' (pos' + init') more' (Input.apply input' pos' init' ~f:with_buffer)
in
prompt input pos fail' succ'
}
Expand Down Expand Up @@ -370,7 +370,7 @@ let rec count_while1 ~f ~with_buffer =
let succ' input' pos' more' =
(count_while ~init:len ~f ~with_buffer).run input' pos' more' fail succ
and fail' input' pos' more' =
succ input' pos' more' (Input.apply input' pos' len ~f:with_buffer)
succ input' (pos' + len) more' (Input.apply input' pos' len ~f:with_buffer)
in
prompt input pos fail' succ'
}
Expand Down
12 changes: 11 additions & 1 deletion lib_test/test_angstrom.ml
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,14 @@ let incremental =
(string "thi" *> string "st" *> commit *> string "hat") ["thi"; "st"; "hat"] "hat";
end ]

let count_while_regression =
[ "proper position set after count_while", `Quick, begin fun () ->
check_s ~msg:"take_while then eof"
(take_while (fun _ -> true) <* end_of_input) ["asdf"; ""] "asdf";
check_s ~msg:"take_while1 then eof"
(take_while1 (fun _ -> true) <* end_of_input) ["asdf"; ""] "asdf";
end ]

let () =
Alcotest.run "test suite"
[ "basic constructors" , basic_constructors
Expand All @@ -350,4 +358,6 @@ let () =
; "applicative interface" , applicative
; "alternative" , alternative
; "combinators" , combinators
; "incremental input" , incremental ]
; "incremental input" , incremental
; "count_while regression", count_while_regression
]

0 comments on commit 88d5127

Please sign in to comment.