-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.lisp
59 lines (46 loc) · 1.5 KB
/
test.lisp
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
(in-package :cl-react.psx)
(defun strip-whitespace (string)
(remove-if (lambda (c) (find c '(#\space #\tab #\newline)))
string))
(defun test-psx* (psx-form expected-js)
(let* ((compiled-psx (ps:ps* (compile-psx psx-form)))
(result (string= (strip-whitespace compiled-psx)
(strip-whitespace expected-js))))
(format t
" PSX: ~s ~% ACTUAL: ~a ~% EXPECTED: ~a ~% RESULT: ~a~%"
psx-form
compiled-psx
expected-js
(if result "passed" "failed"))))
(defmacro test-psx (psx-form expected-js)
`(test-psx* ',psx-form ,expected-js))
(defmacro define-test-suite (name &body tests)
`(defun ,name ()
,@(mapcar (lambda (test)
`(progn ,test
(format t "-----------~%")))
tests)))
(define-test-suite psx-tests
(test-psx
(:br)
"React.DOM.br();")
(test-psx
(:span :class-name "icon")
"React.DOM.span(cl_react_mergeObjects({ className : 'icon' }));")
(test-psx
(:span "Test")
"React.DOM.span(null, 'Test');")
(test-psx
(:a :href "#"
(:span "Test"))
"React.DOM.a(cl_react_mergeObjects({ href : '#' }), React.DOM.span(null, 'Test'));")
(test-psx
(:p (:b "Bold")
(:i "Italic"))
"React.DOM.p(null, [React.DOM.b(null, 'Bold'), React.DOM.i(null, 'Italic')]);")
(test-psx
(:fragment (:td "foo") (:td "bar"))
"React.createElement(React.Fragment, null, [React.DOM.td(null, 'foo'), React.DOM.td(null, 'bar')]);")
(test-psx
(:foo.bar)
"React.createElement(foo.bar);"))