Example #1
0
        public void TestTokenize_When_MissingStartParentheses_Then_Exception()
        {
            const string input     = "try something func2 ('123'))";
            IATokenizer  tokenizer = ATokenizerFactory.CreateInstance();

            tokenizer.Tokenize(input);
        }
Example #2
0
        private void TestUnicodeString(IATokenizer tokenizer, bool unicodeStringMark)
        {
            const string input = "N'value'";

            tokenizer.UnicodeStringMark = unicodeStringMark;
            tokenizer.Tokenize(input);
        }
Example #3
0
        public void TestTokenize_When_MissingQuote_Then_Exception()
        {
            const string input     = "try 'something  (func2 ('123'))";
            IATokenizer  tokenizer = ATokenizerFactory.CreateInstance();

            tokenizer.Tokenize(input);
        }
Example #4
0
        public void TestToString()
        {
            const string input     = "try func  (func2 (123))";
            IATokenizer  tokenizer = ATokenizerFactory.CreateInstance();

            tokenizer.Tokenize(input);
            tokenizer.ToString().Should().Be("try func (func2 (123))", "because it should keep spaces (but truncate several contiguous spaces to one)");
        }
Example #5
0
        public void TestParenteces_When_ContainsCompoundElement()
        {
            const string input     = "try func(func2((123)))";
            IATokenizer  tokenizer = ATokenizerFactory.CreateInstance();

            tokenizer.Tokenize(input);
            tokenizer.Tokens[6].Text.Should().Be("123", "because 123 is the 6th element");
        }
Example #6
0
        public void TestParenteces_When_ContainsOneSimpleElement()
        {
            const string input     = "try func(123)";
            IATokenizer  tokenizer = ATokenizerFactory.CreateInstance();

            tokenizer.Tokenize(input);
            tokenizer.Tokens.Count.Should().Be(5, "because there are 5 tokens");
        }
Example #7
0
        public void TestTokenizer_When_StringIsLastToken()
        {
            const string input     = "one ''''";
            IATokenizer  tokenizer = ATokenizerFactory.CreateInstance();

            tokenizer.Tokenize(input);
            tokenizer.Tokens[1].Text.Should().Be("''''", "because two quotes is ok");
        }
Example #8
0
        public void TestTokenizer_When_StringContainsQuoteInMiddle()
        {
            const string input     = "one 'this '' two' three";
            IATokenizer  tokenizer = ATokenizerFactory.CreateInstance();

            tokenizer.Tokenize(input);
            tokenizer.Tokens[1].Text.Should().Be("'this '' two'", "because two quotes is ok");
        }
Example #9
0
        public void TestSqlServerQuotedIdentifier()
        {
            const string input     = "select int_col as [mycol] from mytable";
            IATokenizer  tokenizer = ATokenizerFactory.CreateInstance();

            tokenizer.Tokenize(input);
            tokenizer.Tokens.Count.Should().Be(6, "because [mycol] is one token, not three");
        }
Example #10
0
        public void TestFunction_When_WrappedWithCurlyBraces()
        {
            const string input     = "try {fn func  ({ fn func2 (123) })}";
            IATokenizer  tokenizer = ATokenizerFactory.CreateInstance();

            tokenizer.Tokenize(input);
            tokenizer.ToString().Should().Be("try func (func2 (123) )", "because wrapping function is legal syntax");
        }
Example #11
0
        public void TestTokenizer_When_EmptyString()
        {
            const string input     = "";
            IATokenizer  tokenizer = ATokenizerFactory.CreateInstance();

            tokenizer.Tokenize(input);
            tokenizer.Tokens.Count.Should().Be(0, "because the string is empty");
        }
Example #12
0
        public void TestTokenizer_When_String()
        {
            const string input     = "one 'this is two' three";
            IATokenizer  tokenizer = ATokenizerFactory.CreateInstance();

            tokenizer.Tokenize(input);
            tokenizer.Tokens.Count.Should().Be(3, "because there are only three tokens");
            tokenizer.Tokens[1].Text.Should().Be("'this is two'", "because the whole string is a single token");
        }
Example #13
0
        public void TestTokenizer_When_EOL_And_Tab()
        {
            const string input     = "one \ttwo \n three";
            IATokenizer  tokenizer = ATokenizerFactory.CreateInstance();

            tokenizer.Tokenize(input);
            tokenizer.Tokens.Count.Should().Be(3, "because there are three words");
            tokenizer.Tokens[0].Text.Should().Be("one", "because first word is one");
            tokenizer.Tokens[1].Text.Should().Be("two", "because second word is two");
            tokenizer.Tokens[2].Text.Should().Be("three", "because third word is three");
        }
Example #14
0
        public ASTNodeList CreateNodeList(string text)
        {
            ASTNodeList nodes;
            IATokenizer tokenizer = ATokenizerFactory.CreateInstance();

            tokenizer.ExpandEmptyStrings = ExpandEmptyStrings;
            tokenizer.Tokenize(text);
            ATokens tokens = tokenizer.Tokens;

            nodes = ParseExpression(tokens);

            return(nodes);
        }