@@ -11,6 +11,7 @@ import (
11
11
"reflect"
12
12
"runtime"
13
13
"sort"
14
+ "strconv"
14
15
"strings"
15
16
"sync/atomic"
16
17
"testing"
@@ -79,12 +80,71 @@ func newChildProcess(tb testing.TB) (v *Nvim, cleanup func()) {
79
80
return v , cleanup
80
81
}
81
82
83
+ type version struct {
84
+ Major int
85
+ Minor int
86
+ Patch int
87
+ }
88
+
89
+ var nvimVersion version
90
+
91
+ func parseVersion (tb testing.TB , version string ) (major , minor , patch int ) {
92
+ tb .Helper ()
93
+
94
+ version = strings .TrimPrefix (version , "v" )
95
+ vpair := strings .Split (version , "." )
96
+ if len (vpair ) != 3 {
97
+ tb .Fatal ("could not parse neovim version" )
98
+ }
99
+
100
+ var err error
101
+ major , err = strconv .Atoi (vpair [0 ])
102
+ if err != nil {
103
+ tb .Fatal (err )
104
+ }
105
+ minor , err = strconv .Atoi (vpair [1 ])
106
+ if err != nil {
107
+ tb .Fatal (err )
108
+ }
109
+ patch , err = strconv .Atoi (vpair [2 ])
110
+ if err != nil {
111
+ tb .Fatal (err )
112
+ }
113
+
114
+ return major , minor , patch
115
+ }
116
+
117
+ func skipVersion (tb testing.TB , version string ) {
118
+ major , minor , patch := parseVersion (tb , version )
119
+
120
+ const skipFmt = "skip test: current neovim version v%d.%d.%d but expected version %s"
121
+ if nvimVersion .Major < major || nvimVersion .Minor < minor || nvimVersion .Patch < patch {
122
+ tb .Skipf (skipFmt , nvimVersion .Major , nvimVersion .Minor , nvimVersion .Patch , version )
123
+ }
124
+ }
125
+
82
126
func TestAPI (t * testing.T ) {
83
127
t .Parallel ()
84
128
85
129
v , cleanup := newChildProcess (t )
86
130
defer cleanup ()
87
131
132
+ apiInfo , err := v .APIInfo ()
133
+ if err != nil {
134
+ t .Fatal (err )
135
+ }
136
+ if len (apiInfo ) != 2 {
137
+ t .Fatalf ("unknown APIInfo: %#v" , apiInfo )
138
+ }
139
+ info , ok := apiInfo [1 ].(map [string ]interface {})
140
+ if ! ok {
141
+ t .Fatalf ("apiInfo[1] is not map[string]interface{} type: %T" , apiInfo [1 ])
142
+ }
143
+ infoV := info ["version" ].(map [string ]interface {})
144
+ nvimVersion .Major = int (infoV ["major" ].(int64 ))
145
+ nvimVersion .Minor = int (infoV ["minor" ].(int64 ))
146
+ nvimVersion .Patch = int (infoV ["patch" ].(int64 ))
147
+
88
148
t .Run ("BufAttach" , testBufAttach (v ))
89
149
t .Run ("SimpleHandler" , testSimpleHandler (v ))
90
150
t .Run ("Buffer" , testBuffer (v ))
0 commit comments