mirror of
https://github.com/richardharrington/robotwar.git
synced 2024-10-31 20:09:53 +00:00
added tests for lex function
This commit is contained in:
parent
76ad864291
commit
7b326c33f5
@ -2,6 +2,44 @@
|
|||||||
(:require [clojure.test :refer :all]
|
(:require [clojure.test :refer :all]
|
||||||
[hs-robotwar.core :refer :all]))
|
[hs-robotwar.core :refer :all]))
|
||||||
|
|
||||||
(deftest a-test
|
(deftest digit?-negative
|
||||||
(testing "FIXME, I fail."
|
(testing "not a digit"
|
||||||
(is (= 0 1))))
|
(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}]))))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user