Merge pull request #174 from KeenS/refactor-contrib

Refactor contrib
This commit is contained in:
Yuichi Nishiwaki 2014-08-06 02:41:08 +09:00
commit 91d2dd0b02
6 changed files with 44 additions and 1 deletions

View File

@ -40,11 +40,14 @@ include(tools/CMakeLists.txt)
add_custom_target(run bin/picrin DEPENDS repl)
# $ make test
add_custom_target(test DEPENDS test-r7rs)
add_custom_target(test DEPENDS test-r7rs test-contribs)
# $ make test-r7rs
add_custom_target(test-r7rs bin/picrin ${PROJECT_SOURCE_DIR}/t/r7rs-tests.scm DEPENDS repl)
# $ make test-contribs
add_custom_target(test-contribs DEPENDS ${CONTRIB_TESTS})
# $ make tak
add_custom_target(tak bin/picrin ${PROJECT_SOURCE_DIR}/etc/tak.scm DEPENDS repl)

View File

@ -1,4 +1,7 @@
# regex
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/contrib/10.regexp/cmake/")
find_package(REGEX)
if (REGEX_FOUND)
@ -10,4 +13,6 @@ if (REGEX_FOUND)
list(APPEND PICRIN_CONTRIB_INITS regexp)
list(APPEND PICRIN_CONTRIB_LIBRARIES ${REGEX_LIBRARIES})
list(APPEND PICRIN_CONTRIB_SOURCES ${PICRIN_REGEX_SOURCES})
add_custom_target(test-regexp for test in ${PROJECT_SOURCE_DIR}/contrib/10.regexp/t/*.scm \; do bin/picrin "$$test" \; done DEPENDS repl)
set(CONTRIB_TESTS ${CONTRIB_TESTS} test-regexp)
endif()

View File

@ -0,0 +1,12 @@
(import (scheme base)
(picrin test)
(picrin regexp))
(test #t (regexp? (regexp "simple")))
(test #f (regexp? "it\\s[s]e+ms\\s(reg)?exp"))
(test-values (values '("abcd" "b") '(5 6)) (regexp-match (regexp "a(b)cd") "abdacabcd"))
(test '("a" "b" "c" "d") (regexp-split (regexp ",") "a,b,c,d"))
(test '("a" "b" "c" "d") (regexp-split (regexp "\\.+") "a.b....c.....d"))
(test "a b c d" (regexp-replace (regexp ",") "a,b,c,d" " "))
(test "newline tab space " (regexp-replace (regexp "\\s") "newline
tab space " " "))

View File

@ -1,2 +1,4 @@
file(GLOB FOR_FILES ${PROJECT_SOURCE_DIR}/contrib/20.for/piclib/*.scm)
list(APPEND PICLIB_CONTRIB_LIBS ${FOR_FILES})
add_custom_target(test-for for test in ${PROJECT_SOURCE_DIR}/contrib/20.for/t/*.scm \; do bin/picrin "$$test" \; done DEPENDS repl)
set(CONTRIB_TESTS ${CONTRIB_TESTS} test-for)

21
contrib/20.for/t/test.scm Normal file
View File

@ -0,0 +1,21 @@
(import (scheme base)
(picrin control list)
(picrin test))
(test '(1 2 3)
(for
(yield (in '(1 2 3)))))
(test '((1 a) (1 b) (1 c) (2 a) (2 b) (2 c) (3 a) (3 b) (3 c))
(for
(let ((n (in '(1 2 3)))
(c (in '(a b c))))
(yield (list n c)))))
(test '((2 a) (2 b) (2 c))
(for
(let ((n (in '(1 2 3)))
(c (in '(a b c))))
(if (even? n)
(yield (list n c))
(null)))))