-
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
25ace7c
commit 8312d90
Showing
1 changed file
with
27 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
(ns sci.safety-test | ||
(:require | ||
[clojure.test :as test :refer [deftest is]] | ||
[sci.core :as sci :refer [eval-string]] | ||
[sci.test-utils :as tu])) | ||
|
||
(deftest iterate-max-test | ||
(when-not tu/native? | ||
(let [d (try (tu/eval* "(loop [i 1000] (if (zero? i) :done (recur (dec i))))" {:iterate-max 100}) | ||
(catch #?(:clj clojure.lang.ExceptionInfo :cljs ExceptionInfo) e | ||
(ex-data e)))] | ||
(is (= :sci.error/iterated-beyond-max (:type d))))) | ||
(is (thrown-with-msg? #?(:clj clojure.lang.ExceptionInfo :cljs ExceptionInfo) | ||
#"iteration" | ||
(tu/eval* "(reduce (fn [_ _]) (range 1000))" {:iterate-max 100}))) | ||
(is (thrown-with-msg? #?(:clj clojure.lang.ExceptionInfo :cljs ExceptionInfo) | ||
#"iteration" | ||
(tu/eval* "((fn pow [x n] (case n 1 x, (* x (pow x (dec n))))) 2 10)" {:iterate-max 10}))) | ||
(is (thrown-with-msg? #?(:clj clojure.lang.ExceptionInfo :cljs ExceptionInfo) | ||
#"iteration" | ||
(tu/eval* "(loop [i 1000] (if (zero? i) :done (recur (dec i))))" {:iterate-max 100}))) | ||
|
||
(is (= :done (tu/eval* "(loop [i 10] (if (zero? i) :done (recur (dec i))))" {:iterate-max 100}))) | ||
(is (= :done (tu/eval* "(loop [i 1000] (if (zero? i) :done (recur (dec i))))" {}))) | ||
|
||
(is (= 1024 (tu/eval* "((fn pow [x n] (case n 1 x, (* x (pow x (dec n))))) 2 10)" {:iterate 100}))) | ||
(is (= 1024 (tu/eval* "((fn pow [x n] (case n 1 x, (* x (pow x (dec n))))) 2 10)" {})))) |