-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial version of expound alpha2 working with spec2
- Loading branch information
Showing
15 changed files
with
6,680 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Spec2 bugs | ||
|
||
A list of bugs in spec2. I will report them as spec2 gets more stable. | ||
|
||
### Using binding in spec fn | ||
|
||
```clojure | ||
;; make sure `n` is not defined | ||
(let [n 1] | ||
(s/def ::foobar #(< n %)) | ||
) | ||
;; Expected: no error | ||
;; Actual: 'Unable to resolve symbol: n in this context' | ||
``` | ||
|
||
Note: this might be doable with a different strategy e.g. | ||
|
||
```clojure | ||
(let [max-v 10] | ||
(s2/register ::foo | ||
(s2/resolve-spec `(s2/int-in 1 (inc ~max-v)))) | ||
(s2/valid? ::foo 20)) | ||
``` | ||
|
||
### Bug with s/nest | ||
|
||
```clojure | ||
(s/def :alt-spec/one-many-int (s/cat :bs (s/alt :one int? | ||
:many (s/nest (s/+ int?))))) | ||
|
||
(s/explain :alt-spec/one-many-int [["2"]]) | ||
;; Attempting to call unbound fn: #'clojure.core/unquote | ||
``` | ||
|
||
### Bug with using symbols in specs e.g. | ||
|
||
``` | ||
> (s/def ::is-foo #{foo}) | ||
:expound.alpha2.core-test/is-foo | ||
> (s/form ::is-foo) | ||
#{foo} | ||
> (s/explain ::is-foo 'foo) | ||
Success! | ||
nil | ||
> (s/def ::is-or #{or}) | ||
:expound.alpha2.core-test/is-or | ||
> (s/form ::is-or) | ||
#{clojure.core/or} | ||
> (s/explain ::is-or 'or) | ||
or - failed: #{clojure.core/or} spec: :expound.alpha2.core-test/is-or | ||
nil | ||
``` | ||
|
||
From Alex Miller: "there is actually a known issue around sets of symbols (kind of a collision with symbol as function reference, which need qualification)" | ||
|
||
### Bug with Clojure 1.9.0 | ||
|
||
`lein with-profile test-common,clj-1.9.0 test` fails (but moving to 1.10.0 works) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
(ns ^:no-doc expound.alpha2.ansi | ||
(:require [clojure.string :as string])) | ||
|
||
;; Copied from strictly-specking, since I see no reason | ||
;; to deviate from the colors displayed in figwheel | ||
;; https://github.com/bhauman/strictly-specking/blob/f102c9bd604f0c238a738ac9e2b1f6968fdfd2d8/src/strictly_specking/ansi_util.clj | ||
|
||
(def sgr-code | ||
"Map of symbols to numeric SGR (select graphic rendition) codes." | ||
{:none 0 | ||
:bold 1 | ||
:underline 3 | ||
:blink 5 | ||
:reverse 7 | ||
:hidden 8 | ||
:strike 9 | ||
:black 30 | ||
:red 31 | ||
:green 32 | ||
:yellow 33 | ||
:blue 34 | ||
:magenta 35 | ||
:cyan 36 | ||
:white 37 | ||
:fg-256 38 | ||
:fg-reset 39 | ||
:bg-black 40 | ||
:bg-red 41 | ||
:bg-green 42 | ||
:bg-yellow 43 | ||
:bg-blue 44 | ||
:bg-magenta 45 | ||
:bg-cyan 46 | ||
:bg-white 47 | ||
:bg-256 48 | ||
:bg-reset 49}) | ||
|
||
(def ^:dynamic *enable-color* false) | ||
|
||
(defn esc | ||
"Returns an ANSI escope string which will apply the given collection of SGR | ||
codes." | ||
[codes] | ||
(let [codes (map sgr-code codes codes) | ||
codes (string/join \; codes)] | ||
(str \u001b \[ codes \m))) | ||
|
||
(defn escape | ||
"Returns an ANSI escope string which will enact the given SGR codes." | ||
[& codes] | ||
(esc codes)) | ||
|
||
(defn sgr | ||
"Wraps the given string with SGR escapes to apply the given codes, then reset | ||
the graphics." | ||
[string & codes] | ||
(str (esc codes) string (escape :none))) | ||
|
||
(def ansi-code? sgr-code) | ||
|
||
(def ^:dynamic *print-styles* | ||
{:highlight [:bold] | ||
:good [:green] | ||
:good-pred [:green] | ||
:good-key [:green] | ||
:bad [:red] | ||
:bad-value [:red] | ||
:error-key [:red] | ||
:focus-key [:bold] | ||
:correct-key [:green] | ||
:header [:cyan] | ||
:footer [:cyan] | ||
:warning-key [:bold] | ||
:focus-path [:magenta] | ||
:message [:magenta] | ||
:pointer [:magenta] | ||
:none [:none]}) | ||
|
||
(defn resolve-styles [styles] | ||
(if-let [res (not-empty | ||
(mapcat #(or | ||
(when-let [res (*print-styles* %)] | ||
res) | ||
[%]) | ||
styles))] | ||
res | ||
;; fall back to bright | ||
[:bold])) | ||
|
||
(defn color [s & styles] | ||
(if *enable-color* | ||
(apply sgr s (resolve-styles styles)) | ||
s)) |
Oops, something went wrong.