commit 7f8ebf5f5e52d9cfabd50006c9460287c3741d4d
parent c91e188d74a0e91051c822d6107e4653103cd162
Author: Florian Dold <dold@taler.net>
Date: Tue, 21 Jul 2026 20:10:15 +0200
util: test the substitution default separators the C accepts
Also corrects the nested-name case: the C does not expand the name part, so
${${w}:-x} looks up the literal name and falls back to the default.
Diffstat:
1 file changed, 31 insertions(+), 2 deletions(-)
diff --git a/packages/taler-util/src/talerconfig.test.ts b/packages/taler-util/src/talerconfig.test.ts
@@ -62,6 +62,34 @@ test("pathsub", (t) => {
"http://example.com/a:-b",
);
+ // The C takes the first ":" as introducing the default and merely skips a
+ // following "-" or "=", so all three spellings mean the same thing.
+ for (const expr of ["${x:-blabla}", "${x:=blabla}", "${x:blabla}"]) {
+ assert.strictEqual(
+ pathsub(expr, (v) => d[v]),
+ "blabla",
+ expr,
+ );
+ }
+ assert.strictEqual(
+ pathsub("${x:=a:=b}", (v) => d[v]),
+ "a:=b",
+ );
+ // An empty default expands to the empty string, it is not "no default".
+ assert.strictEqual(
+ pathsub("${x:}", (v) => d[v]),
+ "",
+ );
+ assert.strictEqual(
+ pathsub("${x:-}", (v) => d[v]),
+ "",
+ );
+ // A variable that is set still wins over its default.
+ assert.strictEqual(
+ pathsub("${w:-fallback}", (v) => d[v]),
+ "world",
+ );
+
// No braces
assert.strictEqual(
pathsub("hello $w!", (v) => d[v]),
@@ -95,10 +123,11 @@ test("pathsub", (t) => {
"hello world!",
);
- // No variables in variable name part
+ // The name part is not expanded: the C looks up the literal name "${w}",
+ // does not find it, and falls back to the default.
assert.strictEqual(
pathsub("hello ${${w}:-x}!", (v) => d[v]),
- "hello ${${w}:-x}!",
+ "hello x!",
);
// Missing closing brace