t_astring.ml 753 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. open Alcotest
  2. open Astring
  3. let tc_affix = "affix", `Quick, (fun () ->
  4. String.is_prefix ~affix:"Hell" "Hello, world!"
  5. |> check bool __LOC__ true
  6. )
  7. let tc_sub = "sub", `Quick, (fun () ->
  8. String.Sub.v ~start:4 "Hello, world!"
  9. |> String.Sub.to_string
  10. |> check string __LOC__ "o, world!"
  11. )
  12. let tc_cuts = "cuts", `Quick, (fun () ->
  13. let sep = "|" in
  14. (match "a|b|c|" |> String.cuts ~sep with
  15. ["a"; "b"; "c"; ""] -> ()
  16. | _ -> fail __LOC__) ;
  17. let is_sep c = c = '|' in
  18. match "a|b|c|" |> String.fields ~is_sep with
  19. ["a"; "b"; "c"; ""] -> ()
  20. | _ -> fail __LOC__
  21. )
  22. let tst : return test = __FILE__, [
  23. tc_affix ;
  24. tc_sub ;
  25. tc_cuts ;
  26. ]
  27. let () =
  28. run
  29. "seppo_suite" [
  30. tst ;
  31. ]