Files
Geneweb/test/place_test.ml
2024-03-05 22:01:20 +01:00

69 lines
2.4 KiB
OCaml
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

open Geneweb
open Alcotest
let normalize () =
(check string) "" "foo-bar, boobar (baz)"
(Place.normalize "[foo-bar] - boobar (baz)");
(check string) "" "[foo-bar - boobar (baz)"
(Place.normalize "[foo-bar - boobar (baz)");
(check string) "" "[foo-bar] boobar (baz)"
(Place.normalize "[foo-bar] boobar (baz)");
()
let split_suburb () =
(check (pair string string))
""
("foo-bar", "boobar (baz)")
(Place.split_suburb "[foo-bar] - boobar (baz)");
(check (pair string string))
"test split suburb emdash - 93"
("foo-bar", "boobar (baz)")
(Place.split_suburb "[foo-bar] boobar (baz)");
(check (pair string string))
"test split suburb endash - 94"
("foo-bar", "boobar (baz)")
(Place.split_suburb "[foo-bar] — boobar (baz)");
(check (pair string string))
"" ("", "boobar (baz)")
(Place.split_suburb "boobar (baz)");
()
let only_suburb () =
(check string) "" "foo-bar" (Place.only_suburb "[foo-bar] - boobar (baz)");
(check string) "" "" (Place.only_suburb "boobar (baz)");
()
let without_suburb () =
(check string) "" "boobar (baz)"
(Place.without_suburb "[foo-bar] - boobar (baz)");
(check string) "" "boobar (baz)" (Place.without_suburb "boobar (baz)");
()
let compare_places () =
(check int) "" 0 (Place.compare_places "boobar (baz)" "boobar (baz)");
(check int) "" (-1) (Place.compare_places "baz (boobar)" "boobar (baz)");
(check int) "" (-1)
(Place.compare_places "baz (boobar)" "[foo-bar] - baz (boobar)");
(check int) "" (-1)
(Place.compare_places "[bar-foo] - baz (boobar)" "[foo-bar] - baz (boobar)");
(check int) "" (-1)
(Place.compare_places "[foo-bar] - baz (boobar)" "[bar-foo] - boobar (baz)");
(check int) "" (-1)
(Place.compare_places "[foo-bar] - ebaz (boobar)"
"[bar-foo] - éboobar (baz)");
(check int) "" (-1)
(Place.compare_places "[foo-bar] - baz, boobar, barboo"
"[foo-bar] - baz, boobar, barboo, bam");
()
let v =
[
("place-normalize", [ test_case "Place normalize" `Quick normalize ]);
( "place-split-suburb",
[ test_case "Place split suburb" `Quick split_suburb ] );
("place-only-suburb", [ test_case "Place only suburb" `Quick only_suburb ]);
( "place-without-suburb",
[ test_case "Place without suburb" `Quick only_suburb ] );
("place-compare", [ test_case "Place compare" `Quick compare_places ]);
]