Add test for string/butlast

This adds a test for the `string/butlast` instruction
This commit is contained in:
Erik Rauer 2021-03-16 21:59:02 -05:00
parent 5c4d033c4f
commit e21ca24d9d

View File

@ -0,0 +1,27 @@
(ns propeller.push.instructions.string-spec
(:require
[clojure.test.check.generators :as gen]
[clojure.test.check.properties :as prop]
[clojure.test.check.clojure-test :as ct :refer [defspec]]
[propeller.push.state :as state]
[propeller.push.core :as core]
[propeller.push.instructions.string :as string]))
;; string/butlast
(defn check-butlast
[value]
(let [start-state (state/push-to-stack state/empty-state
:string
value)
end-state ((:string_butlast @core/instruction-table) start-state)
expected-result (apply str (butlast value))]
(= expected-result
(state/peek-stack end-state :string))))
(defspec butlast-spec 100
(prop/for-all [s gen/string]
(check-butlast s)))