public void ShouldReturnTextNodeWhenGivenNewlyOpenedElementAtEndOfLine()
        {
            var node = SparkSyntax.ParseNode(String.Format("<div><{0}</div>", Environment.NewLine), position: 7);

            Assert.That(node, Is.InstanceOf(typeof(TextNode)));
            Assert.That(((TextNode)node).Text, Is.EqualTo("<"));
        }
        public void ShouldReturnTextNodeWhenGivenNewlyOpenedElement()
        {
            var node = SparkSyntax.ParseNode("<div><</div>", position: 6);

            Assert.That(node, Is.InstanceOf(typeof(TextNode)));
            Assert.That(((TextNode)node).Text, Is.EqualTo("<"));
        }
        public void ShouldReturnElementNodeGivenPositionInsideAnyElement()
        {
            var node = SparkSyntax.ParseNode("<div></div>", position: 1);

            Assert.That(node, Is.InstanceOf(typeof(ElementNode)));
            Assert.That(((ElementNode)node).Name, Is.EqualTo("div"));
        }
        private IEnumerable <Completion> GetForAttributeValue()
        {
            var attributeValues = new List <Completion>();

            var chunk = SparkSyntax.ParseContextChunk(CurrentContent, _triggerPoint);

            if (chunk == typeof(ContentChunk))
            {
                attributeValues.AddRange(GetContentNames());
            }
            else if (chunk == typeof(ConditionalChunk))
            {
                attributeValues.AddRange(GetVariables());
            }
            else if (chunk == typeof(ForEachChunk))
            {
                attributeValues.AddRange(GetVariables());
            }
            // TODO: Rob G first?{bool} last?{bool} ?{bool}
            // TODO: Rob G for "Index", "Count", "IsFirst", and "IsLast"
            else if (chunk == typeof(UseMasterChunk))
            {
                attributeValues.AddRange(GetPossibleMasterNames());
            }

            return(attributeValues);
        }
        public void ShouldReturnExpressionNodeGivenAnUnclosedExpression()
        {
            var node = SparkSyntax.ParseNode("<div>${item</div>", position: 11);

            Assert.That(node, Is.InstanceOf(typeof(ExpressionNode)));
            Assert.That(((ExpressionNode)node).Code.Count, Is.EqualTo(1));
        }
Beispiel #6
0
        public void ParseNodeShouldReturnElementNodeGivenPositionOne()
        {
            var sparkSyntax = new SparkSyntax();
            var node        = sparkSyntax.ParseNode("<div></div>", position: 1);

            Assert.That(node, Is.InstanceOfType(typeof(ElementNode)));
            Assert.That(((ElementNode)node).Name, Is.EqualTo("div"));
        }
