added tests for lex function

This commit is contained in:
Richard Harrington 2013-07-08 17:27:03 -04:00
parent 76ad864291
commit 7b326c33f5
1 changed files with 41 additions and 3 deletions

View File

@ -2,6 +2,44 @@
(:require [clojure.test :refer :all]
[hs-robotwar.core :refer :all]))
(deftest a-test
(testing "FIXME, I fail."
(is (= 0 1))))
(deftest digit?-negative
(testing "not a digit"
(is (not (digit? \f)))))
(deftest digit?-char-positive
(testing "digit char"
(is (digit? "6"))))
(deftest digit?-str-positive
(testing "digit str"
(is (digit? \6))))
(deftest lex-simple
(testing "lexing of simple line"
(is (= (lex "IF DAMAGE # D GOTO MOVE")
[{:token "IF", :column 0}
{:token "DAMAGE", :column 3}
{:token "#", :column 10}
{:token "D", :column 12}
{:token "GOTO", :column 14}
{:token "MOVE", :column 19}]))))
(deftest lex-scrunched-chars
(testing "lexing with no whitespace between operators and operands"
(is (= (lex "AIM-17 TO AIM")
[{:token "AIM", :column 0}
{:token "-", :column 3}
{:token "17", :column 4}
{:token "TO", :column 7}
{:token "AIM", :column 10}]))))
(deftest lex-negative-numbers
(testing "lexing with unary negative operator"
(is (= (lex "IF X<-5 GOTO SCAN")
[{:token "IF", :column 0}
{:token "X", :column 3}
{:token "<", :column 4}
{:token "-5", :column 5}
{:token "GOTO", :column 8}
{:token "SCAN", :column 13}]))))