2020-02-19 22:49:50 +01:00
|
|
|
#lang racket
|
2020-02-16 21:39:42 +01:00
|
|
|
|
|
|
|
;;; Tests for dds/utils.
|
|
|
|
|
2020-02-19 22:49:50 +01:00
|
|
|
(require rackunit "utils.rkt")
|
2020-02-16 21:39:42 +01:00
|
|
|
|
2020-02-19 22:09:09 +01:00
|
|
|
(test-case "HashTable Injection"
|
2020-02-16 21:39:42 +01:00
|
|
|
(test-case "auto-hash-ref/explicit"
|
|
|
|
(let ([mytable #hash((a . 3) (b . 4))])
|
|
|
|
(check-equal? (auto-hash-ref/explicit (mytable b a)
|
|
|
|
(* a b))
|
|
|
|
12))
|
|
|
|
(let ([ht #hash((a . #t) (b . #f))])
|
|
|
|
(check-equal? (auto-hash-ref/explicit (ht a b)
|
|
|
|
(and (not a) b))
|
2020-02-17 00:16:44 +01:00
|
|
|
#f)))
|
|
|
|
|
|
|
|
(test-case "auto-hash-ref/:"
|
|
|
|
(let ([ht #hash((x . #t) (y . #t) (t . #f))]
|
|
|
|
[z #t])
|
|
|
|
(check-equal? (auto-hash-ref/: ht
|
|
|
|
(and :x (not :y) z (or (and :t) :x)))
|
|
|
|
#f))
|
|
|
|
(let ([ht #hash((a . 1) (b . 2))])
|
|
|
|
(check-equal? (auto-hash-ref/: ht (+ :a (* 2 :b)))
|
2020-02-17 23:52:15 +01:00
|
|
|
5)))
|
|
|
|
|
|
|
|
(test-case "eval-with"
|
|
|
|
(check-equal? (let ([ht #hash((a . 1) (b . 1))])
|
2020-02-19 23:12:58 +01:00
|
|
|
(eval-with ht '(+ b a 1)))
|
2020-02-17 23:52:15 +01:00
|
|
|
3)))
|
2020-02-19 22:11:44 +01:00
|
|
|
|
|
|
|
(test-case "Analysis of quoted expressions"
|
|
|
|
(check-equal? (extract-symbols '(1 (2 3) x (y z 3)))
|
|
|
|
'(x y z)))
|
2020-02-21 18:01:08 +01:00
|
|
|
|
|
|
|
(test-case "Variable mapping and Org-mode"
|
|
|
|
(check-equal? (any->string 'a) "a")
|
|
|
|
(check-equal? (any->string '(a 1 (x y))) "(a 1 (x y))")
|
2020-02-22 10:29:34 +01:00
|
|
|
(check-equal? (any->string "hello") "hello")
|
2020-02-22 12:12:57 +01:00
|
|
|
(let ([mp (stringify-variable-mapping #hash((a . (and a b)) (b . (not b))))])
|
2020-02-22 10:40:40 +01:00
|
|
|
(check-equal? (hash-ref mp 'a) "(and a b)")
|
|
|
|
(check-equal? (hash-ref mp 'b) "(not b)"))
|
|
|
|
(let ([mp (sgfy #hash((a . (and a b)) (b . (not b))))])
|
2020-02-22 10:29:34 +01:00
|
|
|
(check-equal? (hash-ref mp 'a) "(and a b)")
|
2020-02-22 12:11:37 +01:00
|
|
|
(check-equal? (hash-ref mp 'b) "(not b)"))
|
|
|
|
(check-equal? (string->any "(or b (not a))") '(or b (not a)))
|
2020-02-22 12:18:37 +01:00
|
|
|
(check-equal? (string->any "14") 14)
|
|
|
|
(check-equal? (read-org-table "((\"a\" \"(and a b)\") (\"b\" \"(or b (not a))\"))")
|
2020-02-22 12:27:28 +01:00
|
|
|
'(("a" "(and a b)") ("b" "(or b (not a))")))
|
|
|
|
(check-equal? (unstringify-pairs '(("a" . "1") ("b" . "(and a (not b))")))
|
|
|
|
'((a . 1) (b . (and a (not b))))))
|