mirror of
https://github.com/janet-lang/janet
synced 2025-01-08 06:30:28 +00:00
Merge branch 'master' into compile-opt
This commit is contained in:
commit
0fb1773c19
@ -154,11 +154,6 @@
|
|||||||
,v
|
,v
|
||||||
(,error ,(if err err (string/format "assert failure in %j" x))))))
|
(,error ,(if err err (string/format "assert failure in %j" x))))))
|
||||||
|
|
||||||
(defmacro assertf
|
|
||||||
"Convenience macro that combines `assert` and `string/format`."
|
|
||||||
[x & args]
|
|
||||||
~(as-macro ,assert ,x (,string/format ,;args)))
|
|
||||||
|
|
||||||
(defmacro defdyn
|
(defmacro defdyn
|
||||||
``Define an alias for a keyword that is used as a dynamic binding. The
|
``Define an alias for a keyword that is used as a dynamic binding. The
|
||||||
alias is a normal, lexically scoped binding that can be used instead of
|
alias is a normal, lexically scoped binding that can be used instead of
|
||||||
@ -210,14 +205,14 @@
|
|||||||
(error (string/format fmt ;args)))
|
(error (string/format fmt ;args)))
|
||||||
|
|
||||||
(defmacro assertf
|
(defmacro assertf
|
||||||
"Throw an error if x is not truthy. Will not evaluate `err` if x is truthy."
|
"Convenience macro that combines `assert` and `string/format`."
|
||||||
[x fmt & args]
|
[x fmt & args]
|
||||||
(def v (gensym))
|
(def v (gensym))
|
||||||
~(do
|
~(do
|
||||||
(def ,v ,x)
|
(def ,v ,x)
|
||||||
(if ,v
|
(if ,v
|
||||||
,v
|
,v
|
||||||
(,error (,string/format ,fmt ,;args)))))
|
(,errorf ,fmt ,;args))))
|
||||||
|
|
||||||
(defmacro default
|
(defmacro default
|
||||||
``Define a default value for an optional argument.
|
``Define a default value for an optional argument.
|
||||||
|
@ -998,11 +998,10 @@
|
|||||||
(setdyn *debug* nil)
|
(setdyn *debug* nil)
|
||||||
|
|
||||||
# issue #1516
|
# issue #1516
|
||||||
(assert (assertf true) "assertf 1 argument")
|
(assert-error "assertf 1 argument" (macex '(assertf true)))
|
||||||
(assert (assertf true "fun message") "assertf 2 arguments")
|
(assert (assertf true "fun message") "assertf 2 arguments")
|
||||||
(assert (assertf true "%s message" "mystery") "assertf 3 arguments")
|
(assert (assertf true "%s message" "mystery") "assertf 3 arguments")
|
||||||
(assert (assertf (not nil) "%s message" "ordinary") "assertf not nil")
|
(assert (assertf (not nil) "%s message" "ordinary") "assertf not nil")
|
||||||
(assert-error "assertf error 1" (assertf false))
|
|
||||||
(assert-error "assertf error 2" (assertf false "fun message"))
|
(assert-error "assertf error 2" (assertf false "fun message"))
|
||||||
(assert-error "assertf error 3" (assertf false "%s message" "mystery"))
|
(assert-error "assertf error 3" (assertf false "%s message" "mystery"))
|
||||||
(assert-error "assertf error 4" (assertf nil "%s %s" "alice" "bob"))
|
(assert-error "assertf error 4" (assertf nil "%s %s" "alice" "bob"))
|
||||||
|
Loading…
Reference in New Issue
Block a user