/* vi:set ts=8 sts=4 sw=4 noet:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
/*
* testing.c: Support for tests.
*/
#include "vim.h"
#if defined(FEAT_EVAL) || defined(PROTO)
/*
* Prepare "gap" for an assert error and add the sourcing position.
*/
static void
prepare_assert_error(garray_T *gap)
{
char buf[NUMBUFLEN];
char_u *sname = estack_sfile(ESTACK_NONE);
ga_init2(gap, 1, 100);
if (sname != NULL)
{
ga_concat(gap, sname);
if (SOURCING_LNUM > 0)
ga_concat(gap, (char_u *)" ");
}
if (SOURCING_LNUM > 0)
{
sprintf(buf, "line %ld", (long)SOURCING_LNUM);
ga_concat(gap, (char_u *)buf);
}
if (sname != NULL || SOURCING_LNUM > 0)
ga_concat(gap, (char_u *)": ");
vim_free(sname);
}
/*
* 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 '\\'<