Beispiel #7
0
        public void ShouldReturnElementNodeGivenPositionAfterColonInElementName()
        {
            var nodeType  = SparkSyntax.ParseContext("<div><use: </div>", position: 10);
            var chunkType = SparkSyntax.ParseContextChunk("<div><use: </div>", position: 10);

            Assert.That(nodeType, Is.EqualTo(typeof(ElementNode)));
            Assert.That(chunkType, Is.EqualTo(typeof(UseContentChunk)));
        }
        public void ShouldReturnElementNodeWithoutAttributesWhenGivenAnUnclosedAttributeValue()
        {
            var node = SparkSyntax.ParseNode("<use content='main ", position: 10);

            Assert.That(node, Is.InstanceOf(typeof(ElementNode)));
            Assert.That(((ElementNode)node).Name, Is.EqualTo("use"));
            Assert.That(((ElementNode)node).Attributes.Count, Is.EqualTo(0));
        }
        public void ShouldReturnElementNodeGivenPositionInsideACompleteElement()
        {
            var node = SparkSyntax.ParseNode("<div><use content='main'/></div>", position: 6);

            Assert.That(node, Is.InstanceOf(typeof(ElementNode)));
            Assert.That(((ElementNode)node).Name, Is.EqualTo("use"));
            Assert.That(((ElementNode)node).Attributes.Count, Is.EqualTo(1));
            Assert.That(((ElementNode)node).Attributes[0].Name, Is.EqualTo("content"));
            Assert.That(((ElementNode)node).Attributes[0].Value, Is.EqualTo("main"));
        }
        public void ShouldReturnElementNodeGivenAnUnclosedElementAtTheEndOfTheContent()
        {
            var node = SparkSyntax.ParseNode("<use content='main'", position: 10);

            Assert.That(node, Is.InstanceOf(typeof(ElementNode)));
            Assert.That(((ElementNode)node).Name, Is.EqualTo("use"));
            Assert.That(((ElementNode)node).Attributes.Count, Is.EqualTo(1));
            Assert.That(((ElementNode)node).Attributes[0].Name, Is.EqualTo("content"));
            Assert.That(((ElementNode)node).Attributes[0].Value, Is.EqualTo("main"));
        }
        private bool TryEvaluateSparkSyntax(int caretPosition, out Node sparkNode)
        {
            var sparkSyntax = new SparkSyntax();
            var currentNode = sparkSyntax.ParseNode(_textView.TextBuffer.CurrentSnapshot.GetText(), caretPosition);

            sparkNode = null;
            return(_projectExplorer.IsCurrentDocumentASparkFile()
                ? sparkSyntax.IsSparkElementNode(currentNode, out sparkNode)
                : false);
        }
        public void IsSparkNodeShouldReturnElementNodeIfNotSparkSyntax()
        {
            var node = SparkSyntax.ParseNode("<div id='products'/>", position: 1);

            Node elementNode;
            var  isSparkNode = SparkSyntax.IsSpecialNode(node, out elementNode);

            Assert.That(!isSparkNode);
            Assert.IsNotNull(elementNode);
            Assert.That(elementNode, Is.InstanceOf(typeof(ElementNode)));
        }
        public void IsSparkNodeShouldReturnSpecialNodeForUnclosedElement()
        {
            var node = SparkSyntax.ParseNode("<use >", position: 1);

            Node sparkNode;
            var  isSparkNode = SparkSyntax.IsSpecialNode(node, out sparkNode);

            Assert.That(isSparkNode);
            Assert.IsNotNull(sparkNode);
            Assert.That(sparkNode, Is.InstanceOf(typeof(SpecialNode)));
        }
        public void IsSparkNodeShouldReturnSpecialNodeForFullElementAtPositionInsideASpecialNode()
        {
            var node = SparkSyntax.ParseNode("<use content='main'/>", position: 1);

            Node sparkNode;
            var  isSparkNode = SparkSyntax.IsSpecialNode(node, out sparkNode);

            Assert.That(isSparkNode);
            Assert.IsNotNull(sparkNode);
            Assert.That(sparkNode, Is.InstanceOf(typeof(SpecialNode)));
        }
Beispiel #15
0
        public void ParseNodeShouldReturnElementNodeGivenAnUnclosedElementWithValidAttributes()
        {
            var sparkSyntax = new SparkSyntax();
            var node        = sparkSyntax.ParseNode("<div><use content='main' </div>", position: 10);

            Assert.That(node, Is.InstanceOfType(typeof(ElementNode)));
            Assert.That(((ElementNode)node).Name, Is.EqualTo("use"));
            Assert.That(((ElementNode)node).Attributes.Count, Is.EqualTo(1));
            Assert.That(((ElementNode)node).Attributes[0].Name, Is.EqualTo("content"));
            Assert.That(((ElementNode)node).Attributes[0].Value, Is.EqualTo("main"));
        }
Beispiel #16
0
        public void IsSparkNodeShouldReturnASpecialNodeForClosedEmptyElement()
        {
            var sparkSyntax = new SparkSyntax();
            var node        = sparkSyntax.ParseNode("<use />", position: 1);

            Node sparkNode;
            var  isSparkNode = sparkSyntax.IsSparkElementNode(node, out sparkNode);

            Assert.That(isSparkNode);
            Assert.IsNotNull(sparkNode);
            Assert.That(sparkNode, Is.InstanceOfType(typeof(SpecialNode)));
        }
