|
@@ -41,26 +41,45 @@ open Core.Std;;
|
|
(* Function truncate *)
|
|
(* Function truncate *)
|
|
let trunc (str, elength, expected) () =
|
|
let trunc (str, elength, expected) () =
|
|
let current = List_rc.truncate ~elength str in
|
|
let current = List_rc.truncate ~elength str in
|
|
- OUnit.assert_equal current expected
|
|
|
|
|
|
+ OUnit.assert_equal ~printer:(sprintf "%s") current expected
|
|
;;
|
|
;;
|
|
|
|
|
|
|
|
+(* TODO Generalise tests *)
|
|
|
|
+Random.self_init ();;
|
|
|
|
+(* Table of chars *)
|
|
|
|
+let table = [
|
|
|
|
+ 'a' ; 'b' ; 'c' ; 'd' ; 'e' ; 'f' ; 'g' ; 'h' ; 'i' ; 'j' ; 'k' ; 'l' ; 'm' ;
|
|
|
|
+ 'n' ; 'o' ; 'p' ; 'q' ; 'r' ; 's' ; 't' ; 'u' ; 'v' ; 'w' ; 'x' ; 'y' ; 'z' ;
|
|
|
|
+ '0' ; '1' ; '2' ; '3' ; '4' ; '5' ; '6' ; '7' ; '8' ; '9'
|
|
|
|
+];;
|
|
|
|
+(* Function to generate string for tests *)
|
|
|
|
+let gen_str len =
|
|
|
|
+ let rec gen_char () =
|
|
|
|
+ match Random.int 1_000_000 |> List.nth table with
|
|
|
|
+ | Some c -> c
|
|
|
|
+ | None -> gen_char ()
|
|
|
|
+ in
|
|
|
|
+ String.init len ~f:(fun _ -> gen_char ())
|
|
|
|
+;;
|
|
|
|
+(* Usefull value for the rest *)
|
|
|
|
+let ti = List_rc.trunc_indicator;;
|
|
|
|
+let til = String.length ti;;
|
|
|
|
+(* Some pseudo command to test *)
|
|
|
|
+let cright = gen_str (til + 6);;
|
|
|
|
+let cbit = "c" ^ gen_str til;;
|
|
|
|
+let ctoo = "c" ^ gen_str (til + 10);;
|
|
|
|
+
|
|
let data = [
|
|
let data = [
|
|
( ("", 4, ""), "Empty string" );
|
|
( ("", 4, ""), "Empty string" );
|
|
|
|
|
|
- ( ("cmd1", 4, "cmd1"), "Right length" );
|
|
|
|
- ( ("cmd11", 4, "c..."), "A bit longer" );
|
|
|
|
- ( ("cmdddd1", 4, "c..."), "Much too long" );
|
|
|
|
|
|
+ ( (cright, til, cright), "Right length" );
|
|
|
|
+ ( (cbit, til, "c" ^ ti), "A bit longer" );
|
|
|
|
+ ( (ctoo, til, "c" ^ ti), "Much too long" );
|
|
|
|
|
|
- ( ("cmd", 3, "cmd"), "Short command" );
|
|
|
|
- ( ("cm", 3, "cm"), "Shorter command" );
|
|
|
|
- ( ("c", 3, "c"), "Tiny command" );
|
|
|
|
|
|
+ ( ("c", til, "c"), "Tiny command" );
|
|
|
|
|
|
( ("cmd1", 0, "cmd1"), "Keep as-is" );
|
|
( ("cmd1", 0, "cmd1"), "Keep as-is" );
|
|
( ("cmd1", -5, "cmd1"), "Negative figure, keep as-is" );
|
|
( ("cmd1", -5, "cmd1"), "Negative figure, keep as-is" );
|
|
- ( ("cmd1", (String.length List_rc.trunc_indicator), "cmd1"), "On the \
|
|
|
|
- indicator, keep as-is" );
|
|
|
|
- ( ("cmd1", (String.length List_rc.trunc_indicator) - 1, "cmd1"), "Under \
|
|
|
|
- indicator, keep as-is" );
|
|
|
|
];;
|
|
];;
|
|
|
|
|
|
let tests =
|
|
let tests =
|