예제 #1
0
        public void IgnoreComments()
        {
            var lexer = new StringLexer ("# this is a comment");

            var token = lexer.GetToken ();
            Assert.AreEqual (TokenType.EOF, token.Type);
        }
예제 #2
0
        public void IgnoreWhitespace(string input)
        {
            var lexer = new StringLexer (input);

            var token = lexer.GetToken ();
            Assert.AreEqual (TokenType.EOF, token.Type);
        }
예제 #3
0
        public void ErrorOnUnfinishedSingleQuote()
        {
            var lexer = new StringLexer ("'foobar");

            var ex = Assert.Throws<LexerException> (() => lexer.GetToken ());
            Assert.That (NOT_CLOSED_RE.IsMatch (ex.Message));
        }
예제 #4
0
        public void LexFunctionCallDelimiters(string input, TokenType expected)
        {
            var lexer = new StringLexer (input);

            var token = lexer.GetToken ();

            Assert.AreEqual (expected, token.Type);
        }
예제 #5
0
        public void ErrorOnInvalidInput()
        {
            var lexer = new StringLexer ("{foobar}");

            var ex = Assert.Throws<LexerException> (() => lexer.GetToken ());

            Assert.That (INVALID_RE.IsMatch (ex.Message));
        }
예제 #6
0
        public void LexNumbers(string input, double expected)
        {
            var lexer = new StringLexer (input);

            var token = lexer.GetToken ();
            Assert.AreEqual (TokenType.Number, token.Type);
            Assert.AreEqual (expected, token.GetNumberValue ());

            token = lexer.GetToken ();
            Assert.AreEqual (TokenType.EOF, token.Type);
        }
예제 #7
0
        public void ReturnEOF()
        {
            var lexer = new StringLexer ("");

            var token = lexer.GetToken ();
            Assert.AreEqual (TokenType.EOF, token.Type);

            token = lexer.GetToken ();
            Assert.AreEqual (TokenType.EOF, token.Type);

            token = lexer.GetToken ();
            Assert.AreEqual (TokenType.EOF, token.Type);
        }
예제 #8
0
        public void LexStrings(string input, string expected)
        {
            var lexer = new StringLexer (input);

            var token = lexer.GetToken ();
            Assert.AreEqual (TokenType.String, token.Type);
            Assert.AreEqual (expected, token.GetStringValue ());

            token = lexer.GetToken ();
            Assert.AreEqual (TokenType.EOF, token.Type);
        }
예제 #9
0
        public void LexReferences(string input, string[] expected)
        {
            var lexer = new StringLexer (input);

            var token = lexer.GetToken ();
            Assert.AreEqual (TokenType.Reference, token.Type);

            var segments = token.GetReferenceValue ();
            Assert.AreEqual (expected.Length, segments.Length);

            for (var i = 0; i < expected.Length; i += 1)
            {
                Assert.AreEqual (expected [i], segments [i]);
            }
        }