Beispiel #17
0
        public void ShouldParseIntoMultipleNodes()
        {
            var nodes   = SparkSyntax.ParseNodes("<div><use content='main'/></div>");
            var visitor = new SpecialNodeVisitor(new VisitorContext());

            visitor.Accept(nodes);

            Assert.That(visitor.Nodes.Count, Is.EqualTo(3));
            Assert.That(visitor.Nodes[0], Is.InstanceOf(typeof(ElementNode)));
            Assert.That(visitor.Nodes[1], Is.InstanceOf(typeof(SpecialNode)));
            Assert.That(visitor.Nodes[2], Is.InstanceOf(typeof(EndElementNode)));
        }
        public void ShouldResultInAttributeNameContext()
        {
            Assert.IsTrue(SparkSyntax.IsPositionInAttributeName("<div><set x</div>", 11));
            Assert.IsFalse(SparkSyntax.IsPositionInAttributeValue("<div><set x</div>", 11));

            Assert.IsTrue(SparkSyntax.IsPositionInAttributeName("<div><set x='500' y='x + '</div>", 11));
            Assert.IsFalse(SparkSyntax.IsPositionInAttributeValue("<div><set x='500' y='x + '</div>", 11));

            Assert.IsTrue(SparkSyntax.IsPositionInAttributeName("<div><set x='500' y</div>", 19));
            Assert.IsFalse(SparkSyntax.IsPositionInAttributeValue("<div><set x='500' y=</div>", 19));

            Assert.IsTrue(SparkSyntax.IsPositionInAttributeName("<div><set x='500' y='x + '</div>", 19));
            Assert.IsFalse(SparkSyntax.IsPositionInAttributeValue("<div><set x='500' y='x + '</div>", 19));
        }
        public void ShouldResultInAttributeValueContext()
        {
            Assert.IsTrue(SparkSyntax.IsPositionInAttributeValue("<div><set x='500' y='x + '</div>", 16));
            Assert.IsFalse(SparkSyntax.IsPositionInAttributeName("<div><set x='500' y='x + '</div>", 16));

            Assert.IsTrue(SparkSyntax.IsPositionInAttributeValue("<div><set x='500' y='x + '</div>", 25));
            Assert.IsFalse(SparkSyntax.IsPositionInAttributeName("<div><set x='500' y='x + '</div>", 25));

            Assert.IsTrue(SparkSyntax.IsPositionInAttributeValue("<div><set x='500' y='x + ' z=\"</div>", 30));
            Assert.IsFalse(SparkSyntax.IsPositionInAttributeName("<div><set x='500' y='x + ' z=\"</div>", 30));

            Assert.IsTrue(SparkSyntax.IsPositionInAttributeValue("<div><test if='x == 5 '</div>", 22));
            Assert.IsFalse(SparkSyntax.IsPositionInAttributeName("<div><test if='x == 5 '</div>", 22));
        }
Beispiel #20
0
 private bool IsSparkSyntax(int caretPosition)
 {
     //TODO: Rob G This is a general catch all trap because if something goes wrong during the Beta.
     // We don't was Visual Studio to explode, but rather just that intellisense stops working for
     // this particular key press - it'll try again next time. The Beta will drive out most syntax issues.
     try
     {
         _currentContext = SparkSyntax.ParseContext(_textView.TextBuffer.CurrentSnapshot.GetText(), caretPosition);
         return(_currentContext != null && _currentContext != typeof(TextNode));
     }
     catch
     {
         return(false);
     }
 }
        private IEnumerable <Completion> GetForElementTypeAndName()
        {
            var  attributesForNode = new List <Completion>();
            Node specialNode;

            if (SparkSyntax.IsSpecialNode(CurrentNode, out specialNode))
            {
                attributesForNode.AddRange(GetForSpecialNode(specialNode));
            }
            else
            {
                attributesForNode.AddRange(GetHtmlNodeExtensions());
                attributesForNode.AddRange(GetPossiblePartialDefaults());
            }

            RemoveAttributesAlreadyUsed(attributesForNode);
            return(attributesForNode.Distinct());
        }
