fix panic on decode of "t=0t d{}"
This commit is contained in:
parent
352bb4b5e3
commit
6816a5c3fb
@ -338,11 +338,8 @@ func TestDecode_interfaceInline(t *testing.T) {
|
||||
Err bool
|
||||
Out interface{}
|
||||
}{
|
||||
{
|
||||
"t t e{{}}",
|
||||
true,
|
||||
nil,
|
||||
},
|
||||
{"t t e{{}}", true, nil},
|
||||
{"t=0t d {}", true, map[string]interface{}{"t": 0}},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
|
@ -133,6 +133,12 @@ type ObjectItem struct {
|
||||
}
|
||||
|
||||
func (o *ObjectItem) Pos() token.Pos {
|
||||
// I'm not entirely sure what causes this, but removing this causes
|
||||
// a test failure. We should investigate at some point.
|
||||
if len(o.Keys) == 0 {
|
||||
return token.Pos{}
|
||||
}
|
||||
|
||||
return o.Keys[0].Pos()
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,8 @@ import (
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
|
||||
"github.com/hashicorp/hcl/hcl/ast"
|
||||
"github.com/hashicorp/hcl/hcl/token"
|
||||
)
|
||||
@ -338,12 +340,15 @@ func TestParse_inline(t *testing.T) {
|
||||
Err bool
|
||||
}{
|
||||
{"t t e{{}}", true},
|
||||
{"o{{}}", true},
|
||||
{"t t e d N{{}}", true},
|
||||
{"t t e d{{}}", true},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
_, err := Parse([]byte(tc.Value))
|
||||
ast, err := Parse([]byte(tc.Value))
|
||||
if (err != nil) != tc.Err {
|
||||
t.Fatalf("Input: %q\n\nError: %s", tc.Value, err)
|
||||
t.Fatalf("Input: %q\n\nError: %s\n\nAST: %s", tc.Value, err, spew.Sdump(ast))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user