Skip to content

Commit 456ae47

Browse files
arvidjArvid Jakobsson
andauthored
[Action.config_lines] document and test behavior of commented lines (#56)
Co-authored-by: Arvid Jakobsson <arvid.jakobsson@ahrefs.com>
1 parent 93587b9 commit 456ae47

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

action.mli

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,16 @@ val io_null : unit IO.output
185185
val file_lines_exn : string -> string list
186186
val file_lines : string -> string list
187187

188-
(** read lines from file skipping empty lines and comments (lines starting with '#') *)
188+
(** Read lines from file skipping empty lines and comments (lines starting with '#').
189+
190+
Moreover, comments are stripped from lines (all characters
191+
including and following a '#') and returned lines are trimmed. *)
189192
val make_config_lines : string list -> string list
190193
val config_lines_exn : string -> string list
194+
195+
(** [config_lines file] read [file] and return the config lines.
196+
197+
See {!make_config_lines} for details on config lines. *)
191198
val config_lines : string -> string list
192199

193200

test.ml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,28 @@ let () = test "Web.urlencode" @@ fun () ->
544544
assert_equal (Web.urlencode "Hello Günter") "Hello+G%C3%BCnter";
545545
()
546546

547+
let () = test "Action.make_config_lines" @@ fun () ->
548+
let config_lines = [
549+
"";
550+
"foobar";
551+
"# only comment line";
552+
"arg # a comment";
553+
"test # comment1 # comment2 ";
554+
" test # comment ";
555+
"foo";
556+
" baz";
557+
"bar ";
558+
] in
559+
assert_equal ~printer:(Stre.list (Printf.sprintf "%S")) (Action.make_config_lines config_lines) [
560+
"foobar";
561+
"arg";
562+
"test";
563+
"test";
564+
"foo";
565+
"baz";
566+
"bar"
567+
]
568+
547569
let () =
548570
let open Lwt.Syntax in
549571
let rec pings f = function

0 commit comments

Comments
 (0)