Skip to content

Commit

Permalink
Merge pull request #52 from EvoEsports/bugfix/interpolation-exception
Browse files Browse the repository at this point in the history
Disable double interpolation test because of bad algorithm
  • Loading branch information
araszka authored Feb 4, 2024
2 parents 9657b5e + eba7d3e commit f7aac28
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
37 changes: 19 additions & 18 deletions src/ManiaTemplates/Lib/MtTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1182,24 +1182,25 @@ public static string ReplaceCurlyBraces(string value, Func<string, string> curly
/// </summary>
public static void CheckInterpolationRecursion(string value)
{
var openCurlyBraces = 0;
foreach (var character in value.ToCharArray())
{
if (character == '{')
{
openCurlyBraces++;

if (openCurlyBraces >= 4)
{
throw new InterpolationRecursionException(
$"Double interpolation found in: {value}. You must not use double curly braces inside other double curly braces.");
}
}
else if (character == '}')
{
openCurlyBraces--;
}
}
//TODO: find proper algorithm
// var openCurlyBraces = 0;
// foreach (var character in value.ToCharArray())
// {
// if (character == '{')
// {
// openCurlyBraces++;
//
// if (openCurlyBraces >= 4)
// {
// throw new InterpolationRecursionException(
// $"Double interpolation found in: {value}. You must not use double curly braces inside other double curly braces.");
// }
// }
// else if (character == '}')
// {
// openCurlyBraces--;
// }
// }
}

/// <summary>
Expand Down
16 changes: 8 additions & 8 deletions tests/ManiaTemplates.Tests/Lib/MtTransformerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ public void Should_Import_Components_Recursively()
", output, ignoreLineEndingDifferences: true);
}

[Fact]
public void Should_Throw_Interpolation_Recursion_Exception()
{
Assert.Throws<InterpolationRecursionException>(() =>
MtTransformer.CheckInterpolationRecursion("{{ {{ a }} {{ b }} }}"));
Assert.Throws<InterpolationRecursionException>(() =>
MtTransformer.CheckInterpolationRecursion("{{ {{ b }} }}"));
}
// [Fact]
// public void Should_Throw_Interpolation_Recursion_Exception()
// {
// Assert.Throws<InterpolationRecursionException>(() =>
// MtTransformer.CheckInterpolationRecursion("{{ {{ a }} {{ b }} }}"));
// Assert.Throws<InterpolationRecursionException>(() =>
// MtTransformer.CheckInterpolationRecursion("{{ {{ b }} }}"));
// }

[Fact]
public void Should_Throw_Curly_Brace_Count_Mismatch_Exception()
Expand Down

0 comments on commit f7aac28

Please sign in to comment.