Proper special indent in let tests.
This commit is contained in:
parent
7abd8ffc2a
commit
9a8886a452
@ -64,16 +64,16 @@
|
|||||||
b "b")
|
b "b")
|
||||||
(let [a "x"
|
(let [a "x"
|
||||||
b "y"]
|
b "y"]
|
||||||
(assert (= (+ a b)
|
(assert (= (+ a b)
|
||||||
"xy"))
|
"xy"))
|
||||||
(let [a "z"]
|
(let [a "z"]
|
||||||
(assert (= (+ a b)
|
(assert (= (+ a b)
|
||||||
"zy")))
|
"zy")))
|
||||||
;; let-shadowed variable doesn't get clobbered.
|
;; let-shadowed variable doesn't get clobbered.
|
||||||
(assert (= (+ a b)
|
(assert (= (+ a b)
|
||||||
"xy")))
|
"xy")))
|
||||||
(let [q "q"]
|
(let [q "q"]
|
||||||
(assert (= q "q")))
|
(assert (= q "q")))
|
||||||
(assert (= a "a"))
|
(assert (= a "a"))
|
||||||
(assert (= b "b"))
|
(assert (= b "b"))
|
||||||
(assert (in "a" (.keys (vars))))
|
(assert (in "a" (.keys (vars))))
|
||||||
@ -85,86 +85,86 @@
|
|||||||
(let [a "a"
|
(let [a "a"
|
||||||
b "b"
|
b "b"
|
||||||
ab (+ a b)]
|
ab (+ a b)]
|
||||||
(assert (= ab "ab"))
|
(assert (= ab "ab"))
|
||||||
(let [c "c"
|
(let [c "c"
|
||||||
abc (+ ab c)]
|
abc (+ ab c)]
|
||||||
(assert (= abc "abc")))))
|
(assert (= abc "abc")))))
|
||||||
|
|
||||||
(defn test-let-early []
|
(defn test-let-early []
|
||||||
(setv a "a")
|
(setv a "a")
|
||||||
(let [q (+ a "x")
|
(let [q (+ a "x")
|
||||||
a 2 ; should not affect q
|
a 2 ; should not affect q
|
||||||
b 3]
|
b 3]
|
||||||
(assert (= q "ax"))
|
(assert (= q "ax"))
|
||||||
(let [q (* a b)
|
(let [q (* a b)
|
||||||
a (+ a b)
|
a (+ a b)
|
||||||
b (* a b)]
|
b (* a b)]
|
||||||
(assert (= q 6))
|
(assert (= q 6))
|
||||||
(assert (= a 5))
|
(assert (= a 5))
|
||||||
(assert (= b 15))))
|
(assert (= b 15))))
|
||||||
(assert (= a "a")))
|
(assert (= a "a")))
|
||||||
|
|
||||||
(defn test-let-special []
|
(defn test-let-special []
|
||||||
;; special forms in function position still work as normal
|
;; special forms in function position still work as normal
|
||||||
(let [, 1]
|
(let [, 1]
|
||||||
(assert (= (, , ,)
|
(assert (= (, , ,)
|
||||||
(, 1 1)))))
|
(, 1 1)))))
|
||||||
|
|
||||||
(defn test-let-quasiquote []
|
(defn test-let-quasiquote []
|
||||||
(setv a-symbol 'a)
|
(setv a-symbol 'a)
|
||||||
(let [a "x"]
|
(let [a "x"]
|
||||||
(assert (= a "x"))
|
(assert (= a "x"))
|
||||||
(assert (= 'a a-symbol))
|
(assert (= 'a a-symbol))
|
||||||
(assert (= `a a-symbol))
|
(assert (= `a a-symbol))
|
||||||
(assert (= `(foo ~a)
|
(assert (= `(foo ~a)
|
||||||
'(foo "x")))
|
'(foo "x")))
|
||||||
(assert (= `(foo `(bar a ~a ~~a))
|
(assert (= `(foo `(bar a ~a ~~a))
|
||||||
'(foo `(bar a ~a ~"x"))))
|
'(foo `(bar a ~a ~"x"))))
|
||||||
(assert (= `(foo ~@[a])
|
(assert (= `(foo ~@[a])
|
||||||
'(foo "x")))
|
'(foo "x")))
|
||||||
(assert (= `(foo `(bar [a] ~@[a] ~@~[a 'a `a] ~~@[a]))
|
(assert (= `(foo `(bar [a] ~@[a] ~@~[a 'a `a] ~~@[a]))
|
||||||
'(foo `(bar [a] ~@[a] ~@["x" a a] ~"x"))))))
|
'(foo `(bar [a] ~@[a] ~@["x" a a] ~"x"))))))
|
||||||
|
|
||||||
(defn test-let-except []
|
(defn test-let-except []
|
||||||
(let [foo 42
|
(let [foo 42
|
||||||
bar 33]
|
bar 33]
|
||||||
(assert (= foo 42))
|
(assert (= foo 42))
|
||||||
(try
|
(try
|
||||||
(do
|
(do
|
||||||
1/0
|
1/0
|
||||||
(assert False))
|
(assert False))
|
||||||
(except [foo Exception]
|
(except [foo Exception]
|
||||||
;; let bindings should work in except block
|
;; let bindings should work in except block
|
||||||
(assert (= bar 33))
|
(assert (= bar 33))
|
||||||
;; but exception bindings can shadow let bindings
|
;; but exception bindings can shadow let bindings
|
||||||
(assert (instance? Exception foo))))
|
(assert (instance? Exception foo))))
|
||||||
;; let binding did not get clobbered.
|
;; let binding did not get clobbered.
|
||||||
(assert (= foo 42))))
|
(assert (= foo 42))))
|
||||||
|
|
||||||
(defn test-let-mutation []
|
(defn test-let-mutation []
|
||||||
(setv foo 42)
|
(setv foo 42)
|
||||||
(setv error False)
|
(setv error False)
|
||||||
(let [foo 12
|
(let [foo 12
|
||||||
bar 13]
|
bar 13]
|
||||||
(assert (= foo 12))
|
(assert (= foo 12))
|
||||||
(setv foo 14)
|
(setv foo 14)
|
||||||
(assert (= foo 14))
|
(assert (= foo 14))
|
||||||
(del foo)
|
(del foo)
|
||||||
;; deleting a let binding should not affect others
|
;; deleting a let binding should not affect others
|
||||||
(assert (= bar 13))
|
(assert (= bar 13))
|
||||||
(try
|
(try
|
||||||
;; foo=42 is still shadowed, but the let binding was deleted.
|
;; foo=42 is still shadowed, but the let binding was deleted.
|
||||||
(do
|
(do
|
||||||
foo
|
foo
|
||||||
(assert False))
|
(assert False))
|
||||||
(except [le LookupError]
|
(except [le LookupError]
|
||||||
(setv error le)))
|
(setv error le)))
|
||||||
(setv foo 16)
|
(setv foo 16)
|
||||||
(assert (= foo 16))
|
(assert (= foo 16))
|
||||||
(setv [foo bar baz] [1 2 3])
|
(setv [foo bar baz] [1 2 3])
|
||||||
(assert (= foo 1))
|
(assert (= foo 1))
|
||||||
(assert (= bar 2))
|
(assert (= bar 2))
|
||||||
(assert (= baz 3)))
|
(assert (= baz 3)))
|
||||||
(assert error)
|
(assert error)
|
||||||
(assert (= foo 42))
|
(assert (= foo 42))
|
||||||
(assert (= baz 3)))
|
(assert (= baz 3)))
|
||||||
@ -172,40 +172,40 @@
|
|||||||
(defn test-let-break []
|
(defn test-let-break []
|
||||||
(for [x (range 3)]
|
(for [x (range 3)]
|
||||||
(let [done (odd? x)]
|
(let [done (odd? x)]
|
||||||
(if done (break))))
|
(if done (break))))
|
||||||
(assert (= x 1)))
|
(assert (= x 1)))
|
||||||
|
|
||||||
(defn test-let-continue []
|
(defn test-let-continue []
|
||||||
(let [foo []]
|
(let [foo []]
|
||||||
(for [x (range 10)]
|
(for [x (range 10)]
|
||||||
(let [odd (odd? x)]
|
(let [odd (odd? x)]
|
||||||
(if odd (continue))
|
(if odd (continue))
|
||||||
(.append foo x)))
|
(.append foo x)))
|
||||||
(assert (= foo [0 2 4 6 8]))))
|
(assert (= foo [0 2 4 6 8]))))
|
||||||
|
|
||||||
(defn test-let-yield []
|
(defn test-let-yield []
|
||||||
(defn grind []
|
(defn grind []
|
||||||
(yield 0)
|
(yield 0)
|
||||||
(let [a 1
|
(let [a 1
|
||||||
b 2]
|
b 2]
|
||||||
(yield a)
|
(yield a)
|
||||||
(yield b)))
|
(yield b)))
|
||||||
(assert (= (tuple (grind))
|
(assert (= (tuple (grind))
|
||||||
(, 0 1 2))))
|
(, 0 1 2))))
|
||||||
|
|
||||||
(defn test-let-return []
|
(defn test-let-return []
|
||||||
(defn get-answer []
|
(defn get-answer []
|
||||||
(let [answer 42]
|
(let [answer 42]
|
||||||
(return answer)))
|
(return answer)))
|
||||||
(assert (= (get-answer)
|
(assert (= (get-answer)
|
||||||
42)))
|
42)))
|
||||||
|
|
||||||
(defn test-let-import []
|
(defn test-let-import []
|
||||||
(let [types 6]
|
(let [types 6]
|
||||||
;; imports don't fail, even if using a let-bound name
|
;; imports don't fail, even if using a let-bound name
|
||||||
(import types)
|
(import types)
|
||||||
;; let-bound name is not affected
|
;; let-bound name is not affected
|
||||||
(assert (= types 6)))
|
(assert (= types 6)))
|
||||||
;; import happened in Python scope.
|
;; import happened in Python scope.
|
||||||
(assert (in "types" (vars)))
|
(assert (in "types" (vars)))
|
||||||
(assert (instance? types.ModuleType types)))
|
(assert (instance? types.ModuleType types)))
|
||||||
@ -213,13 +213,13 @@
|
|||||||
(defn test-let-defclass []
|
(defn test-let-defclass []
|
||||||
(let [Foo 42
|
(let [Foo 42
|
||||||
quux object]
|
quux object]
|
||||||
;; the name of the class is just a symbol, even if it's a let binding
|
;; the name of the class is just a symbol, even if it's a let binding
|
||||||
(defclass Foo [quux] ; let bindings apply in inheritance list
|
(defclass Foo [quux] ; let bindings apply in inheritance list
|
||||||
;; let bindings apply inside class body
|
;; let bindings apply inside class body
|
||||||
(setv x Foo)
|
(setv x Foo)
|
||||||
;; quux is not local
|
;; quux is not local
|
||||||
(setv quux "quux"))
|
(setv quux "quux"))
|
||||||
(assert (= quux "quux")))
|
(assert (= quux "quux")))
|
||||||
;; defclass always creates a python-scoped variable, even if it's a let binding name
|
;; defclass always creates a python-scoped variable, even if it's a let binding name
|
||||||
(assert (= Foo.x 42)))
|
(assert (= Foo.x 42)))
|
||||||
|
|
||||||
@ -229,82 +229,82 @@
|
|||||||
(let [a 1
|
(let [a 1
|
||||||
b []
|
b []
|
||||||
bar (fn [])]
|
bar (fn [])]
|
||||||
(setv bar.a 13)
|
(setv bar.a 13)
|
||||||
(assert (= bar.a 13))
|
(assert (= bar.a 13))
|
||||||
(setv (. bar a) 14)
|
(setv (. bar a) 14)
|
||||||
(assert (= bar.a 14))
|
(assert (= bar.a 14))
|
||||||
(assert (= a 1))
|
(assert (= a 1))
|
||||||
(assert (= b []))
|
(assert (= b []))
|
||||||
;; method syntax not affected
|
;; method syntax not affected
|
||||||
(.append b 2)
|
(.append b 2)
|
||||||
(assert (= b [2]))
|
(assert (= b [2]))
|
||||||
;; attrs access is not affected
|
;; attrs access is not affected
|
||||||
(assert (= foo.a 42))
|
(assert (= foo.a 42))
|
||||||
(assert (= (. foo a)
|
(assert (= (. foo a)
|
||||||
42))
|
42))
|
||||||
;; but indexing is
|
;; but indexing is
|
||||||
(assert (= (. [1 2 3]
|
(assert (= (. [1 2 3]
|
||||||
[a])
|
[a])
|
||||||
2))))
|
2))))
|
||||||
|
|
||||||
(defn test-let-positional []
|
(defn test-let-positional []
|
||||||
(let [a 0
|
(let [a 0
|
||||||
b 1
|
b 1
|
||||||
c 2]
|
c 2]
|
||||||
(defn foo [a b]
|
(defn foo [a b]
|
||||||
(, a b c))
|
(, a b c))
|
||||||
(assert (= (foo 100 200)
|
(assert (= (foo 100 200)
|
||||||
(, 100 200 2)))
|
(, 100 200 2)))
|
||||||
(setv c 300)
|
(setv c 300)
|
||||||
(assert (= (foo 1000 2000)
|
(assert (= (foo 1000 2000)
|
||||||
(, 1000 2000 300)))
|
(, 1000 2000 300)))
|
||||||
(assert (= a 0))
|
(assert (= a 0))
|
||||||
(assert (= b 1))
|
(assert (= b 1))
|
||||||
(assert (= c 300))))
|
(assert (= c 300))))
|
||||||
|
|
||||||
(defn test-let-rest []
|
(defn test-let-rest []
|
||||||
(let [xs 6
|
(let [xs 6
|
||||||
a 88
|
a 88
|
||||||
c 64
|
c 64
|
||||||
&rest 12]
|
&rest 12]
|
||||||
(defn foo [a b &rest xs]
|
(defn foo [a b &rest xs]
|
||||||
(-= a 1)
|
(-= a 1)
|
||||||
(setv xs (list xs))
|
(setv xs (list xs))
|
||||||
(.append xs 42)
|
(.append xs 42)
|
||||||
(, &rest a b c xs))
|
(, &rest a b c xs))
|
||||||
(assert (= xs 6))
|
(assert (= xs 6))
|
||||||
(assert (= a 88))
|
(assert (= a 88))
|
||||||
(assert (= (foo 1 2 3 4)
|
(assert (= (foo 1 2 3 4)
|
||||||
(, 12 0 2 64 [3 4 42])))
|
(, 12 0 2 64 [3 4 42])))
|
||||||
(assert (= xs 6))
|
(assert (= xs 6))
|
||||||
(assert (= c 64))
|
(assert (= c 64))
|
||||||
(assert (= a 88))))
|
(assert (= a 88))))
|
||||||
|
|
||||||
(defn test-let-kwargs []
|
(defn test-let-kwargs []
|
||||||
(let [kws 6
|
(let [kws 6
|
||||||
&kwargs 13]
|
&kwargs 13]
|
||||||
(defn foo [&kwargs kws]
|
(defn foo [&kwargs kws]
|
||||||
(, &kwargs kws))
|
(, &kwargs kws))
|
||||||
(assert (= kws 6))
|
(assert (= kws 6))
|
||||||
(assert (= (foo :a 1)
|
(assert (= (foo :a 1)
|
||||||
(, 13 {"a" 1})))))
|
(, 13 {"a" 1})))))
|
||||||
|
|
||||||
(defn test-let-optional []
|
(defn test-let-optional []
|
||||||
(let [a 1
|
(let [a 1
|
||||||
b 6
|
b 6
|
||||||
d 2]
|
d 2]
|
||||||
(defn foo [&optional [a a] b [c d]]
|
(defn foo [&optional [a a] b [c d]]
|
||||||
(, a b c))
|
(, a b c))
|
||||||
(assert (= (foo)
|
(assert (= (foo)
|
||||||
(, 1 None 2)))
|
(, 1 None 2)))
|
||||||
(assert (= (foo 10 20 30)
|
(assert (= (foo 10 20 30)
|
||||||
(, 10 20 30)))))
|
(, 10 20 30)))))
|
||||||
|
|
||||||
(defn test-let-closure []
|
(defn test-let-closure []
|
||||||
(let [count 0]
|
(let [count 0]
|
||||||
(defn +count [&optional [x 1]]
|
(defn +count [&optional [x 1]]
|
||||||
(+= count x)
|
(+= count x)
|
||||||
count))
|
count))
|
||||||
;; let bindings can still exist outside of a let body
|
;; let bindings can still exist outside of a let body
|
||||||
(assert (= 1 (+count)))
|
(assert (= 1 (+count)))
|
||||||
(assert (= 2 (+count)))
|
(assert (= 2 (+count)))
|
||||||
@ -323,9 +323,9 @@
|
|||||||
(let [a 1
|
(let [a 1
|
||||||
b (triple a)
|
b (triple a)
|
||||||
c (ap-triple)]
|
c (ap-triple)]
|
||||||
(assert (= (triple a)
|
(assert (= (triple a)
|
||||||
3))
|
3))
|
||||||
(assert (= (ap-triple)
|
(assert (= (ap-triple)
|
||||||
3))
|
3))
|
||||||
(assert (= b 3))
|
(assert (= b 3))
|
||||||
(assert (= c 3))))
|
(assert (= c 3))))
|
||||||
|
Loading…
Reference in New Issue
Block a user