2025-01-13 19:51:49 -08:00
|
|
|
package ast
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
2025-01-13 19:56:56 -08:00
|
|
|
"code.jmug.me/jmug/compiler-in-go/pkg/token"
|
2025-01-13 19:51:49 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
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())
|
|
|
|
|
}
|
|
|
|
|
}
|