summaryrefslogtreecommitdiff
path: root/lib/inifile
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-11-25 09:56:59 -0800
committerOri Bernstein <ori@eigenstate.org>2015-11-25 09:56:59 -0800
commit3a884b83d030cd14cf4ee631b5b474fb411c976a (patch)
treecce717ae85eaae937cec7a9ea4c2b3a2ca8f037b /lib/inifile
parentda67a46215a8c4f16e958e86354c7514132abc92 (diff)
downloadmc-3a884b83d030cd14cf4ee631b5b474fb411c976a.tar.gz
Add initial smoke tests.
Diffstat (limited to 'lib/inifile')
-rw-r--r--lib/inifile/bld.sub9
-rw-r--r--lib/inifile/test/inifile.myr43
-rw-r--r--lib/inifile/test/test.ini11
3 files changed, 63 insertions, 0 deletions
diff --git a/lib/inifile/bld.sub b/lib/inifile/bld.sub
index 976b01b..14bfa64 100644
--- a/lib/inifile/bld.sub
+++ b/lib/inifile/bld.sub
@@ -8,3 +8,12 @@ lib inifile =
lib ../sys:sys
lib ../bio:bio
;;
+
+test test/inifile =
+ test/inifile.myr
+
+ lib ../std:std
+ lib ../sys:sys
+ lib ../bio:bio
+ lib inifile
+;;
diff --git a/lib/inifile/test/inifile.myr b/lib/inifile/test/inifile.myr
new file mode 100644
index 0000000..51722b9
--- /dev/null
+++ b/lib/inifile/test/inifile.myr
@@ -0,0 +1,43 @@
+use std
+use inifile
+
+const main = {
+ failopen()
+ getkeys()
+}
+
+const failopen = {
+ match inifile.load("figment-of-my-imagination.ini")
+ | `std.Ok _: std.die("found imaginary file\n")
+ | `std.Fail _: /* as expected */
+ ;;
+}
+
+const getkeys = {
+ var ini
+
+ ini = std.try(inifile.load("test/test.ini"))
+
+ checkval(ini, "", "toplev", "stuff")
+
+ checkval(ini, "somesect", "key", "foo")
+ checkval(ini, "somesect", "otherkey", "meh")
+ checkval(ini, "somesect", "whatever", "\"stuff here\"")
+
+ checkval(ini, "another section", "key", "foo1")
+ checkval(ini, "another section", "otherkey", "meh1")
+ checkval(ini, "another section", "whatever", "\"more stuff here\"")
+
+ inifile.free(ini)
+}
+
+const checkval = {ini, sect, key, expected
+ match inifile.get(ini, sect, key)
+ | `std.Some val:
+ if !std.sleq(val, expected)
+ std.fatal("{}.{}: expected {}, got {}\n", sect, key, expected, val)
+ ;;
+ | `std.None:
+ std.fatal("{}.{}: missing key\n", sect, key)
+ ;;
+}
diff --git a/lib/inifile/test/test.ini b/lib/inifile/test/test.ini
new file mode 100644
index 0000000..b10eaa3
--- /dev/null
+++ b/lib/inifile/test/test.ini
@@ -0,0 +1,11 @@
+toplev = stuff
+[somesect]
+ key= foo
+ otherkey =meh
+ whatever = "stuff here"
+
+[another section]
+ key = foo1
+ otherkey = meh1
+ whatever = "more stuff here"
+