Skip to content

Commit 28abca1

Browse files
authored
Merge pull request #16 from kit-ty-kate/rename-to_diffs-parse
Rename Patch.to_diffs to Patch.parse
2 parents 72181c0 + cad944e commit 28abca1

File tree

5 files changed

+12
-13
lines changed

5 files changed

+12
-13
lines changed

src/patch.ml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,7 @@ let operation_of_strings git mine their =
261261
| Some a, Some b -> Edit (a, b)
262262
| None, None -> assert false (* ??!?? *)
263263

264-
(* parses a list of lines to a diff.t list *)
265-
let to_diff data =
264+
let parse_one data =
266265
(* first locate --- and +++ lines *)
267266
let rec find_start git ?hdr = function
268267
| [] -> hdr, []
@@ -288,11 +287,11 @@ let to_diff data =
288287

289288
let to_lines = String.cuts '\n'
290289

291-
let to_diffs data =
290+
let parse data =
292291
let lines = to_lines data in
293292
let rec doit acc = function
294293
| [] -> List.rev acc
295-
| xs -> match to_diff xs with
294+
| xs -> match parse_one xs with
296295
| None -> List.rev acc
297296
| Some (diff, rest) -> doit (diff :: acc) rest
298297
in

src/patch.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ val pp_list : git:bool -> Format.formatter -> t list -> unit
4848
(** [pp ~git ppf diffs] pretty-prints [diffs] on [ppf]. If [git] is true, "git diff"
4949
style will be printed. *)
5050

51-
val to_diffs : string -> t list
52-
(** [to_diffs data] decodes [data] as a list of diffs. *)
51+
val parse : string -> t list
52+
(** [parse data] decodes [data] as a list of diffs. *)
5353

5454
val patch : string option -> t -> string option
5555
(** [patch file_contents diff] applies [diff] on [file_contents], resulting in

src/patch_command.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let exit_several_chunks = 3
1414
let exit_patch_failure = 4
1515

1616
let run ~input ~diff =
17-
match Patch.to_diffs diff with
17+
match Patch.parse diff with
1818
| [] -> input
1919
| _::_::_ ->
2020
prerr_endline "Error: The diff contains several chunks,\n\

test/crowbar_test.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ let get_diffs (file1 : file) (file2 : file) : file =
136136

137137
let check_Patch file1 file2 =
138138
let text_diff = string_of_file (get_diffs file1 file2) in
139-
match Patch.to_diffs text_diff with
139+
match Patch.parse text_diff with
140140
| [] -> Crowbar.check_eq (string_of_file file1) (string_of_file file2)
141141
| _::_::_ -> Crowbar.fail "not a single diff!"
142142
| [diff] ->

test/test.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ foo
295295
]
296296

297297
let basic_parse diff exp () =
298-
let diffs = Patch.to_diffs diff in
298+
let diffs = Patch.parse diff in
299299
Alcotest.(check (list test_t) __LOC__ exp diffs)
300300

301301
let parse_diffs =
@@ -304,7 +304,7 @@ let parse_diffs =
304304
(List.combine basic_diffs basic_hunks)
305305

306306
let basic_apply file diff exp () =
307-
match Patch.to_diffs diff with
307+
match Patch.parse diff with
308308
| [ diff ] ->
309309
let res = Patch.patch file diff in
310310
Alcotest.(check (option string) __LOC__ exp res)
@@ -367,7 +367,7 @@ let multi_files = [ Some "bar" ; Some "baz" ; None ; Some "foobarbaz" ]
367367
let multi_exp = [ Some "foobar" ; None ; Some "baz" ; Some "foobar" ]
368368

369369
let multi_apply () =
370-
let diffs = Patch.to_diffs multi_diff in
370+
let diffs = Patch.parse multi_diff in
371371
Alcotest.(check int __LOC__ (List.length multi_files) (List.length diffs));
372372
Alcotest.(check int __LOC__ (List.length multi_exp) (List.length diffs));
373373
List.iter2 (fun diff (input, expected) ->
@@ -416,7 +416,7 @@ let op_test = Alcotest.testable (Patch.pp_operation ~git:false) Patch.operation_
416416

417417
let parse_real_diff_header file hdr () =
418418
let data = read (file ^ ".diff") in
419-
let diffs = Patch.to_diffs data in
419+
let diffs = Patch.parse data in
420420
Alcotest.(check int __LOC__ 1 (List.length diffs));
421421
Alcotest.check op_test __LOC__ hdr (List.hd diffs).Patch.operation
422422

@@ -435,7 +435,7 @@ let regression_test name () =
435435
let old = opt_read (name ^ ".old") in
436436
let diff = read (name ^ ".diff") in
437437
let exp = opt_read (name ^ ".new") in
438-
match Patch.to_diffs diff with
438+
match Patch.parse diff with
439439
| [ diff ] ->
440440
let res = Patch.patch old diff in
441441
Alcotest.(check (option string) __LOC__ exp res)

0 commit comments

Comments
 (0)