From 8b755b97d17e8507610b774900a82b46c467803b Mon Sep 17 00:00:00 2001 From: Koichi Shiraishi Date: Thu, 31 Dec 2020 03:44:00 +0900 Subject: [PATCH] nvim: add OptionsInfo testcases --- nvim/nvim_test.go | 115 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/nvim/nvim_test.go b/nvim/nvim_test.go index 8f696f95..eae7c5f2 100644 --- a/nvim/nvim_test.go +++ b/nvim/nvim_test.go @@ -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) { @@ -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()