Skip to content

Commit c2a9a19

Browse files
Fix the string interpolation issue (Azure#48988)
* add a solution for simplicity * have a try * fix the issue * add a new case * refactor test cases * just noticed that we have a sln * update test case data * refactor * resolve comments * fix test cases
1 parent fb3ca00 commit c2a9a19

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

sdk/provisioning/Azure.Provisioning/src/Expressions/BicepStringBuilder.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ public void AppendFormatted<T>(T t)
104104
_expressions.Add(b.Compile());
105105
_isSecure = _isSecure || b.IsSecure;
106106
}
107+
else if (t is BicepExpression exp)
108+
{
109+
_expressions.Add(exp);
110+
}
107111
else
108112
{
109113
string? s = t?.ToString();
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using Azure.Provisioning.Expressions;
5+
using NUnit.Framework;
6+
7+
namespace Azure.Provisioning.Tests.Expressions
8+
{
9+
public class InterpolatedStringExpressionTest
10+
{
11+
[Test]
12+
public void ValidateBicepFunctionInterpolate()
13+
{
14+
// test provisionable variable
15+
AssertExpression(
16+
"'Var=${foo}'",
17+
BicepFunction.Interpolate(
18+
$"Var={new ProvisioningVariable("foo", typeof(string))}"
19+
)
20+
);
21+
22+
// test index expression in interpolation
23+
AssertExpression(
24+
"'Endpoint=${foo['bar']}'",
25+
BicepFunction.Interpolate(
26+
$"Endpoint={new IndexExpression(
27+
new IdentifierExpression("foo"),
28+
new StringLiteralExpression("bar")
29+
)}")
30+
);
31+
32+
static void AssertExpression(string expected, BicepValue<string> expression)
33+
=> Assert.AreEqual(expected, expression.ToString());
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)