mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-05 03:17:50 +08:00
31 lines
690 B
Go
31 lines
690 B
Go
package eval
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
. "src.elv.sh/pkg/tt"
|
|
)
|
|
|
|
type opts struct {
|
|
Foo string
|
|
bar int
|
|
}
|
|
|
|
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"}),
|
|
})
|
|
}
|