/
test.esl
40 lines (33 loc) · 1.24 KB
/
test.esl
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
(var runTest
(lambda (name func)
((require "tape") name
(lambda (t)
(func t)
((. t end)))))) ; Automatically end tests
(= eslc
(lambda (code)
(= fullCode ; wrap in a call
(+ "(macro propertify (require \"./index.js\")) (propertify "
code
")"))
(return ((require "eslisp") fullCode))))
(macro test
(lambda (name body)
(return `(runTest ,name (lambda (t) ,@body)))))
; - - -
(test "dot" (((. t equals) (eslc "a.b") "a.b;")))
(test "dots" (((. t equals) (eslc "a.b.c") "a.b.c;")))
(test "dot & call" (((. t equals) (eslc "(a.b 42)") "a.b(42);")))
(test "plain dot" (((. t equals) (eslc "(. a b)") "a.b;")))
(test "strings unaffected" (((. t equals) (eslc "\"a.b\"") "'a.b';")))
(test "numbers unaffected" (((. t equals) (eslc "3.2") "3.2;")))
(test "ignore start or end dots"
(((. t equals)
(eslc "(macro ..a (lambda ()
(return ((. this string) (. '.b.. value)))))
(..a)")
"'.b..';")))
(test "pass to other macro"
(((. t equals) (eslc "(macro replace (lambda () (return 'x)))
(replace (. a b))")
"x;")))