1 /*******************************/
2 /* GENERATED FILE, DO NOT EDIT */
3 /*******************************/
7 /*******************************/
8 /* GENERATED FILE, DO NOT EDIT */
9 /*******************************/
11 #line 293 "xbt/xbt_strbuff.c"
12 #include "xbt/strbuff.h"
14 /* buffstr have 512 chars by default. Adding 1000 chars like this will force a resize, allowing us to test that b->used and b->size are consistent */
15 #define force_resize \
16 "1.........1.........2.........3.........4.........5.........6.........7.........8.........9........." \
17 "2.........1.........2.........3.........4.........5.........6.........7.........8.........9........." \
18 "3.........1.........2.........3.........4.........5.........6.........7.........8.........9........." \
19 "4.........1.........2.........3.........4.........5.........6.........7.........8.........9........." \
20 "5.........1.........2.........3.........4.........5.........6.........7.........8.........9........." \
21 "6.........1.........2.........3.........4.........5.........6.........7.........8.........9........." \
22 "7.........1.........2.........3.........4.........5.........6.........7.........8.........9........." \
23 "8.........1.........2.........3.........4.........5.........6.........7.........8.........9........." \
24 "9.........1.........2.........3.........4.........5.........6.........7.........8.........9........." \
25 "0.........1.........2.........3.........4.........5.........6.........7.........8.........9........."
27 static void mytest(const char *input, const char *patterns,
30 xbt_dynar_t dyn_patterns; /* splited string */
31 xbt_dict_t p; /* patterns */
33 char *str; /*foreach */
34 xbt_strbuff_t sb; /* what we test */
37 dyn_patterns = xbt_str_split(patterns, " ");
38 xbt_dynar_foreach(dyn_patterns, cpt, str) {
39 xbt_dynar_t keyvals = xbt_str_split(str, "=");
40 char *key = xbt_dynar_get_as(keyvals, 0, char *);
41 char *val = xbt_dynar_get_as(keyvals, 1, char *);
42 xbt_str_subst(key, '_', ' ', 0); // to put space in names without breaking the enclosing dynar_foreach
43 xbt_dict_set(p, key, xbt_strdup(val), free);
44 xbt_dynar_free(&keyvals);
46 xbt_dynar_free(&dyn_patterns);
47 sb = xbt_strbuff_new();
48 xbt_strbuff_append(sb, input);
49 xbt_strbuff_varsubst(sb, p);
51 xbt_test_assert4(!strcmp(sb->data, expected),
52 "Input (%s) with patterns (%s) leads to (%s) instead of (%s)",
53 input, patterns, sb->data, expected);
57 XBT_TEST_UNIT("xbt_strbuff_substitute", test_strbuff_substitute,"test the function xbt_strbuff_substitute")
59 xbt_test_add0("Empty");
62 xbt_test_add0("Value shorter, no braces, only variable");
63 mytest("$tutu", "tutu=t", "t");
64 xbt_test_add0("Value shorter, braces, only variable");
65 mytest("${tutu}", "tutu=t", "t");
66 xbt_test_add0("Value shorter, no braces, data after");
67 mytest("$tutu toto", "tutu=t", "t toto");
68 xbt_test_add0("Value shorter, braces, data after");
69 mytest("${tutu} toto", "tutu=t", "t toto");
70 xbt_test_add0("Value shorter, no braces, data before");
71 mytest("toto $tutu", "tutu=t", "toto t");
72 xbt_test_add0("Value shorter, braces, data before");
73 mytest("toto ${tutu}", "tutu=t", "toto t");
74 xbt_test_add0("Value shorter, no braces, data before and after");
75 mytest("toto $tutu tata", "tutu=t", "toto t tata");
76 xbt_test_add0("Value shorter, braces, data before and after");
77 mytest("toto ${tutu} tata", "tutu=t", "toto t tata");
79 xbt_test_add0("Value as long, no braces, only variable");
80 mytest("$tutu", "tutu=12345", "12345");
81 xbt_test_add0("Value as long, braces, only variable");
82 mytest("${tutu}", "tutu=1234567", "1234567");
83 xbt_test_add0("Value as long, no braces, data after");
84 mytest("$tutu toto", "tutu=12345", "12345 toto");
85 xbt_test_add0("Value as long, braces, data after");
86 mytest("${tutu} toto", "tutu=1234567", "1234567 toto");
87 xbt_test_add0("Value as long, no braces, data before");
88 mytest("toto $tutu", "tutu=12345", "toto 12345");
89 xbt_test_add0("Value as long, braces, data before");
90 mytest("toto ${tutu}", "tutu=1234567", "toto 1234567");
91 xbt_test_add0("Value as long, no braces, data before and after");
92 mytest("toto $tutu tata", "tutu=12345", "toto 12345 tata");
93 xbt_test_add0("Value as long, braces, data before and after");
94 mytest("toto ${tutu} tata", "tutu=1234567", "toto 1234567 tata");
96 xbt_test_add0("Value longer, no braces, only variable");
97 mytest("$t", "t=tututu", "tututu");
98 xbt_test_add0("Value longer, braces, only variable");
99 mytest("${t}", "t=tututu", "tututu");
100 xbt_test_add0("Value longer, no braces, data after");
101 mytest("$t toto", "t=tututu", "tututu toto");
102 xbt_test_add0("Value longer, braces, data after");
103 mytest("${t} toto", "t=tututu", "tututu toto");
104 xbt_test_add0("Value longer, no braces, data before");
105 mytest("toto $t", "t=tututu", "toto tututu");
106 xbt_test_add0("Value longer, braces, data before");
107 mytest("toto ${t}", "t=tututu", "toto tututu");
108 xbt_test_add0("Value longer, no braces, data before and after");
109 mytest("toto $t tata", "t=tututu", "toto tututu tata");
110 xbt_test_add0("Value longer, braces, data before and after");
111 mytest("toto ${t} tata", "t=tututu", "toto tututu tata");
113 xbt_test_add0("Value much longer, no braces, only variable");
114 mytest("$t", "t=" force_resize, force_resize);
115 xbt_test_add0("Value much longer, no braces, data after");
116 mytest("$t toto", "t=" force_resize, force_resize " toto");
117 xbt_test_add0("Value much longer, braces, data after");
118 mytest("${t} toto", "t=" force_resize, force_resize " toto");
119 xbt_test_add0("Value much longer, no braces, data before");
120 mytest("toto $t", "t=" force_resize, "toto " force_resize);
121 xbt_test_add0("Value much longer, braces, data before");
122 mytest("toto ${t}", "t=" force_resize, "toto " force_resize);
123 xbt_test_add0("Value much longer, no braces, data before and after");
124 mytest("toto $t tata", "t=" force_resize, "toto " force_resize " tata");
125 xbt_test_add0("Value much longer, braces, data before and after");
126 mytest("toto ${t} tata", "t=" force_resize, "toto " force_resize " tata");
128 xbt_test_add0("Escaped $");
129 mytest("\\$tutu", "tutu=t", "\\$tutu");
130 xbt_test_add0("Space in var name (with braces)");
131 mytest("${tu ti}", "tu_ti=t", "t");
133 xbt_test_add0("Two variables");
134 mytest("$toto $tutu", "toto=1 tutu=2", "1 2");
136 // Commented: I'm too lazy to do a memmove in var name to remove the backslash after use.
137 // Users should use braces.
138 // xbt_test_add0("Escaped space in var name", "$tu\\ ti", "tu_ti=t", "t");
140 xbt_test_add0("Default value");
141 mytest("${t:-toto}", "", "toto");
142 xbt_test_add0("Useless default value (variable already defined)");
143 mytest("${t:-toto}", "t=TRUC", "TRUC");
147 /*******************************/
148 /* GENERATED FILE, DO NOT EDIT */
149 /*******************************/