Beispiel #22
0
        public static CompletionSet GetCompletionSetFor(SnapshotPoint triggerPoint, ITrackingSpan trackingSpan, IViewExplorer viewExplorer)
        {
            Type currentContext = SparkSyntax.ParseContext(triggerPoint.Snapshot.GetText(), triggerPoint);

            if (currentContext == typeof(ElementNode))
            {
                return(Create <ElementCompletionSet>(triggerPoint, trackingSpan, viewExplorer));
            }
            if (currentContext == typeof(AttributeNode))
            {
                return(Create <AttributeCompletionSet>(triggerPoint, trackingSpan, viewExplorer));
            }
            if (currentContext == typeof(ExpressionNode))
            {
                return(Create <ExpressionCompletionSet>(triggerPoint, trackingSpan, viewExplorer));
            }
            return(null);
        }
Beispiel #23
0
        public void AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> completionSets)
        {
            _triggerPoint = session.GetTriggerPoint(_textBuffer).GetPoint(_textBuffer.CurrentSnapshot);

            if (!session.Properties.TryGetProperty(typeof(ITrackingSpan), out _trackingSpan))
            {
                _trackingSpan = _triggerPoint.Snapshot.CreateTrackingSpan(new Span(_triggerPoint, 0), SpanTrackingMode.EdgeInclusive);
            }

            var           syntax           = new SparkSyntax();
            Node          currentNode      = syntax.ParseNode(_textBuffer.CurrentSnapshot.GetText(), _triggerPoint);
            CompletionSet sparkCompletions = GetCompletionSetFor(currentNode);

            if (sparkCompletions == null)
            {
                return;
            }

            MergeSparkWithAllCompletionsSet(completionSets, sparkCompletions);
            completionSets.Add(sparkCompletions);
        }
        public void ShouldReturnNullGivenPositionAtEndOfLine()
        {
            var node = SparkSyntax.ParseNode(String.Format("<div><use content='main'/>{0}</div>", Environment.NewLine), position: 27);

            Assert.That(node, Is.Null);
        }
        public void ShouldReturnNullGivenPositionBetweenNodes()
        {
            var node = SparkSyntax.ParseNode("<div><use content='main'/></div>", position: 5);

            Assert.That(node, Is.Null);
        }
        public void ShouldReturnNullGivenPositionInAnEndElement()
        {
            var node = SparkSyntax.ParseNode("<div></div>", position: 10);

            Assert.That(node, Is.Null);
        }
        public void ShouldReturnNullGivenPositionAtTheEnd()
        {
            var node = SparkSyntax.ParseNode("<div></div>", position: 11);

            Assert.That(node, Is.Null);
        }
        public void ShouldReturnRenderChunkGivenPositionInsideSingleQuotes()
        {
            Type nodeType = SparkSyntax.ParseContextChunk("<div><render partial='' </div>", position: 22);

            Assert.That(nodeType, Is.EqualTo(typeof(RenderPartialChunk)));
        }
        public void ShouldReturnUseChunkGivenPositionAfterUseElementColon()
        {
            Type nodeType = SparkSyntax.ParseContextChunk("<div><use:header /></div>", position: 10);

            Assert.That(nodeType, Is.EqualTo(typeof(UseContentChunk)));
        }
        public void ShouldReturnUseChunkGivenPositionInsideSingleQuotes()
        {
            Type nodeType = SparkSyntax.ParseContextChunk("<div><use content='' </div>", position: 19);

            Assert.That(nodeType, Is.EqualTo(typeof(UseContentChunk)));
        }