From 2008712e0afc857cdfccb4f32da74f022bc9dc56 Mon Sep 17 00:00:00 2001 From: Erik Rauer Date: Thu, 18 Mar 2021 22:48:15 -0500 Subject: [PATCH] Add test for `string/first` This adds a test for the `string/first` instruction --- .../push/instructions/string_spec.clj | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/test/propeller/push/instructions/string_spec.clj b/test/propeller/push/instructions/string_spec.clj index 18af4b2..e9e0f6a 100644 --- a/test/propeller/push/instructions/string_spec.clj +++ b/test/propeller/push/instructions/string_spec.clj @@ -128,4 +128,24 @@ (defspec empty-string-spec 100 (prop/for-all [str gen/string] - (check-empty-string str))) \ No newline at end of file + (check-empty-string str))) + + +;; string/first + +(defn check-first + [value] + (let [start-state (state/push-to-stack state/empty-state :string value) + end-state ((:string_first @core/instruction-table) start-state) + expected-result (first value)] + (or + (and (empty? value) + (= (state/peek-stack end-state :string) value) + (state/empty-stack? end-state :char)) + (and (= expected-result + (state/peek-stack end-state :char)) + (state/empty-stack? end-state :string))))) + +(defspec first-spec 100 + (prop/for-all [str gen/string] + (check-first str))) \ No newline at end of file