Skip to content
Browse files

tests around bf parser

  • Loading branch information...
1 parent 292a210 commit 644dfa553b0a5121827e762bacd8daacbd0bdbbe @youngnh committed Feb 7, 2011
Showing with 29 additions and 1 deletion.
  1. +2 −1 src/parsatron/languages/bf.clj
  2. +27 −0 test/parsatron/languages/test_bf.clj
View
3 src/parsatron/languages/bf.clj
@@ -11,4 +11,5 @@
(between (char \[) (char \]) (many (instruction)))))
(defparser bf []
- (many (instruction)))
+ (many (instruction))
+ (eof))
View
27 test/parsatron/languages/test_bf.clj
@@ -0,0 +1,27 @@
+(ns parsatron.languages.test-bf
+ (:use [the.parsatron]
+ [parsatron.languages.bf]
+ [clojure.test]))
+
+(deftest test-accepts-valid-brainf*ck
+ (are [input] (try
+ (run (bf) input)
+ true
+ (catch Exception _
+ false))
+ ">"
+ "<"
+ "+"
+ "-"
+ "."
+ ","
+ "[+]"
+ ",>++++++[<-------->-],[<+>-]<."))
+
+(deftest test-rejects-invalid-brainf*ck
+ (are [input] (thrown? RuntimeException (run (bf) input))
+ "a"
+ "abc"
+ "[+"
+ "]"
+ "[+>[+]"))

0 comments on commit 644dfa5

Please sign in to comment.
Something went wrong with that request. Please try again.