aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorCalvin Rose <calsrose@gmail.com>2021-01-09 09:43:58 -0600
committerCalvin Rose <calsrose@gmail.com>2021-01-09 09:43:58 -0600
commit248dadd25e330baba0b2c7f6d4202afd793d5c1c (patch)
treef16c358d0612cee0468ba83b0b3df8ba51368c66 /test
parentMove argparse into spork. (diff)
Add path to spork.
Diffstat (limited to 'test')
-rw-r--r--test/helper.janet4
-rw-r--r--test/suite5.janet2
-rw-r--r--test/suite6.janet52
3 files changed, 56 insertions, 2 deletions
diff --git a/test/helper.janet b/test/helper.janet
index c0ae2ea..822eba6 100644
--- a/test/helper.janet
+++ b/test/helper.janet
@@ -43,10 +43,10 @@
(defn start-suite [x]
(set suite-num x)
(set start-time (os/clock))
- (print "\nRunning test suite " x " tests...\n "))
+ (print))
(defn end-suite []
(def delta (- (os/clock) start-time))
- (printf "\n\nTest suite %d finished in %.3f seconds" suite-num delta)
+ (printf "\n\ntest suite %d finished in %.3f seconds" suite-num delta)
(print num-tests-passed " of " num-tests-run " tests passed.\n")
(if (not= num-tests-passed num-tests-run) (os/exit 1)))
diff --git a/test/suite5.janet b/test/suite5.janet
index dc0601e..7df7471 100644
--- a/test/suite5.janet
+++ b/test/suite5.janet
@@ -1,6 +1,8 @@
(use ./helper)
(use ../spork/argparse)
+(start-suite 5)
+
(def argparse-params
["A simple CLI tool. An example to show the capabilities of argparse."
"debug" {:kind :flag
diff --git a/test/suite6.janet b/test/suite6.janet
new file mode 100644
index 0000000..74c4768
--- /dev/null
+++ b/test/suite6.janet
@@ -0,0 +1,52 @@
+(use ./helper)
+(import ../spork/path)
+
+(start-suite 6)
+
+(defn aeq
+ "assert equal"
+ [x y &opt deep]
+ (assert ((if deep deep= =) x y)
+ (string "expected " x " to equal " y)))
+
+(aeq (path/posix/abspath? "/home") true)
+(aeq (path/posix/abspath? "home") false)
+(aeq (path/posix/abspath? "./home") false)
+(aeq (path/posix/abspath? "../home") false)
+(aeq (path/posix/abspath? "") false)
+(aeq (path/posix/abspath? "//") true)
+
+(aeq (path/abspath "home") (path/join (os/cwd) "home"))
+(aeq (path/posix/join "1" "2" "3") "1/2/3")
+(aeq (path/posix/join "1" ".." "2" ".." "3") "3")
+(aeq (path/posix/join "/home/" "for") "/home/for")
+
+(aeq (path/posix/normalize "/abc/../") "/")
+(aeq (path/posix/normalize "/abc/abc") "/abc/abc")
+(aeq (path/posix/normalize "/abc/abc/..") "/abc")
+(aeq (path/posix/normalize "/abc/abc/../") "/abc/")
+(aeq (path/posix/normalize "/abc/abc/../.") "/abc")
+(aeq (path/posix/normalize "//////abc/abc/../.") "/abc")
+(aeq (path/posix/normalize "//////.") "/")
+(aeq (path/posix/normalize "//////") "/")
+
+(aeq (path/posix/dirname "abc/def") "abc/")
+(aeq (path/posix/dirname "abc/") "abc/")
+(aeq (path/posix/basename "abc") "abc")
+(aeq (path/posix/dirname "abc") "./")
+
+(aeq (path/posix/ext "project.janet") ".janet")
+(aeq (path/posix/ext "/home/pork/work/project.janet") ".janet")
+
+(aeq (path/posix/parts "/home/pork/.local/share")
+ @["" "home" "pork" ".local" "share"] true)
+
+(aeq (path/posix/parts ".local/share")
+ @[".local" "share"] true)
+
+(with-dyns [:path-cwd "D:\\Users\\sumbuddy"]
+ (aeq (path/win32/abspath "C:\\home\\pork") "C:\\home\\pork")
+ (aeq (path/win32/abspath "q:\\home\\pork") "q:\\home\\pork")
+ (aeq (path/win32/abspath "..\\home\\pork") "D:\\Users\\home\\pork"))
+
+(end-suite)