Skip to content

Commit

Permalink
[chore] add test, upgrade go-starlark version for aug-2023 (#21)
Browse files Browse the repository at this point in the history
* Update tests

* For newer starlark version
  • Loading branch information
hyorigo authored Aug 29, 2023
1 parent 03af9a8 commit 8d8af4b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
28 changes: 27 additions & 1 deletion convert/call_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,7 @@ func TestCustomStructInStarlark(t *testing.T) {
ReadMessage: b.String,
NumberChan: make(chan int, 10),
StarDict: starlark.NewDict(10),
DataBytes: []byte("hello world"),
}
_ = p.StarDict.SetKey(starlark.String("foo"), starlark.String("bar"))
return p
Expand Down Expand Up @@ -936,7 +937,7 @@ func TestCustomStructInStarlark(t *testing.T) {
{
name: "list prop fields",
codeSnippet: `fields = dir(pn); out = pn`,
checkEqual: getInterfaceStringSliceCompare("fields", []string{"Aging", "GetSecretKey", "Nothing", "SetCustomer", "SetSecretKey", "String", "age", "anything", "customer", "customer_ptr", "dict", "message_writer", "name", "nested_values", "nil_custom", "nil_person", "nil_string", "number_chan", "parent", "profile", "read_message", "tags"}),
checkEqual: getInterfaceStringSliceCompare("fields", []string{"Aging", "GetSecretKey", "Nothing", "SetCustomer", "SetSecretKey", "String", "age", "anything", "customer", "customer_ptr", "data", "dict", "message_writer", "name", "nested_values", "nil_custom", "nil_person", "nil_string", "number_chan", "parent", "profile", "read_message", "tags"}),
},
{
name: "read slice of string",
Expand Down Expand Up @@ -1028,6 +1029,30 @@ out = pn
return nil
},
},
{
name: "read bytes",
codeSnippet: `foo = pn.data; out = pn`,
checkEqual: func(_ *personStruct, m map[string]interface{}) error {
if v, ok := m["foo"]; !ok {
return fmt.Errorf(`expected "foo" to be in globals, but not found`)
} else if n, ok := v.([]byte); !ok {
return fmt.Errorf(`expected "foo" to be a []byte, but got %T`, v)
} else if !bytes.Equal(n, []byte("hello world")) {
return fmt.Errorf(`expected "foo" to be "hello world", but got %v`, n)
}
return nil
},
},
{
name: "write bytes",
codeSnippet: `pn.data = "aloha"; out = pn`,
checkEqual: func(p *personStruct, _ map[string]interface{}) error {
if !bytes.Equal(p.DataBytes, []byte("aloha")) {
return fmt.Errorf(`expected "data" to be "aloha", but got %v`, p.DataBytes)
}
return nil
},
},
{
name: "read string map field",
codeSnippet: `foo = pn.profile["email"]; out = pn`,
Expand Down Expand Up @@ -1305,6 +1330,7 @@ type personStruct struct {
NilPerson *personStruct `starlark:"nil_person"`
buffer bytes.Buffer `starlark:"-"`
StarDict *starlark.Dict `starlark:"dict"`
DataBytes []byte `starlark:"data"`
}

func (p *personStruct) String() string {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/1set/starlight

go 1.16

require go.starlark.net v0.0.0-20230718153141-1c3ac63bd217
require go.starlark.net v0.0.0-20230814145427-12f4cb8177e4
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.1 h1:JFrFEBb2xKufg6XkJsJr+WbKb4FQlURi5RUcBveYu9k=
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
go.starlark.net v0.0.0-20230718153141-1c3ac63bd217 h1:PZww6GnYa6qc38W5SJu0iPhSCmW+ca3MuNO1FVe6aPw=
go.starlark.net v0.0.0-20230718153141-1c3ac63bd217/go.mod h1:jxU+3+j+71eXOW14274+SmmuW82qJzl6iZSeqEtTGds=
go.starlark.net v0.0.0-20230814145427-12f4cb8177e4 h1:Ydko8M6UfXgvSpGOnbAjRMQDIvBheUsjBjkm6Azcpf4=
go.starlark.net v0.0.0-20230814145427-12f4cb8177e4/go.mod h1:jxU+3+j+71eXOW14274+SmmuW82qJzl6iZSeqEtTGds=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down

0 comments on commit 8d8af4b

Please sign in to comment.