bind expression (:=) instead of let
Some checks failed
Build / build (push) Successful in 10m26s
Test / build (push) Failing after 16m44s

This commit is contained in:
Chuck Smith
2024-03-21 17:43:03 -04:00
parent 66d5453ecc
commit 6282075e66
36 changed files with 425 additions and 583 deletions

View File

@@ -1,6 +1,7 @@
package ast
import (
"github.com/stretchr/testify/assert"
"monkey/token"
"testing"
)
@@ -8,21 +9,22 @@ import (
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",
&ExpressionStatement{
Token: token.Token{Type: token.IDENT, Literal: "myVar"},
Expression: &BindExpression{
Token: token.Token{Type: token.BIND, Literal: ":="},
Left: &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())
}
assert.Equal(t, "myVar:=anotherVar", program.String())
}