-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#289 Only use the --stdin-display-name flag if the flake8 version sup…
…ports it
- Loading branch information
Showing
3 changed files
with
100 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
" Given some text, parse a semantic versioning string from the text | ||
" into a triple of integeers [major, minor, patch]. | ||
" | ||
" If no match can be performed, then an empty List will be returned instead. | ||
function! ale#semver#Parse(text) abort | ||
let l:match = matchlist(a:text, '^ *\(\d\+\)\.\(\d\+\)\.\(\d\+\)') | ||
|
||
if empty(l:match) | ||
return [] | ||
endif | ||
|
||
return [l:match[1] + 0, l:match[2] + 0, l:match[3] + 0] | ||
endfunction | ||
|
||
" Given two triples of integers [major, minor, patch], compare the triples | ||
" and return 1 if the lhs is greater than or equal to the rhs. | ||
function! ale#semver#GreaterOrEqual(lhs, rhs) abort | ||
if a:lhs[0] > a:rhs[0] | ||
return 1 | ||
elseif a:lhs[0] == a:rhs[0] | ||
if a:lhs[1] > a:rhs[1] | ||
return 1 | ||
elseif a:lhs[1] == a:rhs[1] | ||
return a:lhs[2] >= a:rhs[2] | ||
endif | ||
endif | ||
|
||
return 0 | ||
endfunction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Execute(ParseSemver should return the correct results): | ||
" We should be able to parse the semver string from flake8 | ||
AssertEqual [3, 0, 4], ale#semver#Parse('3.0.4 (mccabe: 0.5.2, pyflakes: 1.2.3, pycodestyle: 2.0.0) CPython 2.7.12 on Linux') | ||
|
||
Execute(GreaterOrEqual should compare triples correctly): | ||
Assert ale#semver#GreaterOrEqual([3, 0, 4], [3, 0, 0]) | ||
Assert ale#semver#GreaterOrEqual([3, 0, 0], [3, 0, 0]) | ||
Assert ale#semver#GreaterOrEqual([3, 0, 0], [2, 0, 0]) | ||
Assert ale#semver#GreaterOrEqual([3, 1, 0], [3, 1, 0]) | ||
Assert ale#semver#GreaterOrEqual([3, 2, 0], [3, 1, 0]) | ||
Assert ale#semver#GreaterOrEqual([3, 2, 2], [3, 1, 6]) | ||
Assert ale#semver#GreaterOrEqual([3, 2, 5], [3, 2, 5]) | ||
Assert ale#semver#GreaterOrEqual([3, 2, 6], [3, 2, 5]) | ||
Assert !ale#semver#GreaterOrEqual([2, 9, 1], [3, 0, 0]) | ||
Assert !ale#semver#GreaterOrEqual([3, 2, 3], [3, 3, 3]) | ||
Assert !ale#semver#GreaterOrEqual([3, 3, 2], [3, 3, 3]) |