public void ConstructorSetsPropertyValue() { // Arrange IEnumerable<SyntaxTreeNode> contents = new SyntaxTreeNode[0]; // Act Block block = new Block(BlockType.Expression, contents); // Assert Assert.AreEqual(BlockType.Expression, block.Type); Assert.AreSame(contents, block.Children); }
private string ParseNode(SyntaxTreeNode node, int tabLevel = -1) { var block = node as Block; var tabs = new string('\t', tabLevel + 1); if (block == null) return string.Format("{0}<{1}>", tabs, node); string children = string.Join("\r\n", block.Children.Select(x => ParseNode(x, tabLevel + 1))); return string.Format("{0}<{1}>\r\n{2}\r\n{0}</{1}>", tabs, block, children); }
public void ConstructorSetsParentPointerOnChildren() { // Arrange SyntaxTreeNode[] contents = new SyntaxTreeNode[2] { new Block(BlockType.Comment, new SyntaxTreeNode[0]), new CodeSpan(String.Empty) }; // Act Block block = new Block(BlockType.Expression, contents); // Assert Assert.AreSame(block, contents[0].Parent); Assert.AreSame(block, contents[1].Parent); }
private bool IsLiteralAttributeValue(SyntaxTreeNode node) { if (node.IsBlock) { return false; } Span span = node as Span; Debug.Assert(span != null); LiteralAttributeCodeGenerator litGen = span.CodeGenerator as LiteralAttributeCodeGenerator; return span != null && ((litGen != null && litGen.ValueGenerator == null) || span.CodeGenerator == SpanCodeGenerator.Null || span.CodeGenerator is MarkupCodeGenerator); }
protected virtual void ParseSyntaxTreeNode(SyntaxTreeNode node, TextWriter output) { if (node == null) return; // Ignore the @ symbol - that's Razor's business if (node is TransitionSpan) return; // Explicitly ignore @model and @inherits spans as part // of the transition from static to dynamic typing if (node is ModelSpan) return; if (node is InheritsSpan) return; if (node is MetaCodeSpan) return; // Explicitly support these types of spans: if (VisitBlock(node as Block, output)) return; if (VisitMarkupSpan(node as MarkupSpan, output)) return; if (VisitCodeSpan(node as CodeSpan, output)) return; // Emit a warning for any span that wasn't handled above Trace.WriteLine(string.Format("Ignoring {0}...", node)); }
public override bool EquivalentTo(SyntaxTreeNode node) { Block other = node as Block; if (other == null || other.Type != Type) { return false; } return Enumerable.SequenceEqual(Children, other.Children, new EquivalenceComparer()); }
/// <summary> /// Determines if the specified node is equivalent to this node /// </summary> /// <param name="node">The node to compare this node with</param> /// <returns> /// true if the provided node has all the same content and metadata, though the specific quantity and type of symbols may be different. /// </returns> public abstract bool EquivalentTo(SyntaxTreeNode node);
private static void AddNullActualError(ErrorCollector collector, SyntaxTreeNode actual, SyntaxTreeNode expected) { collector.AddError("{0} - FAILED :: Actual: << Null >>", expected); }
/// <summary> /// Checks that the specified span is equivalent to the other in that it has the same start point and content. /// </summary> public override bool EquivalentTo(SyntaxTreeNode node) { Span other = node as Span; return other != null && Kind.Equals(other.Kind) && Start.Equals(other.Start) && EditHandler.Equals(other.EditHandler) && String.Equals(other.Content, Content, StringComparison.Ordinal); }
private static void EvaluateSyntaxTreeNode(ErrorCollector collector, SyntaxTreeNode actual, SyntaxTreeNode expected) { if (actual == null) { AddNullActualError(collector, actual, expected); } if (actual.IsBlock != expected.IsBlock) { AddMismatchError(collector, actual, expected); } else { if (expected.IsBlock) { EvaluateBlock(collector, (Block)actual, (Block)expected); } else { EvaluateSpan(collector, (Span)actual, (Span)expected); } } }
private void WriteNode(int indent, SyntaxTreeNode node) { string content = node.ToString().Replace("\r", "\\r") .Replace("\n", "\\n") .Replace("{", "{{") .Replace("}", "}}"); if (indent > 0) { content = new String('.', indent * 2) + content; } WriteTraceLine(content); Block block = node as Block; if (block != null) { foreach (SyntaxTreeNode child in block.Children) { WriteNode(indent + 1, child); } } }
internal void ParseSyntaxTreeNode(SyntaxTreeNode node, TextWriter output) { if (node == null) return; // sanity. if (node is TransitionSpan) return; // ignore the @ symbol. // ignore @model and @inherits as part of the transition from static to dynamic typing. if (node is ModelSpan) return; if (node is InheritsSpan) return; if (node is MetaCodeSpan) return; // explicitly support these types of node if (VisitBlock(node as Block, output)) return; if (VisitMarkupSpan(node as MarkupSpan, output)) return; if (VisitCodeSpan(node as CodeSpan, output)) return; log.DebugFormat(NODE_IGNORED, node); // emit a warning for any node that wasn't handled above. }
public string Visualize(SyntaxTreeNode node) { return ParseNode(node); }
private bool IsMultiLineBlock(SyntaxTreeNode node) { var block = node as Block; // will be true for markup spans as well, but they are handled elsewhere if (!node.IsBlock || block == null || !block.Children.Any()) return false; return block.Children.First().Start.LineIndex != block.Children.Last().Start.LineIndex; }
private static void AddPassedMessage(ErrorCollector collector, SyntaxTreeNode expected) { collector.AddMessage("{0} - PASSED", expected); }
private static void AddMismatchError(ErrorCollector collector, SyntaxTreeNode actual, SyntaxTreeNode expected) { collector.AddError("{0} - FAILED :: Actual: {1}", expected, actual); }
private static void WriteTree(SyntaxTreeNode node, StringBuilder treeBuilder, int depth = 0) { if (node == null) { return; } if (depth > 1) { WriteIndent(treeBuilder, depth); } if (depth > 0) { treeBuilder.Append("|-- "); } treeBuilder.AppendLine(ConvertEscapseSequences(node.ToString())); if (node.IsBlock) { foreach (SyntaxTreeNode child in ((Block)node).Children) { WriteTree(child, treeBuilder, depth + 1); } } }
private void RunUnterminatedBlockTest(string keyword, string expectedTerminator, BlockType blockType = BlockType.Statement, bool keywordIsMetaCode = false) { const string blockBody = @" ' This block is not correctly terminated!"; IEnumerable<SyntaxTreeNode> expectedNodes = null; if (keywordIsMetaCode) { expectedNodes = new SyntaxTreeNode[] { new MetaCodeSpan(keyword, hidden: false, acceptedCharacters: AcceptedCharacters.None), new CodeSpan(blockBody) }; } else { expectedNodes = new SyntaxTreeNode[] { new CodeSpan(keyword + blockBody) }; } ParseBlockTest(keyword + blockBody, new Block(blockType, expectedNodes), new RazorError(String.Format(RazorResources.ParseError_BlockNotTerminated, keyword, expectedTerminator), SourceLocation.Zero)); }