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:
Přemysl Eric Janouch 2015-12-10 20:01:41 +01:00
parent a0becea2fc
commit 28e4bc1399
2 changed files with 36 additions and 10 deletions

View File

@ -9491,10 +9491,12 @@ expand_alias_escape (const char *p, const char *arguments, struct str *output)
cstr_split_ignore_empty (arguments, ' ', &words); cstr_split_ignore_empty (arguments, ' ', &words);
// TODO: eventually also add support for argument ranges // TODO: eventually also add support for argument ranges
int as_number = *p - '0'; if (*p >= '1' && *p <= '9')
if (as_number > 0 && as_number <= 9 {
&& (size_t) as_number <= words.len) size_t offset = *p - '1';
str_append (output, words.vector[as_number - 1]); if (offset < words.len)
str_append (output, words.vector[offset]);
}
else if (*p == '*') else if (*p == '*')
str_append (output, arguments); str_append (output, arguments);
else if (strchr ("$;", *p)) else if (strchr ("$;", *p))
@ -9507,14 +9509,14 @@ expand_alias_escape (const char *p, const char *arguments, struct str *output)
} }
static void 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_vector *commands)
{ {
struct str expanded; struct str expanded;
str_init (&expanded); str_init (&expanded);
bool escape = false; bool escape = false;
for (const char *p = definition->str; *p; p++) for (const char *p = definition; *p; p++)
{ {
if (escape) if (escape)
{ {
@ -9550,7 +9552,7 @@ expand_alias (struct app_context *ctx,
return false; return false;
} }
expand_alias_definition (&entry->value.string, input, commands); expand_alias_definition (entry->value.string.str, input, commands);
return true; return true;
} }
@ -11199,10 +11201,25 @@ init_poller_events (struct app_context *ctx)
// --- Tests ------------------------------------------------------------------- // --- 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 #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 static void
test_wrapping (void) test_wrapping (void)
{ {
@ -11221,12 +11238,21 @@ test_wrapping (void)
str_vector_free (&v); 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 int
main (int argc, char *argv[]) main (int argc, char *argv[])
{ {
struct test test; struct test test;
test_init (&test, argc, argv); test_init (&test, argc, argv);
test_add_simple (&test, "/aliases", NULL, test_aliases);
test_add_simple (&test, "/wrapping", NULL, test_wrapping); test_add_simple (&test, "/wrapping", NULL, test_wrapping);
test_add_simple (&test, "/utf8-prefix", NULL, test_utf8_prefix);
return test_run (&test); return test_run (&test);
} }

@ -1 +1 @@
Subproject commit 0adcaf67c23fdc2a5082aa11aefd4fdc0aafd70a Subproject commit 5d3e911f015b33d0b4dcc3aa94f7af630438cbf8