@@ -10,9 +10,10 @@ import (
1010 "testing"
1111
1212 "github.com/davecgh/go-spew/spew"
13+ "github.com/zclconf/go-cty/cty"
14+
1315 "github.com/hashicorp/hcl/v2"
1416 hclJSON "github.com/hashicorp/hcl/v2/json"
15- "github.com/zclconf/go-cty/cty"
1617)
1718
1819func TestDecodeBody (t * testing.T ) {
@@ -681,6 +682,76 @@ func TestDecodeBody(t *testing.T) {
681682 },
682683 0 ,
683684 },
685+ {
686+ map [string ]interface {}{
687+ "foo" : map [string ]interface {}{
688+ "foo_type" : map [string ]interface {}{
689+ "foo_name" : map [string ]interface {}{
690+ "value" : "foo" ,
691+ },
692+ },
693+ },
694+ },
695+ makeInstantiateType (struct {
696+ Foo struct {
697+ Type string `hcl:"type,label"`
698+ TypeLabelRange hcl.Range `hcl:"type,label_range"`
699+ Name string `hcl:"name,label"`
700+ NameLabelRange hcl.Range `hcl:"name,label_range"`
701+
702+ DefRange hcl.Range `hcl:",def_range"`
703+ TypeRange hcl.Range `hcl:",type_range"`
704+
705+ Attribute string `hcl:"value,attr"`
706+ AttributeRange hcl.Range `hcl:"value,attr_range"`
707+ AttributeNameRange hcl.Range `hcl:"value,attr_name_range"`
708+ AttributeValueRange hcl.Range `hcl:"value,attr_value_range"`
709+ } `hcl:"foo,block"`
710+ }{}),
711+ deepEquals (struct {
712+ Foo struct {
713+ Type string `hcl:"type,label"`
714+ TypeLabelRange hcl.Range `hcl:"type,label_range"`
715+ Name string `hcl:"name,label"`
716+ NameLabelRange hcl.Range `hcl:"name,label_range"`
717+
718+ DefRange hcl.Range `hcl:",def_range"`
719+ TypeRange hcl.Range `hcl:",type_range"`
720+
721+ Attribute string `hcl:"value,attr"`
722+ AttributeRange hcl.Range `hcl:"value,attr_range"`
723+ AttributeNameRange hcl.Range `hcl:"value,attr_name_range"`
724+ AttributeValueRange hcl.Range `hcl:"value,attr_value_range"`
725+ } `hcl:"foo,block"`
726+ }{
727+ Foo : struct {
728+ Type string `hcl:"type,label"`
729+ TypeLabelRange hcl.Range `hcl:"type,label_range"`
730+ Name string `hcl:"name,label"`
731+ NameLabelRange hcl.Range `hcl:"name,label_range"`
732+
733+ DefRange hcl.Range `hcl:",def_range"`
734+ TypeRange hcl.Range `hcl:",type_range"`
735+
736+ Attribute string `hcl:"value,attr"`
737+ AttributeRange hcl.Range `hcl:"value,attr_range"`
738+ AttributeNameRange hcl.Range `hcl:"value,attr_name_range"`
739+ AttributeValueRange hcl.Range `hcl:"value,attr_value_range"`
740+ }{
741+ Type : "foo_type" ,
742+ TypeLabelRange : makeRange ("test.json" , 1 , 9 , 19 ),
743+ Name : "foo_name" ,
744+ NameLabelRange : makeRange ("test.json" , 1 , 21 , 31 ),
745+ DefRange : makeRange ("test.json" , 1 , 32 , 33 ),
746+ TypeRange : makeRange ("test.json" , 1 , 2 , 7 ),
747+ Attribute : "foo" ,
748+ AttributeRange : makeRange ("test.json" , 1 , 33 , 46 ),
749+ AttributeNameRange : makeRange ("test.json" , 1 , 33 , 40 ),
750+ AttributeValueRange : makeRange ("test.json" , 1 , 41 , 46 ),
751+ },
752+ }),
753+ 0 ,
754+ },
684755 }
685756
686757 for i , test := range tests {
@@ -811,3 +882,19 @@ func makeInstantiateType(target interface{}) func() interface{} {
811882 return reflect .New (reflect .TypeOf (target )).Interface ()
812883 }
813884}
885+
886+ func makeRange (filename string , line int , start , end int ) hcl.Range {
887+ return hcl.Range {
888+ Filename : filename ,
889+ Start : hcl.Pos {
890+ Line : line ,
891+ Column : start ,
892+ Byte : start - 1 ,
893+ },
894+ End : hcl.Pos {
895+ Line : line ,
896+ Column : end ,
897+ Byte : end - 1 ,
898+ },
899+ }
900+ }
0 commit comments