version: has("nvim-1.2.3")

Helped-by: Daniel Hahler <git@thequod.de>
This commit is contained in:
Justin M. Keyes 2015-05-05 00:15:09 -04:00
parent f96dfae52f
commit e7e2844d46
5 changed files with 131 additions and 32 deletions

View File

@ -7453,7 +7453,11 @@ There are four types of features:
Example: >
:if has("gui_running")
< *has-patch*
3. Included patches. The "patch123" feature means that patch 123 has been
3. {Nvim} version. The "nvim-1.2.3" feature means that the Nvim version is
1.2.3 or later. Example: >
:if has("nvim-1.2.3")
<
4. Included patches. The "patch123" feature means that patch 123 has been
included. Note that this form does not check the version of Vim, you need
to inspect |v:version| for that.
Example (checking version 6.2.148 or later): >
@ -7461,7 +7465,7 @@ There are four types of features:
< Note that it's possible for patch 147 to be omitted even though 148 is
included.
4. Beyond a certain version or at a certain version and including a specific
5. Beyond a certain version or at a certain version and including a specific
patch. The "patch-7.4.237" feature means that the Vim version is 7.5 or
later, or it is version 7.4 and patch 237 was included.
Note that this only works for patch 7.4.237 and later, before that you
@ -7533,6 +7537,7 @@ multi_byte Compiled with support for 'encoding'
multi_byte_encoding 'encoding' is set to a multi-byte encoding.
multi_byte_ime Compiled with support for IME input method.
multi_lang Compiled with support for multiple languages.
nvim This is Nvim. |has-patch|
ole Compiled with OLE automation support for Win32.
path_extra Compiled with up/downwards search in 'path' and 'tags'
persistent_undo Compiled with support for persistent undo history.

View File

