Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:

jobs:
setup:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
Expand Down Expand Up @@ -48,7 +48,7 @@ jobs:
;;
esac
lint:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
Expand All @@ -71,7 +71,7 @@ jobs:
needs: setup
strategy:
matrix: ${{fromJson(needs.setup.outputs.matrix)}}
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
Expand Down Expand Up @@ -100,7 +100,7 @@ jobs:
env:
CMD: ${{ matrix.cmd }}
all-pr-checks:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
timeout-minutes: 10
needs: [test, lint]
steps:
Expand Down
5 changes: 5 additions & 0 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
["change" "version" "leiningen.release/bump-version"]
["vcs" "commit"]
["vcs" "push"]]
;; exclude ^:integration tests by default (e.g., ocsf-test/test-all-ocsf-versions requires Docker)
;; run them explicitly with: lein test :integration
:test-selectors {:default (complement :integration)
:integration :integration
:all (constantly true)}
:resource-paths ["resources"]
:profiles {:dev
{:resource-paths ["test-resources"]
Expand Down
18 changes: 14 additions & 4 deletions src/flanders/spec.clj
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,26 @@
map-kw))

SequenceOfType
(->spec' [{:keys [type]} ns f]
(->spec' [{:keys [type spec]} ns f]
(let [result-kw (keyword ns "seq-of")]
(eval `(s/def ~result-kw ~(f type (str ns "." "seq-of"))))
(eval `(s/coll-of ~result-kw))))
(let [coll-spec (eval `(s/coll-of ~result-kw))]
(if spec
(s/and-spec-impl [`(s/coll-of ~result-kw) `~spec]
[coll-spec spec]
nil)
coll-spec))))

SetOfType
(->spec' [{:keys [type]} ns f]
(->spec' [{:keys [type spec]} ns f]
(let [result-kw (keyword ns "set-of")]
(eval `(s/def ~result-kw ~(f type (str ns "." "set-of"))))
(eval `(s/coll-of ~result-kw :kind set?))))
(let [coll-spec (eval `(s/coll-of ~result-kw :kind set?))]
(if spec
(s/and-spec-impl [`(s/coll-of ~result-kw :kind set?) `~spec]
[coll-spec spec]
nil)
coll-spec))))

SignatureType
(->spec' [{:keys [parameters rest-parameter return]} ns f]
Expand Down
42 changes: 42 additions & 0 deletions test/flanders/spec_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,48 @@
(fs/->spec (f/set-of (f/set-of f/any-str)) "test-set")
#{#{"foo"}})))

(defn max-len [n]
(fn [coll] (<= (count coll) n)))

(deftest test-seq-of-with-spec
(testing "seq-of with custom spec predicate (max length)"
(is (s/valid?
(fs/->spec (f/seq-of f/any-str :spec #(<= (count %) 3))
"test-seq-spec-1")
["a" "b" "c"]))
(is ((complement s/valid?)
(fs/->spec (f/seq-of f/any-str :spec #(<= (count %) 3))
"test-seq-spec-2")
["a" "b" "c" "d"])))
(testing "seq-of with closure spec (e.g. from pred/max-len)"
(is (s/valid?
(fs/->spec (f/seq-of f/any-str :spec (max-len 2))
"test-seq-spec-closure-1")
["a" "b"]))
(is ((complement s/valid?)
(fs/->spec (f/seq-of f/any-str :spec (max-len 2))
"test-seq-spec-closure-2")
["a" "b" "c"])))
(testing "seq-of without spec still works"
(is (s/valid?
(fs/->spec (f/seq-of f/any-str) "test-seq-spec-3")
["a" "b" "c" "d"]))))

(deftest test-set-of-with-spec
(testing "set-of with custom spec predicate (max length)"
(is (s/valid?
(fs/->spec (f/set-of f/any-str :spec #(<= (count %) 2))
"test-set-spec-1")
#{"a" "b"}))
(is ((complement s/valid?)
(fs/->spec (f/set-of f/any-str :spec #(<= (count %) 2))
"test-set-spec-2")
#{"a" "b" "c"})))
(testing "set-of without spec still works"
(is (s/valid?
(fs/->spec (f/set-of f/any-str) "test-set-spec-3")
#{"a" "b" "c"}))))

(deftest sig-spec-test
(let [spec-key (fs/->spec (f/sig :parameters [(f/int)]) "foo")]
(is (match (s/describe spec-key)
Expand Down
Loading