summaryrefslogtreecommitdiff
path: root/test/session_test.ml
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2016-12-30 22:41:58 +0700
committerDaniil Baturin <daniil@baturin.org>2016-12-30 22:41:58 +0700
commita9fa58b61db7c634e2b54842c734a6a00e986c02 (patch)
treebd8f6b851c3d19cac51ec145d5a17c9b2d0115d2 /test/session_test.ml
parent63616d9c4337bde77cbc1cf8fbd763bef7befa2e (diff)
downloadvyconf-a9fa58b61db7c634e2b54842c734a6a00e986c02.tar.gz
vyconf-a9fa58b61db7c634e2b54842c734a6a00e986c02.zip
Add some unit tests for the Session.string_of_op function.
Diffstat (limited to 'test/session_test.ml')
-rw-r--r--test/session_test.ml40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/session_test.ml b/test/session_test.ml
new file mode 100644
index 0000000..a3a1fb0
--- /dev/null
+++ b/test/session_test.ml
@@ -0,0 +1,40 @@
+open OUnit2
+open Session
+
+module CT = Config_tree
+module RT = Reference_tree
+
+
+(* I'm not sure if we want to account for superfluous spaces inside the strings,
+ but for now let's say we want strings "normalized"
+
+ We also assume that quotes around the values are double quotes,
+ even though the lexer will also accept single quotes.
+ *)
+
+let test_op_string_set test_ctxt =
+ let op = CfgSet (["foo"; "bar"], Some "baz quux", CT.ReplaceValue) in
+ let str = (String.trim @@ string_of_op op) in
+ assert_equal str "set foo bar \"baz quux\""
+
+let test_op_string_set_valueless test_ctxt =
+ let op = CfgSet (["foo"; "bar"], None, CT.ReplaceValue) in
+ let str = (String.trim @@ string_of_op op) in
+ assert_equal str "set foo bar"
+
+let test_op_string_delete test_ctxt =
+ let op = CfgDelete (["foo"; "bar"], Some "baz quux") in
+ let str = (String.trim @@ string_of_op op) in
+ assert_equal str "delete foo bar \"baz quux\""
+
+
+let suite =
+ "VyConf session tests" >::: [
+ "test_op_string_set" >:: test_op_string_set;
+ "test_op_string_set_valueless" >:: test_op_string_set_valueless;
+ "test_op_string_delete" >:: test_op_string_delete;
+ ]
+
+let () =
+ run_test_tt_main suite
+