Skip to content

Commit

Permalink
testdata, wit: correctly decode Resource TypeDefKind
Browse files Browse the repository at this point in the history
  • Loading branch information
ydnar committed Sep 23, 2023
1 parent e2359e9 commit fcfc107
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 30 deletions.
2 changes: 1 addition & 1 deletion testdata/cross-package-resource.wit.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
TypeDefs: map[string]*wit.TypeDef{
"r": &wit.TypeDef{
Name: &"r",
Kind: nil,
Kind: &wit.Resource{},
Owner: &wit.Interface{...},
Docs: wit.Docs{
Contents: "",
Expand Down
2 changes: 1 addition & 1 deletion testdata/name-both-resource-and-type.wit.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
TypeDefs: map[string]*wit.TypeDef{
"a": &wit.TypeDef{
Name: &"a",
Kind: nil,
Kind: &wit.Resource{},
Owner: &wit.Interface{...},
Docs: wit.Docs{
Contents: "",
Expand Down
4 changes: 2 additions & 2 deletions testdata/resources-empty.wit.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
TypeDefs: map[string]*wit.TypeDef{
"r1": &wit.TypeDef{
Name: &"r1",
Kind: nil,
Kind: &wit.Resource{},
Owner: &wit.Interface{...},
Docs: wit.Docs{
Contents: "",
Expand All @@ -16,7 +16,7 @@
Functions: map[string]*wit.Function{
"t1": &wit.Function{
Name: "t1",
Kind: &wit.Freestanding{},
Kind: &wit.Freestanding{...},
Params: []wit.Param{
wit.Param{
Name: "a",
Expand Down
4 changes: 2 additions & 2 deletions testdata/resources-multiple-returns-borrow.wit.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
TypeDefs: map[string]*wit.TypeDef{
"r1": &wit.TypeDef{
Name: &"r1",
Kind: nil,
Kind: &wit.Resource{},
Owner: &wit.Interface{...},
Docs: wit.Docs{
Contents: "",
Expand Down Expand Up @@ -50,7 +50,7 @@
},
"t1": &wit.Function{
Name: "t1",
Kind: &wit.Freestanding{},
Kind: &wit.Freestanding{...},
Params: []wit.Param{
wit.Param{
Name: "a",
Expand Down
4 changes: 2 additions & 2 deletions testdata/resources-multiple-returns-own.wit.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
TypeDefs: map[string]*wit.TypeDef{
"r1": &wit.TypeDef{
Name: &"r1",
Kind: nil,
Kind: &wit.Resource{},
Owner: &wit.Interface{...},
Docs: wit.Docs{
Contents: "",
Expand Down Expand Up @@ -59,7 +59,7 @@
},
"t1": &wit.Function{
Name: "t1",
Kind: &wit.Freestanding{},
Kind: &wit.Freestanding{...},
Params: []wit.Param{
wit.Param{
Name: "a",
Expand Down
4 changes: 2 additions & 2 deletions testdata/resources-multiple.wit.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
TypeDefs: map[string]*wit.TypeDef{
"r1": &wit.TypeDef{
Name: &"r1",
Kind: nil,
Kind: &wit.Resource{},
Owner: &wit.Interface{...},
Docs: wit.Docs{
Contents: "",
Expand Down Expand Up @@ -270,7 +270,7 @@
},
"t1": &wit.Function{
Name: "t1",
Kind: &wit.Freestanding{},
Kind: &wit.Freestanding{...},
Params: []wit.Param{
wit.Param{
Name: "a",
Expand Down
4 changes: 2 additions & 2 deletions testdata/resources-return-borrow.wit.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
TypeDefs: map[string]*wit.TypeDef{
"r1": &wit.TypeDef{
Name: &"r1",
Kind: nil,
Kind: &wit.Resource{},
Owner: &wit.Interface{...},
Docs: wit.Docs{
Contents: "",
Expand Down Expand Up @@ -46,7 +46,7 @@
},
"t1": &wit.Function{
Name: "t1",
Kind: &wit.Freestanding{},
Kind: &wit.Freestanding{...},
Params: []wit.Param{
wit.Param{
Name: "a",
Expand Down
4 changes: 2 additions & 2 deletions testdata/resources-return-own.wit.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
TypeDefs: map[string]*wit.TypeDef{
"r1": &wit.TypeDef{
Name: &"r1",
Kind: nil,
Kind: &wit.Resource{},
Owner: &wit.Interface{...},
Docs: wit.Docs{
Contents: "",
Expand Down Expand Up @@ -55,7 +55,7 @@
},
"t1": &wit.Function{
Name: "t1",
Kind: &wit.Freestanding{},
Kind: &wit.Freestanding{...},
Params: []wit.Param{
wit.Param{
Name: "a",
Expand Down
18 changes: 9 additions & 9 deletions testdata/resources.wit.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Kind: &wit.Constructor{
Type: &wit.TypeDef{
Name: &"c",
Kind: nil,
Kind: &wit.Resource{},
Owner: &wit.World{...},
Docs: wit.Docs{
Contents: "",
Expand Down Expand Up @@ -37,15 +37,15 @@
},
"a": &wit.TypeDef{
Name: &"a",
Kind: nil,
Kind: &wit.Resource{...},
Owner: &wit.World{...},
Docs: wit.Docs{
Contents: "",
},
},
"b": &wit.TypeDef{
Name: &"b",
Kind: nil,
Kind: &wit.Resource{...},
Owner: &wit.World{...},
Docs: wit.Docs{
Contents: "",
Expand All @@ -66,39 +66,39 @@
TypeDefs: map[string]*wit.TypeDef{
"a": &wit.TypeDef{
Name: &"a",
Kind: nil,
Kind: &wit.Resource{...},
Owner: &wit.Interface{...},
Docs: wit.Docs{
Contents: "",
},
},
"b": &wit.TypeDef{
Name: &"b",
Kind: nil,
Kind: &wit.Resource{...},
Owner: &wit.Interface{...},
Docs: wit.Docs{
Contents: "",
},
},
"c": &wit.TypeDef{
Name: &"c",
Kind: nil,
Kind: &wit.Resource{...},
Owner: &wit.Interface{...},
Docs: wit.Docs{
Contents: "",
},
},
"d": &wit.TypeDef{
Name: &"d",
Kind: nil,
Kind: &wit.Resource{...},
Owner: &wit.Interface{...},
Docs: wit.Docs{
Contents: "",
},
},
"e": &wit.TypeDef{
Name: &"e",
Kind: nil,
Kind: &wit.Resource{...},
Owner: &wit.Interface{...},
Docs: wit.Docs{
Contents: "",
Expand Down Expand Up @@ -308,7 +308,7 @@
TypeDefs: map[string]*wit.TypeDef{
"a": &wit.TypeDef{
Name: &"a",
Kind: nil,
Kind: &wit.Resource{...},
Owner: &wit.Interface{...},
Docs: wit.Docs{
Contents: "",
Expand Down
4 changes: 2 additions & 2 deletions testdata/resources1.wit.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
TypeDefs: map[string]*wit.TypeDef{
"r1": &wit.TypeDef{
Name: &"r1",
Kind: nil,
Kind: &wit.Resource{},
Owner: &wit.Interface{...},
Docs: wit.Docs{
Contents: "",
Expand Down Expand Up @@ -41,7 +41,7 @@
},
"t1": &wit.Function{
Name: "t1",
Kind: &wit.Freestanding{},
Kind: &wit.Freestanding{...},
Params: []wit.Param{
wit.Param{
Name: "a",
Expand Down
6 changes: 3 additions & 3 deletions testdata/world-top-level-resources.wit.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
TypeDefs: map[string]*wit.TypeDef{
"request": &wit.TypeDef{
Name: &"request",
Kind: nil,
Kind: &wit.Resource{},
Owner: &wit.Interface{...},
Docs: wit.Docs{
Contents: "",
},
},
"response": &wit.TypeDef{
Name: &"response",
Kind: nil,
Kind: &wit.Resource{...},
Owner: &wit.Interface{...},
Docs: wit.Docs{
Contents: "",
Expand Down Expand Up @@ -154,7 +154,7 @@
Functions: map[string]*wit.Function{
"handle": &wit.Function{
Name: "handle",
Kind: &wit.Freestanding{},
Kind: &wit.Freestanding{...},
Params: []wit.Param{
wit.Param{
Name: "some",
Expand Down
10 changes: 9 additions & 1 deletion wit/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,21 @@ type typeDefKindCodec struct {
v *TypeDefKind
}

func (c *typeDefKindCodec) DecodeString(s string) error {
switch s {
case "resource":
*c.v = &Resource{}
}
return nil
}

func (c *typeDefKindCodec) DecodeField(dec codec.Decoder, name string) error {
var err error
switch name {
case "record":
v := &Record{}
*c.v, err = v, dec.Decode(v)
case "resource":
case "resource": // TODO: this might not be necessary
v := &Resource{}
*c.v, err = v, dec.Decode(v)
case "handle":
Expand Down
3 changes: 2 additions & 1 deletion wit/golden_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package wit
import (
"flag"
"os"
"strings"
"testing"

"github.com/k0kubun/pp/v3"
Expand All @@ -17,7 +18,7 @@ func TestGoldenFiles(t *testing.T) {
p.SetColoringEnabled(false)

err := loadTestdata(func(path string, res *Resolve) error {
t.Run(path, func(t *testing.T) {
t.Run(strings.TrimPrefix(path, testdataDir), func(t *testing.T) {
data := p.Sprint(res)
compareOrWrite(t, path, data)
})
Expand Down
1 change: 1 addition & 0 deletions wit/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"strings"
"unsafe"

Check failure on line 7 in wit/resolve.go

View workflow job for this annotation

GitHub Actions / Test

"unsafe" imported and not used

"github.com/coreos/go-semver/semver"
)
Expand Down

0 comments on commit fcfc107

Please sign in to comment.