aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-03-22 23:18:01 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-03-22 23:18:01 +0100
commitdf5fe0927002868c32ddf7d2f604e31fb6fefe9c (patch)
treeb6b24590cfdd2fa3783d98e8a094ed704c34d18f
parent0c83ea39dfdf9f4509bfcfb00c73bb0f9984470c (diff)
Add testing
-rw-r--r--lexer_test.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/lexer_test.go b/lexer_test.go
new file mode 100644
index 0000000..1c64735
--- /dev/null
+++ b/lexer_test.go
@@ -0,0 +1,36 @@
+package main
+
+import "testing"
+
+func testInput(t *testing.T, s []string, ty int) {
+ for _, input := range s {
+ l := lex(input + "\n")
+ typ, s := l.Lex()
+ if input[0] == '\'' {
+ input = input[1 : len(input)-1]
+ }
+ if typ != ty || s != input {
+ t.Error("expeced", input, "got", s)
+ }
+ }
+}
+
+func TestInteger(t *testing.T) {
+ testInput(t, []string{"1", "¯1"}, INTEGER)
+}
+
+func TestFloat(t *testing.T) {
+ testInput(t, []string{"1.1", "¯1.1", "1e1", "¯1.1e1"}, FLOAT)
+}
+
+func TestComplex(t *testing.T) {
+ testInput(t, []string{"1.1J1", "¯1J1", "1J¯1.1", "¯1.1e1J¯1"}, COMPLEX)
+}
+
+func TestString(t *testing.T) {
+ testInput(t, []string{"abc"}, STRING)
+}
+
+func TestQuoted(t *testing.T) {
+ testInput(t, []string{"'abc''xyz'"}, QUOTED)
+}