31 lines
682 B
Go
31 lines
682 B
Go
package ast
|
|
|
|
import (
|
|
"github.com/stretchr/testify/assert"
|
|
"monkey/internal/token"
|
|
"testing"
|
|
)
|
|
|
|
func TestString(t *testing.T) {
|
|
program := &Program{
|
|
Statements: []Statement{
|
|
&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",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
assert.Equal(t, "myVar:=anotherVar", program.String())
|
|
}
|