Skip to content

Commit

Permalink
nvim: add OptionsInfo testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
zchee committed Dec 30, 2020
1 parent 4517f53 commit 8b755b9
Showing 1 changed file with 115 additions and 0 deletions.
115 changes: 115 additions & 0 deletions nvim/nvim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func TestAPI(t *testing.T) {
t.Run("Context", testContext(t, v))
t.Run("Extmarks", testExtmarks(t, v))
t.Run("RuntimeFiles", testRuntimeFiles(t, v))
t.Run("OptionsInfo", testOptionsInfo(t, v))
}

func testSimpleHandler(t *testing.T, v *Nvim) func(*testing.T) {
Expand Down Expand Up @@ -838,6 +839,120 @@ func testRuntimeFiles(t *testing.T, v *Nvim) func(*testing.T) {
}
}

func testOptionsInfo(t *testing.T, v *Nvim) func(*testing.T) {
return func(t *testing.T) {
want := &OptionInfo{
Name: "",
ShortName: "",
Type: "",
Default: nil,
WasSet: false,
LastSetSid: 0,
LastSetLinenr: 0,
LastSetChan: 0,
Scope: "",
GlobalLocal: false,
CommaList: false,
FlagList: false,
}
got, err := v.AllOptionsInfo()
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(want, got) {
t.Fatalf("got %v but want %v", got, want)
}

tests := map[string]struct {
name string
want *OptionInfo
}{
"filetype": {
name: "filetype",
want: &OptionInfo{
Name: "filetype",
ShortName: "ft",
Type: "string",
Default: "",
WasSet: false,
LastSetSid: 0,
LastSetLinenr: 0,
LastSetChan: 0,
Scope: "buf",
GlobalLocal: false,
CommaList: false,
FlagList: false,
},
},
"cmdheight": {
name: "cmdheight",
want: &OptionInfo{
Name: "cmdheight",
ShortName: "ch",
Type: "number",
Default: int64(1),
WasSet: false,
LastSetSid: 0,
LastSetLinenr: 0,
LastSetChan: 0,
Scope: "global",
GlobalLocal: false,
CommaList: false,
FlagList: false,
},
},
"hidden": {
name: "hidden",
want: &OptionInfo{
Name: "hidden",
ShortName: "hid",
Type: "boolean",
Default: false,
WasSet: false,
LastSetSid: 0,
LastSetLinenr: 0,
LastSetChan: 0,
Scope: "global",
GlobalLocal: false,
CommaList: false,
FlagList: false,
},
},
}
for name, tt := range tests {
tt := tt
t.Run("Nvim/"+name, func(t *testing.T) {
t.Parallel()

got, err := v.OptionInfo(tt.name)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(tt.want, got) {
t.Fatalf("got %#v but want %#v", got, tt.want)
}
})
}
for name, tt := range tests {
tt := tt
t.Run("Atomic/"+name, func(t *testing.T) {
t.Parallel()

b := v.NewBatch()

var got OptionInfo
b.OptionInfo(tt.name, &got)
if err := b.Execute(); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(tt.want, &got) {
t.Fatalf("got %#v but want %#v", &got, tt.want)
}
})
}
}
}

// clearBuffer clears the buffer text.
func clearBuffer(tb testing.TB, v *Nvim, buffer Buffer) {
tb.Helper()
Expand Down

0 comments on commit 8b755b9

Please sign in to comment.