Beispiel #1
0
        public void ParenthesisLexingTest(string data, string parseResult)
        {
            var stream = DataFactory.StreamFactory(data);

            using (var reader = new StreamReader(stream))
            {
                var           streamer = new InputStreamer(reader);
                var           lexer    = new Lexer(streamer);
                List <IToken> tokens   = new List <IToken>();
                foreach (var item in lexer.ProduceToken())
                {
                    tokens.Add(item);
                    TestContext.WriteLine(item.ToString());
                }

                var parse = parseResult.Split(',');
                Assert.AreEqual(parse.Length, tokens.Count);
                int i = 0;
                foreach (var s in parse)
                {
                    Assert.AreEqual(s, tokens[i].TokenValue);
                    i++;
                }
            }
        }
Beispiel #2
0
        public void TestInputStreamer()
        {
            string        data     = "0 1 2 3 4 5 6 7 8 9 \"123bbbcc\"";
            string        expected = "0 1 2 3 4 5 6 7 8 9 \"123bbbcc\"";
            StringBuilder sb       = new StringBuilder();
            Stream        stream   = DataFactory.StreamFactory(data);

            using (var reader = new StreamReader(stream))
            {
                var streamer = new InputStreamer(reader);
                while (!streamer.Eos())
                {
                    sb.Append(streamer.Next());
                }
            }
            Assert.AreEqual(expected, sb.ToString());
        }
Beispiel #3
0
        public void BasicLexingTest(string data, int qttToken)
        {
            var stream = DataFactory.StreamFactory(data);

            using (var reader = new StreamReader(stream))
            {
                var           streamer = new InputStreamer(reader);
                var           lexer    = new Lexer(streamer);
                List <IToken> tokens   = new List <IToken>();
                foreach (var item in lexer.ProduceToken())
                {
                    tokens.Add(item);
                    TestContext.WriteLine(item.ToString());
                }
                Assert.AreEqual(qttToken, tokens.Count);
            }
        }
Beispiel #4
0
        public void IdentifierLexingTest(string data, TokenType token, string value)
        {
            var stream = DataFactory.StreamFactory(data);

            using (var reader = new StreamReader(stream))
            {
                var           streamer = new InputStreamer(reader);
                var           lexer    = new Lexer(streamer);
                List <IToken> tokens   = new List <IToken>();
                foreach (var item in lexer.ProduceToken())
                {
                    tokens.Add(item);
                    TestContext.WriteLine(item.ToString());
                }
                Assert.AreEqual(1, tokens.Count);
                Assert.AreEqual(token, tokens[0].TokenType);
                Assert.AreEqual(value, tokens[0].TokenValue);
            }
        }