diff --git a/contrib/10.readline/CMakeLists.txt b/contrib/10.readline/CMakeLists.txt index 67d78733..793b29f6 100644 --- a/contrib/10.readline/CMakeLists.txt +++ b/contrib/10.readline/CMakeLists.txt @@ -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() diff --git a/contrib/10.readline/t/test.scm b/contrib/10.readline/t/test.scm index 68b39de4..af695621 100644 --- a/contrib/10.readline/t/test.scm +++ b/contrib/10.readline/t/test.scm @@ -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)