本文整理汇总了C#中AST.Prune方法的典型用法代码示例。如果您正苦于以下问题:C# AST.Prune方法的具体用法?C# AST.Prune怎么用?C# AST.Prune使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AST
的用法示例。
在下文中一共展示了AST.Prune方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Nested_Nodes_Content
public void Nested_Nodes_Content()
{
const string TEMPLATE = @"<c:out>Hello world</c:out>";
var formatter = new Formatter(TEMPLATE).Parse();
var ast = new AST(formatter.ParsedTemplate, AST.Options.DontTrackContext|AST.Options.PruneRawTexts);
var expected = new AST()
.Add(new TagNode("c", "out").Add(new TextNode("Hello world")));
expected.Prune(AST.Options.PruneRawTexts);
Assert.That(ast, Deeply.Is.EqualTo(expected));
}
示例2: Nested_Nodes_No_Variables
public void Nested_Nodes_No_Variables()
{
const string TEMPLATE = @"<c:out value=""Hello""><c:out value=""World""/></c:out>";
var formatter = new Formatter(TEMPLATE).Parse();
var ast = new AST(formatter.ParsedTemplate, AST.Options.DontTrackContext|AST.Options.PruneRawTexts);
var expected = new AST()
.Add(new TagNode("c", "out").With("Value", "Hello")
.Add(new TagNode("c", "out").With("Value", "World")));
expected.Prune(AST.Options.PruneRawTexts);
Assert.That(ast, Deeply.Is.EqualTo(expected));
}
示例3: Should_Still_Collect_Parse_Fragment
public void Should_Still_Collect_Parse_Fragment()
{
var formatter = new Formatter("<c:out>${a}</c:out>${a}<c:out>");
try
{
formatter.Parse();
Assert.Fail();
}
catch (ExceptionWithContext ewc)
{
Assert.That(ewc.Context.Index, Is.EqualTo(26));
}
var ast = new AST(formatter.ParsedTemplate, AST.Options.TrimEmptyTextNodes | AST.Options.DontTrackContext|AST.Options.PruneRawTexts);
var expected = new AST().
Add(new TagNode("c", "out").Add(new ExpressionNode("a", "Property", null))).
Add(new ExpressionNode("a", "Property", null));
expected.Prune(AST.Options.PruneRawTexts);
Assert.That(ast, Deeply.Is.EqualTo(expected));
}
示例4: Should_Track_Context
public void Should_Track_Context()
{
const string TEMPLATE = @"
<c:set var=""Status"" value=""Nice""/>
<c:out value=""Hello"">
<c:out value=""${Status}""/>
</c:out>
<c:out>World ${(A+B)*C}</c:out>";
var formatter = new Formatter(TEMPLATE).Parse();
var ast = new AST(formatter.ParsedTemplate, AST.Options.TrimEmptyTextNodes|AST.Options.PruneRawTexts);
var expected = new AST().At(1,1).
Add(new TagNode("c","set").At(2,1).With("Var","Status", new Context(2,13)).With("Value", "Nice", new Context(2, 28))).
Add(new TagNode("c", "out").At(3, 1).With("Value", "Hello", new Context(3, 15)).
Add(new TagNode("c", "out").At(4, 5).With("Value", new ExpressionNode("Status", "Property", null).At(4,21)))).
Add(new TagNode("c", "out").At(6, 1).Add(
new TextNode("World ").At(6,8)).Add(
new ExpressionNode("(A+B)*C", "Multiply", typeof(decimal)).At(6, 21).
Add(new ExpressionNode("(A+B)", "Brackets", typeof(decimal)).At(6, 16).
Add(new ExpressionNode("A+B", "Add", typeof(decimal)).At(6, 18).
Add(new ExpressionNode("A", "Property", null).At(6, 17)).
Add(new ExpressionNode("B", "Property", null).At(6, 19)))).
Add(new ExpressionNode("C", "Property", null).At(6, 22))));
expected.Prune(AST.Options.PruneRawTexts);
Assert.That(ast, Deeply.Is.EqualTo(expected));
}
示例5: Should_Collected_NestedTags
public void Should_Collected_NestedTags()
{
const string TEMPLATE = @"<c:choose><c:when test=""${Yes}"">WHEN</c:when><c:otherwise>OTHERWISE</c:otherwise></c:choose>";
var formatter = new Formatter(TEMPLATE).Parse();
var ast = new AST(formatter.ParsedTemplate, AST.Options.DontTrackContext|AST.Options.PruneRawTexts);
var expected = new AST()
.Add(new TagNode("c", "choose").
Add(new TagNode("c", "when").With("Test",new ExpressionNode("Yes","Property",null)).Add(new TextNode("WHEN"))).
Add(new TagNode("c", "otherwise").Add(new TextNode("OTHERWISE")))
);
expected.Prune(AST.Options.PruneRawTexts);
Assert.That(ast, Deeply.Is.EqualTo(expected));
}