elvish/pkg/eval/options_test.go

31 lines
690 B
Go
Raw Normal View History

2018-02-15 17:16:41 +08:00
package eval
import (
"reflect"
"testing"
. "src.elv.sh/pkg/tt"
)
2018-02-15 17:16:41 +08:00
type opts struct {
Foo string
bar int
}
2018-02-15 17:16:41 +08:00
func TestScanOptions(t *testing.T) {
// A wrapper of ScanOptions, to make it easier to test
wrapper := func(src RawOptions, dstInit interface{}) (interface{}, error) {
ptr := reflect.New(reflect.TypeOf(dstInit))
ptr.Elem().Set(reflect.ValueOf(dstInit))
err := scanOptions(src, ptr.Interface())
return ptr.Elem().Interface(), err
}
Test(t, Fn("scanOptions", wrapper), Table{
Args(RawOptions{"foo": "lorem ipsum"}, opts{}).
Rets(opts{Foo: "lorem ipsum"}, nil),
Args(RawOptions{"bar": 20}, opts{bar: 10}).
Rets(opts{bar: 10}, UnknownOption{"bar"}),
})
2018-02-15 17:16:41 +08:00
}