Skip to content

Commit 8b755b9

Browse files
committed
nvim: add OptionsInfo testcases
1 parent 4517f53 commit 8b755b9

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

nvim/nvim_test.go

+115
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func TestAPI(t *testing.T) {
6767
t.Run("Context", testContext(t, v))
6868
t.Run("Extmarks", testExtmarks(t, v))
6969
t.Run("RuntimeFiles", testRuntimeFiles(t, v))
70+
t.Run("OptionsInfo", testOptionsInfo(t, v))
7071
}
7172

7273
func testSimpleHandler(t *testing.T, v *Nvim) func(*testing.T) {
@@ -838,6 +839,120 @@ func testRuntimeFiles(t *testing.T, v *Nvim) func(*testing.T) {
838839
}
839840
}
840841

842+
func testOptionsInfo(t *testing.T, v *Nvim) func(*testing.T) {
843+
return func(t *testing.T) {
844+
want := &OptionInfo{
845+
Name: "",
846+
ShortName: "",
847+
Type: "",
848+
Default: nil,
849+
WasSet: false,
850+
LastSetSid: 0,
851+
LastSetLinenr: 0,
852+
LastSetChan: 0,
853+
Scope: "",
854+
GlobalLocal: false,
855+
CommaList: false,
856+
FlagList: false,
857+
}
858+
got, err := v.AllOptionsInfo()
859+
if err != nil {
860+
t.Fatal(err)
861+
}
862+
if !reflect.DeepEqual(want, got) {
863+
t.Fatalf("got %v but want %v", got, want)
864+
}
865+
866+
tests := map[string]struct {
867+
name string
868+
want *OptionInfo
869+
}{
870+
"filetype": {
871+
name: "filetype",
872+
want: &OptionInfo{
873+
Name: "filetype",
874+
ShortName: "ft",
875+
Type: "string",
876+
Default: "",
877+
WasSet: false,
878+
LastSetSid: 0,
879+
LastSetLinenr: 0,
880+
LastSetChan: 0,
881+
Scope: "buf",
882+
GlobalLocal: false,
883+
CommaList: false,
884+
FlagList: false,
885+
},
886+
},
887+
"cmdheight": {
888+
name: "cmdheight",
889+
want: &OptionInfo{
890+
Name: "cmdheight",
891+
ShortName: "ch",
892+
Type: "number",
893+
Default: int64(1),
894+
WasSet: false,
895+
LastSetSid: 0,
896+
LastSetLinenr: 0,
897+
LastSetChan: 0,
898+
Scope: "global",
899+
GlobalLocal: false,
900+
CommaList: false,
901+
FlagList: false,
902+
},
903+
},
904+
"hidden": {
905+
name: "hidden",
906+
want: &OptionInfo{
907+
Name: "hidden",
908+
ShortName: "hid",
909+
Type: "boolean",
910+
Default: false,
911+
WasSet: false,
912+
LastSetSid: 0,
913+
LastSetLinenr: 0,
914+
LastSetChan: 0,
915+
Scope: "global",
916+
GlobalLocal: false,
917+
CommaList: false,
918+
FlagList: false,
919+
},
920+
},
921+
}
922+
for name, tt := range tests {
923+
tt := tt
924+
t.Run("Nvim/"+name, func(t *testing.T) {
925+
t.Parallel()
926+
927+
got, err := v.OptionInfo(tt.name)
928+
if err != nil {
929+
t.Fatal(err)
930+
}
931+
if !reflect.DeepEqual(tt.want, got) {
932+
t.Fatalf("got %#v but want %#v", got, tt.want)
933+
}
934+
})
935+
}
936+
for name, tt := range tests {
937+
tt := tt
938+
t.Run("Atomic/"+name, func(t *testing.T) {
939+
t.Parallel()
940+
941+
b := v.NewBatch()
942+
943+
var got OptionInfo
944+
b.OptionInfo(tt.name, &got)
945+
if err := b.Execute(); err != nil {
946+
t.Fatal(err)
947+
}
948+
if !reflect.DeepEqual(tt.want, &got) {
949+
t.Fatalf("got %#v but want %#v", &got, tt.want)
950+
}
951+
})
952+
}
953+
}
954+
}
955+
841956
// clearBuffer clears the buffer text.
842957
func clearBuffer(tb testing.TB, v *Nvim, buffer Buffer) {
843958
tb.Helper()

0 commit comments

Comments
 (0)