ref: 3a884b83d030cd14cf4ee631b5b474fb411c976a
parent: da67a46215a8c4f16e958e86354c7514132abc92
author: Ori Bernstein <[email protected]>
date: Wed Nov 25 04:56:59 EST 2015
Add initial smoke tests.
--- a/Makefile
+++ b/Makefile
@@ -2,6 +2,7 @@
mi \
6 \
muse \
+ mxref \
rt \
doc
--- a/lib/inifile/bld.sub
+++ b/lib/inifile/bld.sub
@@ -8,3 +8,12 @@
lib ../sys:sys
lib ../bio:bio
;;
+
+test test/inifile =
+ test/inifile.myr
+
+ lib ../std:std
+ lib ../sys:sys
+ lib ../bio:bio
+ lib inifile
+;;
--- /dev/null
+++ b/lib/inifile/test/inifile.myr
@@ -1,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)
+ ;;
+}
--- /dev/null
+++ b/lib/inifile/test/test.ini
@@ -1,0 +1,11 @@
+toplev = stuff
+[somesect]
+ key= foo
+ otherkey =meh
+ whatever = "stuff here"
+
+[another section]
+ key = foo1
+ otherkey = meh1
+ whatever = "more stuff here"
+