(require-extension test filepath) ;; test cases from Haskell implementation (test-group "split-search-path" (let ((ex (list "File1" "File2" "File3"))) (let ((p "File1;File2;File3")) (filepath:posix #f) (test (sprintf "(split-search-path ~S) => ~S (Windows)" p ex) ex (filepath:split-search-path p))) (let ((p "File1:File2:File3")) (filepath:posix #t) (test (sprintf "(split-search-path ~S) => ~S (POSIX)" p ex) ex (filepath:split-search-path p))))) (define split-extension-tests `(("file.txt" ("file" ".txt")) ("file" ("file" "")) ("file/file.txt" ("file/file" ".txt")) ("file.txt/boris" ("file.txt/boris" "")) ("file.txt/boris.ext" ("file.txt/boris" ".ext")) ("file/path.txt.bob.fred" ("file/path.txt.bob" ".fred")) ("file/path.txt/" ("file/path.txt/" "")))) (test-group "split-extension" (for-each (lambda (pr) (let ((p (first pr)) (res (second pr))) (test (sprintf "(split-extension ~S) => ~S" p res) res (filepath:split-extension p)))) split-extension-tests)) (define replace-extension-tests `((("file.txt" ".bob") "file.bob") (("file.txt" "bob") "file.bob") (("file" ".bob") "file.bob") (("file.txt" "") "file") (("file.fred.bob" "txt") "file.fred.txt"))) (test-group "replace-extension" (for-each (lambda (pr) (let ((p (first pr)) (res (second pr))) (test (sprintf "~S => ~S" (cons 'replace-extension p) res) res (apply filepath:replace-extension p)))) replace-extension-tests)) (define add-extension-tests `((("file.txt" "bib") "file.txt.bib") (("file." ".bib") "file..bib") (("file" ".bib") "file.bib") (("/" "x") "/.x"))) (test-group "add-extension" (for-each (lambda (pr) (let ((p (first pr)) (res (second pr))) (test (sprintf "~S => ~S" (cons 'add-extension p) res) res (apply filepath:add-extension p)))) add-extension-tests)) (define split-drive-windows-tests `(("file" ("" "file")) ("c:/file" ("c:/" "file")) ("c:\\file" ("c:\\" "file")) ("\\\\shared\\test" ("\\\\shared\\" "test")) ("\\\\shared" ("\\\\shared" "")) ("\\\\?\\UNC\\shared\\file" ("\\\\?\\UNC\\shared\\" "file")) ("\\\\?\\d:\\file" ("\\\\?\\d:\\" "file")) ("/d" ("" "/d")))) (define split-drive-posix-tests `(("/test" ("/" "test")) ("//test" ("//" "test")) ("test/file" ("" "test/file")) ("file" ("" "file")))) (test-group "split-drive" (filepath:posix #f) (for-each (lambda (pr) (let ((p (first pr)) (res (second pr))) (test (sprintf "~S => ~S" (list 'split-drive p) res) res (filepath:split-drive p)))) split-drive-windows-tests) (filepath:posix #t) (for-each (lambda (pr) (let ((p (first pr)) (res (second pr))) (test (sprintf "~S => ~S" (list 'split-drive p) res) res (filepath:split-drive p)))) split-drive-posix-tests)) (define split-file-name-tests `(("file/bob.txt" ("file/" "bob.txt")) ("file/" ("file/" "")) ("bob" ("" "bob")) ("/" ("/" "")))) (test-group "split-file-name" (filepath:posix #f) (let ((p "c:") (res (list "c:" ""))) (test (sprintf "~S => ~S" (list 'split-file-name p) res) res (filepath:split-file-name p))) (filepath:posix #t) (for-each (lambda (pr) (let ((p (first pr)) (res (second pr))) (test (sprintf "~S => ~S" (list 'split-file-name p) res) res (filepath:split-file-name p)))) split-file-name-tests)) (define take-directory-windows-tests `(("foo\\bar" "foo") ("foo\\bar\\\\" "foo\\bar") ("C:\\" "C:\\"))) (define take-directory-posix-tests `(("/foo/bar/baz" "/foo/bar") ("/foo/bar/baz/" "/foo/bar/baz"))) (test-group "take-directory" (filepath:posix #f) (for-each (lambda (pr) (let ((p (first pr)) (res (second pr))) (test (sprintf "~S => ~S" (list 'take-directory p) res) res (filepath:take-directory p)))) take-directory-windows-tests) (filepath:posix #t) (for-each (lambda (pr) (let ((p (first pr)) (res (second pr))) (test (sprintf "~S => ~S" (list 'take-directory p) res) res (filepath:take-directory p)))) take-directory-posix-tests)) (define split-path-tests `(("test//item/" ("test//" "item/")) ("test/item/file" ("test/" "item/" "file")) ("" ()) ("/file/test" ("/" "file/" "test")))) (test-group "split-path" (filepath:posix #f) (let ((p "c:\\test\\path") (res (list "c:\\" "test\\" "path"))) (test (sprintf "~S => ~S" (list 'split-path p) res) res (filepath:split-path p))) (filepath:posix #t) (for-each (lambda (pr) (let ((p (first pr)) (res (second pr))) (test (sprintf "~S => ~S" (list 'split-path p) res) res (filepath:split-path p)))) split-path-tests)) (define make-relative-windows-tests `((("C:\\Home" "c:\\home\\bob") "bob") (("C:\\Home" "D:\\Home\\Bob") "D:\\Home\\Bob"))) (define make-relative-posix-tests `((("/Home" "/home/bob") "/home/bob") (("/home/" "/home/bob/foo/bar") "bob/foo/bar") (("/fred" "bob") "bob") (("/file/test" "/file/test/fred") "fred") (("/file/test" "/file/test/fred/") "fred/") (("some/path" "some/path/a/b/c") "a/b/c"))) (test-group "make-relative" (filepath:posix #f) (for-each (lambda (pr) (let ((p (first pr)) (res (second pr))) (test (sprintf "~S => ~S" (cons 'make-relative p) res) res (apply filepath:make-relative p)))) make-relative-windows-tests) (filepath:posix #t) (for-each (lambda (pr) (let ((p (first pr)) (res (second pr))) (test (sprintf "~S => ~S" (cons 'make-relative p) res) res (apply filepath:make-relative p)))) make-relative-posix-tests)) (define normalise-posix-tests `(("/file/\\test////" "/file/\\test/") ("/file/./test" "/file/test") ("/test/file/../bob/fred/" "/test/file/../bob/fred/") ("../bob/fred/" "../bob/fred/") ("./bob/fred/" "bob/fred/") ("./" "./"))) (define normalise-windows-tests `(("c:\\file/bob\\" "C:\\file\\bob\\") ("c:\\" "C:\\") ("\\\\server\\test" "\\\\server\\test") ("c:/file" "C:\\file") ("." "."))) (test-group "normalise" (filepath:posix #f) (for-each (lambda (pr) (let ((p (first pr)) (res (second pr))) (test (sprintf "~S => ~S" (list 'normalise p) res) res (filepath:normalise p)))) normalise-windows-tests) (filepath:posix #t) (for-each (lambda (pr) (let ((p (first pr)) (res (second pr))) (test (sprintf "~S => ~S" (list 'normalise p) res) res (filepath:normalise p)))) normalise-posix-tests)) (define is-valid-posix-tests `(("/random_ path:*" #t))) (define is-valid-windows-tests `(( "c:\\test" #t) ( "c:\\test:of_test" #f) ( "test*" #f) ( "c:\\test\\nul" #f) ( "c:\\test\\prn.txt" #f) ( "c:\\nul\\file" #f))) (test-group "is-valid?" (filepath:posix #f) (for-each (lambda (pr) (let ((p (first pr)) (res (second pr))) (test (sprintf "~S => ~S" (list 'is-valid? p) res) res (filepath:is-valid? p)))) is-valid-windows-tests) (filepath:posix #t) (for-each (lambda (pr) (let ((p (first pr)) (res (second pr))) (test (sprintf "~S => ~S" (list 'is-valid? p) res) res (filepath:is-valid? p)))) is-valid-posix-tests)) (define make-valid-tests `(("c:\\test:of_test" "c:\\test_of_test") ("test*" "test_") ("c:\\test\\nul" "c:\\test\\nul_") ("c:\\test\\prn.txt" "c:\\test\\prn_.txt") ("c:\\test/prn.txt" "c:\\test/prn_.txt") ("c:\\nul\\file" "c:\\nul_\\file"))) (test-group "make-valid" (filepath:posix #f) (for-each (lambda (pr) (let ((p (first pr)) (res (second pr))) (test (sprintf "~S => ~S" (list 'make-valid p) res) res (filepath:make-valid p)))) make-valid-tests) (filepath:posix #t) ) (test-exit)