Added some further tests

This commit is contained in:
Paul Grimshaw 2016-09-23 16:05:15 +01:00
parent 98b0c501e2
commit d4f6004ec4
2 changed files with 28 additions and 31 deletions

View File

@ -1365,6 +1365,31 @@ Item Number: foo<br />
Assert.AreEqual("BeforeContentAfter", result, "The wrong text was generated.");
}
/// <summary>
/// If the two values match, the content of an eq statement should be printed.
/// </summary>
[TestMethod]
public void TestCompile_Eq_EvaluatesToTrueInLoop_PrintsContent() {
FormatCompiler parser = new FormatCompiler();
const string format = "Before{{#each Items}}{{#eq Name OtherValue}}Content{{/eq}}{{/each}}After";
Generator generator = parser.Compile(format);
string result = generator.Render(new { Items = new List<object> { new {Name="Test"}, new { Name = "Foo" } }, OneValue = "Foo", OtherValue = "Foo" });
Assert.AreEqual("BeforeContentAfter", result, "The wrong text was generated.");
}
/// <summary>
/// If the two values match, the content of an eq statement should be printed.
/// </summary>
[TestMethod]
public void TestCompile_Eq_EvaluatesToTrueInLoopWithNumber_PrintsContent() {
FormatCompiler parser = new FormatCompiler();
const string format = "Before{{#each Items}}{{#eq Name OtherValue}}Content{{/eq}}{{/each}}After";
Generator generator = parser.Compile(format);
string result = generator.Render(new { Items = new List<object> { new { Name = 1 }, new { Name = 2 } }, OneValue = "1", OtherValue = "2" });
Assert.AreEqual("BeforeContentAfter", result, "The wrong text was generated.");
}
#endregion
@ -1707,35 +1732,7 @@ Odd
Assert.AreEqual(expected, actual, "Value field didn't work");
}
public class UrlEncodeTagDefinition : ContentTagDefinition
{
public UrlEncodeTagDefinition()
: base("urlencode")
{
}
public override IEnumerable<NestedContext> GetChildContext(TextWriter writer, Scope keyScope, Dictionary<string, object> arguments, Scope contextScope)
{
NestedContext context = new NestedContext()
{
KeyScope = keyScope,
Writer = new StringWriter(),
WriterNeedsConsidated = true,
};
yield return context;
}
public override IEnumerable<TagParameter> GetChildContextParameters()
{
return new TagParameter[] { new TagParameter("collection") };
}
public override string ConsolidateWriter(TextWriter writer, Dictionary<string, object> arguments)
{
return HttpUtility.UrlEncode(writer.ToString());
}
}
#endregion
}
}

View File

@ -52,8 +52,8 @@ namespace Mustache
_tagLookup.Add(gteTagDefinition.Name, gteTagDefinition);
LteTagDefinition lteTagDefinition = new LteTagDefinition();
_tagLookup.Add(lteTagDefinition.Name, lteTagDefinition);
// UrlEncodeTagDefinition urlEncodeTagDefinition = new UrlEncodeTagDefinition();
// _tagLookup.Add(urlEncodeTagDefinition.Name, urlEncodeTagDefinition);
UrlEncodeTagDefinition urlEncodeTagDefinition = new UrlEncodeTagDefinition();
_tagLookup.Add(urlEncodeTagDefinition.Name, urlEncodeTagDefinition);
UrlDecodeTagDefinition urlDecodeTagDefinition = new UrlDecodeTagDefinition();
_tagLookup.Add(urlDecodeTagDefinition.Name,urlDecodeTagDefinition);