mirror of
https://github.com/neovim/neovim.git
synced 2025-09-13 14:58:18 +00:00
vim-patch:7.4.2095
Problem: Man test fails when run with the GUI.
Solution: Adjust for different behavior of GUI. Add assert_inrange().
61c04493b0
Only changes related to assert_inrange() were included, since we have a
distinct man plugin.
This commit is contained in:
@@ -1946,6 +1946,8 @@ assert_equal({exp}, {act} [, {msg}]) none assert {exp} is equal to {act}
|
||||
assert_exception( {error} [, {msg}]) none assert {error} is in v:exception
|
||||
assert_fails( {cmd} [, {error}]) none assert {cmd} fails
|
||||
assert_false({actual} [, {msg}]) none assert {actual} is false
|
||||
assert_inrange({lower}, {upper}, {actual} [, {msg}])
|
||||
none assert {actual} is inside the range
|
||||
assert_match( {pat}, {text} [, {msg}]) none assert {pat} matches {text}
|
||||
assert_notequal( {exp}, {act} [, {msg}]) none assert {exp} is not equal {act}
|
||||
assert_notmatch( {pat}, {text} [, {msg}]) none assert {pat} not matches {text}
|
||||
@@ -2460,8 +2462,16 @@ assert_false({actual} [, {msg}]) *assert_false()*
|
||||
|v:errors|, like with |assert_equal()|.
|
||||
A value is false when it is zero or |v:false|. When "{actual}"
|
||||
is not a number or |v:false| the assert fails.
|
||||
When {msg} is omitted an error in the form "Expected False but
|
||||
got {actual}" is produced.
|
||||
When {msg} is omitted an error in the form
|
||||
"Expected False but got {actual}" is produced.
|
||||
|
||||
assert_inrange({lower}, {upper}, {actual} [, {msg}]) *assert_inrange()*
|
||||
This asserts number values. When {actual} is lower than
|
||||
{lower} or higher than {upper} an error message is added to
|
||||
|v:errors|.
|
||||
When {msg} is omitted an error in the form
|
||||
"Expected range {lower} - {upper}, but got {actual}" is
|
||||
produced.
|
||||
|
||||
*assert_match()*
|
||||
assert_match({pattern}, {actual} [, {msg}])
|
||||
@@ -2476,8 +2486,8 @@ assert_match({pattern}, {actual} [, {msg}])
|
||||
Use "^" and "$" to match with the start and end of the text.
|
||||
Use both to match the whole text.
|
||||
|
||||
When {msg} is omitted an error in the form "Pattern {pattern}
|
||||
does not match {actual}" is produced.
|
||||
When {msg} is omitted an error in the form
|
||||
"Pattern {pattern} does not match {actual}" is produced.
|
||||
Example: >
|
||||
assert_match('^f.*o$', 'foobar')
|
||||
< Will result in a string to be added to |v:errors|:
|
||||
|
@@ -8111,6 +8111,30 @@ static void f_assert_fails(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
set_vim_var_string(VV_ERRMSG, NULL, 0);
|
||||
}
|
||||
|
||||
void assert_inrange(typval_T *argvars)
|
||||
{
|
||||
int error = (int)false;
|
||||
varnumber_T lower = get_tv_number_chk(&argvars[0], &error);
|
||||
varnumber_T upper = get_tv_number_chk(&argvars[1], &error);
|
||||
varnumber_T actual = get_tv_number_chk(&argvars[2], &error);
|
||||
|
||||
if (error) {
|
||||
return;
|
||||
}
|
||||
if (actual < lower || actual > upper) {
|
||||
garray_T ga;
|
||||
prepare_assert_error(&ga);
|
||||
|
||||
char msg[55];
|
||||
vim_snprintf(msg, sizeof(msg), "range %" PRId64 " - %" PRId64 ",",
|
||||
(int64_t)lower, (int64_t)upper);
|
||||
fill_assert_error(&ga, &argvars[3], (char_u *)msg, NULL, &argvars[2],
|
||||
ASSERT_INRANGE);
|
||||
assert_error(&ga);
|
||||
ga_clear(&ga);
|
||||
}
|
||||
}
|
||||
|
||||
// Common for assert_true() and assert_false().
|
||||
static void assert_bool(typval_T *argvars, bool is_true)
|
||||
{
|
||||
@@ -8158,6 +8182,12 @@ static void assert_match_common(typval_T *argvars, assert_type_T atype)
|
||||
}
|
||||
}
|
||||
|
||||
/// "assert_inrange(lower, upper[, msg])" function
|
||||
static void f_assert_inrange(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
{
|
||||
assert_inrange(argvars);
|
||||
}
|
||||
|
||||
/// "assert_match(pattern, actual[, msg])" function
|
||||
static void f_assert_match(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
{
|
||||
|
@@ -29,6 +29,7 @@ return {
|
||||
assert_exception={args={1, 2}},
|
||||
assert_fails={args={1, 2}},
|
||||
assert_false={args={1, 2}},
|
||||
assert_inrange={args={2, 3}},
|
||||
assert_match={args={2, 3}},
|
||||
assert_notequal={args={2, 3}},
|
||||
assert_notmatch={args={2, 3}},
|
||||
|
@@ -278,6 +278,7 @@ typedef enum
|
||||
ASSERT_NOTEQUAL,
|
||||
ASSERT_MATCH,
|
||||
ASSERT_NOTMATCH,
|
||||
ASSERT_INRANGE,
|
||||
ASSERT_OTHER,
|
||||
} assert_type_T;
|
||||
|
||||
|
@@ -345,7 +345,7 @@ static int included_patches[] = {
|
||||
2098,
|
||||
// 2097,
|
||||
2096,
|
||||
// 2095,
|
||||
2095,
|
||||
// 2094 NA
|
||||
// 2093 NA
|
||||
// 2092 NA
|
||||
|
@@ -235,6 +235,26 @@ describe('assert function:', function()
|
||||
end)
|
||||
end)
|
||||
|
||||
-- assert_inrange({lower}, {upper}, {actual}[, {msg}])
|
||||
describe('assert_inrange()', function()
|
||||
it('should not change v:errors when actual is in range', function()
|
||||
call('assert_inrange', 7, 7, 7)
|
||||
call('assert_inrange', 5, 7, 5)
|
||||
call('assert_inrange', 5, 7, 6)
|
||||
call('assert_inrange', 5, 7, 7)
|
||||
expected_empty()
|
||||
end)
|
||||
|
||||
it('should change v:errors when actual is not in range', function()
|
||||
call('assert_inrange', 5, 7, 4)
|
||||
call('assert_inrange', 5, 7, 8)
|
||||
expected_errors({
|
||||
"Expected range 5 - 7, but got 4",
|
||||
"Expected range 5 - 7, but got 8",
|
||||
})
|
||||
end)
|
||||
end)
|
||||
|
||||
-- assert_exception({cmd}, [, {error}])
|
||||
describe('assert_exception()', function()
|
||||
it('should assert thrown exceptions properly', function()
|
||||
|
Reference in New Issue
Block a user