Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RwHtmlClassifier"/> class.
 /// </summary>
 public RwHtmlClassifier(IClassificationTypeRegistryService registry, ITextBuffer buffer)
 {
     tokenizer = new RwHtmlTokenizer();
     this.buffer = buffer;
     bindingBrace = registry.GetClassificationType(RwHtmlClassificationTypes.BindingBrace);
     bindingContent = registry.GetClassificationType(RwHtmlClassificationTypes.BindingContent);
 }
        public void RwHtmlTokenizer_CommentParsing_Valid()
        {
            var input = @"test <!-- this is a text < > "" ' --> test2";

            // parse
            var tokenizer = new RwHtmlTokenizer();
            tokenizer.Tokenize(new StringReader(input));
            CheckForErrors(tokenizer, input.Length);

            // first line
            var i = 0;
            Assert.AreEqual("test ", tokenizer.Tokens[i].Text);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);

            Assert.AreEqual("<!--", tokenizer.Tokens[i].Text);
            Assert.AreEqual(RwHtmlTokenType.OpenComment, tokenizer.Tokens[i++].Type);

            Assert.AreEqual(@" this is a text < > "" ' ", tokenizer.Tokens[i].Text);
            Assert.AreEqual(RwHtmlTokenType.CommentBody, tokenizer.Tokens[i++].Type);

            Assert.AreEqual("-->", tokenizer.Tokens[i].Text);
            Assert.AreEqual(RwHtmlTokenType.CloseComment, tokenizer.Tokens[i++].Type);

            Assert.AreEqual(" test2", tokenizer.Tokens[i].Text);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
        }
Exemplo n.º 3
0
        public void RwHtmlTokenizer_ValidInput_AttributeWithLiteralValue_NoQuotes()
        {
            var input = "<element attr=value_2 /> ";
            var tokens = new RwHtmlTokenizer().Parse(input).ToList();

            Assert.AreEqual(4, tokens.Count);

            Assert.IsInstanceOfType(tokens[0], typeof(RwOpenTagBeginToken));
            Assert.AreEqual("element", ((RwOpenTagBeginToken)tokens[0]).TagName);
            ValidateSpanContent(input, "<element", tokens[0].SpanPosition);

            Assert.IsInstanceOfType(tokens[1], typeof(RwAttributeToken));
            Assert.AreEqual("attr", ((RwAttributeToken)tokens[1]).Name);
            Assert.AreEqual("value_2", ((RwValueToken)((RwAttributeToken)tokens[1]).Value).Text);
            ValidateSpanContent(input, " attr=value_2", tokens[1].SpanPosition);

            Assert.IsInstanceOfType(tokens[2], typeof(RwOpenTagEndToken));
            Assert.IsTrue(((RwOpenTagEndToken)tokens[2]).IsSelfClosing);
            ValidateSpanContent(input, " />", tokens[2].SpanPosition);

            Assert.IsInstanceOfType(tokens[3], typeof(RwValueToken));
            Assert.AreEqual(" ", ((RwValueToken)tokens[3]).Text);

            ValidateTokenSequence(tokens, input.Length);
        }
        public void RwHtmlTokenizer_DirectiveParsing_Invalid_AtSymbol_DirectiveName_NewLine_Content()
        {
            var input = @"@viewmodel
            test";

            // parse
            var tokenizer = new RwHtmlTokenizer();
            tokenizer.Tokenize(new StringReader(input));
            CheckForErrors(tokenizer, input.Length);

            var i = 0;
            Assert.AreEqual(RwHtmlTokenType.DirectiveStart, tokenizer.Tokens[i++].Type);

            Assert.AreEqual("viewmodel", tokenizer.Tokens[i].Text);
            Assert.AreEqual(RwHtmlTokenType.DirectiveName, tokenizer.Tokens[i++].Type);

            Assert.IsTrue(tokenizer.Tokens[i].HasError);
            Assert.AreEqual(0, tokenizer.Tokens[i].Length);
            Assert.AreEqual(RwHtmlTokenType.WhiteSpace, tokenizer.Tokens[i++].Type);

            Assert.IsTrue(tokenizer.Tokens[i].HasError);
            Assert.AreEqual(0, tokenizer.Tokens[i].Length);
            Assert.AreEqual(RwHtmlTokenType.DirectiveValue, tokenizer.Tokens[i++].Type);

            Assert.AreEqual("\r\n", tokenizer.Tokens[i].Text);
            Assert.AreEqual(RwHtmlTokenType.WhiteSpace, tokenizer.Tokens[i++].Type);

            Assert.AreEqual("test", tokenizer.Tokens[i].Text);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
        }
