diff options
-rw-r--r-- | degesch.c | 44 | ||||
m--------- | liberty | 0 |
2 files changed, 35 insertions, 9 deletions
@@ -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,11 +11201,26 @@ 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) { struct str_vector v; @@ -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); } diff --git a/liberty b/liberty -Subproject 0adcaf67c23fdc2a5082aa11aefd4fdc0aafd70 +Subproject 5d3e911f015b33d0b4dcc3aa94f7af630438cbf |