Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Romain Slootmaekers
committed
Sep 13, 2011
1 parent
c6baeec
commit 1387513
Showing
4 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
open Client_cfg | ||
open OUnit | ||
|
||
let test_parsing () = | ||
let lines = [ | ||
"[global]"; | ||
"cluster_id = sturdy"; | ||
"cluster = sturdy_0,sturdy_1, sturdy_2 "; | ||
"\n"; | ||
"[sturdy_0]"; | ||
"client_port = 7080"; | ||
"name = sturdy_0"; | ||
"ip = 127.0.0.1"; | ||
"\n"; | ||
"[sturdy_1]"; | ||
"client_port = 7081"; | ||
"name = sturdy_1"; | ||
"ip = 127.0.0.1"; | ||
"\n"; | ||
"[sturdy_2]"; | ||
"ip = 127.0.0.1"; | ||
"client_port = 7082"; | ||
"name = sturdy_2"] | ||
in | ||
let contents = List.fold_left (fun acc v -> acc ^ "\n" ^ v) "" lines in | ||
let fn = "/tmp/client_cfg_test.ml" in | ||
let oc = open_out "/tmp/client_cfg_test.ml" in | ||
let () = output_string oc contents in | ||
let () = close_out oc in | ||
let cfg = ClientCfg.from_file fn in | ||
let sa0 = ClientCfg.get cfg "sturdy_0" in | ||
OUnit.assert_equal sa0 ("127.0.0.1",7080) | ||
|
||
let suite = "client_cfg" >:::[ | ||
"parsing" >:: test_parsing; | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
let p_string s = Scanf.sscanf s "%s" (fun s -> s) | ||
|
||
let p_int s = Scanf.sscanf s "%i" (fun i -> i) | ||
|
||
let p_string_list s = Str.split (Str.regexp "[, \t]+") s | ||
|
||
let p_bool s = Scanf.sscanf s "%b" (fun b -> b) | ||
|
||
let required section name = failwith (Printf.sprintf "missing: %s %s" section name) | ||
|
||
let get inifile section name s2a not_found = | ||
try | ||
let v_s = inifile # getval section name in | ||
s2a v_s | ||
with (Inifiles.Invalid_element _) -> not_found section name |