@ -10524,16 +10524,10 @@ static void f_glob2regpat(typval_T *argvars, typval_T *rettv, FunPtr fptr)
: file_pat_to_reg_pat(pat, NULL, NULL, false);
}
/*
* "has()" function
*/
/// "has()" function
static void f_has(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int i;
char_u *name;
int n = FALSE;
static char *(has_list[]) =
{
static char *(has_list[]) = {
#ifdef UNIX
"unix",
#endif
@ -10646,36 +10640,44 @@ static void f_has(typval_T *argvars, typval_T *rettv, FunPtr fptr)
NULL
};
name = get_tv_string(&argvars[0]);
for (i = 0; has_list[i] != NULL; ++i)
bool n = false;
char *name = (char *)get_tv_string(&argvars[0]);
for (int i = 0; has_list[i] != NULL; i++) {
if (STRICMP(name, has_list[i]) == 0) {
n = TRUE;
n = true;
break;
}
}
if (n == FALSE) {
if (!n) {
if (STRNICMP(name, "patch", 5) == 0) {
if (name[5] == '-'
&& STRLEN(name) > 11
&& strlen(name) > 11
&& ascii_isdigit(name[6])
&& ascii_isdigit(name[8])
&& ascii_isdigit(name[10])) {
int major = atoi((char *)name + 6);
int minor = atoi((char *)name + 8);
int major = atoi(name + 6);
int minor = atoi(name + 8);
// Expect "patch-9.9.01234".
n = (major < VIM_VERSION_MAJOR
|| (major == VIM_VERSION_MAJOR
&& (minor < VIM_VERSION_MINOR
|| (minor == VIM_VERSION_MINOR
&& has_patch(atoi((char *)name + 10))))));
&& has_vim_patch(atoi(name + 10))))));
} else {
n = has_patch(atoi((char *)name + 5));
n = has_vim_patch(atoi(name + 5));
}
} else if (STRNICMP(name, "nvim", 4) == 0) {
// Expect "nvim-x.y.z"
if (name[4] == '-' && strlen(name) >= 10) {
n = has_nvim_version(name + 5);
}
} else if (STRICMP(name, "vim_starting") == 0) {
n = (starting != 0);
} else if (STRICMP(name, "multi_byte_encoding") == 0) {
n = has_mbyte;
n = has_mbyte != 0;
#if defined(USE_ICONV) && defined(DYNAMIC_ICONV)
} else if (STRICMP(name, "iconv") == 0) {
n = iconv_enabled(false);
@ -10685,8 +10687,8 @@ static void f_has(typval_T *argvars, typval_T *rettv, FunPtr fptr)
}
}
if (n == FALSE && eval_has_provider((char *)name)) {
n = TRUE;
if (!n && eval_has_provider(name)) {
n = true;
}
rettv->vval.v_number = n;

View File

@ -5537,7 +5537,7 @@ void ex_ownsyntax(exarg_T *eap)
}
}
int syntax_present(win_T *win)
bool syntax_present(win_T *win)
{
return win->w_s->b_syn_patterns.ga_len != 0
|| win->w_s->b_syn_clusters.ga_len != 0

View File

@ -2457,20 +2457,61 @@ static char *(extra_patches[]) = {
NULL
};
/// Checks whether patch `n` has been included.
/// Compares a version string to the current Nvim version.
///
/// @param n The patch number.
/// @param version Version string like "1.3.42"
///
/// @return TRUE if patch "n" has been included.
int has_patch(int n)
/// @return true if Nvim is at or above the version.
bool has_nvim_version(char *version_str)
FUNC_ATTR_NONNULL_ALL
{
int i;
for (i = 0; included_patches[i] != 0; ++i) {
if (included_patches[i] == n) {
return TRUE;
char *p = version_str;
int major = 0;
int minor = 0;
int patch = 0;
if (!ascii_isdigit(*p)) {
return false;
}
major = atoi(p);
p = strchr(p, '.'); // Find the next dot.
if (p) {
p++; // Advance past the dot.
if (!ascii_isdigit(*p)) {
return false;
}
minor = atoi(p);
p = strchr(p, '.');
if (p) {
p++;
if (!ascii_isdigit(*p)) {
return false;
}
patch = atoi(p);
}
}
return FALSE;
return (major < NVIM_VERSION_MAJOR
|| (major == NVIM_VERSION_MAJOR
&& (minor < NVIM_VERSION_MINOR
|| (minor == NVIM_VERSION_MINOR
&& patch <= NVIM_VERSION_PATCH))));
}
/// Checks whether a Vim patch has been included.
///
/// @param n Patch number.
///
/// @return true if patch `n` has been included.
bool has_vim_patch(int n)
{
for (int i = 0; included_patches[i] != 0; i++) {
if (included_patches[i] == n) {
return true;
}
}
return false;
}
void ex_version(exarg_T *eap)

View File

@ -0,0 +1,51 @@
local helpers = require('test.functional.helpers')(after_each)
local eq = helpers.eq
local clear = helpers.clear
local funcs = helpers.funcs
describe('has()', function()
before_each(clear)
it('"nvim-x.y.z"', function()
eq(0, funcs.has("nvim-"))
eq(0, funcs.has("nvim- "))
eq(0, funcs.has("nvim- \t "))
eq(0, funcs.has("nvim-0. 1. 1"))
eq(0, funcs.has("nvim-0. 1.1"))
eq(0, funcs.has("nvim-0.1. 1"))
eq(0, funcs.has("nvim-a"))
eq(0, funcs.has("nvim-a.b.c"))
eq(0, funcs.has("nvim-0.b.c"))
eq(0, funcs.has("nvim-0.0.c"))
eq(0, funcs.has("nvim-0.b.0"))
eq(0, funcs.has("nvim-a.b.0"))
eq(0, funcs.has("nvim-0.1"))
eq(0, funcs.has("nvim-.0.0.0"))
eq(0, funcs.has("nvim-.0"))
eq(0, funcs.has("nvim-0."))
eq(0, funcs.has("nvim-0.."))
eq(0, funcs.has("nvim-."))
eq(0, funcs.has("nvim-.."))
eq(0, funcs.has("nvim-..."))
eq(0, funcs.has("nvim-42"))
eq(0, funcs.has("nvim-9999"))
eq(0, funcs.has("nvim-99.001.05"))
eq(1, funcs.has("nvim"))
eq(1, funcs.has("nvim-0.0.0"))
eq(1, funcs.has("nvim-0.1.1."))
eq(1, funcs.has("nvim-0.1.1.abc"))
eq(1, funcs.has("nvim-0.1.1.."))
eq(1, funcs.has("nvim-0.1.1.. .."))
eq(1, funcs.has("nvim-0.1.1.... "))
eq(1, funcs.has("nvim-0.0.0"))
eq(1, funcs.has("nvim-0.0.1"))
eq(1, funcs.has("nvim-0.1.0"))
eq(1, funcs.has("nvim-0.1.1"))
eq(1, funcs.has("nvim-0.1.5"))
eq(1, funcs.has("nvim-0000.001.05"))
eq(1, funcs.has("nvim-0.01.005"))
eq(1, funcs.has("nvim-00.001.05"))
end)
end)