viml/parser/expressions: Create tests for latest additions

This commit is contained in:
ZyX 2017-10-15 19:06:41 +03:00
parent 8178ba2871
commit c286155bfa
4 changed files with 1519 additions and 6 deletions

View File

@ -1937,9 +1937,22 @@ viml_pexpr_parse_process_token:
OP_MISSING; OP_MISSING;
} }
NEW_NODE_WITH_CUR_POS(cur_node, kExprNodeOption); NEW_NODE_WITH_CUR_POS(cur_node, kExprNodeOption);
cur_node->data.opt.ident = cur_token.data.opt.name; if (cur_token.type == kExprLexInvalid) {
cur_node->data.opt.ident_len = cur_token.data.opt.len; assert(cur_token.len == 1
cur_node->data.opt.scope = cur_token.data.opt.scope; || (cur_token.len == 3
&& pline.data[cur_token.start.col + 2] == ':'));
cur_node->data.opt.ident = (
pline.data + cur_token.start.col + cur_token.len);
cur_node->data.opt.ident_len = 0;
cur_node->data.opt.scope = (
cur_token.len == 3
? (ExprOptScope)pline.data[cur_token.start.col + 1]
: kExprOptScopeUnspecified);
} else {
cur_node->data.opt.ident = cur_token.data.opt.name;
cur_node->data.opt.ident_len = cur_token.data.opt.len;
cur_node->data.opt.scope = cur_token.data.opt.scope;
}
*top_node_p = cur_node; *top_node_p = cur_node;
want_node = kENodeOperator; want_node = kENodeOperator;
viml_parser_highlight(pstate, cur_token.start, 1, HL(OptionSigil)); viml_parser_highlight(pstate, cur_token.start, 1, HL(OptionSigil));
@ -1953,7 +1966,7 @@ viml_pexpr_parse_process_token:
} }
viml_parser_highlight( viml_parser_highlight(
pstate, shifted_pos(cur_token.start, scope_shift + 1), pstate, shifted_pos(cur_token.start, scope_shift + 1),
cur_token.len - scope_shift + 1, HL(Option)); cur_token.len - (scope_shift + 1), HL(Option));
break; break;
} }
case kExprLexEnv: { case kExprLexEnv: {
@ -1963,6 +1976,10 @@ viml_pexpr_parse_process_token:
NEW_NODE_WITH_CUR_POS(cur_node, kExprNodeEnvironment); NEW_NODE_WITH_CUR_POS(cur_node, kExprNodeEnvironment);
cur_node->data.env.ident = pline.data + cur_token.start.col + 1; cur_node->data.env.ident = pline.data + cur_token.start.col + 1;
cur_node->data.env.ident_len = cur_token.len - 1; cur_node->data.env.ident_len = cur_token.len - 1;
if (cur_node->data.env.ident_len == 0) {
ERROR_FROM_TOKEN_AND_MSG(cur_token,
_("E15: Environment variable name missing"));
}
*top_node_p = cur_node; *top_node_p = cur_node;
want_node = kENodeOperator; want_node = kENodeOperator;
viml_parser_highlight(pstate, cur_token.start, 1, HL(EnvironmentSigil)); viml_parser_highlight(pstate, cur_token.start, 1, HL(EnvironmentSigil));

View File

@ -352,7 +352,14 @@ format_luav = function(v, indent)
end end
end end
ret = ret .. indent .. '}' ret = ret .. indent .. '}'
elseif type(v) == 'number' then
if v % 1 == 0 then
ret = ('%d'):format(v)
else
ret = ('%e'):format(v)
end
else else
print(type(v))
-- Not implemented yet -- Not implemented yet
assert(false) assert(false)
end end

View File

@ -89,10 +89,69 @@ char_u *string_convert(const vimconv_T *conv, char_u *data, size_t *size)
return NULL; return NULL;
} }
int utf_ptr2len_len(const char_u *p, int size)
{
int len;
int i;
int m;
len = utf8len_tab[*p];
if (len == 1)
return 1; /* NUL, ascii or illegal lead byte */
if (len > size)
m = size; /* incomplete byte sequence. */
else
m = len;
for (i = 1; i < m; ++i)
if ((p[i] & 0xc0) != 0x80)
return 1;
return len;
}
int utfc_ptr2len_len(const char_u *p, int size) int utfc_ptr2len_len(const char_u *p, int size)
{ {
assert(false); int len;
return 0; int prevlen;
if (size < 1 || *p == NUL)
return 0;
if (p[0] < 0x80 && (size == 1 || p[1] < 0x80)) /* be quick for ASCII */
return 1;
/* Skip over first UTF-8 char, stopping at a NUL byte. */
len = utf_ptr2len_len(p, size);
/* Check for illegal byte and incomplete byte sequence. */
if ((len == 1 && p[0] >= 0x80) || len > size)
return 1;
/*
* Check for composing characters. We can handle only the first six, but
* skip all of them (otherwise the cursor would get stuck).
*/
prevlen = 0;
while (len < size) {
int len_next_char;
if (p[len] < 0x80)
break;
/*
* Next character length should not go beyond size to ensure that
* UTF_COMPOSINGLIKE(...) does not read beyond size.
*/
len_next_char = utf_ptr2len_len(p + len, size - len);
if (len_next_char > size - len)
break;
if (!UTF_COMPOSINGLIKE(p + prevlen, p + len))
break;
/* Skip over composing char */
prevlen = len;
len += len_next_char;
}
return len;
} }
int utf_char2len(const int c) int utf_char2len(const int c)

File diff suppressed because it is too large Load Diff