Skip to content

Commit 61c0449

Browse files
committed
patch 7.4.2095
Problem: Man test fails when run with the GUI. Solution: Adjust for different behavior of GUI. Add assert_inrange().
1 parent 4658228 commit 61c0449

7 files changed

Lines changed: 86 additions & 15 deletions

File tree

runtime/doc/eval.txt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*eval.txt* For Vim version 7.4. Last change: 2016 Jul 22
1+
*eval.txt* For Vim version 7.4. Last change: 2016 Jul 23
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1947,6 +1947,8 @@ assert_equal({exp}, {act} [, {msg}]) none assert {exp} is equal to {act}
19471947
assert_exception({error} [, {msg}]) none assert {error} is in v:exception
19481948
assert_fails({cmd} [, {error}]) none assert {cmd} fails
19491949
assert_false({actual} [, {msg}]) none assert {actual} is false
1950+
assert_inrange({lower}, {upper}, {actual} [, {msg}])
1951+
none assert {actual} is inside the range
19501952
assert_match({pat}, {text} [, {msg}]) none assert {pat} matches {text}
19511953
assert_notequal({exp}, {act} [, {msg}]) none assert {exp} is not equal {act}
19521954
assert_notmatch({pat}, {text} [, {msg}]) none assert {pat} not matches {text}
@@ -2478,8 +2480,16 @@ assert_false({actual} [, {msg}]) *assert_false()*
24782480
|v:errors|, like with |assert_equal()|.
24792481
A value is false when it is zero. When {actual} is not a
24802482
number the assert fails.
2481-
When {msg} is omitted an error in the form "Expected False but
2482-
got {actual}" is produced.
2483+
When {msg} is omitted an error in the form
2484+
"Expected False but got {actual}" is produced.
2485+
2486+
assert_inrange({lower}, {upper}, {actual} [, {msg}]) *assert_inrange()*
2487+
This asserts number values. When {actual} is lower than
2488+
{lower} or higher than {upper} an error message is added to
2489+
|v:errors|.
2490+
When {msg} is omitted an error in the form
2491+
"Expected range {lower} - {upper}, but got {actual}" is
2492+
produced.
24832493

24842494
*assert_match()*
24852495
assert_match({pattern}, {actual} [, {msg}])
@@ -2494,8 +2504,8 @@ assert_match({pattern}, {actual} [, {msg}])
24942504
Use "^" and "$" to match with the start and end of the text.
24952505
Use both to match the whole text.
24962506

2497-
When {msg} is omitted an error in the form "Pattern {pattern}
2498-
does not match {actual}" is produced.
2507+
When {msg} is omitted an error in the form
2508+
"Pattern {pattern} does not match {actual}" is produced.
24992509
Example: >
25002510
assert_match('^f.*o$', 'foobar')
25012511
< Will result in a string to be added to |v:errors|:

src/eval.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8992,6 +8992,39 @@ assert_match_common(typval_T *argvars, assert_type_T atype)
89928992
}
89938993
}
89948994

8995+
void
8996+
assert_inrange(typval_T *argvars)
8997+
{
8998+
garray_T ga;
8999+
int error = FALSE;
9000+
varnumber_T lower = get_tv_number_chk(&argvars[0], &error);
9001+
varnumber_T upper = get_tv_number_chk(&argvars[1], &error);
9002+
varnumber_T actual = get_tv_number_chk(&argvars[2], &error);
9003+
char_u *tofree;
9004+
char msg[200];
9005+
char_u numbuf[NUMBUFLEN];
9006+
9007+
if (error)
9008+
return;
9009+
if (actual < lower || actual > upper)
9010+
{
9011+
prepare_assert_error(&ga);
9012+
if (argvars[3].v_type != VAR_UNKNOWN)
9013+
{
9014+
ga_concat(&ga, tv2string(&argvars[3], &tofree, numbuf, 0));
9015+
vim_free(tofree);
9016+
}
9017+
else
9018+
{
9019+
vim_snprintf(msg, 200, "Expected range %ld - %ld, but got %ld",
9020+
(long)lower, (long)upper, (long)actual);
9021+
ga_concat(&ga, (char_u *)msg);
9022+
}
9023+
assert_error(&ga);
9024+
ga_clear(&ga);
9025+
}
9026+
}
9027+
89959028
/*
89969029
* Common for assert_true() and assert_false().
89979030
*/

src/evalfunc.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ static void f_assert_equal(typval_T *argvars, typval_T *rettv);
4848
static void f_assert_exception(typval_T *argvars, typval_T *rettv);
4949
static void f_assert_fails(typval_T *argvars, typval_T *rettv);
5050
static void f_assert_false(typval_T *argvars, typval_T *rettv);
51+
static void f_assert_inrange(typval_T *argvars, typval_T *rettv);
5152
static void f_assert_match(typval_T *argvars, typval_T *rettv);
5253
static void f_assert_notequal(typval_T *argvars, typval_T *rettv);
5354
static void f_assert_notmatch(typval_T *argvars, typval_T *rettv);
@@ -460,6 +461,7 @@ static struct fst
460461
{"assert_exception", 1, 2, f_assert_exception},
461462
{"assert_fails", 1, 2, f_assert_fails},
462463
{"assert_false", 1, 2, f_assert_false},
464+
{"assert_inrange", 2, 3, f_assert_inrange},
463465
{"assert_match", 2, 3, f_assert_match},
464466
{"assert_notequal", 2, 3, f_assert_notequal},
465467
{"assert_notmatch", 2, 3, f_assert_notmatch},
@@ -1277,6 +1279,15 @@ f_assert_false(typval_T *argvars, typval_T *rettv UNUSED)
12771279
assert_bool(argvars, FALSE);
12781280
}
12791281

