babashka/test-resources/lib_tests/progrock/core_test.clj
Gabriel Horner 665ae4dd97
Finish up library tests (#1120)
* Add tests for markdown-clj and tools.namespace

See comment for why only one markdown test could be run.
Closes #1069 and #1064

* Convert 10 test libs using add-libtest

Also improved add-libtest to only require maven artifact
and rely on clojars for getting git-url most of the time

* Convert 8 more test libs using add-libtest

Also updated table and added comment for newline test

* Fix doric test

* Disable tools.namespace test that fails on windows

* Added dozen manual test libs and converted 2 test libs

add-libtest.clj supports manually-added and test-directories options

* Converts last tests to test namespaces and write libraries.csv

* Add a number of library tests from projects.md

Also add more docs around adding test libs and tweak add script

* Use :sha for gitlib and older clojure cli

* Revert "Use :sha for gitlib and older clojure cli"

This reverts commit c663ab8368.

* Fix and disable failing tests

Disabled tests that fail consistently and fixed windows one
2021-12-29 16:35:14 +01:00

43 lines
1.7 KiB
Clojure

(ns progrock.core-test
(:require [clojure.test :refer :all]
[clojure.string :as str]
[progrock.core :as pr]))
(deftest test-progress-bar
(let [bar (pr/progress-bar 50)]
(is (= (:total bar) 50))
(is (= (:progress bar) 0))
(is (not (:done? bar)))))
(deftest test-tick
(let [bar (pr/progress-bar 50)]
(is (= (-> bar pr/tick :progress) 1))
(is (= (-> bar (pr/tick 16) :progress) 16))
(is (= (-> bar (pr/tick 5) pr/tick :progress) 6))))
(deftest test-done
(let [bar (pr/progress-bar 50)]
(is (-> bar pr/done :done?))))
(deftest test-render
(let [bar (pr/progress-bar 50)]
(is (= (pr/render bar)
" 0/50 0% [ ] ETA: --:--"))
(is (= (pr/render (pr/tick bar 25))
"25/50 50% [========================= ] ETA: 00:00"))
(is (= (pr/render (pr/tick bar 25) {:format "(:bar)", :length 10})
"(===== )"))
(is (= (pr/render (pr/tick bar 25) {:format "[:bar]", :complete \#, :incomplete \-})
"[#########################-------------------------]"))
(is (= (pr/render (pr/progress-bar 0))
"0/0 0% [ ] ETA: --:--"))))
(deftest test-print
(let [bar (pr/progress-bar 50)]
(is (= (with-out-str (pr/print bar))
"\r 0/50 0% [ ] ETA: --:--"))
(is (= (with-out-str (pr/print bar {:length 10}))
"\r 0/50 0% [ ] ETA: --:--"))
;; BB-TEST-PATCH: Make windows compatible
(is (= (str/trim (with-out-str (pr/print (pr/done bar) {:length 10})))
"0/50 0% [ ] ETA: --:--"))))