Exemplo n.º 1
0
        public void ParseTextWithEquals()
        {
            const string html   = "=";
            List <Token> tokens = new TokenParser().Parse(html).ToList();
            Token        first  = tokens.First();

            Assert.Equal(first.Type, TokenType.Text);
            Assert.Equal("=", first.Value);
        }
Exemplo n.º 2
0
        public void DoesNotParseAsCommentLtWithSingleMinus()
        {
            const string html = "<!- head x=y z-->";

            IEnumerable<Token> tokens = new TokenParser().Parse(html);
            Token token = tokens.First();
            Assert.Equal(TokenType.Text, token.Type);
            Assert.Equal("<!- head x=y z-->", token.Value);
        }
Exemplo n.º 3
0
        public void DoesNotParseAsCommentLtWithSingleMinus()
        {
            const string html = "<!- head x=y z-->";

            IEnumerable <Token> tokens = new TokenParser().Parse(html);
            Token token = tokens.First();

            Assert.Equal(TokenType.Text, token.Type);
            Assert.Equal("<!- head x=y z-->", token.Value);
        }
Exemplo n.º 4
0
        public void ParseCommentWithTripleCloseMinus()
        {
            const string html = "<!--head x=y z--->";

            IEnumerable <Token> tokens = new TokenParser().Parse(html);
            Token token = tokens.First();

            Assert.Equal(TokenType.Comment, token.Type);
            Assert.Equal("head x=y z-", token.Value);
        }
Exemplo n.º 5
0
        public void ParseCommentWithDoubleMinusInside()
        {
            const string html = "<!--head x--y-- z-->";

            IEnumerable <Token> tokens = new TokenParser().Parse(html);
            Token token = tokens.First();

            Assert.Equal(TokenType.Comment, token.Type);
            Assert.Equal("head x--y-- z", token.Value);
        }
Exemplo n.º 6
0
        public void ParseEmptyComment2()
        {
            const string html = "<!---->";

            IEnumerable <Token> tokens = new TokenParser().Parse(html);
            Token token = tokens.First();

            Assert.Equal(TokenType.Comment, token.Type);
            Assert.Equal("", token.Value);
        }
Exemplo n.º 7
0
        public void ParseAttributeNameWithoutWhitespaces()
        {
            const string html   = "<head x >";
            List <Token> tokens = new TokenParser().Parse(html).ToList();

            Assert.Equal("head", tokens.First().Value);
            Token last = tokens.Last();

            Assert.Equal(TokenType.AttributeName, last.Type);
            Assert.Equal("x", last.Value);
        }
Exemplo n.º 8
0
 public void ParseAttributeDoubleQuotedValueWithLtInside()
 {
     const string html = "<head x=\"y<z\">";
     List<Token> tokens = new TokenParser().Parse(html).ToList();
     Assert.Equal("head", tokens.First().Value);
     Token attrName = tokens[1];
     Assert.Equal(TokenType.AttributeName, attrName.Type);
     Assert.Equal("x", attrName.Value);
     Token attrValue = tokens[2];
     Assert.Equal(TokenType.AttributeValue, attrValue.Type);
     Assert.Equal("y<z", attrValue.Value);
 }
Exemplo n.º 9
0
        public void ParseAttributeSingleQuotedValueWithSlashInside()
        {
            const string html   = "<head x='y/z'>";
            List <Token> tokens = new TokenParser().Parse(html).ToList();

            Assert.Equal("head", tokens.First().Value);
            Token attrName = tokens[1];

            Assert.Equal(TokenType.AttributeName, attrName.Type);
            Assert.Equal("x", attrName.Value);
            Token attrValue = tokens[2];

            Assert.Equal(TokenType.AttributeValue, attrValue.Type);
            Assert.Equal("y/z", attrValue.Value);
        }
Exemplo n.º 10
0
        public void ParseAttributeDoubleQuotedValueWithWhitespaces()
        {
            const string html   = "<head x=\"y z\">";
            List <Token> tokens = new TokenParser().Parse(html).ToList();

            Assert.Equal("head", tokens.First().Value);
            Token attrName = tokens[1];

            Assert.Equal(TokenType.AttributeName, attrName.Type);
            Assert.Equal("x", attrName.Value);
            Token attrValue = tokens[2];

            Assert.Equal(TokenType.AttributeValue, attrValue.Type);
            Assert.Equal("y z", attrValue.Value);
        }
Exemplo n.º 11
0
        public void ParseAttributeValueWithGt()
        {
            const string html   = "<head x=>>x";
            List <Token> tokens = new TokenParser().Parse(html).ToList();

            Assert.Equal("head", tokens.First().Value);
            Token attrName = tokens[1];

            Assert.Equal(TokenType.AttributeName, attrName.Type);
            Assert.Equal("x", attrName.Value);
            Token attrValue = tokens[2];

            Assert.Equal(TokenType.Text, attrValue.Type);
            Assert.Equal(">x", attrValue.Value);
        }
