-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.scm
78 lines (58 loc) · 1.78 KB
/
test.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
(import (scheme base)
(scheme inexact)
(srfi 1)
(cyclone test)
(cyclone clojurian))
;; Original tests by Moritz Heidkamp on
;; https://bitbucket.org/DerGuteMoritz/clojurian/src/master/tests/syntax.scm
(define add1 (lambda (x) (+ 1 x)))
(test-group "clojurian-syntax"
(test (vector 1 2)
(doto (make-vector 2)
(vector-set! 0 1)
(vector-set! 1 2)))
(test 'foo (doto 'foo)))
(test-group ""
(test 1.0 (-> 99 (/ 11) (/ 9)))
(test '(1 2 3 4)
(->* (values 1 2)
(list 3)
(append '(4))))
(test 3 (as-> 3 x))
(test 2.0 (as-> 1 x (+ x 3) (/ x 2)))
(test 5.0 (-> 10 (* 2) (as-> state (/ state 4))))
(test 7 (-> 10 (- 3)))
(test -7 (->> 10 (- 3)))
(test 9 (->> 1 (+ 2) (* 3)))
(test -1 (-> 1 -))
(test 2.0 (-> 14 (+ 2) sqrt (- 2)))
(test '(1 2) (->* (values 1 2) list))
(test 9 (->> '(1 2 3)
(map add1)
(fold + 0)))
(test -1 (->> 1 -))
(test '((foo . 100) (bar . 200))
(->>* (values '(foo bar) '(100 200))
(map cons)))
(test '("a" "b")
(->>* (values 'a 'b)
list
(map symbol->string)))
(test 9 (and-> 1 (+ 2) (* 3)))
(test -1 (and-> 1 -))
(test #f (and-> #f not))
(test 2 (and-> (assq 'x '((x . 1))) cdr add1))
(test #f (and-> (assq 'x '((y . 1))) cdr add1)))
(test-group "if-let & if-let*"
(test 2 (if-let (x 1) (+ x x) 9))
(test 9 (if-let (x #f) (+ x x) 9))
(test (list 3 6)
(if-let* ((foo 3) (bar (* foo 2)))
(list foo bar)
'wrong))
(test 'wrong
(if-let* ((foo #f) (bar (* foo 2)))
(list foo bar)
'wrong))
(test #f (if-let (x #t) #f 'wrong))
(test #f (if-let* ((x #t)) #f 'wrong)))