Skip to content

Commit

Permalink
Merge pull request #193 from CFiggers/master
Browse files Browse the repository at this point in the history
Reorganize tests to be one file per module and to give more descriptive file names
  • Loading branch information
bakpakin authored Aug 23, 2024
2 parents 43701d3 + 8022201 commit 1c081c7
Show file tree
Hide file tree
Showing 20 changed files with 263 additions and 270 deletions.
2 changes: 1 addition & 1 deletion test/suite0005.janet → test/suite-argparse.janet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(use ../spork/test)
(import ../spork/argparse)

(start-suite 5)
(start-suite)

(def argparse-params
["A simple CLI tool. An example to show the capabilities of argparse."
Expand Down
2 changes: 1 addition & 1 deletion test/suite0021.janet → test/suite-data.janet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(use ../spork/test)
(import ../spork/data :as d)

(start-suite 21)
(start-suite)

(assert-docs "/spork/data")

Expand Down
2 changes: 1 addition & 1 deletion test/suite0010.janet → test/suite-ev-utils.janet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(use ../spork/test)
(import ../spork/ev-utils :as eu)

(start-suite 10)
(start-suite)

(var x 0)
(eu/pcall (fn workerf [&] (++ x)) 10)
Expand Down
2 changes: 1 addition & 1 deletion test/suite0011.janet → test/suite-generators.janet
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(import ../spork/ev-utils :as eu)
(import ../spork/generators :as generators)

(start-suite 11)
(start-suite)

(defn- generator-assert!
[s]
Expand Down
2 changes: 1 addition & 1 deletion test/suite0016.janet → test/suite-htmlgen.janet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(use ../spork/test)
(import ../spork/htmlgen :as htmlgen)

(start-suite 16)
(start-suite)

(var check-count 0)
(defn check-render
Expand Down
2 changes: 1 addition & 1 deletion test/suite0012.janet → test/suite-http.janet
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(import ../spork/http :as http)
(import ../spork/httpf :as httpf)

(start-suite 12)
(start-suite)

(defn- test-http-item
[x
Expand Down
211 changes: 211 additions & 0 deletions test/suite-misc.janet
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,215 @@
```)
(assert (= (-> output2 string/trim) (-> expected2 string/trim)))

(assert
(deep= (misc/map-keys string {1 2 3 4}) @{"1" 2 "3" 4})
"map-keys in dictionary")
(assert
(deep= (misc/map-keys string {1 2 3 {:a :b :c {:d 3}}})
@{"1" 2 "3" @{"a" :b "c" @{"d" 3}}})
"map-keys in nested struct")

(assert
(deep= (misc/map-keys-flat string {1 [1 2 3] 3 [1 2]}) @{"1" [1 2 3] "3" [1 2]})
"map-keys-flat in dictionary")
(assert
(deep= (misc/map-keys-flat string {1 2 3 {:a :b :c {:d 3}}})
@{"1" 2 "3" {:a :b :c {:d 3}}})
"map-keys-flat in nested struct")

(assert
(deep= (misc/map-vals string {1 2 3 4}) @{1 "2" 3 "4"})
"map-vals of the dictionary 1")
(assert
(deep= (misc/map-vals type {1 2 3 {:a :b}}) @{1 :number 3 :struct})
"map-vals of the dictionary 1")

(assert
(deep= (misc/select-keys {1 2 3 4 5 6} [1 5]) @{1 2 5 6})
"selects keys from dictionary")
(assert
(deep= (misc/select-keys {1 2 3 4 5 6} [1]) @{1 2})
"selects key from dictionary")
(assert
(deep= (misc/select-keys {1 2 3 4 5 {:a :b}} [1 5]) @{1 2 5 {:a :b}})
"selects keys from nested dictionary")

(assert
(deep=
(misc/cond-> @{:a :b}
(pos? 1) (put :a :c)
(pos? 0) (put :a :d))
@{:a :c})
"cond->")

(assert
(deep=
(misc/cond->> @{:a :b}
(pos? 1) (merge {:d :e})
(pos? 0) (merge {:e :f}))
@{:a :b
:d :e})
"cond->>")

(assert
(=
(do
(def Proto @{:greet |(string "Hello " ($ :name))})
(def t (misc/make Proto :name "pepe"))
(:greet t))
"Hello pepe")
"make")

(assert (= (misc/do-var res 0 (set res 100) (++ res))
101)
"do-var")

(assert (deep= (misc/do-def res @"" (buffer/push res "a")) @"a")
"do-def")

(assert (deep= (misc/capout (prin "HOHOHO"))
@"HOHOHO")
"capout one")
(assert (deep= (misc/capout
(def p "HOHOHO")
(prin p))
@"HOHOHO")
"capout many")

(assert (deep= (misc/caperr (eprin "HOHOHO"))
@"HOHOHO")
"caperr one")
(assert (deep= (misc/caperr
(def p "HOHOHO")
(eprin p))
@"HOHOHO")
"caperr many")

(assert (= (do (misc/vars a 2 b 1) a) 2)
"vars")

(assert (= (do (misc/defs a 2 b 1) a) 2)
"defs")

(let [always-true (misc/always true)]
(assert (always-true) "always true")
(assert (always-true) "always true")
(assert (always-true) "always true")
(assert (always-true 1 2 3) "always true (args)"))

(assert (= (misc/second [1 2 3]) 2)
"second")
(assert (nil? (misc/second [1]))
"second (short)")
(assert (nil? (misc/second []))
"second (empty)")

(assert (= (misc/third [1 2 3]) 3)
"third")
(assert (nil? (misc/third [1 2]))
"third (short)")
(assert (nil? (misc/third []))
"third (empty)")

(assert (= (misc/penultimate [1 2 3 4 5]) 4)
"penultimate")
(assert (nil? (misc/penultimate [1]))
"penultimate (short)")
(assert (nil? (misc/penultimate []))
"penultimate (empty)")

(assert (= (misc/antepenultimate [1 2 3 4 5]) 3)
"antepenultimate")
(assert (nil? (misc/antepenultimate [1 2]))
"antepenultimate (short)")
(assert (nil? (misc/antepenultimate []))
"antepenultimate (empty)")

(assert (= (misc/int/ 11 3) 3)
"int/ (pos/pos)")
(assert (= 3 (misc/int/ -11 -3))
"int/ (neg/neg)")
(assert (= -3 (misc/int/ -11 3))
"int/ (neg/pos)")
(assert (= -3 (misc/int/ 11 -3))
"int/ (pos/neg)")

(assert (= (misc/gett {:a {:b {:c :c}}} :a :b :c) :c)
"gett")
(assert (nil? (misc/gett {:a {:b {:c :c}}} :d :b :c))
"gett (nil)")

(assert
(= (misc/do-var res 0 (misc/until (> res 3) (++ res)))
4)
"until")

(assert (deep= (misc/table-filter |(even? $1) @{:zero 0 :one 1 :two 2 :three 3})
@{:zero 0 :two 2})
"table-filter 1")
(assert (deep= (misc/table-filter |(odd? $1) @{:zero 0 :one 1 :two 2 :three 3})
@{:one 1 :three 3})
"table-filter 2")

(assert (= (misc/string->int "101" 2) 2r101)
"string->int (base 2)")
(assert (= (misc/string->int "42") 10r42)
"string->int (base 10 default)")
(assert (= (misc/string->int "42" 16) 16r42)
"string->int (base 16)")
(assert (= (misc/string->int "42z" 36) 36r42z)
"string->int (base 36)")

(assert (= (misc/int->string 36r42z) (string 36r42z))
"int->string (base 10 default)")
(assert (= (misc/int->string 2r11011011 2) "11011011")
"int->string (base 2)")
(assert (= (misc/int->string 16rabacaba 16) "abacaba")
"int->string (base 16)")
(assert (= (misc/int->string 36rxyzzy 36) "xyzzy")
"int->string (base 36)")

(assert (deep= (misc/insert-sorted @[1 2 3 5] < 4)
@[1 2 3 4 5])
"insert-sorted 1")
(assert (deep= (misc/insert-sorted @[4 5] < 3 2 1)
@[1 2 3 4 5])
"array/insert-sorted 2")
(assert (deep= (misc/insert-sorted @[1 2 3] |(error "invoked callback needlessly!"))
@[1 2 3])
"array/insert-sorted 3")

(assert (deep= (misc/insert-sorted-by @[1 2 3 5] identity 4)
@[1 2 3 4 5])
"array/insert-sorted-by 1")
(assert (deep= (misc/insert-sorted-by @[4 5] identity 3 2 1)
@[1 2 3 4 5])
"array/insert-sorted-by 2")
(assert (deep= (misc/insert-sorted-by @[2] - 1 3)
@[3 2 1])
"array/insert-sorted-by 3")
(assert (deep= (misc/insert-sorted-by @[1 2 3] |(error "invoked callback needlessly!"))
@[1 2 3])
"array/insert-sorted-by 4")

(assert (deep= (misc/merge-sorted @[2 3 6 7] @[1 4 5 8])
@[1 2 3 4 5 6 7 8])
"misc/merge-sorted 1")
(assert (deep= (misc/merge-sorted @[3 2 1] @[8 7 6 5 4] >)
@[8 7 6 5 4 3 2 1])
"misc/merge-sorted 2")
(assert (deep= (misc/merge-sorted @[1 2 3 4 5 6 7 8] @[] |(error "invoked callback needlessly!"))
@[1 2 3 4 5 6 7 8])
"misc/merge-sorted 3")

(assert (deep= (misc/merge-sorted-by @[2 3 6 7] @[1 4 5 8] identity)
@[1 2 3 4 5 6 7 8])
"misc/merge-sorted-by 1")
(assert (deep= (misc/merge-sorted-by @[3 2 1] @[8 7 6 5 4] -)
@[8 7 6 5 4 3 2 1])
"misc/merge-sorted-by 2")
(assert (deep= (misc/merge-sorted-by @[1 2 3 4 5 6 7 8] @[] |(error "invoked callback needlessly!"))
@[1 2 3 4 5 6 7 8])
"misc/merge-sorted-by 3")

(end-suite)
2 changes: 1 addition & 1 deletion test/suite0003.janet → test/suite-msg.janet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(use ../spork/test)
(import ../spork/msg)

(start-suite 3)
(start-suite)

(defn handler [s]
(def recv (msg/make-recv s))
Expand Down
2 changes: 1 addition & 1 deletion test/suite0009.janet → test/suite-netrepl.janet
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(import ../spork/msg)
(import ../spork/netrepl)

(start-suite 9)
(start-suite)

(with [wt (netrepl/server "127.0.0.1" "8000")]
(with [s (net/connect "127.0.0.1" "8000")]
Expand Down
12 changes: 11 additions & 1 deletion test/suite0006.janet → test/suite-path.janet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(use ../spork/test)
(import ../spork/path)

(start-suite 6)
(start-suite)

(defn aeq
"assert equal"
Expand Down Expand Up @@ -49,4 +49,14 @@
(aeq (path/win32/abspath "q:\\home\\pork") "q:\\home\\pork")
(aeq (path/win32/abspath "..\\home\\pork") "D:\\Users\\home\\pork"))

(assert (= (path/posix/relpath "dir1" "dir2") "../dir2"))

(assert (= (path/win32/relpath "dir1" "dir2") "..\\dir2"))

(assert (= (path/relpath "dir1" "dir2") (path/join ".." "dir2")))

(assert (= (path/posix/relpath "a/bit/deeper/with/some/nested/dir" "a/bit/deeper/with/other/nested/dir") "../../../other/nested/dir"))

(assert (= (path/posix/relpath "a/nested/directory/with/a/few/children" "a/nested/directory/with/different/children") "../../../different/children"))

(end-suite)
2 changes: 1 addition & 1 deletion test/suite0019.janet → test/suite-rawterm.janet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(use ../spork/test)
(import spork/rawterm)

(start-suite 19)
(start-suite)

# TODO: This tests the reduced set of codepoints based on the original set in
# Bestline:
Expand Down
2 changes: 1 addition & 1 deletion test/suite0004.janet → test/suite-regex.janet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(use ../spork/test)
(import ../spork/regex)

(start-suite 4)
(start-suite)

(assert (regex/match `abc` `abcdefg`) "match 1")
(assert (regex/match `a.c` `azcdefg`) "match 2")
Expand Down
2 changes: 1 addition & 1 deletion test/suite0002.janet → test/suite-rpc.janet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(use ../spork/test)
(import ../spork/rpc)

(start-suite 2)
(start-suite)

(def fns
{:hi (fn [self msg]
Expand Down
2 changes: 1 addition & 1 deletion test/suite0013.janet → test/suite-schema.janet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(use ../spork/test)
(import ../spork/schema :as schema)

(start-suite 13)
(start-suite)

(def c1 (schema/predicate :number))
(assert (not (c1 :test)) "checker c1 1")
Expand Down
2 changes: 1 addition & 1 deletion test/suite0017.janet → test/suite-sh.janet
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(import ../spork/sh)
(import ../spork/path)

(start-suite 17)
(start-suite)

(def base-path "test")

Expand Down
2 changes: 1 addition & 1 deletion test/suite0015.janet → test/suite-tarray.janet
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(use ../spork/math)
(import spork/tarray)

(start-suite 15)
(start-suite)

(defn inspect-tarray
[x]
Expand Down
2 changes: 1 addition & 1 deletion test/suite0008.janet → test/suite-temple.janet
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

(temple/add-loader)

(test/start-suite 8)
(test/start-suite)

(defn- remove-r [x] (string/replace-all "\r" "" x))

Expand Down
Loading

0 comments on commit 1c081c7

Please sign in to comment.