readme
[Seppo.git] / test / t_search.ml
blob5b2bf402ea4edee40943cf5c9541f24fe17b55f1
1 (* *)
2 open Seppo_lib
4 let test_ubase () =
5 let nfc = "V\197\169 Ng\225\187\141c Phan"
6 and nfd = "Vu\204\131 Ngo\204\163c Phan" in
7 Assrt.equals_string __LOC__ "Vũ Ngọc Phan" nfc;
8 Assrt.equals_string __LOC__ "Vũ Ngọc Phan" nfd;
9 Assrt.equals_string __LOC__ "Vu Ngoc Phan" (Ubase.from_utf8 nfc);
10 Assrt.equals_string __LOC__ "Vu Ngoc Phan" (Ubase.from_utf8 nfd)
12 let test_regexp () =
13 let t0 = Str.regexp_case_fold ".*yst.*" in
14 assert (Str.string_match t0 "haystack" 0);
15 let t2 = Str.regexp_string_case_fold "ySt" in
16 assert (2 = Str.search_forward t2 "haystack" 0);
17 assert (2 = try Str.search_forward t2 "haystack" 0 with Not_found -> -1);
18 assert (-1 = try Str.search_forward t2 "hay_stack" 0 with Not_found -> -1);
19 assert (0 <= try Str.search_forward t2 "haystack" 0 with Not_found -> -1)
22 Assrt.equals_int __LOC__ 5 (List.length c0.url_cleaner);
23 Assrt.equals_int __LOC__ 2 (List.length c0.posse)
26 let test_needle () =
27 let t = Str.regexp_case_fold ".*yst.*" in
28 Assrt.equals_int __LOC__ 1 (Search.string_rank t "haystack")
30 let test_needles () =
31 let tp = [ "föo"; "bär"; "báz" ] |> Search.needles_prepare in
32 ("my fÓo", "", "") |> Search.entry_rank tp |> Assrt.equals_int __LOC__ 2
34 let test_emoji () =
35 "my 😷 ö" |> Ubase.from_utf8 |> Assrt.equals_string __LOC__ "my 😷 o"
37 let () =
38 Unix.chdir "../../../test/";
39 test_ubase ();
40 test_regexp ();
41 test_needle ();
42 test_needles ();
43 test_emoji ()