Fix parsing the third part of version string (#2355)

* Fix parsing the third part of version string
* Add test
* Test: fix checking cached version
This commit is contained in:
Tomasz N 2019-03-12 18:49:48 +01:00 committed by w0rp
parent 365ffae6c4
commit 5f03bae41c
2 changed files with 4 additions and 3 deletions

View File

@ -14,10 +14,10 @@ function! ale#semver#GetVersion(executable, version_lines) abort
let l:version = get(s:version_cache, a:executable, [])
for l:line in a:version_lines
let l:match = matchlist(l:line, '\v(\d+)\.(\d+)\.?(\d?)')
let l:match = matchlist(l:line, '\v(\d+)\.(\d+)(\.(\d+))?')
if !empty(l:match)
let l:version = [l:match[1] + 0, l:match[2] + 0, l:match[3] + 0]
let l:version = [l:match[1] + 0, l:match[2] + 0, l:match[4] + 0]
let s:version_cache[a:executable] = l:version
break

View File

@ -15,7 +15,8 @@ Execute(GetVersion should return an empty list when no vesrion can be found):
Execute(GetVersion should cache the version):
AssertEqual [], ale#semver#GetVersion('dummy', [])
AssertEqual [3, 4, 7], ale#semver#GetVersion('dummy', ['Version 3.4.7'])
AssertEqual [3, 4, 7], ale#semver#GetVersion('dummy', [])
AssertEqual [3, 4, 17], ale#semver#GetVersion('dummy', ['Version 3.4.17'])
AssertEqual [3, 4, 17], ale#semver#GetVersion('dummy', [])
Execute(GetVersion should tolerate missing patch numbers):
" This goes against the semver spec, but we handle it anyway.