(import (rnrs)
(mosh test)
(shorten)
(mosh file)
(template))
(define temp-file "template-temp")
(define (test-equal-template expected template vars)
(when (file-exists? temp-file)
(delete-file temp-file))
(with-output-to-file temp-file
(^()
(eval-template template vars)))
(test-equal expected (file->string temp-file))
(delete-file temp-file))
(define big "<%
(define (for-each-with-index proc lst)
(let ([len (length lst)])
(do ((i 1 (+ i 1)) ; start with 1
(lst lst (cdr lst)))
((null? lst))
(proc i (car lst)))))
%>
SameAge - 同い年のための掲示板
<%include _header.html %>
同い年のための掲示板 |
<% (cond [user %>
/\">自分の同い年掲示板に書き込む
<% ][else %>
書き込みするには\">ログインが必要です
<% ]) %>
|
|
<%include _footer.html %>
"
)
(define big2 "<%
(define (for-each-with-index proc lst)
(let ([len (length lst)])
(do ((i 1 (+ i 1)) ; start with 1
(lst lst (cdr lst)))
((null? lst))
(proc i (car lst)))))
%>
<%include _header.html %>3"
)
(test-equal-template "hige" "<%= a %>" '((a . "hige")))
(test-equal-template "hige" "<% (display a) %>" '((a . "hige")))
(test-equal-template "" "" '((a . "hige")))
(test-equal-template "hoge" "<%= a %>" '((a . "hoge")))
(test-equal-template "\nhoge" "\n<%= a %>" '((a . "hoge")))
(test-equal-template "higehage" "<% (for-each (lambda (x) %><%= x %><% ) b) %>" '((b . '("hige" "hage"))))
(test-equal-template "" "" '())
(test-equal-template "\n3" "<%\n (define a 3)%>\n3" '())
(test-equal-template "34" "<% (display 3) %><% (display 4) %>" '())
(test-equal-template "3%4" "<% (display 3) %>%<% (display 4) %>" '())
(test-equal-template "34" "<%= a %><%= b %>" '((a . "3") (b . "4")))
(test-equal-template "3%4" "<%= a %>%<%= b %>" '((a . "3") (b . "4")))
(test-equal-template "3%4" "<%=unsafe a %>%<%=unsafe b %>" '((a . "3") (b . "4")))
(test-equal-template "%4" "<%# hoge %>%<%=unsafe b %>" '((a . "3") (b . "4")))
(test-equal 3 (ref '((a . 3)) a))
(test-equal-template "" "<% \n %>" '())
;; (test-equal-template "" big '((a . "3") (b . "4")))
;; (test-equal-template "" big2 '((a . "3") (b . "4")))
;; todo: works on only nmosh
;(test-equal-template "#t" "<%= (hashtable? a) %>" `((a . ,(make-eq-hashtable))))
(test-results)