Exemplo n.º 5
0
 public static RwHtmlRootNode ParseMarkup(string markup)
 {
     var tokenizer = new RwHtmlTokenizer();
     tokenizer.Tokenize(new StringReader(markup));
     var parser = new RwHtmlParser();
     var node = parser.Parse(tokenizer.Tokens);
     return node;
 }
Exemplo n.º 6
0
        public void RwHtmlTokenizer_InvalidInput_AdditionalCharsInBindingAttribute()
        {
            try
            {
                var input = "<rw:Button Text=\"{Binding Title} aa\" />";
                var tokens = new RwHtmlTokenizer().Parse(input).ToList();

                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ParserException));
                Assert.AreEqual(32, ((ParserException)ex).Position.PositionOnLine);
            }
        }
        public void RwHtmlTokenizer_ElementParsing_Incomplete_OpenTag()
        {
            var input = @"<html";

            // parse
            var tokenizer = new RwHtmlTokenizer();
            tokenizer.Tokenize(new StringReader(input));
            CheckForErrors(tokenizer, input.Length);

            var i = 0;
            Assert.AreEqual(RwHtmlTokenType.OpenTag, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);

            Assert.AreEqual(0, tokenizer.Tokens[i].Length);
            Assert.IsTrue(tokenizer.Tokens[i].HasError);
            Assert.AreEqual(RwHtmlTokenType.CloseTag, tokenizer.Tokens[i++].Type);
        }
Exemplo n.º 8
0
        public void RwHtmlTokenizer_BindingParsing_Incomplete_OpenBinding()
        {
            var input = @"<input value=""{";

            // parse
            var tokenizer = new RwHtmlTokenizer();
            tokenizer.Tokenize(new StringReader(input));
            CheckForErrors(tokenizer, input.Length);

            var i = 0;
            Assert.AreEqual(RwHtmlTokenType.OpenTag, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.WhiteSpace, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Equals, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.DoubleQuote, tokenizer.Tokens[i++].Type);

            Assert.AreEqual(RwHtmlTokenType.OpenBinding, tokenizer.Tokens[i++].Type);

            Assert.AreEqual(0, tokenizer.Tokens[i].Length);
            Assert.IsTrue(tokenizer.Tokens[i].HasError);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);

            Assert.AreEqual(0, tokenizer.Tokens[i].Length);
            Assert.IsTrue(tokenizer.Tokens[i].HasError);
            Assert.AreEqual(RwHtmlTokenType.Colon, tokenizer.Tokens[i++].Type);

            Assert.AreEqual(0, tokenizer.Tokens[i].Length);
            Assert.IsTrue(tokenizer.Tokens[i].HasError);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);

            Assert.AreEqual(0, tokenizer.Tokens[i].Length);
            Assert.IsTrue(tokenizer.Tokens[i].HasError);
            Assert.AreEqual(RwHtmlTokenType.CloseBinding, tokenizer.Tokens[i++].Type);

            Assert.AreEqual(0, tokenizer.Tokens[i].Length);
            Assert.IsTrue(tokenizer.Tokens[i].HasError);
            Assert.AreEqual(RwHtmlTokenType.DoubleQuote, tokenizer.Tokens[i++].Type);

            Assert.AreEqual(0, tokenizer.Tokens[i].Length);
            Assert.IsTrue(tokenizer.Tokens[i].HasError);
            Assert.AreEqual(RwHtmlTokenType.CloseTag, tokenizer.Tokens[i++].Type);
        }
        public void RwHtmlTokenizer_DoctypeParsing_Invalid_Incomplete_NoValue()
        {
            var input = @"<!DOCTYPE";

            // parse
            var tokenizer = new RwHtmlTokenizer();
            tokenizer.Tokenize(new StringReader(input));
            CheckForErrors(tokenizer, input.Length);

            // first line
            var i = 0;
            Assert.AreEqual("<!DOCTYPE", tokenizer.Tokens[i].Text);
            Assert.AreEqual(RwHtmlTokenType.OpenDoctype, tokenizer.Tokens[i++].Type);

            Assert.IsTrue(tokenizer.Tokens[i].HasError);
            Assert.AreEqual(0, tokenizer.Tokens[i].Length);
            Assert.AreEqual(RwHtmlTokenType.DoctypeBody, tokenizer.Tokens[i++].Type);

            Assert.IsTrue(tokenizer.Tokens[i].HasError);
            Assert.AreEqual(0, tokenizer.Tokens[i].Length);
            Assert.AreEqual(RwHtmlTokenType.CloseDoctype, tokenizer.Tokens[i++].Type);
        }
