Example #1
0
        public void Execute_RewritesHtml_MalformedHtmlAtEnd()
        {
            // Arrange
            var document = CreateDocument(@"
<ht");

            var documentNode = Lower(document);

            // Act
            Pass.Execute(document, documentNode);

            // Assert
            var method = documentNode.FindPrimaryMethod();

            Assert.Collection(
                method.Children,
                c => Assert.IsType <CSharpCodeIntermediateNode>(c),
                c => NodeAssert.Whitespace(c),
                c => NodeAssert.Content(c, "<ht"));

            var content    = NodeAssert.Content(method.Children[2], "<ht");
            var diagnostic = Assert.Single(content.Diagnostics);

            Assert.Same(BlazorDiagnosticFactory.InvalidHtmlContent.Id, diagnostic.Id);
            Assert.Equal(2, diagnostic.Span.AbsoluteIndex);
            Assert.Equal(1, diagnostic.Span.LineIndex);
            Assert.Equal(0, diagnostic.Span.CharacterIndex);
            Assert.Equal(3, diagnostic.Span.Length);
        }
Example #2
0
        public void Execute_RewritesHtml_Basic()
        {
            // Arrange
            var document = CreateDocument(@"
<html>
  <head cool=""beans"">
    Hello, World!
  </head>
</html>");

            var documentNode = Lower(document);

            // Act
            Pass.Execute(document, documentNode);

            // Assert
            var method = documentNode.FindPrimaryMethod();

            Assert.Collection(
                method.Children,
                c => Assert.IsType <CSharpCodeIntermediateNode>(c),
                c => NodeAssert.Whitespace(c),
                c => NodeAssert.Element(c, "html"));

            var html = NodeAssert.Element(method.Children[2], "html");

            Assert.Equal(2, html.Source.Value.AbsoluteIndex);
            Assert.Equal(1, html.Source.Value.LineIndex);
            Assert.Equal(0, html.Source.Value.CharacterIndex);
            Assert.Equal(68, html.Source.Value.Length);
            Assert.Collection(
                html.Children,
                c => NodeAssert.Whitespace(c),
                c => NodeAssert.Element(c, "head"),
                c => NodeAssert.Whitespace(c));

            var head = NodeAssert.Element(html.Children[1], "head");

            Assert.Equal(12, head.Source.Value.AbsoluteIndex);
            Assert.Equal(2, head.Source.Value.LineIndex);
            Assert.Equal(2, head.Source.Value.CharacterIndex);
            Assert.Equal(49, head.Source.Value.Length);
            Assert.Collection(
                head.Children,
                c => NodeAssert.Attribute(c, "cool", "beans"),
                c => NodeAssert.Content(c, "Hello, World!"));
        }
Example #3
0
        public void Execute_RewritesHtml_TagHelper()
        {
            // Arrange
            var document = CreateDocument(@"
@addTagHelper ""*, test""
<html>
  <test>
    <head cool=""beans"">
      Hello, World!
    </head>
  </test>
</html>");

            var documentNode = Lower(document);

            // Act
            Pass.Execute(document, documentNode);

            // Assert
            var method = documentNode.FindPrimaryMethod();

            Assert.Collection(
                method.Children,
                c => Assert.IsType <CSharpCodeIntermediateNode>(c),
                c => NodeAssert.Whitespace(c),
                c => Assert.IsType <DirectiveIntermediateNode>(c),
                c => NodeAssert.Element(c, "html"));

            var html = NodeAssert.Element(method.Children[3], "html");

            Assert.Equal(27, html.Source.Value.AbsoluteIndex);
            Assert.Equal(2, html.Source.Value.LineIndex);
            Assert.Equal(0, html.Source.Value.CharacterIndex);
            Assert.Equal(95, html.Source.Value.Length);
            Assert.Collection(
                html.Children,
                c => NodeAssert.Whitespace(c),
                c => Assert.IsType <TagHelperIntermediateNode>(c),
                c => NodeAssert.Whitespace(c));

            var body = html.Children
                       .OfType <TagHelperIntermediateNode>().Single().Children
                       .OfType <TagHelperBodyIntermediateNode>().Single();

            Assert.Collection(
                body.Children,
                c => NodeAssert.Whitespace(c),
                c => NodeAssert.Element(c, "head"),
                c => NodeAssert.Whitespace(c));

            var head = body.Children[1];

            Assert.Equal(49, head.Source.Value.AbsoluteIndex);
            Assert.Equal(4, head.Source.Value.LineIndex);
            Assert.Equal(4, head.Source.Value.CharacterIndex);
            Assert.Equal(53, head.Source.Value.Length);
            Assert.Collection(
                head.Children,
                c => NodeAssert.Attribute(c, "cool", "beans"),
                c => NodeAssert.Content(c, "Hello, World!"));
        }