shithub: mc

ref: b2d29ed0eebd0e3e2c162b5e83d6d0e8b6ddee57
dir: /lib/inifile/test/inifile.myr/

View raw version
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.put(ini, "new sect", "key", "val")
	/* TODO: check this for validity */
	std.assert(inifile.write(ini, "test/out.ini"), "failed to write test ini")

	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)
	;;
}