Exemplo n.º 10
0
        protected override bool Execute(uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut, IOleCommandTarget nextCommandTarget)
        {
            var groupId = CommandGroupId;
            if (nextCommandTarget.Exec(ref groupId, nCmdID, nCmdexecopt, pvaIn, pvaOut) == VSConstants.S_OK)
            {
                // parse the content
                var tokenizer = new RwHtmlTokenizer();
                var text = TextView.TextSnapshot.GetText();
                tokenizer.Tokenize(new StringReader(text));
                var parser = new RwHtmlParser();
                var node = parser.Parse(tokenizer.Tokens);

                // prepare the metadata control resolver
                var completionSource = TextView.TextBuffer.Properties.GetProperty<RwHtmlCompletionSource>(typeof(RwHtmlCompletionSource));
                var metadataControlResolver = completionSource.MetadataControlResolver;
                metadataControlResolver.ReloadAllControls(completionSource.GetCompletionContext());

                try
                {
                    CompletionHelper.DTE.UndoContext.Open("Format RWHTML document");
                    var edit = TextView.TextBuffer.CreateEdit(EditOptions.None, null, null);

                    // fix the casing of all elements
                    var editText = new StringBuilder(text);
                    foreach (var element in node.EnumerateNodes().OfType<RwHtmlElementNode>())
                    {
                        FixElement(editText, metadataControlResolver, TextView.TextBuffer, element);
                    }
                    edit.Replace(0, editText.Length, editText.ToString());
                    edit.Apply();
                }
                finally
                {
                    CompletionHelper.DTE.UndoContext.Close();
                }
            }

            return true;
        }
Exemplo n.º 11
0
        protected void CheckForErrors(RwHtmlTokenizer tokenizer, int inputLength)
        {
            // check for parsing errors
            if (tokenizer.Tokens.Any(t => t.Length != t.Text.Length))
            {
                throw new Exception("The length of the token does not match with its text content length!");
            }

            // check that the token sequence is complete
            var position = 0;
            foreach (var token in tokenizer.Tokens)
            {
                if (token.StartPosition != position)
                {
                    throw new Exception("The token sequence is not complete!");
                }
                position += token.Length;
            }

            if (position != inputLength)
            {
                throw new Exception("The parser didn't finished the file!");
            }
        }
Exemplo n.º 12
0
        public void RwHtmlTokenizer_ValidInput_ScriptEndsAtEndOfFile()
        {
            var input = "test <script>if (xxx < 15) return;</script>";
            var tokens = new RwHtmlTokenizer().Parse(input).ToList();

            Assert.AreEqual(5, tokens.Count);

            Assert.IsInstanceOfType(tokens[0], typeof(RwValueToken));
            Assert.AreEqual("test ", ((RwValueToken)tokens[0]).Text);
            ValidateSpanContent(input, "test ", tokens[0].SpanPosition);

            Assert.IsInstanceOfType(tokens[1], typeof(RwOpenTagBeginToken));
            Assert.AreEqual("script", ((RwOpenTagBeginToken)tokens[1]).TagName);
            ValidateSpanContent(input, "<script", tokens[1].SpanPosition);

            Assert.IsInstanceOfType(tokens[2], typeof(RwOpenTagEndToken));
            Assert.IsFalse(((RwOpenTagEndToken)tokens[2]).IsSelfClosing);
            ValidateSpanContent(input, ">", tokens[2].SpanPosition);

            Assert.IsInstanceOfType(tokens[3], typeof(RwValueToken));
            Assert.AreEqual("if (xxx < 15) return;", ((RwValueToken)tokens[3]).Text);
            ValidateSpanContent(input, "if (xxx < 15) return;", tokens[3].SpanPosition);

            Assert.IsInstanceOfType(tokens[4], typeof(RwCloseTagToken));
            Assert.AreEqual("script", ((RwCloseTagToken)tokens[4]).TagName);
            ValidateSpanContent(input, "</script>", tokens[4].SpanPosition);

            ValidateTokenSequence(tokens, input.Length);
        }
