diff options
author | David Robillard <d@drobilla.net> | 2012-01-17 18:40:12 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-01-17 18:40:12 +0000 |
commit | f5356014a3ea31f820c5df86270258b2a6c1be1f (patch) | |
tree | f1bf4c7e0598ab3bc4621071a9fbb7cd9a9f3c29 | |
parent | 1ad081967284c99a5f86ff7b7e84416c0a601281 (diff) | |
download | lilv-f5356014a3ea31f820c5df86270258b2a6c1be1f.tar.gz lilv-f5356014a3ea31f820c5df86270258b2a6c1be1f.tar.bz2 lilv-f5356014a3ea31f820c5df86270258b2a6c1be1f.zip |
Add test cases for lilv_expand and fix bugs.
git-svn-id: http://svn.drobilla.net/lad/trunk/lilv@3958 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r-- | src/util.c | 4 | ||||
-rw-r--r-- | test/lilv_test.c | 10 |
2 files changed, 12 insertions, 2 deletions
@@ -170,7 +170,7 @@ lilv_expand(const char* path) if (*s == '$') { // Hit $ (variable reference, e.g. $VAR_NAME) for (const char* t = s + 1; ; ++t) { - if (*t == '\0' || !(isupper(*t) || *t == '_')) { + if (!*t || !(isupper(*t) || isdigit(*t) || *t == '_')) { // Append preceding chunk out = strappend(out, &len, start, s - start); @@ -185,7 +185,7 @@ lilv_expand(const char* path) break; } } - } else if (*s == '~' && (*(s + 1) == '/' || (*(s + 1) == '\0'))) { + } else if (*s == '~' && (*(s + 1) == '/' || !*(s + 1))) { // Hit ~ before slash or end of string (home directory reference) out = strappend(out, &len, start, s - start); append_var(out, &len, "HOME"); diff --git a/test/lilv_test.c b/test/lilv_test.c index c8c565a..1a02889 100644 --- a/test/lilv_test.c +++ b/test/lilv_test.c @@ -1421,6 +1421,16 @@ test_string(void) TEST_ASSERT(!strcmp((s = lilv_path_join("/a/", "/b")), "/a/b")); TEST_ASSERT(!strcmp((s = lilv_path_join("/a/", "b")), "/a/b")); + setenv("LILV_TEST_1", "test", 1); + char* home_foo = lilv_strjoin(getenv("HOME"), "/foo", NULL); + TEST_ASSERT(!strcmp((s = lilv_expand("$LILV_TEST_1")), "test")); + TEST_ASSERT(!strcmp((s = lilv_expand("~")), getenv("HOME"))); + TEST_ASSERT(!strcmp((s = lilv_expand("~foo")), "~foo")); + TEST_ASSERT(!strcmp((s = lilv_expand("~/foo")), home_foo)); + TEST_ASSERT(!strcmp((s = lilv_expand("$NOT_A_VAR")), "$NOT_A_VAR")); + free(home_foo); + unsetenv("LILV_TEST_1"); + return 1; } |