(load "../simple-configuration.scm") (import simple-configuration) (define sample-config '((connection (username "test") (password "testpass") (another-level (yes "yes") (no "no"))) (logging (destination "/this/is/a/test") (levels (error warning))))) (describe "Simple configuration" (context "atomic values" (it "can reference atomic values" (expect (config-ref sample-config '(connection username)) (be "test"))) (it "can reference atomic values from any level" (expect (config-ref sample-config '(connection password)) (be "testpass")))) (context "list values" (it "can handle values that are lists" (expect (config-ref sample-config '(logging levels)) (be '(error warning))))) (it "allows to postprocess any retrieved value" (expect (config-ref sample-config '(logging levels) post-process: reverse) (be'(warning error)))) (it "allows to specify default values for an unknown path" (expect (config-ref sample-config '(i dont exist) default: 'test) (be 'test))) (it "can reference entire subsections easily" (expect (config-ref sample-config '(connection another-level)) (be '((yes "yes") (no "no"))))) (it "provides convenient syntax to bind variables to confguration values" (let ((logging (config-ref sample-config '(logging)))) (config-let logging ((dest (destination)) (lvls (levels))) (expect dest (be "/this/is/a/test")) (expect lvls (be '(error warning)))))) (it "reads configuration from a port" (let ((cfg-string "((test value))")) (call-with-input-string cfg-string (lambda (input) (let ((cfg (config-read input))) (expect cfg (be '((test value))))))))) (it "reads file from path" (with-output-to-file "/tmp/testcfg" (lambda () (display '((test value))))) (let ((cfg (config-read "/tmp/testcfg"))) (expect cfg (be '((test value)))))) (it "allows extended configs through evaling them" (let ((cfg-string "((test ,(iota 4 1)))")) (call-with-input-string cfg-string (lambda (input) (expect (config-read input eval-config: #t) (be '((test (1 2 3 4))))))))) )