1282+
/*
1283+
* "assert_inrange(lower, upper[, msg])" function
1284+
*/
1285+
static void
1286+
f_assert_inrange(typval_T *argvars, typval_T *rettv UNUSED)
1287+
{
1288+
assert_inrange(argvars);
1289+
}
1290+
12801291
/*
12811292
* "assert_match(pattern, actual[, msg])" function
12821293
*/

src/proto/eval.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ void prepare_assert_error(garray_T *gap);
121121
void assert_error(garray_T *gap);
122122
void assert_equal_common(typval_T *argvars, assert_type_T atype);
123123
void assert_match_common(typval_T *argvars, assert_type_T atype);
124+
void assert_inrange(typval_T *argvars);
124125
void assert_bool(typval_T *argvars, int isTrue);
125126
void assert_exception(typval_T *argvars);
126127
void assert_fails(typval_T *argvars);

src/testdir/test_assert.vim

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,19 @@ func Test_assert_fail_fails()
105105
call remove(v:errors, 0)
106106
endfunc
107107

108+
func Test_assert_inrange()
109+
call assert_inrange(7, 7, 7)
110+
call assert_inrange(5, 7, 5)
111+
call assert_inrange(5, 7, 6)
112+
call assert_inrange(5, 7, 7)
113+
114+
call assert_inrange(5, 7, 4)
115+
call assert_match("Expected range 5 - 7, but got 4", v:errors[0])
116+
call remove(v:errors, 0)
117+
call assert_inrange(5, 7, 8)
118+
call assert_match("Expected range 5 - 7, but got 8", v:errors[0])
119+
call remove(v:errors, 0)
120+
endfunc
108121

109122
func Test_user_is_happy()
110123
smile

src/testdir/test_man.vim

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
11
runtime ftplugin/man.vim
22

33
function Test_g_ft_man_open_mode()
4-
let l:w = winwidth(1)
54
vnew
65
let l:h = winheight(1)
76
q
7+
let l:w = winwidth(1)
88

99
" split horizontally
1010
let wincnt = winnr('$')
11-
Man 'vim'
11+
Man vim
1212
if wincnt == winnr('$')
1313
" Vim manual page cannot be found.
1414
return
1515
endif
16-
call assert_equal(l:w, winwidth(1))
16+
17+
call assert_inrange(l:w - 2, l:w + 2, winwidth(1))
1718
call assert_true(l:h > winheight(1))
1819
call assert_equal(1, tabpagenr('$'))
1920
call assert_equal(1, tabpagenr())
2021
q
2122

2223
" split horizontally
2324
let g:ft_man_open_mode = "horz"
24-
Man 'vim'
25-
call assert_equal(l:w, winwidth(1))
25+
Man vim
26+
call assert_inrange(l:w - 2, l:w + 2, winwidth(1))
2627
call assert_true(l:h > winheight(1))
2728
call assert_equal(1, tabpagenr('$'))
2829
call assert_equal(1, tabpagenr())
2930
q
3031

3132
" split vertically
3233
let g:ft_man_open_mode = "vert"
33-
Man 'vim'
34+
Man vim
3435
call assert_true(l:w > winwidth(1))
3536
call assert_equal(l:h, winheight(1))
3637
call assert_equal(1, tabpagenr('$'))
@@ -39,17 +40,17 @@ function Test_g_ft_man_open_mode()
3940

4041
" separate tab
4142
let g:ft_man_open_mode = "tab"
42-
Man 'vim'
43-
call assert_equal(l:w, winwidth(1))
44-
call assert_equal(l:h, winheight(1))
43+
Man vim
44+
call assert_inrange(l:w - 2, l:w + 2, winwidth(1))
45+
call assert_inrange(l:h - 1, l:h + 1, winheight(1))
4546
call assert_equal(2, tabpagenr('$'))
4647
call assert_equal(2, tabpagenr())
4748
q
4849
endfunction
4950

5051
function Test_nomodifiable()
5152
let wincnt = winnr('$')
52-
Man 'vim'
53+
Man vim
5354
if wincnt == winnr('$')
5455
" Vim manual page cannot be found.
5556
return

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,8 @@ static char *(features[]) =
758758

759759
static int included_patches[] =
760760
{ /* Add new patch number below this line */
761+
/**/
762+
2095,
761763
/**/
762764
2094,
763765
/**/

0 commit comments

Comments
 (0)