aboutsummaryrefslogtreecommitdiff
path: root/ast/ast_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'ast/ast_test.go')
-rw-r--r--ast/ast_test.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/ast/ast_test.go b/ast/ast_test.go
new file mode 100644
index 0000000..14a49dc
--- /dev/null
+++ b/ast/ast_test.go
@@ -0,0 +1,28 @@
+package ast
+
+import (
+ "monkey/token"
+ "testing"
+)
+
+func TestString(t *testing.T) {
+ program := &Program{
+ Statements: []Statement{
+ &LetStatement{
+ Token: token.Token{Type: token.LET, Literal: "let"},
+ Name: &Identifier{
+ Token: token.Token{Type: token.IDENT, Literal: "myVar"},
+ Value: "myVar",
+ },
+ Value: &Identifier{
+ Token: token.Token{Type: token.IDENT, Literal: "anotherVar"},
+ Value: "anotherVar",
+ },
+ },
+ },
+ }
+
+ if program.String() != "let myVar = anotherVar;" {
+ t.Errorf("program.String() wrong. got=%q", program.String())
+ }
+}