Exemplo n.º 13
0
        public void RwHtmlTokenizer_ValidInput_SelfClosedControl()
        {
            var input = "<html><c:Control Text=\"{Text, HtmlEncode=true}\" /></html>";
            var tokens = new RwHtmlTokenizer().Parse(input).ToList();

            Assert.AreEqual(6, tokens.Count);

            Assert.IsInstanceOfType(tokens[0], typeof(RwOpenTagBeginToken));
            Assert.AreEqual("html", ((RwOpenTagBeginToken)tokens[0]).TagName);
            ValidateSpanContent(input, "<html", tokens[0].SpanPosition);

            Assert.IsInstanceOfType(tokens[1], typeof(RwOpenTagEndToken));
            Assert.IsFalse(((RwOpenTagEndToken)tokens[1]).IsSelfClosing);
            ValidateSpanContent(input, ">", tokens[1].SpanPosition);

            Assert.IsInstanceOfType(tokens[2], typeof(RwOpenTagBeginToken));
            Assert.AreEqual("c:Control", ((RwOpenTagBeginToken)tokens[2]).TagName);
            ValidateSpanContent(input, "<c:Control", tokens[2].SpanPosition);

            Assert.IsInstanceOfType(tokens[3], typeof(RwAttributeToken));
            Assert.AreEqual("Text", ((RwAttributeToken)tokens[3]).Name);
            Assert.IsInstanceOfType(((RwAttributeToken)tokens[3]).Value, typeof(RwValueToken));
            Assert.AreEqual("Text, HtmlEncode=true", ((RwValueToken)(((RwAttributeToken)tokens[3]).Value)).Expression);
            ValidateSpanContent(input, "{Text, HtmlEncode=true}", ((RwAttributeToken)tokens[3]).Value.SpanPosition);
            ValidateSpanContent(input, " Text=\"{Text, HtmlEncode=true}\"", tokens[3].SpanPosition);

            Assert.IsInstanceOfType(tokens[4], typeof(RwOpenTagEndToken));
            Assert.IsTrue(((RwOpenTagEndToken)tokens[4]).IsSelfClosing);
            ValidateSpanContent(input, " />", tokens[4].SpanPosition);

            Assert.IsInstanceOfType(tokens[5], typeof(RwCloseTagToken));
            Assert.AreEqual("html", ((RwCloseTagToken)tokens[5]).TagName);
            ValidateSpanContent(input, "</html>", tokens[5].SpanPosition);

            ValidateTokenSequence(tokens, input.Length);
        }
Exemplo n.º 14
0
        public void RwHtmlTokenizer_ValidInput_Sample()
        {
            var fileName = Path.Combine(TestContext.TestDeploymentDir, "..\\..\\..\\Redwood.Samples.Basic\\TaskList.rwhtml");
            var input = File.ReadAllText(fileName, Encoding.UTF8);

            var tokens = new RwHtmlTokenizer().Parse(input).ToList();
            ValidateTokenSequence(tokens, input.Length);
        }
Exemplo n.º 15
0
        public void RwHtmlTokenizer_BindingParsing_Invalid_BindingInPlainText_SingleBraces_TreatedAsText()
        {
            var input = @"tr {binding: FirstName}test"" />";

            // parse
            var tokenizer = new RwHtmlTokenizer();
            tokenizer.Tokenize(new StringReader(input));
            CheckForErrors(tokenizer, input.Length);

            var i = 0;
            Assert.AreEqual(1, tokenizer.Tokens.Count);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
        }
        public void RwHtmlTokenizer_DirectiveParsing_Valid_NoDirectives_WhiteSpaceOnStart()
        {
            var input = @"
            this is a test content";

            // parse
            var tokenizer = new RwHtmlTokenizer();
            tokenizer.Tokenize(new StringReader(input));
            CheckForErrors(tokenizer, input.Length);

            // first line
            var i = 0;
            Assert.AreEqual(RwHtmlTokenType.WhiteSpace, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
        }
Exemplo n.º 17
0
        public void RwHtmlTokenizer_ValidInput_PlainOpenCloseTagsAndText()
        {
            var input = "test <element> text </element> test";
            var tokens = new RwHtmlTokenizer().Parse(input).ToList();

            Assert.AreEqual(6, tokens.Count);

            Assert.IsInstanceOfType(tokens[0], typeof(RwValueToken));
            Assert.AreEqual("test ", ((RwValueToken)tokens[0]).Text);

            Assert.IsInstanceOfType(tokens[1], typeof(RwOpenTagBeginToken));
            Assert.AreEqual("element", ((RwOpenTagBeginToken)tokens[1]).TagName);
            ValidateSpanContent(input, "<element", tokens[1].SpanPosition);

            Assert.IsInstanceOfType(tokens[2], typeof(RwOpenTagEndToken));
            Assert.IsFalse(((RwOpenTagEndToken)tokens[2]).IsSelfClosing);
            ValidateSpanContent(input, ">", tokens[2].SpanPosition);

            Assert.IsInstanceOfType(tokens[3], typeof(RwValueToken));
            Assert.AreEqual(" text ", ((RwValueToken)tokens[3]).Text);

            Assert.IsInstanceOfType(tokens[4], typeof(RwCloseTagToken));
            Assert.AreEqual("element", ((RwCloseTagToken)tokens[4]).TagName);

            Assert.IsInstanceOfType(tokens[5], typeof(RwValueToken));
            Assert.AreEqual(" test", ((RwValueToken)tokens[5]).Text);

            ValidateTokenSequence(tokens, input.Length);
        }
Exemplo n.º 18
0
        public void RwHtmlTokenizer_ValidInput_BindingInsideScript()
        {
            var input = "test <script>if (xxx < {{Binding MaxValue}}) { return; }</script>";
            var tokens = new RwHtmlTokenizer().Parse(input).ToList();

            Assert.AreEqual(7, tokens.Count);

            Assert.IsInstanceOfType(tokens[0], typeof(RwValueToken));
            Assert.AreEqual("test ", ((RwValueToken)tokens[0]).Text);
            ValidateSpanContent(input, "test ", tokens[0].SpanPosition);

            Assert.IsInstanceOfType(tokens[1], typeof(RwOpenTagBeginToken));
            Assert.AreEqual("script", ((RwOpenTagBeginToken)tokens[1]).TagName);
            ValidateSpanContent(input, "<script", tokens[1].SpanPosition);

            Assert.IsInstanceOfType(tokens[2], typeof(RwOpenTagEndToken));
            Assert.IsFalse(((RwOpenTagEndToken)tokens[2]).IsSelfClosing);
            ValidateSpanContent(input, ">", tokens[2].SpanPosition);

            Assert.IsInstanceOfType(tokens[3], typeof(RwValueToken));
            Assert.IsFalse(((RwValueToken)tokens[3]).IsExpression);
            Assert.AreEqual("if (xxx < ", ((RwValueToken)tokens[3]).Text);
            ValidateSpanContent(input, "if (xxx < ", tokens[3].SpanPosition);

            Assert.IsInstanceOfType(tokens[4], typeof(RwValueToken));
            Assert.IsTrue(((RwValueToken)tokens[4]).IsExpression);
            Assert.AreEqual("Binding MaxValue", ((RwValueToken)tokens[4]).Text);
            ValidateSpanContent(input, "{{Binding MaxValue}}", tokens[4].SpanPosition);

            Assert.IsInstanceOfType(tokens[5], typeof(RwValueToken));
            Assert.IsFalse(((RwValueToken)tokens[5]).IsExpression);
            Assert.AreEqual(") { return; }", ((RwValueToken)tokens[5]).Text);
            ValidateSpanContent(input, ") { return; }", tokens[5].SpanPosition);

            Assert.IsInstanceOfType(tokens[6], typeof(RwCloseTagToken));
            Assert.AreEqual("script", ((RwCloseTagToken)tokens[6]).TagName);
            ValidateSpanContent(input, "</script>", tokens[6].SpanPosition);

            ValidateTokenSequence(tokens, input.Length);
        }
Exemplo n.º 19
0
        public void RwHtmlTokenizer_ElementParsing_Valid_SelfClosing_NoAttributes_TextOnEnd()
        {
            var input = @"<html/>aaa";

            // parse
            var tokenizer = new RwHtmlTokenizer();
            tokenizer.Tokenize(new StringReader(input));
            CheckForErrors(tokenizer, input.Length);

            var i = 0;
            Assert.AreEqual(RwHtmlTokenType.OpenTag, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Slash, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.CloseTag, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
        }
Exemplo n.º 20
0
        public void RwHtmlTokenizer_BindingParsing_Valid_SelfClosing_BindingAttribute()
        {
            var input = @" tr <input value=""{binding: FirstName}"" />";

            // parse
            var tokenizer = new RwHtmlTokenizer();
            tokenizer.Tokenize(new StringReader(input));
            CheckForErrors(tokenizer, input.Length);

            var i = 0;
            Assert.AreEqual(RwHtmlTokenType.WhiteSpace, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.OpenTag, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.WhiteSpace, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Equals, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.DoubleQuote, tokenizer.Tokens[i++].Type);

            Assert.AreEqual(RwHtmlTokenType.OpenBinding, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Colon, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.WhiteSpace, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.CloseBinding, tokenizer.Tokens[i++].Type);

            Assert.AreEqual(RwHtmlTokenType.DoubleQuote, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.WhiteSpace, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Slash, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.CloseTag, tokenizer.Tokens[i++].Type);
        }
Exemplo n.º 21
0
        public void RwHtmlTokenizer_BindingParsing_Valid_BindingInPlainText()
        {
            var input = @"tr {{binding: FirstName}}"" />";

            // parse
            var tokenizer = new RwHtmlTokenizer();
            tokenizer.Tokenize(new StringReader(input));
            CheckForErrors(tokenizer, input.Length);

            var i = 0;
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.OpenBinding, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Colon, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.WhiteSpace, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.CloseBinding, tokenizer.Tokens[i++].Type);
        }
Exemplo n.º 22
0
        public void RwHtmlTokenizer_ElementParsing_Valid_NestedTags_MultipleAttributes()
        {
            var input = @"<html><body lang=cs><h1 class=alert size=big>Test</h1>  </body></html>";

            // parse
            var tokenizer = new RwHtmlTokenizer();
            tokenizer.Tokenize(new StringReader(input));
            CheckForErrors(tokenizer, input.Length);

            var i = 0;
            Assert.AreEqual(RwHtmlTokenType.OpenTag, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.CloseTag, tokenizer.Tokens[i++].Type);

            Assert.AreEqual(RwHtmlTokenType.OpenTag, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.WhiteSpace, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Equals, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.CloseTag, tokenizer.Tokens[i++].Type);

            Assert.AreEqual(RwHtmlTokenType.OpenTag, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.WhiteSpace, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Equals, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.WhiteSpace, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Equals, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.CloseTag, tokenizer.Tokens[i++].Type);

            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);

            Assert.AreEqual(RwHtmlTokenType.OpenTag, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Slash, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.CloseTag, tokenizer.Tokens[i++].Type);

            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);

            Assert.AreEqual(RwHtmlTokenType.OpenTag, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Slash, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.CloseTag, tokenizer.Tokens[i++].Type);

            Assert.AreEqual(RwHtmlTokenType.OpenTag, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Slash, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.CloseTag, tokenizer.Tokens[i++].Type);
        }
        public void RwHtmlTokenizer_DoctypeParsing_Valid_End()
        {
            var input = @"test <!DOCTYPE html>";

            // parse
            var tokenizer = new RwHtmlTokenizer();
            tokenizer.Tokenize(new StringReader(input));
            CheckForErrors(tokenizer, input.Length);

            // first line
            var i = 0;
            Assert.AreEqual("test ", tokenizer.Tokens[i].Text);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);

            Assert.AreEqual("<!DOCTYPE", tokenizer.Tokens[i].Text);
            Assert.AreEqual(RwHtmlTokenType.OpenDoctype, tokenizer.Tokens[i++].Type);

            Assert.AreEqual(" html", tokenizer.Tokens[i].Text);
            Assert.AreEqual(RwHtmlTokenType.DoctypeBody, tokenizer.Tokens[i++].Type);

            Assert.AreEqual(">", tokenizer.Tokens[i].Text);
            Assert.AreEqual(RwHtmlTokenType.CloseDoctype, tokenizer.Tokens[i++].Type);
        }
        public void RwHtmlTokenizer_DirectiveParsing_Invalid_OnlyAtSymbol()
        {
            var input = @"@";

            // parse
            var tokenizer = new RwHtmlTokenizer();
            tokenizer.Tokenize(new StringReader(input));
            CheckForErrors(tokenizer, input.Length);

            var i = 0;
            Assert.AreEqual(RwHtmlTokenType.DirectiveStart, tokenizer.Tokens[i++].Type);

            Assert.IsTrue(tokenizer.Tokens[i].HasError);
            Assert.AreEqual(0, tokenizer.Tokens[i].Length);
            Assert.AreEqual(RwHtmlTokenType.DirectiveName, tokenizer.Tokens[i++].Type);

            Assert.IsTrue(tokenizer.Tokens[i].HasError);
            Assert.AreEqual(0, tokenizer.Tokens[i].Length);
            Assert.AreEqual(RwHtmlTokenType.WhiteSpace, tokenizer.Tokens[i++].Type);

            Assert.IsTrue(tokenizer.Tokens[i].HasError);
            Assert.AreEqual(0, tokenizer.Tokens[i].Length);
            Assert.AreEqual(RwHtmlTokenType.DirectiveValue, tokenizer.Tokens[i++].Type);
        }
Exemplo n.º 25
0
        public void RwHtmlTokenizer_ValidInput_XmlProcessingInstruction()
        {
            var input = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><!DOCTYPE html5><html><!--<c:Control Text=\"{Text, HtmlEncode=true}\" />--!></html>";
            var tokens = new RwHtmlTokenizer().Parse(input).ToList();

            Assert.AreEqual(6, tokens.Count);

            Assert.IsInstanceOfType(tokens[0], typeof(RwValueToken));
            Assert.AreEqual("<?xml version=\"1.0\" encoding=\"utf-8\" ?>", ((RwValueToken)tokens[0]).Text);
            ValidateSpanContent(input, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>", tokens[0].SpanPosition);

            Assert.IsInstanceOfType(tokens[1], typeof(RwValueToken));
            Assert.AreEqual("<!DOCTYPE html5>", ((RwValueToken)tokens[1]).Text);
            ValidateSpanContent(input, "<!DOCTYPE html5>", tokens[1].SpanPosition);

            Assert.IsInstanceOfType(tokens[2], typeof(RwOpenTagBeginToken));
            Assert.AreEqual("html", ((RwOpenTagBeginToken)tokens[2]).TagName);
            ValidateSpanContent(input, "<html", tokens[2].SpanPosition);

            Assert.IsInstanceOfType(tokens[3], typeof(RwOpenTagEndToken));
            Assert.IsFalse(((RwOpenTagEndToken)tokens[3]).IsSelfClosing);
            ValidateSpanContent(input, ">", tokens[3].SpanPosition);

            Assert.IsInstanceOfType(tokens[4], typeof(RwValueToken));
            Assert.AreEqual("<!--<c:Control Text=\"{Text, HtmlEncode=true}\" />--!>", ((RwValueToken)tokens[4]).Text);
            ValidateSpanContent(input, "<!--<c:Control Text=\"{Text, HtmlEncode=true}\" />--!>", tokens[4].SpanPosition);

            Assert.IsInstanceOfType(tokens[5], typeof(RwCloseTagToken));
            Assert.AreEqual("html", ((RwCloseTagToken)tokens[5]).TagName);
            ValidateSpanContent(input, "</html>", tokens[5].SpanPosition);

            ValidateTokenSequence(tokens, input.Length);
        }
Exemplo n.º 26
0
        public void RwHtmlTokenizer_ValidInput_EmptyLiteral()
        {
            var input = "";
            var tokens = new RwHtmlTokenizer().Parse(input).ToList();

            Assert.AreEqual(0, tokens.Count);
        }
Exemplo n.º 27
0
        public void RwHtmlTokenizer_ElementParsing_Valid_SelfClosing_SingleQuotedAttribute()
        {
            var input = @" tr <html xmlns='hello dolly' />";

            // parse
            var tokenizer = new RwHtmlTokenizer();
            tokenizer.Tokenize(new StringReader(input));
            CheckForErrors(tokenizer, input.Length);

            var i = 0;
            Assert.AreEqual(RwHtmlTokenType.WhiteSpace, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.OpenTag, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.WhiteSpace, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Equals, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.SingleQuote, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.SingleQuote, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.WhiteSpace, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Slash, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.CloseTag, tokenizer.Tokens[i++].Type);
        }
Exemplo n.º 28
0
        public void RwHtmlTokenizer_ValidInput_HtmlComment()
        {
            var input = "<html><!--<c:Control Text=\"{Text, HtmlEncode=true}\" />---!></html>";
            var tokens = new RwHtmlTokenizer().Parse(input).ToList();

            Assert.AreEqual(4, tokens.Count);

            Assert.IsInstanceOfType(tokens[0], typeof(RwOpenTagBeginToken));
            Assert.AreEqual("html", ((RwOpenTagBeginToken)tokens[0]).TagName);
            ValidateSpanContent(input, "<html", tokens[0].SpanPosition);

            Assert.IsInstanceOfType(tokens[1], typeof(RwOpenTagEndToken));
            Assert.IsFalse(((RwOpenTagEndToken)tokens[1]).IsSelfClosing);
            ValidateSpanContent(input, ">", tokens[1].SpanPosition);

            Assert.IsInstanceOfType(tokens[2], typeof(RwValueToken));
            Assert.AreEqual("<!--<c:Control Text=\"{Text, HtmlEncode=true}\" />---!>", ((RwValueToken)tokens[2]).Text);
            ValidateSpanContent(input, "<!--<c:Control Text=\"{Text, HtmlEncode=true}\" />---!>", tokens[2].SpanPosition);

            Assert.IsInstanceOfType(tokens[3], typeof(RwCloseTagToken));
            Assert.AreEqual("html", ((RwCloseTagToken)tokens[3]).TagName);
            ValidateSpanContent(input, "</html>", tokens[3].SpanPosition);

            ValidateTokenSequence(tokens, input.Length);
        }
        public void RwHtmlTokenizer_XmlProcessingInstructionParsing_Valid()
        {
            var input = @"test <?xml version=""1.0"" encoding=""utf-8"" ?> test2";

            // parse
            var tokenizer = new RwHtmlTokenizer();
            tokenizer.Tokenize(new StringReader(input));
            CheckForErrors(tokenizer, input.Length);

            // first line
            var i = 0;
            Assert.AreEqual("test ", tokenizer.Tokens[i].Text);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);

            Assert.AreEqual("<?", tokenizer.Tokens[i].Text);
            Assert.AreEqual(RwHtmlTokenType.OpenXmlProcessingInstruction, tokenizer.Tokens[i++].Type);

            Assert.AreEqual(@"xml version=""1.0"" encoding=""utf-8"" ", tokenizer.Tokens[i].Text);
            Assert.AreEqual(RwHtmlTokenType.XmlProcessingInstructionBody, tokenizer.Tokens[i++].Type);

            Assert.AreEqual("?>", tokenizer.Tokens[i].Text);
            Assert.AreEqual(RwHtmlTokenType.CloseXmlProcessingInstruction, tokenizer.Tokens[i++].Type);

            Assert.AreEqual(" test2", tokenizer.Tokens[i].Text);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
        }
        public void RwHtmlTokenizer_DirectiveParsing_Valid_TwoDirectives()
        {
            var input = @"
            @viewmodel Redwood.Samples.Sample1.IndexViewModel
            @masterpage ~/Site.rwhtml

            this is a test content";

            // parse
            var tokenizer = new RwHtmlTokenizer();
            tokenizer.Tokenize(new StringReader(input));
            CheckForErrors(tokenizer, input.Length);

            // first line
            var i = 0;
            Assert.AreEqual(RwHtmlTokenType.WhiteSpace, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.DirectiveStart, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.DirectiveName, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.WhiteSpace, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.DirectiveValue, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.WhiteSpace, tokenizer.Tokens[i++].Type);

            Assert.AreEqual(RwHtmlTokenType.DirectiveStart, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.DirectiveName, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.WhiteSpace, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.DirectiveValue, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.WhiteSpace, tokenizer.Tokens[i++].Type);

            Assert.AreEqual(RwHtmlTokenType.WhiteSpace, tokenizer.Tokens[i++].Type);
            Assert.AreEqual(RwHtmlTokenType.Text, tokenizer.Tokens[i++].Type);
        }