bind expression (:=) instead of let
This commit is contained in:
@@ -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())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user