diff --git a/CMakeLists.txt b/CMakeLists.txt index c38e5802..2ee8e462 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/contrib/10.regexp/CMakeLists.txt b/contrib/10.regexp/CMakeLists.txt index 6ab06aaa..c13c76d3 100644 --- a/contrib/10.regexp/CMakeLists.txt +++ b/contrib/10.regexp/CMakeLists.txt @@ -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() diff --git a/cmake/FindREGEX.cmake b/contrib/10.regexp/cmake/FindREGEX.cmake similarity index 100% rename from cmake/FindREGEX.cmake rename to contrib/10.regexp/cmake/FindREGEX.cmake diff --git a/contrib/10.regexp/t/test.scm b/contrib/10.regexp/t/test.scm new file mode 100644 index 00000000..3c90493f --- /dev/null +++ b/contrib/10.regexp/t/test.scm @@ -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 " " ")) diff --git a/contrib/20.for/CMakeLists.txt b/contrib/20.for/CMakeLists.txt index ebe66a42..5e109d90 100644 --- a/contrib/20.for/CMakeLists.txt +++ b/contrib/20.for/CMakeLists.txt @@ -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) diff --git a/contrib/20.for/t/test.scm b/contrib/20.for/t/test.scm new file mode 100644 index 00000000..64873a4b --- /dev/null +++ b/contrib/20.for/t/test.scm @@ -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)))))