fix(pp): slicing needs attention

This commit is contained in:
Simon Cruanes 2023-03-31 22:45:24 -04:00
parent 94640e9efe
commit 679534597d
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 9 additions and 4 deletions

View file

@ -89,10 +89,10 @@ let split_text_ (str : string) : t =
match String.index_from str !i '\n' with
| exception Not_found ->
(* last chunk *)
if !i + 1 < len then cur := !cur ^ text_sub_ str !i (len - 1 - !i);
if !i + 1 < len then cur := !cur ^ text_sub_ str !i (len - !i);
i := len
| j ->
cur := !cur ^ text_sub_ str !i (j - 1 - !i) ^ nl;
cur := !cur ^ text_sub_ str !i (j - !i) ^ nl;
i := j + 1
done;
group !cur

View file

@ -6,6 +6,11 @@ let spf = Printf.sprintf
let () =
eq "hello world" (Flatten.to_string @@ text "hello" ^ newline ^ text "world")
let () =
eq ~name:"split text" ~printer:(spf "%S") "let rec f x =\n x+2\n"
(let d = text "let rec f x =\n x+2\n" in
Pretty.to_string ~width:15 d)
let () =
eq ~name:"l1" ~printer:(spf "%S") "[0; 1; 2; 3;\n 4; 5; 6; 7;\n 8; 9]"
(let d = Dump.list (List.init 10 int) in