add tests

This commit is contained in:
Sunrim KIM (keen) 2014-08-08 06:28:00 +09:00
parent 88f9fac5a2
commit 8b88b73d74
2 changed files with 56 additions and 11 deletions

View File

@ -14,6 +14,6 @@ if (Libedit_FOUND)
list(APPEND PICRIN_CONTRIB_INITS readline)
list(APPEND PICRIN_CONTRIB_LIBRARIES ${Libedit_LIBRARIES})
list(APPEND PICRIN_CONTRIB_SOURCES ${PICRIN_READLINE_SOURCES})
# add_custom_target(test-readline for test in ${PROJECT_SOURCE_DIR}/contrib/10.regexp/t/*.scm \; do bin/picrin "$$test" \; done DEPENDS repl)
# set(CONTRIB_TESTS ${CONTRIB_TESTS} test-readline)
add_custom_target(test-readline for test in ${PROJECT_SOURCE_DIR}/contrib/10.readline/t/*.scm \; do bin/picrin "$$test" \; done DEPENDS repl)
set(CONTRIB_TESTS ${CONTRIB_TESTS} test-readline)
endif()

View File

@ -2,14 +2,59 @@
(scheme read)
(scheme eval)
(scheme write)
(picrin readline))
(picrin readline)
(picrin readline history)
(picrin test))
;; (let loop ((n 1))
;; (let ((input (readline "> ")))
;; (if (eof-object? input)
;; (newline)
;; (begin
;; (add-history input)
;; (write (eval (read (open-input-string input)) '(picrin user)))
;; (newline)
;; (loop 1)))))
;; (readline "prompt")
(define testfile "./picrin_readline_test_file")
(test-begin)
(test 0 (history-length))
(add-history "0")
(test 1 (history-length))
(let loop ((n 1))
(let ((input (readline "> ")))
(if (eof-object? input)
(newline)
(begin
(add-history input)
(write (eval (read (open-input-string input)) '(picrin user)))
(newline)
(loop 1)))))
(if (> 10 n)
(begin
(add-history (number->string n))
(loop (+ n 1)))))
(test 10 (history-length))
(stifle-history 7)
(test 7 (history-length))
(add-history "10")
(test 7 (history-length))
(test #t (history-stifled?))
(unstifle-history)
(test #f (history-stifled?))
(test 7 (history-length))
(add-history "11")
(test 8 (history-length))
(test "10" (history-get 11))
(remove-history 1)
(test "10" (history-get 11))
(test 7 (history-length))
(write-history testfile)
(test 7 (history-length))
(clear-history)
(test 0 (history-length))
(read-history testfile)
(test 7 (history-length))
(clear-history)
(truncate-file testfile 5)
(read-history testfile)
(test 5 (history-length))
(test-end)