Exemplo n.º 12
0
        public void ParseTextInsideTag()
        {
            const string html   = "<head>text</head>";
            List <Token> tokens = new TokenParser().Parse(html).ToList();

            Token first = tokens.First();

            Assert.Equal(TokenType.OpenTag, first.Type);
            Assert.Equal("head", first.Value);

            Token text = tokens[1];

            Assert.Equal(TokenType.Text, text.Type);
            Assert.Equal("text", text.Value);

            Token closeTag = tokens[2];

            Assert.Equal(TokenType.CloseTag, closeTag.Type);
            Assert.Equal("head", closeTag.Value);
        }
Exemplo n.º 13
0
        public void ParseAttributeNameAfterAttributeValue()
        {
            const string html   = "<head x=y z>";
            List <Token> tokens = new TokenParser().Parse(html).ToList();

            Assert.Equal("head", tokens.First().Value);

            Token attrName = tokens[1];

            Assert.Equal(TokenType.AttributeName, attrName.Type);
            Assert.Equal("x", attrName.Value);

            Token attrValue = tokens[2];

            Assert.Equal(TokenType.AttributeValue, attrValue.Type);
            Assert.Equal("y", attrValue.Value);

            Token secondAttrName = tokens[3];

            Assert.Equal(TokenType.AttributeName, secondAttrName.Type);
            Assert.Equal("z", secondAttrName.Value);
        }
Exemplo n.º 14
0
 public void ParseAttributeNameWithoutWhitespaces()
 {
     const string html = "<head x >";
     List<Token> tokens = new TokenParser().Parse(html).ToList();
     Assert.Equal("head", tokens.First().Value);
     Token last = tokens.Last();
     Assert.Equal(TokenType.AttributeName, last.Type);
     Assert.Equal("x", last.Value);
 }
Exemplo n.º 15
0
        public void ParseCommentWithMinusInside()
        {
            const string html = "<!--head x-y- z-->";

            IEnumerable<Token> tokens = new TokenParser().Parse(html);
            Token token = tokens.First();
            Assert.Equal(TokenType.Comment, token.Type);
            Assert.Equal("head x-y- z", token.Value);
        }
Exemplo n.º 16
0
        public void ParseCommentWithTripleCloseMinus()
        {
            const string html = "<!--head x=y z--->";

            IEnumerable<Token> tokens = new TokenParser().Parse(html);
            Token token = tokens.First();
            Assert.Equal(TokenType.Comment, token.Type);
            Assert.Equal("head x=y z-", token.Value);
        }
Exemplo n.º 17
0
        public void ParseEmptyComment2()
        {
            const string html = "<!---->";

            IEnumerable<Token> tokens = new TokenParser().Parse(html);
            Token token = tokens.First();
            Assert.Equal(TokenType.Comment, token.Type);
            Assert.Equal("", token.Value);
        }
Exemplo n.º 18
0
        public void ParseTextInsideTag()
        {
            const string html = "<head>text</head>";
            List<Token> tokens = new TokenParser().Parse(html).ToList();

            Token first = tokens.First();
            Assert.Equal(TokenType.OpenTag, first.Type);
            Assert.Equal("head", first.Value);

            Token text = tokens[1];
            Assert.Equal(TokenType.Text, text.Type);
            Assert.Equal("text", text.Value);

            Token closeTag = tokens[2];
            Assert.Equal(TokenType.CloseTag, closeTag.Type);
            Assert.Equal("head", closeTag.Value);
        }
Exemplo n.º 19
0
 public void ParseTextWithSlash()
 {
     const string html = "/";
     List<Token> tokens = new TokenParser().Parse(html).ToList();
     Token first = tokens.First();
     Assert.Equal(first.Type, TokenType.Text);
     Assert.Equal("/", first.Value);
 }
Exemplo n.º 20
0
        public void ParseAttributeNameAfterAttributeValue()
        {
            const string html = "<head x=y z>";
            List<Token> tokens = new TokenParser().Parse(html).ToList();
            Assert.Equal("head", tokens.First().Value);

            Token attrName = tokens[1];
            Assert.Equal(TokenType.AttributeName, attrName.Type);
            Assert.Equal("x", attrName.Value);

            Token attrValue = tokens[2];
            Assert.Equal(TokenType.AttributeValue, attrValue.Type);
            Assert.Equal("y", attrValue.Value);

            Token secondAttrName = tokens[3];
            Assert.Equal(TokenType.AttributeName, secondAttrName.Type);
            Assert.Equal("z", secondAttrName.Value);
        }
Exemplo n.º 21
0
 public void ParseAttributeValueWithWhitespaces()
 {
     const string html = "<head x= y >";
     List<Token> tokens = new TokenParser().Parse(html).ToList();
     Assert.Equal("head", tokens.First().Value);
     Token attrName = tokens[1];
     Assert.Equal(TokenType.AttributeName, attrName.Type);
     Assert.Equal("x", attrName.Value);
     Token attrValue = tokens[2];
     Assert.Equal(TokenType.AttributeValue, attrValue.Type);
     Assert.Equal("y", attrValue.Value);
 }