本文整理汇总了C#中FormatCompiler类的典型用法代码示例。如果您正苦于以下问题:C# FormatCompiler类的具体用法?C# FormatCompiler怎么用?C# FormatCompiler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FormatCompiler类属于命名空间,在下文中一共展示了FormatCompiler类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: TestCompile_CommentAloneOnlyLine_PrintsSurroundingSpace
public void TestCompile_CommentAloneOnlyLine_PrintsSurroundingSpace()
{
FormatCompiler compiler = new FormatCompiler();
Generator generator = compiler.Compile(" {{#! comment }} ");
string result = generator.Render(null);
Assert.AreEqual(" ", result, "The wrong text was generated.");
}
开发者ID:sithembisophp,项目名称:mustache-sharp,代码行数:7,代码来源:FormatCompilerTester.cs
示例2: TestCompile_CommentContentComment_RemovesComment
public void TestCompile_CommentContentComment_RemovesComment()
{
FormatCompiler compiler = new FormatCompiler();
const string format = "{{#! comment }}Middle{{#! comment }}";
Generator generator = compiler.Compile(format);
string result = generator.Render(new object());
Assert.AreEqual("Middle", result, "The wrong text was generated.");
}
开发者ID:Zocdoc,项目名称:mustache-sharp,代码行数:8,代码来源:FormatCompilerTester.cs
示例3: TestCompile_Key_ReplacesWithValue
public void TestCompile_Key_ReplacesWithValue()
{
FormatCompiler compiler = new FormatCompiler();
const string format = @"Hello, {{Name}}!!!";
Generator generator = compiler.Compile(format);
string result = generator.Render(new { Name = "Bob" });
Assert.AreEqual("Hello, Bob!!!", result, "The wrong text was generated.");
}
开发者ID:khoaho,项目名称:mustache-sharp,代码行数:8,代码来源:FormatCompilerTester.cs
示例4: TestCompile_LineAllWhitespace_PrintsWhitespace
public void TestCompile_LineAllWhitespace_PrintsWhitespace()
{
FormatCompiler compiler = new FormatCompiler();
const string format = "\t \t";
Generator generator = compiler.Compile(format);
string result = generator.Render(null);
Assert.AreEqual(format, result, "The generated text was wrong.");
}
开发者ID:khoaho,项目名称:mustache-sharp,代码行数:8,代码来源:FormatCompilerTester.cs
示例5: TestCompile_NoTags_PrintsFormatString
public void TestCompile_NoTags_PrintsFormatString()
{
FormatCompiler compiler = new FormatCompiler();
const string format = "This is an ordinary string.";
Generator generator = compiler.Compile(format);
string result = generator.Render(null);
Assert.AreEqual(format, result, "The generated text was wrong.");
}
开发者ID:khoaho,项目名称:mustache-sharp,代码行数:8,代码来源:FormatCompilerTester.cs
示例6: TestCompile_CommentBlankComment_RemovesLine
public void TestCompile_CommentBlankComment_RemovesLine()
{
FormatCompiler compiler = new FormatCompiler();
const string format = "{{#! comment }} {{#! comment }}";
Generator generator = compiler.Compile(format);
string result = generator.Render(new object());
Assert.AreEqual(String.Empty, result, "The wrong text was generated.");
}
开发者ID:Zocdoc,项目名称:mustache-sharp,代码行数:8,代码来源:FormatCompilerTester.cs
示例7: TestCompile_CanUseContextVariablesToMakeDecisions
public void TestCompile_CanUseContextVariablesToMakeDecisions()
{
FormatCompiler compiler = new FormatCompiler();
const string format = @"{{#each this}}{{#if @index}}{{#index}}{{/if}}{{/each}}";
Generator generator = compiler.Compile(format);
string actual = generator.Render(new int[] { 1, 1, 1, 1, });
string expected = "123";
Assert.AreEqual(expected, actual, "The numbers were not valid.");
}
开发者ID:sithembisophp,项目名称:mustache-sharp,代码行数:9,代码来源:FormatCompilerTester.cs
示例8: TestCompile_CanUseContextStartEndVariablesToMakeDecisions
public void TestCompile_CanUseContextStartEndVariablesToMakeDecisions()
{
FormatCompiler compiler = new FormatCompiler();
const string format = @"{{#each this}}{{#if @start}}<li class=""first""></li>{{#elif @end}}<li class=""last""></li>{{#else}}<li class=""middle""></li>{{/if}}{{/each}}";
Generator generator = compiler.Compile(format);
string actual = generator.Render(new int[] { 1, 1, 1, 1, });
string expected = @"<li class=""first""></li><li class=""middle""></li><li class=""middle""></li><li class=""last""></li>";
Assert.AreEqual(expected, actual, "The string is not valid.");
}
开发者ID:sheigl,项目名称:mustache-sharp,代码行数:9,代码来源:FormatCompilerTester.cs
示例9: TestCompile_CommentNewLineBlank_PrintsBlank
public void TestCompile_CommentNewLineBlank_PrintsBlank()
{
FormatCompiler compiler = new FormatCompiler();
const string format = @" {{#! comment }}
";
Generator generator = compiler.Compile(format);
string result = generator.Render(null);
Assert.AreEqual(" ", result, "The wrong text was generated.");
}
开发者ID:Zocdoc,项目名称:mustache-sharp,代码行数:9,代码来源:FormatCompilerTester.cs
示例10: TestCompile_OutputNewLineBlank_PrintsBothLines
public void TestCompile_OutputNewLineBlank_PrintsBothLines()
{
FormatCompiler compiler = new FormatCompiler();
const string format = @"Hello{{#newline}}
";
const string expected = @"Hello
";
Generator generator = compiler.Compile(format);
string result = generator.Render(null);
Assert.AreEqual(expected, result, "The wrong text was generated.");
}
开发者ID:khoaho,项目名称:mustache-sharp,代码行数:12,代码来源:FormatCompilerTester.cs
示例11: TestCompile_CanUseContextVariableToToggle
public void TestCompile_CanUseContextVariableToToggle()
{
FormatCompiler compiler = new FormatCompiler();
const string format = @"{{#set even}}{{#each this}}{{#if @even}}Even {{#else}}Odd {{/if}}{{#set even}}{{/each}}";
Generator generator = compiler.Compile(format);
generator.ValueRequested += (sender, e) =>
{
e.Value = !(bool)(e.Value ?? false);
};
string actual = generator.Render(new int[] { 1, 1, 1, 1 });
string expected = "Even Odd Even Odd ";
Assert.AreEqual(expected, actual, "The context variable was not toggled.");
}
开发者ID:sithembisophp,项目名称:mustache-sharp,代码行数:13,代码来源:FormatCompilerTester.cs
示例12: TestEach
public void TestEach()
{
Dictionary<string, object> allparameters = new Dictionary<string, object>();
allparameters.Add("stuName", "Jason");
allparameters.Add("schoolName", "SH LJZ");
//-----------------------------------------------------
var class1 = new Dictionary<string, object>();
class1.Add("Address", "Tong ren road 258号");
class1.Add("Date", DateTime.Now);
var Class2 = new Dictionary<string, object>();
Class2.Add("Address", "People square");
Class2.Add("Date", DateTime.Now);
List<object> classes = new List<object>();
classes.Add(class1);
classes.Add(Class2);
//-------------------------------------------------------
allparameters.Add("Classes", classes);
//--------------------------------------------------------
var school1 = new Dictionary<string, object>();
school1.Add("SchoolName", "LJZ");
school1.Add("StuCount", 10);
var school2 = new Dictionary<string, object>();
school2.Add("SchoolName", "PSQ");
school2.Add("StuCount", "20");
List<object> schools = new List<object>();
schools.Add(school1);
schools.Add(school2);
//---------------------------------------------------------
allparameters.Add("Schools", schools);
FormatCompiler compiler = new FormatCompiler();
Generator generator = compiler.Compile(template);
string actual = generator.Render(allparameters);
Assert.IsNotNull(actual);
}
开发者ID:RuhuiCheng,项目名称:Talent,代码行数:38,代码来源:Test.cs
示例13: TestCompile_IfElse_TwoElses_IncludesSecondElseInElse_Throws
public void TestCompile_IfElse_TwoElses_IncludesSecondElseInElse_Throws()
{
FormatCompiler parser = new FormatCompiler();
const string format = "Before{{#if this}}Yay{{#else}}Nay{{#else}}Bad{{/if}}After";
Generator generator = parser.Compile(format);
string result = generator.Render(false);
Assert.AreEqual("BeforeNay{{#else}}BadAfter", result, "The wrong text was generated.");
}
开发者ID:sithembisophp,项目名称:mustache-sharp,代码行数:8,代码来源:FormatCompilerTester.cs
示例14: TestCompile_IfElse_EvaluatesToFalse_PrintsElse
public void TestCompile_IfElse_EvaluatesToFalse_PrintsElse()
{
FormatCompiler parser = new FormatCompiler();
const string format = "Before{{#if this}}Yay{{#else}}Nay{{/if}}After";
Generator generator = parser.Compile(format);
string result = generator.Render(false);
Assert.AreEqual("BeforeNayAfter", result, "The wrong text was generated.");
}
开发者ID:sithembisophp,项目名称:mustache-sharp,代码行数:8,代码来源:FormatCompilerTester.cs
示例15: TestCompile_IfElif_ElifFalse_PrintsNothing
public void TestCompile_IfElif_ElifFalse_PrintsNothing()
{
FormatCompiler parser = new FormatCompiler();
const string format = "Before{{#if First}}First{{#elif Second}}Second{{/if}}After";
Generator generator = parser.Compile(format);
string result = generator.Render(new { First = false, Second = false });
Assert.AreEqual("BeforeAfter", result, "The wrong text was generated.");
}
开发者ID:sithembisophp,项目名称:mustache-sharp,代码行数:8,代码来源:FormatCompilerTester.cs
示例16: TestCompile_FindsVariables_RecordsVariables
public void TestCompile_FindsVariables_RecordsVariables()
{
FormatCompiler compiler = new FormatCompiler();
HashSet<string> variables = new HashSet<string>();
compiler.VariableFound += (o, e) =>
{
variables.Add(e.Name);
};
compiler.Compile(@"{{@FirstName}}{{@LastName}}");
string[] expected = new string[] { "FirstName", "LastName" };
string[] actual = variables.OrderBy(s => s).ToArray();
CollectionAssert.AreEqual(expected, actual, "Not all variables were found.");
}
开发者ID:sithembisophp,项目名称:mustache-sharp,代码行数:13,代码来源:FormatCompilerTester.cs
示例17: TestCompile_MissingDefaultParameter_ProvidesDefault
public void TestCompile_MissingDefaultParameter_ProvidesDefault()
{
FormatCompiler compiler = new FormatCompiler();
compiler.RegisterTag(new DefaultTagDefinition(), true);
const string format = @"{{#default}}";
Generator generator = compiler.Compile(format);
string result = generator.Render(null);
Assert.AreEqual("123", result, "The wrong text was generated.");
}
开发者ID:sithembisophp,项目名称:mustache-sharp,代码行数:9,代码来源:FormatCompilerTester.cs
示例18: TestCompile_KeyWithFormat_AppliesFormatting
public void TestCompile_KeyWithFormat_AppliesFormatting()
{
FormatCompiler compiler = new FormatCompiler();
const string format = @"Hello, {{When:yyyyMMdd}}!!!";
Generator generator = compiler.Compile(format);
string result = generator.Render(new { When = new DateTime(2012, 01, 31) });
Assert.AreEqual("Hello, 20120131!!!", result, "The wrong text was generated.");
}
开发者ID:sithembisophp,项目名称:mustache-sharp,代码行数:8,代码来源:FormatCompilerTester.cs
示例19: TestCompile_KeyInParent_LooksUpKeyInParent
public void TestCompile_KeyInParent_LooksUpKeyInParent()
{
FormatCompiler compiler = new FormatCompiler();
const string format = @"{{#with Address}}{{FirstName}} from {{City}}{{/with}}";
Generator generator = compiler.Compile(format);
string actual = generator.Render(new
{
FirstName = "Bob",
Address = new
{
City = "Philadelphia",
}
});
string expected = "Bob from Philadelphia";
Assert.AreEqual(expected, actual, "The wrong message was generated.");
}
开发者ID:sithembisophp,项目名称:mustache-sharp,代码行数:16,代码来源:FormatCompilerTester.cs
示例20: TestCompile_IfNewLineEndIfNewLineContentNewLineIfNewLineEndIf_PrintsContent
public void TestCompile_IfNewLineEndIfNewLineContentNewLineIfNewLineEndIf_PrintsContent()
{
FormatCompiler parser = new FormatCompiler();
const string format = @"{{#if this}}
{{/if}}
Content
{{#if this}}
{{/if}}";
Generator generator = parser.Compile(format);
string result = generator.Render(true);
const string expected = @"Content";
Assert.AreEqual(expected, result, "The wrong text was generated.");
}
开发者ID:sithembisophp,项目名称:mustache-sharp,代码行数:13,代码来源:FormatCompilerTester.cs
注:本文中的FormatCompiler类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论