--- var_test.c 2001/11/13 12:46:50 1.2
+++ var_test.c 2001/11/13 13:25:18 1.3
@@ -79,7 +79,8 @@
{ "${FOO:p/15/../r}", ".............os" },
{ "${FOO:p/15/12345/r}", "1234512345123os" },
{ "${FOO:p/15/../c}", "......os......." },
- { "${FOO:p/15/12345/c}", "123451os1234512" }
+ { "${FOO:p/15/12345/c}", "123451os1234512" },
+ { "${FOO:s/os/\\x{4F}\\123/g}", "OS" }
};
/*
{ "${HOME:s/g(res)s/x\\\\1x/g}","/homE/rEgrEssion-tEsts" }
@@ -89,6 +90,7 @@
size_t tmp_len;
var_rc_t rc;
size_t i;
+ char buffer[1024];
if (setenv("HOME", "/home/regression-tests", 1) != 0 ||
setenv("OSTYPE", "regression-os", 1) != 0 ||
@@ -104,8 +106,15 @@
for (i = 0; i < sizeof(tests) / sizeof(struct test_case); ++i)
{
- rc = var_expand(tests[i].input, strlen(tests[i].input),
- &tmp, &tmp_len,
+ printf("Test case #%02d: Original input is '%s'.\n", i, tests[i].input);
+ rc = var_unescape(tests[i].input, strlen(tests[i].input), buffer, 0);
+ if (rc != VAR_OK)
+ {
+ printf("Test case #%d: First var_unescape() failed with return code %d.\n", i, rc);
+ return 1;
+ }
+ printf("Test case #%02d: Unescaped input is '%s'.\n", i, buffer);
+ rc = var_expand(buffer, strlen(buffer), &tmp, &tmp_len,
&env_lookup, NULL,
NULL, 0);
if (rc != VAR_OK)
@@ -113,12 +122,19 @@
printf("Test case #%d: var_expand() failed with return code %d.\n", i, rc);
return 1;
}
+ printf("Test case #%02d: Expanded output is '%s'.\n", i, tmp);
if (tmp_len != strlen(tests[i].expected) || tmp == NULL || memcmp(tests[i].expected, tmp, tmp_len) != 0)
{
printf("Test case #%d: Expected result '%s' but got '%s'.\n", i, tests[i].expected, tmp);
return 1;
}
- printf("Test case #%02d: '%s' --> '%s'.\n", i, tests[i].input, tmp);
+ rc = var_unescape(tests[i].input, strlen(tests[i].input), buffer, 1);
+ if (rc != VAR_OK)
+ {
+ printf("Test case #%d: Second var_unescape() failed with return code %d.\n", i, rc);
+ return 1;
+ }
+ printf("Test case #%02d: Unescaped output is '%s'.\n\n", i, tmp);
free(tmp);
}
|