diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/test/lux/reader.clj | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/test/test/lux/reader.clj b/test/test/lux/reader.clj new file mode 100644 index 000000000..9b4954c5a --- /dev/null +++ b/test/test/lux/reader.clj @@ -0,0 +1,57 @@ +(ns text.lux.reader + (:use clojure.test) + (:require (lux [base :as & :refer [deftags |do return* return fail fail* |let |case]] + [reader :as &reader]) + :reload-all)) + +;; [Utils] +(def source (&reader/from "yolo" "lol\nmeme\nnyan cat\n\nlolcat")) +(def init-state (&/set$ &/$source source (&/init-state nil))) + +;; [Tests] +(deftest test-source-code-reading + (is (= 4 (&/|length source)))) + +(deftest test-text-reading + ;; Should be capable of recognizing literal texts. + (let [input "lo"] + (|case (&/run-state (&reader/read-text input) init-state) + (&/$Right state [cursor output]) + (is (= input output)) + + _ + (is false "Couldn't read.") + ))) + +(deftest test-regex-reading + ;; Should be capable of matching simple, grouping regex-patterns. + (|case (&/run-state (&reader/read-regex #"l(.)l") init-state) + (&/$Right state [cursor output]) + (is (= "lol" "lol")) + + _ + (is false "Couldn't read.") + )) + +(deftest test-regex2-reading + ;; Should be capable of matching double, grouping regex-patterns. + (|case (&/run-state (&reader/read-regex2 #"(.)(..)") init-state) + (&/$Right state [cursor [left right]]) + (is (and (= "l" left) + (= "ol" right))) + + _ + (is false "Couldn't read.") + )) + +(deftest test-regex+-reading + ;; Should be capable of matching multi-line regex-patterns. + (|case (&/run-state (&reader/read-regex+ #"(?is)^(.*?)(cat|$)") init-state) + (&/$Right state [cursor output]) + (is (= "lol\nmeme\nnyan " output)) + + _ + (is false "Couldn't read.") + )) + +;; (run-all-tests) |