Skip to content

Commit

Permalink
Add test cases for #35
Browse files Browse the repository at this point in the history
  • Loading branch information
Ygg01 committed Oct 23, 2023
1 parent 5a032dd commit 8970a47
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
30 changes: 29 additions & 1 deletion Linguini.Syntax.Tests/Parser/LinguiniParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public void TestTermComment(string input, bool inTerm, string expTerm, string ex
public void TestNumExpressions(string input, string identifier, string value)
{
var res = new LinguiniParser(input).Parse();

Assert.AreEqual(0, res.Errors.Count);
Assert.AreEqual(1, res.Entries.Count);
Assert.IsInstanceOf(typeof(AstMessage), res.Entries[0]);
Expand All @@ -192,5 +192,33 @@ public void TestNumExpressions(string input, string identifier, string value)
Assert.AreEqual(value, numberLiteral.ToString());
}
}

private const string CrlfEscape = "message = \r\n" +
" Line1\r\n" +
" \r\n" +
" \r\n" +
" Line2.\r\n";

private const string CrEscape = "message = \n" +
" Line1\n" +
"\n" +
"\n" +
" Line2.\n";

private const string expected = "Line1\n\n\nLine2.";

[Test]
[TestCase(CrlfEscape)]
// [TestCase(CrEscape)]
public void TestNewlinePreservation(string input)
{
var parse = new LinguiniParser(input).Parse();

Assert.AreEqual(0, parse.Errors.Count);
var msg = parse.Entries[0];
Assert.IsInstanceOf(typeof(AstMessage), msg);
var astMsg = (AstMessage)msg;
Assert.AreEqual(expected, astMsg.Debug());
}
}
}
52 changes: 52 additions & 0 deletions Linguini.Syntax/Ast/AstDebugHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Text;

namespace Linguini.Syntax.Ast
{
public static class AstDebugHelper
{
public static string Debug(this AstMessage message)
{
var stringBuilder = new StringBuilder();
if (message.Value != null)
{
foreach (var patternElement in message.Value.Elements)
{
switch (patternElement)
{
case TextLiteral textLiteral:
stringBuilder.Append(textLiteral.Value);
break;
case Placeable placeable:
Debug(placeable, stringBuilder);
break;
}
}
}

return stringBuilder.ToString();
}

private static void Debug(Placeable placeable, StringBuilder stringBuilder)
{
switch (placeable.Expression)
{
case SelectExpression selectExpression:
Debug(selectExpression, stringBuilder);
break;
case IInlineExpression inlineExpression:
Debug(inlineExpression, stringBuilder);
break;
}
}

private static void Debug(IInlineExpression inlineExpression, StringBuilder stringBuilder)
{
throw new System.NotImplementedException();
}

private static void Debug(SelectExpression selectExpression, StringBuilder stringBuilder)
{
throw new System.NotImplementedException();
}
}
}
3 changes: 3 additions & 0 deletions qodana.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ exclude:
- name: All
paths:
- Linguini.Bundle\IsExternalInit.cs
- name: CheckNamespace
paths:
- Linguini.Bundle\IsExternalInit.cs

0 comments on commit 8970a47

Please sign in to comment.