From d4f6004ec480a86392e32b6a6d8fd0a430da0d81 Mon Sep 17 00:00:00 2001 From: Paul Grimshaw Date: Fri, 23 Sep 2016 16:05:15 +0100 Subject: [PATCH] Added some further tests --- mustache-sharp.test/FormatCompilerTester.cs | 55 ++++++++++----------- mustache-sharp/FormatCompiler.cs | 4 +- 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/mustache-sharp.test/FormatCompilerTester.cs b/mustache-sharp.test/FormatCompilerTester.cs index 98e8b63..a91858d 100644 --- a/mustache-sharp.test/FormatCompilerTester.cs +++ b/mustache-sharp.test/FormatCompilerTester.cs @@ -1365,6 +1365,31 @@ Item Number: foo
Assert.AreEqual("BeforeContentAfter", result, "The wrong text was generated."); } + /// + /// If the two values match, the content of an eq statement should be printed. + /// + [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 { new {Name="Test"}, new { Name = "Foo" } }, OneValue = "Foo", OtherValue = "Foo" }); + Assert.AreEqual("BeforeContentAfter", result, "The wrong text was generated."); + } + + /// + /// If the two values match, the content of an eq statement should be printed. + /// + [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 { 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 GetChildContext(TextWriter writer, Scope keyScope, Dictionary arguments, Scope contextScope) - { - NestedContext context = new NestedContext() - { - KeyScope = keyScope, - Writer = new StringWriter(), - WriterNeedsConsidated = true, - }; - yield return context; - } - - public override IEnumerable GetChildContextParameters() - { - return new TagParameter[] { new TagParameter("collection") }; - } - - public override string ConsolidateWriter(TextWriter writer, Dictionary arguments) - { - return HttpUtility.UrlEncode(writer.ToString()); - } - } - + #endregion } } diff --git a/mustache-sharp/FormatCompiler.cs b/mustache-sharp/FormatCompiler.cs index 64236f4..986a721 100644 --- a/mustache-sharp/FormatCompiler.cs +++ b/mustache-sharp/FormatCompiler.cs @@ -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);