github.com/oweisse/u-root@v0.0.0-20181109060735-d005ad25fef1/cmds/elvish/eval/raw_options_test.go (about)

     1  package eval
     2  
     3  import "testing"
     4  
     5  type opts struct {
     6  	FooBar string
     7  	POSIX  bool `name:"posix"`
     8  	Min    int
     9  }
    10  
    11  var scanTests = []struct {
    12  	rawOpts  RawOptions
    13  	preScan  opts
    14  	postScan opts
    15  }{
    16  	{RawOptions{"foo-bar": "lorem ipsum"},
    17  		opts{}, opts{FooBar: "lorem ipsum"}},
    18  	{RawOptions{"posix": true},
    19  		opts{}, opts{POSIX: true}},
    20  }
    21  
    22  func TestScan(t *testing.T) {
    23  	for _, test := range scanTests {
    24  		opts := test.preScan
    25  		test.rawOpts.Scan(&opts)
    26  		if opts != test.postScan {
    27  			t.Errorf("Scan %v => %v, want %v", test.rawOpts, opts, test.postScan)
    28  		}
    29  	}
    30  }