From 92cdfe9e590db8ae78eef809a3c5fe685a13d68a Mon Sep 17 00:00:00 2001 From: Erik Rauer Date: Sun, 21 Mar 2021 00:39:25 -0500 Subject: [PATCH] Add a test for `string/indexof-char` This adds a test for the `string/indexof-char` instruction --- .../push/instructions/string_spec.clj | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/test/propeller/push/instructions/string_spec.clj b/test/propeller/push/instructions/string_spec.clj index c32ae2c..363f4fa 100644 --- a/test/propeller/push/instructions/string_spec.clj +++ b/test/propeller/push/instructions/string_spec.clj @@ -208,4 +208,27 @@ (defspec from-integer-spec 100 (prop/for-all [int gen/small-integer] - (check-from-integer int))) \ No newline at end of file + (check-from-integer int))) + + +;; string/indexof-char + +(defn check-indexof-char + [value char] + (let [start-state (-> state/empty-state + (state/push-to-stack :string value) + (state/push-to-stack :char char)) + end-state ((:string_indexof_char @core/instruction-table) start-state) + expected-result (string/index-of value char)] + (or + (and (not expected-result) + (= (state/peek-stack end-state :string) value) + (= (state/peek-stack end-state :char) char) + (state/empty-stack? end-state :integer)) + (= expected-result + (state/peek-stack end-state :integer))))) + +(defspec indexof-char-spec 100 + (prop/for-all [str gen/string + char gen/char] + (check-indexof-char str char))) \ No newline at end of file