test_end();
}
+static void test_var_has_key(void)
+{
+ static struct {
+ const char *str;
+ char key;
+ const char *long_key;
+ bool result;
+ } tests[] = {
+ { "%x%y", 'x', NULL, TRUE },
+ { "%x%y", 'y', NULL, TRUE },
+ { "%x%y", 'z', NULL, FALSE },
+ { "%{foo}", 'f', NULL, FALSE },
+ { "%{foo}", 'o', NULL, FALSE },
+ { "%{foo}", '\0', "foo", TRUE },
+ { "%{foo}", 'o', "foo", TRUE },
+ { "%2.5Mx%y", 'x', NULL, TRUE },
+ { "%2.5M{foo}", '\0', "foo", TRUE },
+ };
+
+ test_begin("var_has_key");
+ for (unsigned int i = 0; i < N_ELEMENTS(tests); i++)
+ test_assert_idx(var_has_key(tests[i].str, tests[i].key, tests[i].long_key) == tests[i].result, i);
+ test_end();
+}
+
void test_var_expand(void)
{
test_var_expand_ranges();
test_var_get_key_range();
test_var_expand_with_funcs();
test_var_get_key();
+ test_var_has_key();
}
keys size=1, while for e.g. %{key} size=3 and idx points to 'k'. */
void var_get_key_range(const char *str, unsigned int *idx_r,
unsigned int *size_r);
-/* Returns TRUE if key variable is used in the string. long_key may be NULL. */
+/* Returns TRUE if key variable is used in the string.
+ If key is '\0', it's ignored. If long_key is NULL, it's ignored. */
bool var_has_key(const char *str, char key, const char *long_key) ATTR_PURE;
const struct var_expand_table *