forked from sebastienros/fluid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ErrorMessagesTests.cs
43 lines (40 loc) · 1.93 KB
/
ErrorMessagesTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using Fluid.Parser;
using Xunit;
namespace Fluid.Tests
{
public class ErrorMessagesTests
{
#if COMPILED
private static FluidParser _parser = new FluidParser().Compile();
#else
private static FluidParser _parser = new FluidParser();
#endif
[Theory]
[InlineData("{% assign a 'b' %}", ErrorMessages.EqualAfterAssignIdentifier)]
[InlineData("{% assign 'foo' %}", ErrorMessages.IdentifierAfterAssign)]
[InlineData("{% assign %}", ErrorMessages.IdentifierAfterAssign)]
[InlineData("{% assign a = | filter %}", ErrorMessages.LogicalExpressionStartsFilter)]
[InlineData("{% assign a = %}", ErrorMessages.LogicalExpressionStartsFilter)]
[InlineData("{% assign a = b | %}", ErrorMessages.IdentifierAfterPipe)]
[InlineData("{% assign a = 1 | plus 2 %}", ErrorMessages.ExpectedTagEnd)]
[InlineData("{{ 1 | plus 2 }}", ErrorMessages.ExpectedOutputEnd)]
[InlineData("{% assing hello = 'world' %}", "Unknown tag 'assing' at (1:10)")]
[InlineData("{% if true %} {{ foo }", ErrorMessages.ExpectedOutputEnd)]
public void WrongTemplateShouldRenderErrorMessage(string source, string expected)
{
Assert.False(_parser.TryParse(source, out var _, out var error));
Assert.StartsWith(expected, error); // e.g., message then 'at (1:15)'
}
[Theory]
[InlineData(" {% assign a 'b' %}")]
[InlineData("{% assign a = 'b' %}\n {% assign a 'b' %}")]
[InlineData(" {% assign a 'b' %}\n {% assign a = 'b' %}")]
[InlineData(" {% assign a 'b' %}\n\r {% assign a = 'b' %}")]
[InlineData(" {% assign a 'b' %}\n{% assign a = 'b' %}\n {% assign a 'b' %}")]
public void ErrorMessageContainsLineSource(string source)
{
Assert.False(_parser.TryParse(source, out var _, out var error));
Assert.Contains("Source:\n {% assign a 'b' %}", error);
}
}
}