Remove extra uses of let in native_tests.language

Tests of `let` itself remain.
This commit is contained in:
Kodi Arfer 2017-02-04 09:18:22 -08:00
parent d72abb39f1
commit b1df5d1428

View File

@ -449,51 +449,51 @@
(try (do) (except [IOError]) (except)) (try (do) (except [IOError]) (except))
;; Test correct (raise) ;; Test correct (raise)
(let [passed False] (setv passed False)
(try (try
(try (try
(raise IndexError) (raise IndexError)
(except [IndexError] (raise))) (except [IndexError] (raise)))
(except [IndexError] (except [IndexError]
(setv passed True))) (setv passed True)))
(assert passed)) (assert passed)
;; Test incorrect (raise) ;; Test incorrect (raise)
(let [passed False] (setv passed False)
(try (try
(raise) (raise)
;; Python 2 raises TypeError ;; Python 2 raises TypeError
;; Python 3 raises RuntimeError ;; Python 3 raises RuntimeError
(except [[TypeError RuntimeError]] (except [[TypeError RuntimeError]]
(setv passed True))) (setv passed True)))
(assert passed)) (assert passed)
;; Test (finally) ;; Test (finally)
(let [passed False] (setv passed False)
(try (try
(do) (do)
(finally (setv passed True))) (finally (setv passed True)))
(assert passed)) (assert passed)
;; Test (finally) + (raise) ;; Test (finally) + (raise)
(let [passed False] (setv passed False)
(try (try
(raise Exception) (raise Exception)
(except) (except)
(finally (setv passed True))) (finally (setv passed True)))
(assert passed)) (assert passed)
;; Test (finally) + (raise) + (else) ;; Test (finally) + (raise) + (else)
(let [passed False (setv passed False
not-elsed True] not-elsed True)
(try (try
(raise Exception) (raise Exception)
(except) (except)
(else (setv not-elsed False)) (else (setv not-elsed False))
(finally (setv passed True))) (finally (setv passed True)))
(assert passed) (assert passed)
(assert not-elsed)) (assert not-elsed)
(try (try
(raise (KeyError)) (raise (KeyError))
@ -553,37 +553,37 @@
(setv foobar42ofthebaz 42) (setv foobar42ofthebaz 42)
(assert (= foobar42ofthebaz 42)))) (assert (= foobar42ofthebaz 42))))
(let [passed False] (setv passed False)
(try (try
(try (do) (except) (else (bla))) (try (do) (except) (else (bla)))
(except [NameError] (setv passed True))) (except [NameError] (setv passed True)))
(assert passed)) (assert passed)
(let [x 0] (setv x 0)
(try (try
(raise IOError) (raise IOError)
(except [IOError] (except [IOError]
(setv x 45)) (setv x 45))
(else (setv x 44))) (else (setv x 44)))
(assert (= x 45))) (assert (= x 45))
(let [x 0] (setv x 0)
(try (try
(raise KeyError) (raise KeyError)
(except [] (except []
(setv x 45)) (setv x 45))
(else (setv x 44))) (else (setv x 44)))
(assert (= x 45))) (assert (= x 45))
(let [x 0] (setv x 0)
(try (try
(try (try
(raise KeyError) (raise KeyError)
(except [IOError] (except [IOError]
(setv x 45)) (setv x 45))
(else (setv x 44))) (else (setv x 44)))
(except)) (except))
(assert (= x 0)))) (assert (= x 0)))
(defn test-earmuffs [] (defn test-earmuffs []
"NATIVE: Test earmuffs" "NATIVE: Test earmuffs"
@ -677,9 +677,9 @@
(defn test-yield-in-try [] (defn test-yield-in-try []
"NATIVE: test yield in try" "NATIVE: test yield in try"
(defn gen [] (defn gen []
(let [x 1] (setv x 1)
(try (yield x) (try (yield x)
(finally (print x))))) (finally (print x))))
(setv output (list (gen))) (setv output (list (gen)))
(assert (= [1] output))) (assert (= [1] output)))
@ -747,17 +747,17 @@
(defn test-for-else [] (defn test-for-else []
"NATIVE: test for else" "NATIVE: test for else"
(let [x 0] (setv x 0)
(for* [a [1 2]] (for* [a [1 2]]
(setv x (+ x a)) (setv x (+ x a))
(else (setv x (+ x 50)))) (else (setv x (+ x 50))))
(assert (= x 53))) (assert (= x 53))
(let [x 0] (setv x 0)
(for* [a [1 2]] (for* [a [1 2]]
(setv x (+ x a)) (setv x (+ x a))
(else)) (else))
(assert (= x 3)))) (assert (= x 3)))
(defn test-list-comprehensions [] (defn test-list-comprehensions []
@ -921,35 +921,36 @@
(defn test-symbol-utf-8 [] (defn test-symbol-utf-8 []
"NATIVE: test symbol encoded" "NATIVE: test symbol encoded"
(let [ "love" (setv "love"
"flower"] "flower")
(assert (= (+ ) "flowerlove")))) (assert (= (+ ) "flowerlove")))
(defn test-symbol-dash [] (defn test-symbol-dash []
"NATIVE: test symbol encoded" "NATIVE: test symbol encoded"
(let [- "doublelove" (setv - "doublelove"
-_- "what?"] -_- "what?")
(assert (= - "doublelove")) (assert (= - "doublelove"))
(assert (= -_- "what?")))) (assert (= -_- "what?")))
(defn test-symbol-question-mark [] (defn test-symbol-question-mark []
"NATIVE: test foo? -> is_foo behavior" "NATIVE: test foo? -> is_foo behavior"
(let [foo? "nachos"] (setv foo? "nachos")
(assert (= is_foo "nachos")))) (assert (= is_foo "nachos")))
(defn test-and [] (defn test-and []
"NATIVE: test the and function" "NATIVE: test the and function"
(let [and123 (and 1 2 3)
(setv and123 (and 1 2 3)
and-false (and 1 False 3) and-false (and 1 False 3)
and-true (and) and-true (and)
and-single (and 1)] and-single (and 1))
(assert (= and123 3)) (assert (= and123 3))
(assert (= and-false False)) (assert (= and-false False))
(assert (= and-true True)) (assert (= and-true True))
(assert (= and-single 1))) (assert (= and-single 1))
; short circuiting ; short circuiting
(setv a 1) (setv a 1)
(and 0 (setv a 2)) (and 0 (setv a 2))
@ -980,16 +981,16 @@
(defn test-or [] (defn test-or []
"NATIVE: test the or function" "NATIVE: test the or function"
(let [or-all-true (or 1 2 3 True "string") (setv or-all-true (or 1 2 3 True "string")
or-some-true (or False "hello") or-some-true (or False "hello")
or-none-true (or False False) or-none-true (or False False)
or-false (or) or-false (or)
or-single (or 1)] or-single (or 1))
(assert (= or-all-true 1)) (assert (= or-all-true 1))
(assert (= or-some-true "hello")) (assert (= or-some-true "hello"))
(assert (= or-none-true False)) (assert (= or-none-true False))
(assert (= or-false None)) (assert (= or-false None))
(assert (= or-single 1))) (assert (= or-single 1))
; short circuiting ; short circuiting
(setv a 1) (setv a 1)
(or 1 (setv a 2)) (or 1 (setv a 2))
@ -1107,17 +1108,16 @@
(defn test-eval-globals [] (defn test-eval-globals []
"NATIVE: test eval with explicit global dict" "NATIVE: test eval with explicit global dict"
(assert (= 'bar (eval (quote foo) {'foo 'bar}))) (assert (= 'bar (eval (quote foo) {'foo 'bar})))
(assert (= 1 (let [d {}] (eval '(setv x 1) d) (eval (quote x) d)))) (assert (= 1 (do (setv d {}) (eval '(setv x 1) d) (eval (quote x) d))))
(let [d1 {} (setv d1 {} d2 {})
d2 {}] (eval '(setv x 1) d1)
(eval '(setv x 1) d1) (try
(try (do
(do ; this should fail with a name error
; this should fail with a name error (eval (quote x) d2)
(eval (quote x) d2) (assert False "We shouldn't have arrived here"))
(assert False "We shouldn't have arrived here")) (except [e Exception]
(except [e Exception] (assert (isinstance e NameError)))))
(assert (isinstance e NameError))))))
(defn test-eval-failure [] (defn test-eval-failure []
"NATIVE: test eval failure modes" "NATIVE: test eval failure modes"