From 3a30a11c1feae0b383399ba85b04347d9b28ed3e Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Wed, 22 Dec 2021 15:27:29 -0500 Subject: [PATCH] Add more library tests (#1114) * Add environ and table tests Also allow for directory option and fix nasty nil test-dir bug * Add 7 libraries via add-libtest.clj Added :branch option and saved additional info to bb-tested-libs.edn to reproduce test fetching later * Disable intermittent failing test --- deps.edn | 7 +- doc/dev.md | 2 +- script/add-libtest.clj | 97 +++-- .../lib_tests/arrangement/core_test.cljc | 2 +- .../lib_tests/babashka/run_all_libtests.clj | 18 +- test-resources/lib_tests/bb-tested-libs.edn | 15 +- .../lib_tests/better_cond/core_test.cljc | 1 + .../clojure/data/json_compat_0_1_test.clj | 226 +++++++++++ .../lib_tests/clojure/data/json_gen_test.clj | 34 ++ .../lib_tests/clojure/data/json_test.clj | 5 +- .../lib_tests/clojure_csv/test/core.clj | 2 +- .../lib_tests/clojure_csv/test/utils.clj | 2 +- .../lib_tests/environ/core_test.cljc | 65 ++++ .../lib_tests/environ/test/runner.cljs | 5 + .../exoscale/coax_cljs_test_runner.cljs | 5 + test-resources/lib_tests/hasch/test.cljc | 7 +- .../reifyhealth/specmonstah/core_test.cljc | 1 + test-resources/lib_tests/ruuter/core_test.clj | 26 -- .../lib_tests/ruuter/core_test.cljc | 64 +++ test-resources/lib_tests/table/core_test.clj | 368 ++++++++++++++++++ test-resources/lib_tests/table/width_test.clj | 28 ++ 21 files changed, 899 insertions(+), 81 deletions(-) create mode 100644 test-resources/lib_tests/clojure/data/json_compat_0_1_test.clj create mode 100644 test-resources/lib_tests/clojure/data/json_gen_test.clj create mode 100644 test-resources/lib_tests/environ/core_test.cljc create mode 100644 test-resources/lib_tests/environ/test/runner.cljs create mode 100644 test-resources/lib_tests/exoscale/coax_cljs_test_runner.cljs delete mode 100644 test-resources/lib_tests/ruuter/core_test.clj create mode 100644 test-resources/lib_tests/ruuter/core_test.cljc create mode 100644 test-resources/lib_tests/table/core_test.clj create mode 100644 test-resources/lib_tests/table/width_test.clj diff --git a/deps.edn b/deps.edn index dc4e8c96..d45a9704 100644 --- a/deps.edn +++ b/deps.edn @@ -95,15 +95,16 @@ hato/hato {:mvn/version "0.8.2"} better-cond/better-cond {:mvn/version "2.1.1"} org.clojure/core.specs.alpha {:mvn/version "0.2.62"} - reifyhealth/specmonstah {:git/url "https://github.com/reifyhealth/specmonstah" - :sha "a2b357009a3aa99a0c2d2361f3bbcd0b0e36505e"} + reifyhealth/specmonstah {:git/url "https://github.com/reifyhealth/specmonstah", :sha "a2b357009a3aa99a0c2d2361f3bbcd0b0e36505e"} exoscale/coax {:mvn/version "1.0.0-alpha14"} orchestra/orchestra {:mvn/version "2021.01.01-1"} expound/expound {:mvn/version "0.8.10"} integrant/integrant {:mvn/version "0.8.0"} com.stuartsierra/dependency {:mvn/version "1.0.0"} listora/again {:mvn/version "1.0.0"} - org.clojure/tools.gitlibs {:mvn/version "2.4.172"}} + org.clojure/tools.gitlibs {:mvn/version "2.4.172"} + environ/environ {:mvn/version "1.2.0"} + table/table {:git/url "https://github.com/cldwalker/table", :sha "55aef3d5fced682942af811bf5d642f79fb87688"}} :classpath-overrides {org.clojure/clojure nil org.clojure/spec.alpha nil}} :clj-nvd diff --git a/doc/dev.md b/doc/dev.md index 3c72864e..c059a9a8 100644 --- a/doc/dev.md +++ b/doc/dev.md @@ -93,7 +93,7 @@ If the library you want to add doesn't work with the script, you can manually do * Run the tests `script/lib_tests/run_all_libtests NS1 NS2` Note: If you have to modify a test to have it work with bb, add an inline -comment with prefix "TEST-FIX:" explaining what you did. +comment with prefix "BB-TEST-PATCH:" explaining what you did. ## Build diff --git a/script/add-libtest.clj b/script/add-libtest.clj index ec450aba..d44e549e 100755 --- a/script/add-libtest.clj +++ b/script/add-libtest.clj @@ -7,6 +7,8 @@ [babashka.fs :as fs] [babashka.tasks :refer [shell]] [clojure.string :as str] + [clojure.java.io :as io] + [clojure.tools.cli :as cli] [clojure.edn :as edn])) (deps/add-deps '{:deps {org.clojure/tools.gitlibs {:mvn/version "2.4.172"} @@ -15,6 +17,37 @@ (require '[clojure.tools.gitlibs :as gl]) (require '[borkdude.rewrite-edn :as r]) +;; CLI Utils +;; ========= +(defn- error + "Print error message(s) and exit" + [& msgs] + (apply println "Error:" msgs) + (System/exit 1)) + +(defn- print-summary + "Print help summary given args and opts strings" + [args-string options-summary] + (println (format "Usage: %s [OPTIONS]%s\nOptions:\n%s" + (.getName (io/file *file*)) + args-string + options-summary))) + +(defn- run-command + "Processes a command's functionality given a cli options definition, arguments + and primary command fn. This handles option parsing, handles any errors with + parsing and then passes parsed input to command fn" + [command-fn args cli-opts & parse-opts-options] + (let [{:keys [errors] :as parsed-input} + (apply cli/parse-opts args cli-opts parse-opts-options)] + (if (seq errors) + (do + (error (str/join "\n" (into ["Options failed to parse:"] errors))) + (System/exit 1)) + (command-fn parsed-input)))) + +;; Add libtest +;; =========== (defn- add-lib-to-deps [lib-name lib-coordinate] (let [nodes (-> "deps.edn" slurp r/parse-string)] @@ -24,36 +57,44 @@ lib-coordinate))))) (defn- copy-tests - [git-url lib-name] - (let [lib-dir (or (gl/procure git-url lib-name "master") - (gl/procure git-url lib-name "main")) - test-dir (some #(when (fs/exists? (fs/file lib-dir %)) - (str (fs/file lib-dir %))) + [git-url lib-name {:keys [directory branch]}] + (let [lib-dir (if branch + (gl/procure git-url lib-name branch) + (or (gl/procure git-url lib-name "master") + (gl/procure git-url lib-name "main"))) + lib-root-dir (if directory + (fs/file lib-dir directory) lib-dir) + test-dir (some #(when (fs/exists? (fs/file lib-root-dir %)) + (str (fs/file lib-root-dir %))) ;; Search common test dirs ["test" ;; official clojure repos like https://github.com/clojure/tools.gitlibs "src/test/clojure"])] + (when-not test-dir + (error "No test dir found")) (shell "cp -R" (str test-dir fs/file-separator) "test-resources/lib_tests/") {:lib-dir lib-dir :test-dir test-dir})) (defn- add-lib-to-tested-libs - [lib-name git-url {:keys [lib-dir test-dir]}] + [lib-name git-url {:keys [lib-dir test-dir]} options] (let [git-sha (fs/file-name lib-dir) - ; (str (fs/relativize lib-dir test-dir)) relative-test-files (map #(str (fs/relativize test-dir %)) (fs/glob test-dir "**/*.{clj,cljc}")) _ (when (empty? relative-test-files) - (throw (ex-info "No test files found" {:test-dir test-dir}))) + (error "No test files found")) namespaces (map #(-> % (str/replace fs/file-separator ".") (str/replace "_" "-") (str/replace-first #"\.clj(c?)$" "") symbol) relative-test-files) - lib {:git-sha git-sha - :git-url git-url - :test-namespaces namespaces} + lib (merge + {:git-sha git-sha + :git-url git-url + :test-namespaces namespaces} + ;; Options needed to update libs + (select-keys options [:branch :directory])) nodes (-> "test-resources/lib_tests/bb-tested-libs.edn" slurp r/parse-string)] (spit "test-resources/lib_tests/bb-tested-libs.edn" (str (r/assoc-in nodes @@ -61,26 +102,34 @@ lib))) namespaces)) -(defn- run-command - [args] - (let [[deps-string git-url test-option] args +(defn- add-libtest* + [args options] + (let [[deps-string git-url] args deps-map (edn/read-string deps-string) _ (when (not= 1 (count deps-map)) - (throw (ex-info "Deps map must have one key" {}))) + (error "Deps map must have one key")) lib-name (ffirst deps-map) lib-coordinate (deps-map lib-name) _ (add-lib-to-deps lib-name lib-coordinate) - dirs (copy-tests git-url lib-name) - namespaces (add-lib-to-tested-libs lib-name git-url dirs)] + dirs (copy-tests git-url lib-name options) + namespaces (add-lib-to-tested-libs lib-name git-url dirs options)] (println "Added lib" lib-name "which tests the following namespaces:" namespaces) - (when (= "--test" test-option) + (when (:test options) (apply shell "script/lib_tests/run_all_libtests" namespaces)))) -(defn main - [args] - (if (< (count args) 2) - (println "Usage: bb add-libtest DEPS-MAP GIT-URL [--test]") - (run-command args))) +(defn add-libtest + [{:keys [arguments options summary]}] + (if (or (< (count arguments) 2) (:help options)) + (print-summary "DEPS-MAP GIT-URL " summary) + (add-libtest* arguments options))) + +(def cli-options + [["-h" "--help"] + ["-t" "--test" "Run tests"] + ;; https://github.com/weavejester/environ/tree/master/environ used this option + ["-d" "--directory DIRECTORY" "Directory where library is located"] + ;; https://github.com/reifyhealth/specmonstah used this option + ["-b" "--branch BRANCH" "Default branch for git url"]]) (when (= *file* (System/getProperty "babashka.file")) - (main *command-line-args*)) + (run-command add-libtest *command-line-args* cli-options)) diff --git a/test-resources/lib_tests/arrangement/core_test.cljc b/test-resources/lib_tests/arrangement/core_test.cljc index 333a0433..c682c5d9 100644 --- a/test-resources/lib_tests/arrangement/core_test.cljc +++ b/test-resources/lib_tests/arrangement/core_test.cljc @@ -75,7 +75,7 @@ #?(:clj (deftest class-ordering (is-sorted - ;; TEST-FIX: bb doesn't have java.util.Currency/getInstance + ;; BB-TEST-PATCH: bb doesn't have java.util.Currency/getInstance #_(java.util.Currency/getInstance "JPY") #_(java.util.Currency/getInstance "USD") (java.util.Date. 1234567890) diff --git a/test-resources/lib_tests/babashka/run_all_libtests.clj b/test-resources/lib_tests/babashka/run_all_libtests.clj index 4dd03e38..a3511e78 100644 --- a/test-resources/lib_tests/babashka/run_all_libtests.clj +++ b/test-resources/lib_tests/babashka/run_all_libtests.clj @@ -65,7 +65,7 @@ ;;;; clojure.data.zip -;; TODO: port to test-namespaces. Blocked until clojure.xml is supported +;; TODO: port to test-namespaces (require '[clojure.data.xml :as xml]) (require '[clojure.zip :as zip]) @@ -201,16 +201,10 @@ ;; 'slingshot.test-test ) -(test-namespaces 'hasch.test - ) - (test-namespaces 'omniconf.core-test) (test-namespaces 'crispin.core-test) -(test-namespaces 'clojure.data.json-test - 'clojure.data.json-test-suite-test) - (test-namespaces 'multigrep.core-test) (test-namespaces @@ -230,22 +224,12 @@ (test-namespaces 'component.component-test) -(test-namespaces 'ruuter.core-test) - (test-namespaces 'clj-commons.digest-test) (test-namespaces 'hato.client-test) -(test-namespaces 'better-cond.core-test) - -(test-namespaces 'exoscale.coax-test) - (test-namespaces 'orchestra.core-test 'orchestra.expound-test 'orchestra.many-fns 'orchestra.reload-test) -(test-namespaces 'reifyhealth.specmonstah.core-test 'reifyhealth.specmonstah.spec-gen-test) - -(test-namespaces 'com.stuartsierra.dependency-test) - (let [lib-tests (edn/read-string (slurp (io/resource "bb-tested-libs.edn")))] (doseq [{tns :test-namespaces} (vals lib-tests)] (apply test-namespaces tns))) diff --git a/test-resources/lib_tests/bb-tested-libs.edn b/test-resources/lib_tests/bb-tested-libs.edn index 20ae0b76..cbc276be 100644 --- a/test-resources/lib_tests/bb-tested-libs.edn +++ b/test-resources/lib_tests/bb-tested-libs.edn @@ -1,8 +1,19 @@ ;; These libraries are tested against babashka and have been added by -;; script/add-libtest.clj +;; script/add-libtest.clj. Each library entry contains enough data to run tests +;; and to update tests later {listora/again {:git-sha "b1a6793f0deaa3cc016eee7626097ba8bf36ba10", :git-url "https://github.com/liwp/again", :test-namespaces (again.core-test)} org.clojure/tools.gitlibs {:git-sha "9f98af7631e34983d5b0886e1ab6eadc3856290b", :git-url "https://github.com/clojure/tools.gitlibs", :test-namespaces (clojure.tools.test-gitlibs clojure.tools.gitlibs.test-impl)} comb/comb {:git-sha "625a63a9c040fa4a2b3153d8c84d08dc2fc8f660", :git-url "https://github.com/weavejester/comb", :test-namespaces (comb.test.template)} mvxcvi/arrangement {:git-sha "360d29e7ae81abbf986b5a8e272f2086227d038d", :git-url "https://github.com/greglook/clj-arrangement", :test-namespaces (arrangement.core-test)} - clojure-csv/clojure-csv {:git-sha "b6bb882a3a9ac1f82e06eb2262ae7c8141935228", :git-url "https://github.com/davidsantiago/clojure-csv", :test-namespaces (clojure-csv.test.utils clojure-csv.test.core)}} + clojure-csv/clojure-csv {:git-sha "b6bb882a3a9ac1f82e06eb2262ae7c8141935228", :git-url "https://github.com/davidsantiago/clojure-csv", :test-namespaces (clojure-csv.test.utils clojure-csv.test.core)} + environ/environ {:git-sha "aa90997b38bb8070d94dc4a00a14e656eb5fc9ae", :git-url "https://github.com/weavejester/environ", :test-namespaces (environ.core-test), :directory "environ"} + table/table {:git-sha "55aef3d5fced682942af811bf5d642f79fb87688", :git-url "https://github.com/cldwalker/table", :test-namespaces (table.width-test table.core-test)} + com.stuartsierra/dependency {:git-sha "3a467918cd0e5b6ab775d344cfb2a80b56daad6d", :git-url "https://github.com/stuartsierra/dependency", :test-namespaces (com.stuartsierra.dependency-test)} + reifyhealth/specmonstah {:git-sha "a2b357009a3aa99a0c2d2361f3bbcd0b0e36505e", :git-url "https://github.com/reifyhealth/specmonstah", :test-namespaces (reifyhealth.specmonstah.spec-gen-test reifyhealth.specmonstah.test-data reifyhealth.specmonstah.core-test), :branch "develop"} + exoscale/coax {:git-sha "0d4212af7c07e4f05f74186f05df8a97777b43fe", :git-url "https://github.com/exoscale/coax", :test-namespaces (exoscale.coax-test)} + better-cond/better-cond {:git-sha "4720bd8bcfd1adc1197b8d5f07873bc46008d333", :git-url "https://github.com/Engelberg/better-cond", :test-namespaces (better-cond.core-test)} + org.clojars.askonomm/ruuter {:git-sha "78659212f95cac827efc816dfbdab8181c25fc3d", :git-url "https://github.com/askonomm/ruuter", :test-namespaces (ruuter.core-test)} + ;; clojure.data.json-gen-test ommitted from test-namespaces b/c it hangs on stest/check + org.clojure/data.json {:git-sha "9f1c9ccf3fd3e5a39cfb7289d3d456e842ddf442", :git-url "https://github.com/clojure/data.json", :test-namespaces (clojure.data.json-test clojure.data.json-test-suite-test clojure.data.json-compat-0-1-test)} + io.replikativ/hasch {:git-sha "04d9c0bd34d86bad79502d8a6963eb2525a22b15", :git-url "https://github.com/replikativ/hasch", :test-namespaces (hasch.test)}} diff --git a/test-resources/lib_tests/better_cond/core_test.cljc b/test-resources/lib_tests/better_cond/core_test.cljc index efb9f5db..455a552b 100644 --- a/test-resources/lib_tests/better_cond/core_test.cljc +++ b/test-resources/lib_tests/better_cond/core_test.cljc @@ -37,4 +37,5 @@ :when (even? 3) 2))) + diff --git a/test-resources/lib_tests/clojure/data/json_compat_0_1_test.clj b/test-resources/lib_tests/clojure/data/json_compat_0_1_test.clj new file mode 100644 index 00000000..67aa0f70 --- /dev/null +++ b/test-resources/lib_tests/clojure/data/json_compat_0_1_test.clj @@ -0,0 +1,226 @@ +;; Copyright (c) Stuart Sierra, 2012. All rights reserved. The use and +;; distribution terms for this software are covered by the Eclipse +;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) +;; By using this software in any fashion, you are agreeing to be bound +;; by the terms of this license. You must not remove this notice, or +;; any other, from this software. + +(ns clojure.data.json-compat-0-1-test + "Compatibility tests for the 0.1.x data.json API." + (:use clojure.test + [clojure.data.json :only (read-json json-str pprint-json)])) + +(deftest can-read-from-pushback-reader + (let [s (java.io.PushbackReader. (java.io.StringReader. "42"))] + (is (= 42 (read-json s))))) + +(deftest can-read-from-reader + (let [s (java.io.StringReader. "42")] + (is (= 42 (read-json s))))) + +(deftest can-read-numbers + (is (= 42 (read-json "42"))) + (is (= -3 (read-json "-3"))) + (is (= 3.14159 (read-json "3.14159"))) + (is (= 6.022e23 (read-json "6.022e23")))) + +(deftest can-read-null + (is (= nil (read-json "null")))) + +(deftest can-read-strings + (is (= "Hello, World!" (read-json "\"Hello, World!\"")))) + +(deftest handles-escaped-slashes-in-strings + (is (= "/foo/bar" (read-json "\"\\/foo\\/bar\"")))) + +(deftest handles-unicode-escapes + (is (= " \u0beb " (read-json "\" \\u0bEb \"")))) + +(deftest handles-unicode-outside-bmp + (is (= "\"smiling face: \uD83D\uDE03\"" + (json-str "smiling face: \uD83D\uDE03" :escape-unicode false))) + (is (= "\"smiling face: \\ud83d\\ude03\"" + (json-str "smiling face: \uD83D\uDE03" :escape-unicode true)))) + +(deftest handles-escaped-whitespace + (is (= "foo\nbar" (read-json "\"foo\\nbar\""))) + (is (= "foo\rbar" (read-json "\"foo\\rbar\""))) + (is (= "foo\tbar" (read-json "\"foo\\tbar\"")))) + +(deftest can-read-booleans + (is (= true (read-json "true"))) + (is (= false (read-json "false")))) + +(deftest can-ignore-whitespace + (is (= nil (read-json "\r\n null")))) + +(deftest can-read-arrays + (is (= [1 2 3] (read-json "[1,2,3]"))) + (is (= ["Ole" "Lena"] (read-json "[\"Ole\", \r\n \"Lena\"]")))) + +(deftest can-read-objects + (is (= {:a 1, :b 2} (read-json "{\"a\": 1, \"b\": 2}")))) + +(deftest can-read-nested-structures + (is (= {:a [1 2 {:b [3 "four"]} 5.5]} + (read-json "{\"a\":[1,2,{\"b\":[3,\"four\"]},5.5]}")))) + +(deftest disallows-non-string-keys + (is (thrown? Exception (read-json "{26:\"z\"")))) + +(deftest disallows-barewords + (is (thrown? Exception (read-json " foo ")))) + +(deftest disallows-unclosed-arrays + (is (thrown? Exception (read-json "[1, 2, ")))) + +(deftest disallows-unclosed-objects + (is (thrown? Exception (read-json "{\"a\":1, ")))) + +(deftest can-get-string-keys + (is (= {"a" [1 2 {"b" [3 "four"]} 5.5]} + (read-json "{\"a\":[1,2,{\"b\":[3,\"four\"]},5.5]}" false true nil)))) + +(declare pass1-string) + +(deftest pass1-test + (let [input (read-json pass1-string false true nil)] + (is (= "JSON Test Pattern pass1" (first input))) + (is (= "array with 1 element" (get-in input [1 "object with 1 member" 0]))) + (is (= 1234567890 (get-in input [8 "integer"]))) + (is (= "rosebud" (last input))))) + +; from http://www.json.org/JSON_checker/test/pass1.json +(def pass1-string + "[ + \"JSON Test Pattern pass1\", + {\"object with 1 member\":[\"array with 1 element\"]}, + {}, + [], + -42, + true, + false, + null, + { + \"integer\": 1234567890, + \"real\": -9876.543210, + \"e\": 0.123456789e-12, + \"E\": 1.234567890E+34, + \"\": 23456789012E66, + \"zero\": 0, + \"one\": 1, + \"space\": \" \", + \"quote\": \"\\\"\", + \"backslash\": \"\\\\\", + \"controls\": \"\\b\\f\\n\\r\\t\", + \"slash\": \"/ & \\/\", + \"alpha\": \"abcdefghijklmnopqrstuvwyz\", + \"ALPHA\": \"ABCDEFGHIJKLMNOPQRSTUVWYZ\", + \"digit\": \"0123456789\", + \"0123456789\": \"digit\", + \"special\": \"`1~!@#$%^&*()_+-={':[,]}|;.?\", + \"hex\": \"\\u0123\\u4567\\u89AB\\uCDEF\\uabcd\\uef4A\", + \"true\": true, + \"false\": false, + \"null\": null, + \"array\":[ ], + \"object\":{ }, + \"address\": \"50 St. James Street\", + \"url\": \"http://www.JSON.org/\", + \"comment\": \"// /* */\": \" \", + \" s p a c e d \" :[1,2 , 3 + +, + +4 , 5 , 6 ,7 ],\"compact\":[1,2,3,4,5,6,7], + \"jsontext\": \"{\\\"object with 1 member\\\":[\\\"array with 1 element\\\"]}\", + \"quotes\": \"" \\u0022 %22 0x22 034 "\", + \"\\/\\\\\\\"\\uCAFE\\uBABE\\uAB98\\uFCDE\\ubcda\\uef4A\\b\\f\\n\\r\\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?\" +: \"A key can be any string\" + }, + 0.5 ,98.6 +, +99.44 +, + +1066, +1e1, +0.1e1, +1e-1, +1e00,2e+00,2e-00 +,\"rosebud\"]") + + +(deftest can-print-json-strings + (is (= "\"Hello, World!\"" (json-str "Hello, World!"))) + (is (= "\"\\\"Embedded\\\" Quotes\"" (json-str "\"Embedded\" Quotes")))) + +(deftest can-print-unicode + (is (= "\"\\u1234\\u4567\"" (json-str "\u1234\u4567")))) + +(deftest can-print-nonescaped-unicode + (is (= "\"\u1234\u4567\"" (json-str "\u1234\u4567" :escape-unicode false)))) + +(deftest can-print-json-null + (is (= "null" (json-str nil)))) + +(deftest can-print-ratios-as-doubles + (is (= "0.75" (json-str 3/4)))) + +(deftest can-print-bigints + (is (= "12345678901234567890" (json-str 12345678901234567890)))) + +(deftest can-print-json-arrays + (is (= "[1,2,3]" (json-str [1 2 3]))) + (is (= "[1,2,3]" (json-str (list 1 2 3)))) + (is (= "[1,2,3]" (json-str (sorted-set 1 2 3)))) + (is (= "[1,2,3]" (json-str (seq [1 2 3]))))) + +(deftest can-print-java-arrays + (is (= "[1,2,3]" (json-str (into-array [1 2 3]))))) + +(deftest can-print-empty-arrays + (is (= "[]" (json-str []))) + (is (= "[]" (json-str (list)))) + (is (= "[]" (json-str #{})))) + +(deftest can-print-json-objects + (is (= "{\"a\":1,\"b\":2}" (json-str (sorted-map :a 1 :b 2))))) + +(deftest object-keys-must-be-strings + (is (= "{\"1\":1,\"2\":2}" (json-str (sorted-map 1 1 2 2))))) + +(deftest can-print-empty-objects + (is (= "{}" (json-str {})))) + +(deftest accept-sequence-of-nils + (is (= "[null,null,null]" (json-str [nil nil nil])))) + +(deftest error-on-nil-keys + (is (thrown? Exception (json-str {nil 1})))) + +(deftest characters-in-symbols-are-escaped + (is (= "\"foo\\u1b1b\"" (json-str (symbol "foo\u1b1b"))))) + +(deftest default-throws-on-eof + (is (thrown? java.io.EOFException (read-json "")))) + +(deftest can-accept-eof + (is (= ::eof (read-json "" true false ::eof)))) + +(deftest characters-in-map-keys-are-escaped + (is (= (json-str {"\"" 42}) "{\"\\\"\":42}"))) + +;;; Pretty-printer + +(deftest pretty-printing + (let [x (read-json pass1-string false)] + (is (= x (read-json (with-out-str (pprint-json x)) false))))) + +(defn benchmark [] + (dotimes [_ 8] + (time + (dotimes [_ 100] + (assert (= (read-json pass1-string false) + (read-json (json-str (read-json pass1-string false)) false))))))) diff --git a/test-resources/lib_tests/clojure/data/json_gen_test.clj b/test-resources/lib_tests/clojure/data/json_gen_test.clj new file mode 100644 index 00000000..885d7aeb --- /dev/null +++ b/test-resources/lib_tests/clojure/data/json_gen_test.clj @@ -0,0 +1,34 @@ +(ns clojure.data.json-gen-test + (:require [clojure.data.json :as json] + [clojure.spec.alpha :as s] + [clojure.spec.gen.alpha :as sgen] + [clojure.spec.test.alpha :as stest] + [clojure.test :refer :all])) + +(s/def ::json-number + (s/with-gen + number? + #(sgen/one-of [(sgen/large-integer) (sgen/double* {:infinite? false :NaN? false})]))) + +(s/def ::json-scalar (s/or :boolean boolean? + :number ::json-number + :string string? + :nil nil?)) + +(s/def ::json-value (s/or :object ::json-object + :array ::json-array + :scalar ::json-scalar)) + +(s/def ::json-array (s/coll-of ::json-value :gen-max 12)) +(s/def ::json-object (s/map-of string? ::json-value + :gen-max 10)) + +(s/fdef json/write-str + :args (s/cat :json ::json-value) + :ret string? + :fn #(= (->> % :args :json (s/unform ::json-value)) + (json/read-str (-> % :ret)))) + +(deftest roundtrip + (let [results (stest/check `json/write-str)] + (is (every? nil? (mapv :failure results))))) diff --git a/test-resources/lib_tests/clojure/data/json_test.clj b/test-resources/lib_tests/clojure/data/json_test.clj index 9e905279..f07f5105 100644 --- a/test-resources/lib_tests/clojure/data/json_test.clj +++ b/test-resources/lib_tests/clojure/data/json_test.clj @@ -68,7 +68,7 @@ (deftest read-objects (is (= {:k1 1, :k2 2, :k3 3, :k4 4, :k5 5, :k6 6, :k7 7, :k8 8 - :k9 9, :k10 10, :k11 11, :k12 12, :k13 13, :k14 14, :k15 15, :k16 16} + :k9 9, :k10 10, :k11 11, :k12 12, :k13 13, :k14 14, :k15 15, :k16 16} (json/read-str "{\"k1\": 1, \"k2\": 2, \"k3\": 3, \"k4\": 4, \"k5\": 5, \"k6\": 6, \"k7\": 7, \"k8\": 8, \"k9\": 9, \"k10\": 10, \"k11\": 11, \"k12\": 12, @@ -241,6 +241,7 @@ roundtripped (java.util.UUID/fromString (json/read-str (json/write-str uid)))] (is (= uid roundtripped)))) +;; BB-TEST-PATCH: bb doesn't have SimpleDateFormat #_(def ^java.text.SimpleDateFormat date-format (doto (java.text.SimpleDateFormat. "dd-MM-yyyy hh:mm:ss") (.setTimeZone (java.util.TimeZone/getDefault)))) @@ -413,7 +414,7 @@ (is (= x (json/read-str (with-out-str (json/pprint x))))))) (deftest pretty-print-nonescaped-unicode - (is (= (str "\"\u1234\u4567\"" (System/lineSeparator)) + (is (= "\"\u1234\u4567\"\n" (with-out-str (json/pprint "\u1234\u4567" :escape-unicode false))))) diff --git a/test-resources/lib_tests/clojure_csv/test/core.clj b/test-resources/lib_tests/clojure_csv/test/core.clj index 7c2b3529..9713c302 100644 --- a/test-resources/lib_tests/clojure_csv/test/core.clj +++ b/test-resources/lib_tests/clojure_csv/test/core.clj @@ -109,7 +109,7 @@ (deftest reader-cases ;; reader will be created and closed in with-open, but used outside. ;; this is actually a java.io.IOException, but thrown at runtime so... - ;; TEST-FIX: bb throws IOException instead of RuntimeException + ;; BB-TEST-PATCH: bb throws IOException instead of RuntimeException (is (thrown? java.io.IOException (dorun (with-open [sr (StringReader. "a,b,c")] (parse-csv sr)))))) diff --git a/test-resources/lib_tests/clojure_csv/test/utils.clj b/test-resources/lib_tests/clojure_csv/test/utils.clj index 430ab085..0c350c6e 100644 --- a/test-resources/lib_tests/clojure_csv/test/utils.clj +++ b/test-resources/lib_tests/clojure_csv/test/utils.clj @@ -1,7 +1,7 @@ (ns clojure-csv.test.utils "Some whitebox testing of the private utility functions used in core." (:import [java.io StringReader]) - ;; TEST-FIX: Had to require since use caused conflict which bb failed on + ;; BB-TEST-PATCH: Had to require since use caused conflict which bb failed on (:require [clojure-csv.core]) (:use clojure.test clojure.java.io)) diff --git a/test-resources/lib_tests/environ/core_test.cljc b/test-resources/lib_tests/environ/core_test.cljc new file mode 100644 index 00000000..1280d338 --- /dev/null +++ b/test-resources/lib_tests/environ/core_test.cljc @@ -0,0 +1,65 @@ +(ns environ.core-test + (:require #?(:clj [clojure.java.io :as io]) + #?(:cljs [goog.object :as obj]) + [clojure.test :refer [deftest is testing]] + [environ.core :as environ])) + +#?(:cljs (def nodejs? (exists? js/require))) +#?(:cljs (def fs (when nodejs? (js/require "fs")))) +#?(:cljs (def process (when nodejs? (js/require "process")))) + +(defn- delete-file [f] + #?(:clj (.delete (io/file f)) + :cljs (when (.existsSync fs f) + (.unlinkSync fs f)))) + +(defn- get-env [x] + #?(:clj (System/getenv x) + :cljs (obj/get (.-env process) x))) + +#?(:clj (defn refresh-ns [] + (remove-ns 'environ.core) + ;; BB-TEST-PATCH: bb doesn't have *loaded-libs* + ; (dosync (alter @#'clojure.core/*loaded-libs* disj 'environ.core)) + (require 'environ.core))) + +#?(:clj (defn refresh-env [] + (refresh-ns) + (var-get (find-var 'environ.core/env)))) + +#?(:cljs (defn refresh-env [] + (set! environ/env (environ/read-env)) + environ/env)) + +#?(:cljs (defn- spit [f data] + (.writeFileSync fs f data))) + +(deftest test-env + (if #?(:clj true :cljs nodejs?) + (testing "JVM and Node.js environment" + (testing "env variables" + (let [env (refresh-env)] + (is (= (:user env) (get-env "USER"))) + (is (= (:java-arch env) (get-env "JAVA_ARCH"))))) + #?(:clj (testing "system properties" + (let [env (refresh-env)] + (is (= (:user-name env) (System/getProperty "user.name"))) + (is (= (:user-country env) (System/getProperty "user.country")))))) + (testing "env file" + (spit ".lein-env" (prn-str {:foo "bar"})) + (let [env (refresh-env)] + (is (= (:foo env) "bar")))) + (testing "env file with irregular keys" + (spit ".lein-env" (prn-str {:foo.bar "baz"})) + (let [env (refresh-env)] + (is (= (:foo-bar env) "baz")))) + (testing "env file with irregular keys" + (spit ".lein-env" "{:foo #=(str \"bar\" \"baz\")}") + (is (thrown? #?(:clj RuntimeException :cljs js/Error) (refresh-env)))) + (testing "env file with non-string values" + (spit ".lein-env" (prn-str {:foo 1 :bar :baz})) + (let [env (refresh-env)] + (is (= (:foo env) "1")) + (is (= (:bar env) ":baz"))))) + (testing "non Node.js environment" + (is (= environ/env {}))))) diff --git a/test-resources/lib_tests/environ/test/runner.cljs b/test-resources/lib_tests/environ/test/runner.cljs new file mode 100644 index 00000000..ca08446a --- /dev/null +++ b/test-resources/lib_tests/environ/test/runner.cljs @@ -0,0 +1,5 @@ +(ns environ.test.runner + (:require [doo.runner :refer-macros [doo-tests]] + [environ.core-test])) + +(doo-tests 'environ.core-test) diff --git a/test-resources/lib_tests/exoscale/coax_cljs_test_runner.cljs b/test-resources/lib_tests/exoscale/coax_cljs_test_runner.cljs new file mode 100644 index 00000000..242019aa --- /dev/null +++ b/test-resources/lib_tests/exoscale/coax_cljs_test_runner.cljs @@ -0,0 +1,5 @@ +(ns exoscale.coax.cljs-test-runner + (:require [doo.runner :refer-macros [doo-tests]] + [exoscale.coax-test])) + +(doo-tests 'exoscale.coax-test) diff --git a/test-resources/lib_tests/hasch/test.cljc b/test-resources/lib_tests/hasch/test.cljc index 48c3ba63..f8918e14 100644 --- a/test-resources/lib_tests/hasch/test.cljc +++ b/test-resources/lib_tests/hasch/test.cljc @@ -74,16 +74,18 @@ (is (= (edn-hash #{1 2 3 4}) '(42 216 217 238 97 125 210 112 2 83 128 62 82 47 119 14 59 95 246 107 191 138 251 102 201 52 9 132 96 243 199 223 218 81 88 130 165 214 125 48 222 30 64 233 101 122 196 84 11 93 186 26 92 225 203 161 196 98 186 138 174 118 244 248))) + ;; BB-TEST-PATCH: bb fails on commented record invocations with + ;; `No method in multimethod '-coerce' for dispatch value` (is (= #_(edn-hash (Bar. "hello")) #_(edn-hash (ic/incognito-reader {'hasch.test.Bar map->Bar} - (ic/incognito-writer {} (Bar. "hello")))) + (ic/incognito-writer {} (Bar. "hello")))) #_(edn-hash (ic/map->IncognitoTaggedLiteral (ic/incognito-writer {} (Bar. "hello")))) (edn-hash (ic/map->IncognitoTaggedLiteral {:tag 'hasch.test.Bar :value {:name "hello"}})) '(194 16 151 144 95 224 245 28 219 137 32 192 218 166 162 177 32 154 132 5 111 169 220 211 204 164 67 231 51 96 248 217 77 78 28 136 150 212 202 152 45 167 120 241 14 152 250 246 187 113 212 216 204 46 163 107 91 24 91 0 72 38 4 31))) (is (= (edn-hash #?(:cljs (js/Uint8Array. #js [1 2 3 42 149]) - :clj (byte-array [1 2 3 42 149]))) + :clj (byte-array [1 2 3 42 149]))) '(135 209 248 171 162 90 41 221 173 216 64 218 222 93 242 60 243 5 190 153 101 194 74 130 55 184 84 148 167 94 210 250 140 211 6 234 221 25 113 83 153 75 180 4 194 163 178 197 243 126 27 172 248 169 161 90 102 172 160 98 249 32 42 157))))) (deftest padded-coercion @@ -144,4 +146,3 @@ (def repl-env (reset! cemerick.austin.repls/browser-repl-env (cemerick.austin/repl-env))) (cemerick.austin.repls/cljs-repl repl-env)) - diff --git a/test-resources/lib_tests/reifyhealth/specmonstah/core_test.cljc b/test-resources/lib_tests/reifyhealth/specmonstah/core_test.cljc index 123e964a..3e3ddce6 100644 --- a/test-resources/lib_tests/reifyhealth/specmonstah/core_test.cljc +++ b/test-resources/lib_tests/reifyhealth/specmonstah/core_test.cljc @@ -10,6 +10,7 @@ [loom.attr :as lat])) (use-fixtures :each td/test-fixture) + (use-fixtures :once (fn [t] (stest/instrument) (t))) (defmacro is-graph= diff --git a/test-resources/lib_tests/ruuter/core_test.clj b/test-resources/lib_tests/ruuter/core_test.clj deleted file mode 100644 index 9260b0ab..00000000 --- a/test-resources/lib_tests/ruuter/core_test.clj +++ /dev/null @@ -1,26 +0,0 @@ -(ns ruuter.core-test - (:require [clojure.test :refer [deftest is testing]] - [org.httpkit.client :as client] - [org.httpkit.server :as server] - [ruuter.core :as ruuter])) - -(def routes [{:path "/" - :method :get - :response {:status 200 - :body "Hi there!"}} - {:path "/hello/:who" - :method :get - :response (fn [req] - {:status 200 - :body (str "Hello, " (:who (:params req)))})}]) - -(def port 8080) - -(deftest ruuter-with-httpkit-test - (let [stop-server (server/run-server #(ruuter/route routes %) {:port port}) - fetch #(:body (deref (client/get (str "http://localhost:" port %) {:as :text}) 500 nil)) - root-result (fetch "/") - hello-result (fetch "/hello/babashka")] - (stop-server) - (is (= "Hi there!" root-result)) - (is (= "Hello, babashka" hello-result)))) diff --git a/test-resources/lib_tests/ruuter/core_test.cljc b/test-resources/lib_tests/ruuter/core_test.cljc new file mode 100644 index 00000000..9f1df23f --- /dev/null +++ b/test-resources/lib_tests/ruuter/core_test.cljc @@ -0,0 +1,64 @@ +(ns ruuter.core-test + #?(:clj (:require [clojure.test :refer :all] + [ruuter.core :as ruuter])) + #?(:cljs (:require [cljs.test :refer-macros [deftest testing is]] + [ruuter.core :as ruuter]))) + + +(deftest path+uri->path-params-test + (let [testfn #'ruuter/path+uri->path-params] + (testing "No params returns an empty map" + (is (= {} + (testfn "/hello/world" "/hello/world")))) + (testing "Having a param returns a map accordingly" + (is (= {:who "world"} + (testfn "/hello/:who" "/hello/world")))) + (testing "Multiple params returns a map accordingly" + (is (= {:who "world" + :why "because"} + (testfn "/hello/:who/:why" "/hello/world/because")))) + (testing "Multiple params, but one is optional" + (is (= {:who "world"} + (testfn "/hello/:who/:why?" "/hello/world"))) + (is (= {:who "world" + :why "because"} + (testfn "/hello/:who/:why?" "/hello/world/because")))))) + + +(deftest match-route-test + (let [testfn #'ruuter/match-route] + (testing "Find a route that exists" + (is (= {:path "/hello" + :method :get + :response {:status 200 + :body "Hello."}} + (testfn [{:path "/hello" + :method :get + :response {:status 200 + :body "Hello."}}] "/hello" :get)))) + (testing "No route found" + (is (= nil + (testfn [] "/hello" :get)))))) + + +(deftest route+req->response-test + (let [testfn #'ruuter/route+req->response] + (testing "Returning a map when the response is a direct map" + (= {:status 200 + :body "Hello."} + (testfn {:path "/hello" + :response {:status 200 + :body "Hello."}} + {:uri "/hello"}))) + (testing "Returning a map via a fn when the response is a fn" + (= {:status 200 + :body "Hello, world."} + (testfn {:path "/hello/:who" + :response (fn [req] + {:status 200 + :body (str "Hello, " (:who (:params req)))})} + {:uri "/hello/world"}))) + (testing "Returning an error map when route is invalid" + (= {:status 404 + :body "Not found."} + (testfn nil {:uri "/hello"}))))) diff --git a/test-resources/lib_tests/table/core_test.clj b/test-resources/lib_tests/table/core_test.clj new file mode 100644 index 00000000..fa9d0fe5 --- /dev/null +++ b/test-resources/lib_tests/table/core_test.clj @@ -0,0 +1,368 @@ +(ns table.core-test + (:require clojure.string) + (:use clojure.test + table.core)) + +(defn unindent [string] + (clojure.string/replace (clojure.string/trim string) #"\n\s*" "\n")) + +(deftest test-table-prints-to-out + (is (= + (str (unindent + " + +---+---+ + | 1 | 2 | + +---+---+ + | 3 | 4 | + +---+---+ + ") "\n") + (with-out-str (table [["1" "2"] ["3" "4"]]))))) + +(deftest test-table-with-vecs-in-vec + (is (= + (unindent + " + +---+---+ + | 1 | 2 | + +---+---+ + | 3 | 4 | + +---+---+ + ") + (table-str [["1" "2"] ["3" "4"]])))) + +(deftest test-table-with-maps-in-vec + (is (= + (unindent + " + +---+---+ + | a | b | + +---+---+ + | 1 | 2 | + | 3 | 4 | + +---+---+ + ") + (table-str [{:a 1 :b 2} {:a 3 :b 4}])))) + +(deftest test-table-with-top-level-map + (is (= + (unindent + " + +-----+-------+ + | key | value | + +-----+-------+ + | :a | 1 | + | :b | 2 | + +-----+-------+ + ") + (table-str {:a 1 :b 2})))) + +(deftest test-table-with-top-level-vec + (is (= + (unindent + " + +-------+ + | value | + +-------+ + | 1 | + | 2 | + | 3 | + +-------+ + ") + (table-str [1 2 3])))) + +(deftest test-table-with-auto-width + (is (= + (unindent + " + +----+----+ + | a | b | + +----+----+ + | 11 | 22 | + | 3 | 4 | + +----+----+ + ") + (table-str [{:a 11 :b 22} {:a 3 :b 4}])))) + +(deftest test-table-with-non-string-values + (is (= + (unindent + " + +---+---+ + | 1 | 2 | + +---+---+ + | 3 | 4 | + +---+---+ + ") + (table-str [[1 2] [3 4]])))) + +(deftest test-table-with-string-keys + (is (= + (unindent + " + +---+ + | a | + +---+ + | 1 | + | 2 | + +---+ + ") + (table-str [{"a" 1} {"a" 2}])))) + +(deftest test-table-with-different-keys-per-row + (is (= + (unindent + " + +---+---+ + | a | b | + +---+---+ + | 1 | | + | | 2 | + +---+---+ + ") + (table-str [{:a 1} {:b 2}])))) + +(deftest test-table-with-lists-in-list + (is (= + (unindent + " + +---+---+ + | 1 | 2 | + +---+---+ + | 3 | 4 | + +---+---+ + ") + (table-str '((1 2) (3 4)))))) + +(deftest test-table-with-vecs-in-list + (is (= + (unindent + " + +---+---+ + | 1 | 2 | + +---+---+ + | 3 | 4 | + +---+---+ + ") + (table-str '([1 2] [3 4]))))) + +(deftest test-table-with-vecs-in-set + (is (= + (unindent + " + +---+---+ + | 3 | 4 | + +---+---+ + | 1 | 2 | + +---+---+ + ") + (table-str #{[1 2] [3 4]})))) + +(deftest test-table-with-nil-values + (is (= + (unindent + " + +---+ + | a | + +---+ + | | + +---+ + ") + (table-str [{:a nil}])))) + +(deftest test-table-with-nil + (is (= + (unindent + " + +--+ + | | + +--+ + +--+ + " + )))) + +(deftest test-table-with-org-style + (is (= + (unindent + " + |---+---| + | 1 | 2 | + |---+---| + | 3 | 4 | + |---+---| + ") + (table-str [[1 2] [3 4]] :style :org)))) + +(deftest test-table-with-unicode-style + (is (= + (unindent + " + ┌───┬───┐ + │ 1 │ 2 │ + ├───┼───┤ + │ 3 ╎ 4 │ + └───┴───┘ + ") + (table-str [[1 2] [3 4]] :style :unicode)))) + +(deftest test-table-with-unicode-3d-style + (is (= + (unindent + " + ┌───┬───╖ + │ 1 │ 2 ║ + ├───┼───╢ + │ 3 │ 4 ║ + ╘═══╧═══╝ + ") + (table-str [[1 2] [3 4]] :style :unicode-3d)))) + +(deftest test-table-with-markdown-style + (is (= + (str "\n" (unindent + " + | 10 | 20 | + |--- | ---| + | 3 | 4 | + ") "\n") + (table-str [[10 20] [3 4]] :style :github-markdown)))) + +(deftest test-table-with-custom-style + (is (= + (unindent + " + ┌────┬────╖ + │ 10 │ 20 ║ + ├────┼────╢ + │ 3 │ 4 ║ + ╘════╧════╝ + ") + (table-str [[10 20] [3 4]] :style {:top ["┌─" "─┬─" "─╖"] + :top-dash "─" + :middle ["├─" "─┼─" "─╢"] + :dash "─" + :bottom ["╘═" "═╧═" "═╝"] + :bottom-dash "═" + :header-walls ["│ " " │ " " ║"] + :body-walls ["│ " " │ " " ║"] })))) + +(deftest test-table-with-empty-cells + (is (= + (unindent + " + +--+---+ + | | 2 | + +--+---+ + | | 4 | + +--+---+ + ") + (table-str [["" "2"] ["" "4"]])))) + +(deftest test-table-with-fields-option-and-maps + (is (= + (unindent + " + +---+---+ + | b | a | + +---+---+ + | 2 | 1 | + | 4 | 3 | + +---+---+ + ") + (table-str '({:a 1 :b 2} {:a 3 :b 4}) :fields [:b :a])))) + +(deftest test-table-with-fields-option-and-incorrect-fields + (is (= + (unindent + " + +---+---+---+ + | b | a | c | + +---+---+---+ + | 2 | 1 | | + | 4 | 3 | | + +---+---+---+ + ") + (table-str [{:a 1 :b 2} {:a 3 :b 4}] :fields [:b :a :c])))) + +(deftest test-table-with-maps-in-vec + (is (= + (unindent + " + +---+---+ + | a | b | + +---+---+ + | 1 | 2 | + | 3 | 4 | + +---+---+ + 2 rows in set + ") + (table-str [{:a 1 :b 2} {:a 3 :b 4}] :desc true)))) + +(deftest test-table-with-sort-option-as-true + (is (= + (unindent + " + +----+----+ + | 1 | 2 | + +----+----+ + | :a | :b | + | :c | :d | + +----+----+ + ") + (table-str [[1 2] [:c :d] [:a :b]] :sort true)))) + +;; BB-TEST-PATCH: Intermittent failing test +#_(deftest test-table-with-sort-option-as-field-name + (is (= + (unindent + " + +----+----+ + | k | v | + +----+----+ + | :a | :b | + | :c | :d | + +----+----+ + ") + (table-str [[:k :v] [:c :d] [:a :b]] :sort :k)))) + +(deftest test-table-with-invalid-sort-option-as-field-name + (is (= + (unindent + " + +----+----+ + | k | v | + +----+----+ + | :c | :d | + | :a | :b | + +----+----+ + ") + (table-str [[:k :v] [:c :d] [:a :b]] :sort :invalid)))) + +(deftest test-table-escapes-newlines + (is (= + (unindent + (format + " + +---+------+ + | 1 | 2 | + +---+------+ + | 3 | 4%s5 | + +---+------+ + " + (char-escape-string \newline))) + (table-str [[1,2] [3, "4\n5"]])))) + +(deftest test-table-shortens-cell-longer-than-allowed-width + (is (= + (unindent + " + +--------+-----------------------------------------------------------------------------------------+ + | key | value | + +--------+-----------------------------------------------------------------------------------------+ + | :short | yep | + | :long | nooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo... | + +--------+-----------------------------------------------------------------------------------------+ + ") + (binding [table.width/*width* (delay 100)] (table-str {:short "yep" :long (apply str "n" (repeat 250 "o"))}))))) + +;(defn test-ns-hook [] +; (test-table-with-top-level-map)) diff --git a/test-resources/lib_tests/table/width_test.clj b/test-resources/lib_tests/table/width_test.clj new file mode 100644 index 00000000..3385ac8f --- /dev/null +++ b/test-resources/lib_tests/table/width_test.clj @@ -0,0 +1,28 @@ +(ns table.width-test + (:require [clojure.test :refer :all] + [table.width :refer :all])) + +(defn auto-resize [widths] + (binding [*width* (delay 238)] (auto-resize-widths widths))) + +; for max width of 238, 76 is the max-width-per-field for 3 fields +(deftest test-auto-resize-allows-over-max-field-to-get-width-from-under-max-fields + (is + (= + [74 74 80] + (auto-resize [74 74 88])))) + +(deftest test-auto-resize-leaves-under-max-fields-alone + (is + (= + [10 10 15] + (auto-resize [10 10 15])))) + +(deftest test-auto-resize-reduces-all-max-fields + (is + (= + [76 76 76] + (auto-resize [80 100 94])))) + +(deftest ensure-valid-width-when-getting-zero-from-stty-detect + (is (= 100 (table.width/ensure-valid-width 0)))) \ No newline at end of file