Skip to content

Commit ac2e873

Browse files
committed
nvim: add OptionsValue and SetOptionValue testcases
Signed-off-by: Koichi Shiraishi <[email protected]>
1 parent 810f51d commit ac2e873

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

nvim/api_test.go

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"log"
88
"os"
99
"os/exec"
10+
"path"
1011
"path/filepath"
1112
"reflect"
1213
"runtime"
@@ -125,6 +126,7 @@ func TestAPI(t *testing.T) {
125126
t.Run("Options", testOptions(v))
126127
t.Run("AllOptionsInfo", testAllOptionsInfo(v))
127128
t.Run("OptionsInfo", testOptionsInfo(v))
129+
t.Run("OptionsValue", testOptionsValue(v))
128130
t.Run("OpenTerm", testTerm(v))
129131
t.Run("ChannelClientInfo", testChannelClientInfo(v))
130132
t.Run("UI", testUI(v))
@@ -4574,6 +4576,99 @@ func testOptionsInfo(v *Nvim) func(*testing.T) {
45744576
}
45754577
}
45764578

4579+
func testOptionsValue(v *Nvim) func(*testing.T) {
4580+
return func(t *testing.T) {
4581+
tests := map[string]struct {
4582+
name string
4583+
opts map[string]OptionValueScope
4584+
want interface{}
4585+
value interface{}
4586+
}{
4587+
"equalalways": {
4588+
name: "equalalways",
4589+
opts: map[string]OptionValueScope{
4590+
"scope": GlobalScope,
4591+
},
4592+
want: true,
4593+
value: false,
4594+
},
4595+
"lazyredraw": {
4596+
name: "lazyredraw",
4597+
opts: map[string]OptionValueScope{
4598+
"scope": LocalScope,
4599+
},
4600+
want: false,
4601+
value: true,
4602+
},
4603+
}
4604+
for name, tt := range tests {
4605+
t.Run(path.Join(name, "Nvim"), func(t *testing.T) {
4606+
skipVersion(t, "v0.7.0")
4607+
4608+
var result interface{}
4609+
if err := v.OptionValue(tt.name, tt.opts, &result); err != nil {
4610+
t.Fatal(err)
4611+
}
4612+
if !reflect.DeepEqual(result, tt.want) {
4613+
t.Fatalf("got %#v but want %#v", result, tt.want)
4614+
}
4615+
4616+
if err := v.SetOptionValue(tt.name, tt.value, tt.opts); err != nil {
4617+
t.Fatal(err)
4618+
}
4619+
4620+
var result2 interface{}
4621+
if err := v.OptionValue(tt.name, tt.opts, &result2); err != nil {
4622+
t.Fatal(err)
4623+
}
4624+
if reflect.DeepEqual(result, result2) {
4625+
t.Fatalf("got %#v but want %#v", result, result2)
4626+
}
4627+
4628+
if err := v.SetOptionValue(tt.name, result, tt.opts); err != nil {
4629+
t.Fatal(err)
4630+
}
4631+
})
4632+
}
4633+
4634+
for name, tt := range tests {
4635+
t.Run(path.Join(name, "Batch"), func(t *testing.T) {
4636+
skipVersion(t, "v0.7.0")
4637+
4638+
b := v.NewBatch()
4639+
4640+
var result interface{}
4641+
b.OptionValue(tt.name, tt.opts, &result)
4642+
if err := b.Execute(); err != nil {
4643+
t.Fatal(err)
4644+
}
4645+
if !reflect.DeepEqual(result, tt.want) {
4646+
t.Fatalf("got %#v but want %#v", result, tt.want)
4647+
}
4648+
4649+
b.SetOptionValue(tt.name, tt.value, tt.opts)
4650+
if err := b.Execute(); err != nil {
4651+
t.Fatal(err)
4652+
}
4653+
4654+
var result2 interface{}
4655+
b.OptionValue(tt.name, tt.opts, &result2)
4656+
if err := b.Execute(); err != nil {
4657+
t.Fatal(err)
4658+
}
4659+
if reflect.DeepEqual(result, result2) {
4660+
t.Fatalf("got %#v but want %#v", result, result2)
4661+
}
4662+
4663+
b.SetOptionValue(tt.name, result, tt.opts)
4664+
if err := b.Execute(); err != nil {
4665+
t.Fatal(err)
4666+
}
4667+
})
4668+
}
4669+
}
4670+
}
4671+
45774672
// TODO(zchee): correct testcase
45784673
func testTerm(v *Nvim) func(*testing.T) {
45794674
return func(t *testing.T) {

0 commit comments

Comments
 (0)