degesch: add more tests, bump liberty
The UTF-8 common prefix test discovered a bug in UTF-8 parsing. Made $[1-9] in aliases insert nothing if there's no argument at that index.
This commit is contained in:
parent
a0becea2fc
commit
28e4bc1399
44
degesch.c
44
degesch.c
@ -9491,10 +9491,12 @@ expand_alias_escape (const char *p, const char *arguments, struct str *output)
|
||||
cstr_split_ignore_empty (arguments, ' ', &words);
|
||||
|
||||
// TODO: eventually also add support for argument ranges
|
||||
int as_number = *p - '0';
|
||||
if (as_number > 0 && as_number <= 9
|
||||
&& (size_t) as_number <= words.len)
|
||||
str_append (output, words.vector[as_number - 1]);
|
||||
if (*p >= '1' && *p <= '9')
|
||||
{
|
||||
size_t offset = *p - '1';
|
||||
if (offset < words.len)
|
||||
str_append (output, words.vector[offset]);
|
||||
}
|
||||
else if (*p == '*')
|
||||
str_append (output, arguments);
|
||||
else if (strchr ("$;", *p))
|
||||
@ -9507,14 +9509,14 @@ expand_alias_escape (const char *p, const char *arguments, struct str *output)
|
||||
}
|
||||
|
||||
static void
|
||||
expand_alias_definition (const struct str *definition, const char *arguments,
|
||||
expand_alias_definition (const char *definition, const char *arguments,
|
||||
struct str_vector *commands)
|
||||
{
|
||||
struct str expanded;
|
||||
str_init (&expanded);
|
||||
|
||||
bool escape = false;
|
||||
for (const char *p = definition->str; *p; p++)
|
||||
for (const char *p = definition; *p; p++)
|
||||
{
|
||||
if (escape)
|
||||
{
|
||||
@ -9550,7 +9552,7 @@ expand_alias (struct app_context *ctx,
|
||||
return false;
|
||||
}
|
||||
|
||||
expand_alias_definition (&entry->value.string, input, commands);
|
||||
expand_alias_definition (entry->value.string.str, input, commands);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -11199,10 +11201,25 @@ init_poller_events (struct app_context *ctx)
|
||||
|
||||
// --- Tests -------------------------------------------------------------------
|
||||
|
||||
// The application is quite monolithic and can only be partially unit-tested
|
||||
// The application is quite monolithic and can only be partially unit-tested.
|
||||
// Locale-, terminal- and filesystem-dependent tests are also somewhat tricky.
|
||||
|
||||
#ifdef TESTING
|
||||
|
||||
static void
|
||||
test_aliases (void)
|
||||
{
|
||||
struct str_vector v;
|
||||
str_vector_init (&v);
|
||||
expand_alias_definition ("/foo; /bar $* $$$;;;$1$2$3$4", "foo bar baz", &v);
|
||||
hard_assert (v.len == 4);
|
||||
hard_assert (!strcmp (v.vector[0], "/foo"));
|
||||
hard_assert (!strcmp (v.vector[1], " /bar foo bar baz $;"));
|
||||
hard_assert (!strcmp (v.vector[2], ""));
|
||||
hard_assert (!strcmp (v.vector[3], "foobarbaz"));
|
||||
str_vector_free (&v);
|
||||
}
|
||||
|
||||
static void
|
||||
test_wrapping (void)
|
||||
{
|
||||
@ -11221,12 +11238,21 @@ test_wrapping (void)
|
||||
str_vector_free (&v);
|
||||
}
|
||||
|
||||
static void
|
||||
test_utf8_prefix (void)
|
||||
{
|
||||
static const char *a[] = { "fřoo", "Fřooř", "fřOOŘ" };
|
||||
hard_assert (utf8_common_prefix (a, N_ELEMENTS (a)) == 5);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
struct test test;
|
||||
test_init (&test, argc, argv);
|
||||
test_add_simple (&test, "/wrapping", NULL, test_wrapping);
|
||||
test_add_simple (&test, "/aliases", NULL, test_aliases);
|
||||
test_add_simple (&test, "/wrapping", NULL, test_wrapping);
|
||||
test_add_simple (&test, "/utf8-prefix", NULL, test_utf8_prefix);
|
||||
return test_run (&test);
|
||||
}
|
||||
|
||||
|
2
liberty
2
liberty
@ -1 +1 @@
|
||||
Subproject commit 0adcaf67c23fdc2a5082aa11aefd4fdc0aafd70a
|
||||
Subproject commit 5d3e911f015b33d0b4dcc3aa94f7af630438cbf8
|
Loading…
Reference in New Issue
Block a user