hcl/ast/ast_test.go
Mitchell Hashimoto 59e0ca9d5a Start the decoder
2014-08-02 15:44:45 -07:00

73 lines
1.1 KiB
Go

package ast
import (
"reflect"
"testing"
)
func TestAssignmentNode_accept(t *testing.T) {
n := AssignmentNode{
K: "foo",
Value: LiteralNode{Value: "foo"},
}
expected := []Node{
n,
n.Value,
}
v := new(MockVisitor)
n.Accept(v)
if !reflect.DeepEqual(v.Nodes, expected) {
t.Fatalf("bad: %#v", v.Nodes)
}
}
func TestListNode_accept(t *testing.T) {
n := ListNode{
Elem: []Node{
LiteralNode{Value: "foo"},
LiteralNode{Value: "bar"},
},
}
expected := []Node{
n,
n.Elem[0],
n.Elem[1],
}
v := new(MockVisitor)
n.Accept(v)
if !reflect.DeepEqual(v.Nodes, expected) {
t.Fatalf("bad: %#v", v.Nodes)
}
}
func TestObjectNode_accept(t *testing.T) {
n := ObjectNode{
K: "foo",
Elem: []KeyedNode{
AssignmentNode{K: "foo", Value: LiteralNode{Value: "foo"}},
AssignmentNode{K: "bar", Value: LiteralNode{Value: "bar"}},
},
}
expected := []Node{
n,
n.Elem[0],
n.Elem[0].(AssignmentNode).Value,
n.Elem[1],
n.Elem[1].(AssignmentNode).Value,
}
v := new(MockVisitor)
n.Accept(v)
if !reflect.DeepEqual(v.Nodes, expected) {
t.Fatalf("bad: %#v", v.Nodes)
}
}