babashka/test-resources/lib_tests/expound/paths_test.cljc
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

39 lines
1.2 KiB
Clojure

(ns expound.paths-test
(:require [clojure.test :as ct :refer [is deftest use-fixtures]]
[clojure.test.check.generators :as gen]
[com.gfredericks.test.chuck.clojure-test :refer [checking]]
[expound.paths :as paths]
[expound.test-utils :as test-utils]
[com.gfredericks.test.chuck :as chuck]))
(def num-tests 100)
(use-fixtures :once
test-utils/check-spec-assertions
test-utils/instrument-all)
(deftest compare-paths-test
(checking
"path to a key comes before a path to a value"
10
[k gen/simple-type-printable]
(is (= -1 (paths/compare-paths [(paths/->KeyPathSegment k)] [k])))
(is (= 1 (paths/compare-paths [k] [(paths/->KeyPathSegment k)])))))
(defn nth-value [form i]
(let [seq (remove map-entry? (tree-seq coll? seq form))]
(nth seq (mod i (count seq)))))
(deftest paths-to-value-test
(checking
"value-in is inverse of paths-to-value"
(chuck/times num-tests)
[form test-utils/any-printable-wo-nan
i gen/nat
:let [x (nth-value form i)
paths (paths/paths-to-value form x [] [])]]
(is (seq paths))
(doseq [path paths]
(is (= x
(paths/value-in form
path))))))