summaryrefslogtreecommitdiff
path: root/data/vim/patches/8.1.0819
blob: 63a8af5493c5f984d01a8dbfd12cd7a165185a18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
To: vim_dev@googlegroups.com
Subject: Patch 8.1.0819
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 8.1.0819
Problem:    A failed assert with a long string is hard to read.
Solution:   Shorten the assert message.
Files:	    src/eval.c, src/testdir/test_assert.vim


*** ../vim-8.1.0818/src/eval.c	2019-01-24 15:04:44.666887862 +0100
--- src/eval.c	2019-01-25 20:41:03.215252969 +0100
***************
*** 9495,9508 ****
  }
  
  /*
   * Append "str" to "gap", escaping unprintable characters.
   * Changes NL to \n, CR to \r, etc.
   */
      static void
! ga_concat_esc(garray_T *gap, char_u *str)
  {
      char_u  *p;
      char_u  buf[NUMBUFLEN];
  
      if (str == NULL)
      {
--- 9495,9548 ----
  }
  
  /*
+  * Append "p[clen]" to "gap", escaping unprintable characters.
+  * Changes NL to \n, CR to \r, etc.
+  */
+     static void
+ ga_concat_esc(garray_T *gap, char_u *p, int clen)
+ {
+     char_u  buf[NUMBUFLEN];
+ 
+     if (clen > 1)
+     {
+ 	mch_memmove(buf, p, clen);
+ 	buf[clen] = NUL;
+ 	ga_concat(gap, buf);
+     }
+     else switch (*p)
+     {
+ 	case BS: ga_concat(gap, (char_u *)"\\b"); break;
+ 	case ESC: ga_concat(gap, (char_u *)"\\e"); break;
+ 	case FF: ga_concat(gap, (char_u *)"\\f"); break;
+ 	case NL: ga_concat(gap, (char_u *)"\\n"); break;
+ 	case TAB: ga_concat(gap, (char_u *)"\\t"); break;
+ 	case CAR: ga_concat(gap, (char_u *)"\\r"); break;
+ 	case '\\': ga_concat(gap, (char_u *)"\\\\"); break;
+ 	default:
+ 		   if (*p < ' ')
+ 		   {
+ 		       vim_snprintf((char *)buf, NUMBUFLEN, "\\x%02x", *p);
+ 		       ga_concat(gap, buf);
+ 		   }
+ 		   else
+ 		       ga_append(gap, *p);
+ 		   break;
+     }
+ }
+ 
+ /*
   * Append "str" to "gap", escaping unprintable characters.
   * Changes NL to \n, CR to \r, etc.
   */
      static void
! ga_concat_shorten_esc(garray_T *gap, char_u *str)
  {
      char_u  *p;
+     char_u  *s;
+     int	    c;
+     int	    clen;
      char_u  buf[NUMBUFLEN];
+     int	    same_len;
  
      if (str == NULL)
      {
***************
*** 9511,9535 ****
      }
  
      for (p = str; *p != NUL; ++p)
! 	switch (*p)
  	{
! 	    case BS: ga_concat(gap, (char_u *)"\\b"); break;
! 	    case ESC: ga_concat(gap, (char_u *)"\\e"); break;
! 	    case FF: ga_concat(gap, (char_u *)"\\f"); break;
! 	    case NL: ga_concat(gap, (char_u *)"\\n"); break;
! 	    case TAB: ga_concat(gap, (char_u *)"\\t"); break;
! 	    case CAR: ga_concat(gap, (char_u *)"\\r"); break;
! 	    case '\\': ga_concat(gap, (char_u *)"\\\\"); break;
! 	    default:
! 		if (*p < ' ')
! 		{
! 		    vim_snprintf((char *)buf, NUMBUFLEN, "\\x%02x", *p);
! 		    ga_concat(gap, buf);
! 		}
! 		else
! 		    ga_append(gap, *p);
! 		break;
  	}
  }
  
  /*
--- 9551,9579 ----
      }
  
      for (p = str; *p != NUL; ++p)
!     {
! 	same_len = 1;
! 	s = p;
! 	c = mb_ptr2char_adv(&s);
! 	clen = s - p;
! 	while (*s != NUL && c == mb_ptr2char(s))
  	{
! 	    ++same_len;
! 	    s += clen;
  	}
+ 	if (same_len > 20)
+ 	{
+ 	    ga_concat(gap, (char_u *)"\\[");
+ 	    ga_concat_esc(gap, p, clen);
+ 	    ga_concat(gap, (char_u *)" occurs ");
+ 	    vim_snprintf((char *)buf, NUMBUFLEN, "%d", same_len);
+ 	    ga_concat(gap, buf);
+ 	    ga_concat(gap, (char_u *)" times]");
+ 	    p = s - 1;
+ 	}
+ 	else
+ 	    ga_concat_esc(gap, p, clen);
+     }
  }
  
  /*
***************
*** 9562,9572 ****
  	ga_concat(gap, (char_u *)"Expected ");
      if (exp_str == NULL)
      {
! 	ga_concat_esc(gap, tv2string(exp_tv, &tofree, numbuf, 0));
  	vim_free(tofree);
      }
      else
! 	ga_concat_esc(gap, exp_str);
      if (atype != ASSERT_NOTEQUAL)
      {
  	if (atype == ASSERT_MATCH)
--- 9606,9616 ----
  	ga_concat(gap, (char_u *)"Expected ");
      if (exp_str == NULL)
      {
! 	ga_concat_shorten_esc(gap, tv2string(exp_tv, &tofree, numbuf, 0));
  	vim_free(tofree);
      }
      else
! 	ga_concat_shorten_esc(gap, exp_str);
      if (atype != ASSERT_NOTEQUAL)
      {
  	if (atype == ASSERT_MATCH)
***************
*** 9575,9581 ****
  	    ga_concat(gap, (char_u *)" does match ");
  	else
  	    ga_concat(gap, (char_u *)" but got ");
! 	ga_concat_esc(gap, tv2string(got_tv, &tofree, numbuf, 0));
  	vim_free(tofree);
      }
  }
--- 9619,9625 ----
  	    ga_concat(gap, (char_u *)" does match ");
  	else
  	    ga_concat(gap, (char_u *)" but got ");
! 	ga_concat_shorten_esc(gap, tv2string(got_tv, &tofree, numbuf, 0));
  	vim_free(tofree);
      }
  }
*** ../vim-8.1.0818/src/testdir/test_assert.vim	2018-10-07 20:14:53.091279680 +0200
--- src/testdir/test_assert.vim	2019-01-25 20:47:28.113426333 +0100
***************
*** 31,36 ****
--- 31,40 ----
    call assert_equal(1, assert_equal('bar', s))
    call assert_match("Expected 'bar' but got 'foo'", v:errors[0])
    call remove(v:errors, 0)
+ 
+   call assert_equal('XxxxxxxxxxxxxxxxxxxxxxX', 'XyyyyyyyyyyyyyyyyyyyyyyyyyX')
+   call assert_match("Expected 'X\\\\\\[x occurs 21 times]X' but got 'X\\\\\\[y occurs 25 times]X'", v:errors[0])
+   call remove(v:errors, 0)
  endfunc
  
  func Test_assert_equalfile()
*** ../vim-8.1.0818/src/version.c	2019-01-24 23:11:44.635650160 +0100
--- src/version.c	2019-01-25 20:33:02.042881289 +0100
***************
*** 789,790 ****
--- 789,792 ----
  {   /* Add new patch number below this line */
+ /**/
+     819,
  /**/

-- 
   LAUNCELOT leaps into SHOT with a mighty cry and runs the GUARD through and
   hacks him to the floor.  Blood.  Swashbuckling music (perhaps).
   LAUNCELOT races through into the castle screaming.
SECOND SENTRY: Hey!
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///