mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-12 17:27:50 +08:00
71cd3835bc
Qualified imports of pkg/tt outnumber unqualified (27 to 24). Improve consistency, and clarity, by changing the dot (unqualified) imports of that package symbols to qualified.
36 lines
826 B
Go
36 lines
826 B
Go
package eval
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"src.elv.sh/pkg/tt"
|
|
)
|
|
|
|
var Args = tt.Args
|
|
|
|
type opts struct {
|
|
Foo string
|
|
bar int
|
|
}
|
|
|
|
// Equal is required by cmp.Diff, since opts contains unexported fields.
|
|
func (o opts) Equal(p opts) bool { return o == p }
|
|
|
|
func TestScanOptions(t *testing.T) {
|
|
// A wrapper of ScanOptions, to make it easier to test
|
|
wrapper := func(src RawOptions, dstInit any) (any, error) {
|
|
ptr := reflect.New(reflect.TypeOf(dstInit))
|
|
ptr.Elem().Set(reflect.ValueOf(dstInit))
|
|
err := scanOptions(src, ptr.Interface())
|
|
return ptr.Elem().Interface(), err
|
|
}
|
|
|
|
tt.Test(t, tt.Fn("scanOptions", wrapper), tt.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"}),
|
|
})
|
|
}
|