mirror of
https://github.com/russolsen/cloforth
synced 2024-11-16 19:48:23 +01:00
WIP: start to clean up tests
This commit is contained in:
parent
cccb028e61
commit
220e1feca8
1 changed files with 7 additions and 22 deletions
|
@ -1,8 +1,10 @@
|
|||
(ns cloforth.test.compiler
|
||||
(:use [cloforth.compiler :as c])
|
||||
(:use [clojure.test]))
|
||||
(:use [clojure.test])
|
||||
(:require [cloforth.environment :as env]))
|
||||
|
||||
(def starting-env {:ip 0 :stack [] :counter 0})
|
||||
|
||||
(def starting-env (env/make-env))
|
||||
|
||||
(defn inc-counter [env] (assoc env :counter (inc (:counter env))))
|
||||
|
||||
|
@ -11,39 +13,22 @@
|
|||
(defn ip-is [expected-value env] (is (= (:ip env) expected-value)))
|
||||
|
||||
(deftest execute-one-function
|
||||
(let [env (c/inner inc-counter starting-env)]
|
||||
(let [env (c/execute-program starting-env inc-counter)]
|
||||
(is (map? env))
|
||||
(is (= 1 (:counter env)))
|
||||
(is (= (:ip env) 0))))
|
||||
|
||||
(deftest execute-one-single-element-vector
|
||||
(let [env (c/inner [inc-counter] starting-env)]
|
||||
(let [env (c/execute-program starting-env [inc-counter])]
|
||||
(is (map? env))
|
||||
(is (= 1 (:counter env)))
|
||||
(is (= (:ip env) 0))))
|
||||
|
||||
(deftest execute-one-two-element-vector
|
||||
(let [env (c/inner [inc-counter inc-counter] starting-env)]
|
||||
(let [env (c/execute-program starting-env [inc-counter inc-counter])]
|
||||
(is (map? env))
|
||||
(is (= 2 (:counter env)))
|
||||
(is (= (:ip env) 0))))
|
||||
|
||||
(deftest ip-is-respected
|
||||
(let [this-env (assoc starting-env :ip 1)
|
||||
env (c/inner [dec-counter inc-counter dec-counter] this-env)]
|
||||
(is (map? env))
|
||||
(is (= -1 (:counter env)))
|
||||
(is (= (:ip env) 1))))
|
||||
|
||||
|
||||
(deftest execute-one-nested-vectors
|
||||
(let [env (c/inner [inc-counter [dec-counter] [inc-counter] inc-counter] starting-env)]
|
||||
(is (= 2 (:counter env))))
|
||||
(let [env (c/inner [inc-counter [dec-counter inc-counter] inc-counter] starting-env)]
|
||||
(is (= 2 (:counter env))))
|
||||
(let [env (c/inner [[inc-counter dec-counter inc-counter] [inc-counter]] starting-env)]
|
||||
(is (= 2 (:counter env))))
|
||||
#_(let [env (c/inner [[inc-counter [dec-counter [inc-counter]]] [inc-counter]] starting-env)]
|
||||
(is (= 2 (:counter env)))))
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue