Exemple #1
0
        public void CssTokenize()
        {
            const string value = @"#someid .someclass {
                                                 font-size: 20px;
                                                 width: 50%;
                                                 text-align: center;
                                                 -webkit-border-radius: 5px;
                                                }";

            StringTokenizer t = new StringTokenizer(value);

            List<TokenTypeEnum> expectedTokens = new List<TokenTypeEnum>
                {
                    TokenTypeEnum.HashName,
                    TokenTypeEnum.Whitespace,
                    TokenTypeEnum.Operator,
                    TokenTypeEnum.Identifier,
                    TokenTypeEnum.Whitespace,
                    TokenTypeEnum.Delimiter,
                    TokenTypeEnum.Whitespace,
                    TokenTypeEnum.Identifier,
                    TokenTypeEnum.Delimiter,
                    TokenTypeEnum.Whitespace,
                    TokenTypeEnum.Dimension,
                    TokenTypeEnum.Delimiter,
                    TokenTypeEnum.Whitespace,
                    TokenTypeEnum.Identifier,
                    TokenTypeEnum.Delimiter,
                    TokenTypeEnum.Whitespace,
                    TokenTypeEnum.Percentage,
                    TokenTypeEnum.Delimiter,
                    TokenTypeEnum.Whitespace,
                    TokenTypeEnum.Identifier,
                    TokenTypeEnum.Delimiter,
                    TokenTypeEnum.Whitespace,
                    TokenTypeEnum.Identifier,
                    TokenTypeEnum.Delimiter,
                    TokenTypeEnum.Whitespace,
                    TokenTypeEnum.Identifier,
                    TokenTypeEnum.Delimiter,
                    TokenTypeEnum.Whitespace,
                    TokenTypeEnum.Dimension,
                    TokenTypeEnum.Delimiter,
                    TokenTypeEnum.Whitespace,
                    TokenTypeEnum.Delimiter
                };

            int i = 0;
            while (t.MoveNext())
            {
                var token = t.Current;
                Assert.Equal(expectedTokens[i++], token.Type);
            }
        }
Exemple #2
0
        public void CDataStartTokenize()
        {
            const string value = @"<!--";

            StringTokenizer t = new StringTokenizer(value);
            bool tokenized = false;
            while (t.MoveNext())
            {
                Assert.Equal(TokenTypeEnum.CDataOpen, t.Current.Type);
                Assert.Equal(value, t.Current.Text);
                tokenized = true;
            }

            Assert.True(tokenized);
        }
Exemple #3
0
        public void WhitespaceTokenize()
        {
            const string value = " \t \r\n";

            StringTokenizer t = new StringTokenizer(value);
            bool tokenized = false;
            while (t.MoveNext())
            {
                Assert.Equal(TokenTypeEnum.Whitespace, t.Current.Type);
                tokenized = true;
            }

            Assert.True(tokenized);
        }
Exemple #4
0
        public void VariableTokenize()
        {
            const string value = "$variableName";

            StringTokenizer t = new StringTokenizer(value);
            bool tokenized = false;
            while (t.MoveNext())
            {
                Assert.Equal(TokenTypeEnum.Variable, t.Current.Type);
                Assert.Equal(value, t.Current.Text);
                tokenized = true;
            }

            Assert.True(tokenized);
        }
Exemple #5
0
        public void UrlWithSingleQuotesTokenize()
        {
            const string value = "url('someurl')";

            StringTokenizer t = new StringTokenizer(value);
            bool tokenized = false;
            while (t.MoveNext())
            {
                Assert.Equal(TokenTypeEnum.Uri, t.Current.Type);
                Assert.Equal(value, t.Current.Text);
                tokenized = true;
            }

            Assert.True(tokenized);
        }
Exemple #6
0
        public void SinglelineCommentsTokenize()
        {
            const string value = @"// Singleline comment";

            StringTokenizer t = new StringTokenizer(value);
            bool tokenized = false;
            while (t.MoveNext())
            {
                Assert.Equal(TokenTypeEnum.Comment, t.Current.Type);
                Assert.Equal(value, t.Current.Text);
                tokenized = true;
            }

            Assert.True(tokenized);
        }
Exemple #7
0
        public void SingleQuotesStringTokenize()
        {
            const string value = "'test'";

            StringTokenizer t = new StringTokenizer(value);
            bool tokenized = false;
            while (t.MoveNext())
            {
                Assert.Equal(TokenTypeEnum.String, t.Current.Type);
                Assert.Equal(value, t.Current.Text);
                tokenized = true;
            }

            Assert.True(tokenized);
        }
Exemple #8
0
        public void OperatorTokenize()
        {
            const string value = @"+-.*/";

            StringTokenizer t = new StringTokenizer(value);
            bool tokenized = false;
            while (t.MoveNext())
            {
                Assert.Equal(TokenTypeEnum.Operator, t.Current.Type);
                tokenized = true;
            }

            Assert.True(tokenized);
        }
Exemple #9
0
        public void PercentageTokenize()
        {
            const string value = @"123.45%";

            StringTokenizer t = new StringTokenizer(value);
            bool tokenized = false;
            while (t.MoveNext())
            {
                Assert.Equal(TokenTypeEnum.Percentage, t.Current.Type);
                Assert.Equal(value, t.Current.Text);
                tokenized = true;
            }

            Assert.True(tokenized);
        }
Exemple #10
0
        public void MutlilineCommentsTokensTokenize()
        {
            const string value = @"/*** ahoj **/";

            StringTokenizer t = new StringTokenizer(value, 0, TokenizerOptions.MultilineCommentBeginEndTokens);

            List<TokenTypeEnum> expectedTokens = new List<TokenTypeEnum>
                {
                    TokenTypeEnum.MultiLineCommentStart,
                    TokenTypeEnum.Operator,
                    TokenTypeEnum.Operator,
                    TokenTypeEnum.Whitespace,
                    TokenTypeEnum.Identifier,
                    TokenTypeEnum.Whitespace,
                    TokenTypeEnum.Operator,
                    TokenTypeEnum.MultiLineCommentEnd
                };

            int i = 0;
            while (t.MoveNext())
            {
                var token = t.Current;
                Assert.Equal(expectedTokens[i++], token.Type);
            }
        }
Exemple #11
0
        public void NumberWithUnitTokenize()
        {
            const string value = @"123.45px";

            StringTokenizer t = new StringTokenizer(value);
            bool tokenized = false;
            while (t.MoveNext())
            {
                Assert.Equal(TokenTypeEnum.Dimension, t.Current.Type);
                Assert.Equal(value, t.Current.Text);
                tokenized = true;
            }

            Assert.True(tokenized);
        }
Exemple #12
0
        public void MultilineCommentStartTokensTokenize()
        {
            const string value = "/*";

            StringTokenizer t = new StringTokenizer(value, 0, TokenizerOptions.MultilineCommentBeginEndTokens);
            bool tokenized = false;
            while (t.MoveNext())
            {
                Assert.Equal(TokenTypeEnum.MultiLineCommentStart, t.Current.Type);
                Assert.Equal(value, t.Current.Text);
                tokenized = true;
            }

            Assert.True(tokenized);
        }
Exemple #13
0
        public void ImportClausuleTokenize()
        {
            const string value = @"@import";

            StringTokenizer t = new StringTokenizer(value);
            bool tokenized = false;
            while (t.MoveNext())
            {
                Assert.Equal(TokenTypeEnum.AtIdentifier, t.Current.Type);
                Assert.Equal(value, t.Current.Text);
                tokenized = true;
            }

            Assert.True(tokenized);
        }
Exemple #14
0
        public void HashTokenize()
        {
            const string value = "#someid";

            StringTokenizer t = new StringTokenizer(value);
            bool tokenized = false;
            while (t.MoveNext())
            {
                Assert.Equal(TokenTypeEnum.HashName, t.Current.Type);
                Assert.Equal(value, t.Current.Text);
                tokenized = true;
            }

            Assert.True(tokenized);
        }
Exemple #15
0
        public void FunctionTokenize()
        {
            const string value = "functionName(";

            StringTokenizer t = new StringTokenizer(value);
            bool tokenized = false;
            while (t.MoveNext())
            {
                Assert.Equal(TokenTypeEnum.Function, t.Current.Type);
                Assert.Equal(value, t.Current.Text);
                tokenized = true;
            }

            Assert.True(tokenized);
        }
Exemple #16
0
        public void DelimitersTokenize()
        {
            const string value = @"{}()[]:;,";

            StringTokenizer t = new StringTokenizer(value);
            bool tokenized = false;
            while (t.MoveNext())
            {
                Assert.Equal(TokenTypeEnum.Delimiter,  t.Current.Type);
                tokenized = true;
            }

            Assert.True(tokenized);
        }