Merge remote-tracking branch 'original-master/master'

# Conflicts:
#	mustache-sharp.test/FormatCompilerTester.cs
This commit is contained in:
Paul Grimshaw 2016-09-23 14:37:16 +01:00
commit 98b0c501e2
6 changed files with 39 additions and 71 deletions

Binary file not shown.

View File

@ -1,4 +1,4 @@
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" ../mustache-sharp.sln /p:Configuration=Release
nuget pack ../mustache-sharp/mustache-sharp.csproj -Properties Configuration=Release
nuget push *.nupkg
nuget push *.nupkg -Source https://www.nuget.org/api/v2/package
del *.nupkg

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Mustache.Test
@ -1690,60 +1691,11 @@ Odd
#endregion
#region ValueIntemplateTests
[TestMethod]
public void TestCompile_CanUseStringValueInEquals() {
FormatCompiler compiler = new FormatCompiler();
const string format = @"{{#eq Value _Yesterday}}Yes!{{/eq}}";
Generator generator = compiler.Compile(format);
string actual = generator.Render(new { Value = "Yesterday" });
string expected = "Yes!";
Assert.AreEqual(expected, actual, "Value field didn't work");
}
#region Custom Tags
[TestMethod]
public void TestCompile_CanUseNumericValueInEquals() {
FormatCompiler compiler = new FormatCompiler();
const string format = @"{{#eq Value _123.3231}}Yes!{{/eq}}";
Generator generator = compiler.Compile(format);
string actual = generator.Render(new { Value = "123.3231" });
string expected = "Yes!";
Assert.AreEqual(expected, actual, "Value field didn't work");
}
[TestMethod]
public void TestCompile_NonEqualNumericValue() {
FormatCompiler compiler = new FormatCompiler();
const string format = @"{{#eq Value _123.3232}}Yes!{{/eq}}";
Generator generator = compiler.Compile(format);
string actual = generator.Render(new { Value = "123.3231" });
string expected = "";
Assert.AreEqual(expected, actual, "Value field didn't work");
}
#endregion
#region UrlDecodeEncode
[TestMethod]
public void TestCompile_UrlEncode() {
FormatCompiler compiler = new FormatCompiler();
compiler.RegisterTag(new UrlEncodeTagDefinition(), true);
const string format = @"{{#urlencode}}https://google.com{{/urlencode}}";
Generator generator = compiler.Compile(format);
string actual = generator.Render(new { });
string expected = "https%3a%2f%2fgoogle.com";
Assert.AreEqual(expected, actual, "Value field didn't work");
}
[TestMethod]
public void TestCompile_UrlEncodeVariableText() {
public void TestCompile_NestedContext_ConsolidatesWriter()
{
FormatCompiler compiler = new FormatCompiler();
compiler.RegisterTag(new UrlEncodeTagDefinition(), true);
@ -1751,24 +1703,39 @@ Odd
Generator generator = compiler.Compile(format);
string actual = generator.Render(new { url = "https://google.com" });
string expected = "https%3a%2f%2fgoogle.com";
string expected = HttpUtility.UrlEncode("https://google.com");
Assert.AreEqual(expected, actual, "Value field didn't work");
}
[TestMethod]
public void TestCompile_UrlDecode() {
FormatCompiler compiler = new FormatCompiler();
const string format = @"{{#urldecode}}https%3a%2f%2fgoogle.com{{/urldecode}}";
Generator generator = compiler.Compile(format);
string actual = generator.Render(new { });
string expected = "https://google.com";
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

@ -42,6 +42,7 @@
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.Web" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">

View File

@ -81,6 +81,7 @@ namespace Mustache
foreach (IGenerator generator in generators)
{
generator.GetText(context.Writer ?? writer, context.KeyScope ?? keyScope, context.ContextScope, postProcessor);
}
if (context.WriterNeedsConsidated)
{
writer.Write(_definition.ConsolidateWriter(context.Writer ?? writer, arguments));
@ -89,4 +90,3 @@ namespace Mustache
}
}
}
}

View File

@ -14,6 +14,6 @@ using System.Runtime.InteropServices;
[assembly: CLSCompliant(true)]
[assembly: ComVisible(false)]
[assembly: Guid("e5a4263d-d450-4d85-a4d5-44c0a2822668")]
[assembly: AssemblyVersion("0.2.9.0")]
[assembly: AssemblyFileVersion("0.2.9.0")]
[assembly: AssemblyVersion("0.2.10.0")]
[assembly: AssemblyFileVersion("0.2.10.0")]
[assembly: InternalsVisibleTo("mustache-sharp.test,PublicKey=0024000004800000940000000602000000240000525341310004000001000100755df5a2b24c568812aae0eb194d08a4e3cba960673bcc07a7d446acf52f3f56ae2155b37b8d547bc5d8c562823bd592d1312bef9ad4740a8bb503d0095c31419f9d190882a2fa46090412bf15b13ca0057ba533c85a853333132ec8b70cf19655ef961b06d1c3fc35b3f68680420562be741456cb7a18bd5ab0fa779f8d47b1")]