-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from jdiamond/dev
Release 1.15.1
- Loading branch information
Showing
5 changed files
with
115 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using NUnit.Framework; | ||
using System.IO; | ||
using Nustache.Compilation; | ||
using Nustache.Core; | ||
|
||
namespace Nustache.Compilation.Tests | ||
{ | ||
[TestFixture] | ||
public class Encoder_Delegate_Usage | ||
{ | ||
class TemplateData | ||
{ | ||
public string Value { get; set; } | ||
} | ||
|
||
[Test] | ||
public void ReplacingHtmlEncodeWorksForCompiledTemplates() | ||
{ | ||
// replace the default encoder with one that wraps the input in "--" | ||
Encoders.HtmlEncoder encoder = (input) => "--" + input + "--"; | ||
Encoders.HtmlEncode = encoder; | ||
|
||
var template = Template("{{Value}}"); | ||
var compiled = template.Compile<TemplateData>(null); | ||
|
||
|
||
var inputText = "Some cool text"; | ||
var data = new TemplateData() | ||
{ | ||
Value = inputText | ||
}; | ||
|
||
var expectedOutput = encoder(inputText); | ||
|
||
Assert.AreEqual(expectedOutput, compiled(data)); | ||
|
||
// reset the used HTML encoder to default | ||
Encoders.HtmlEncode = Encoders.DefaultHtmlEncode; | ||
} | ||
|
||
private Template Template(string text) | ||
{ | ||
var template = new Template(); | ||
template.Load(new StringReader(text)); | ||
return template; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters