示例#1
0
文件: Tests.cs 项目: pzhin/MMCS_CS311
        public void TestOps()
        {
            string     text        = @",:+-* / -+ /**/";
            TextReader inputReader = new StringReader(text);
            Lexer      l           = new Lexer(inputReader);

            var lexems = TestSimpleLexer.getLexerOutput(l);

            Assert.IsTrue(lexems.Count == 12);
            CollectionAssert.AreEqual(new LexemList()
            {
                { Tok.COMMA, "," },
                { Tok.COLON, ":" },
                { Tok.PLUS, "+" },
                { Tok.MINUS, "-" },
                { Tok.MULT, "*" },
                { Tok.DIVISION, "/" },
                { Tok.MINUS, "-" },
                { Tok.PLUS, "+" },
                { Tok.DIVISION, "/" },
                { Tok.MULT, "*" },
                { Tok.MULT, "*" },
                { Tok.DIVISION, "/" },
            }.ToList(), lexems);
        }
示例#2
0
文件: Tests.cs 项目: pzhin/MMCS_CS311
        public void TestComparisonsAndOps()
        {
            string     text        = @">+6<>>=<= +<> >+=<= <==";
            TextReader inputReader = new StringReader(text);
            Lexer      l           = new Lexer(inputReader);

            var lexems = TestSimpleLexer.getLexerOutput(l);

            Assert.IsTrue(lexems.Count == 13);
            CollectionAssert.AreEqual(new LexemList()
            {
                { Tok.GT, ">" },
                { Tok.PLUS, "+" },
                { Tok.INUM, "6" },
                { Tok.NEQ, "<>" },
                { Tok.GEQ, ">=" },
                { Tok.LEQ, "<=" },
                { Tok.PLUS, "+" },
                { Tok.NEQ, "<>" },
                { Tok.GT, ">" },
                { Tok.PLUSASSIGN, "+=" },
                { Tok.LEQ, "<=" },
                { Tok.LEQ, "<=" },
                { Tok.EQ, "=" }
            }.ToList(), lexems);
        }
示例#3
0
文件: Tests.cs 项目: pzhin/MMCS_CS311
        public void TestAssigns()
        {
            string     text        = @"+ = -= *= /= +==:=6-=-*+/";
            TextReader inputReader = new StringReader(text);
            Lexer      l           = new Lexer(inputReader);

            var lexems = TestSimpleLexer.getLexerOutput(l);

            Assert.IsTrue(lexems.Count == 14);
            CollectionAssert.AreEqual(new LexemList()
            {
                { Tok.PLUS, "+" },
                { Tok.EQ, "=" },
                { Tok.MINUSASSIGN, "-=" },
                { Tok.MULTASSIGN, "*=" },
                { Tok.DIVASSIGN, "/=" },
                { Tok.PLUSASSIGN, "+=" },
                { Tok.EQ, "=" },
                { Tok.ASSIGN, ":=" },
                { Tok.INUM, "6" },
                { Tok.MINUSASSIGN, "-=" },
                { Tok.MINUS, "-" },
                { Tok.MULT, "*" },
                { Tok.PLUS, "+" },
                { Tok.DIVISION, "/" }
            }.ToList(), lexems);
        }
示例#4
0
文件: Tests.cs 项目: pzhin/MMCS_CS311
        public void TestOpsFail()
        {
            string     text        = @"-`-$ # @";
            TextReader inputReader = new StringReader(text);
            Lexer      l           = new Lexer(inputReader);

            Assert.Throws <LexerException>(() =>
            {
                var lexems = TestSimpleLexer.getLexerOutput(l);
            });
        }
示例#5
0
文件: Tests.cs 项目: pzhin/MMCS_CS311
        public void TestCommentNotClosed()
        {
            string     text        = @" ts:=623 { cmt
                           cmt  id := 22";
            TextReader inputReader = new StringReader(text);
            Lexer      l           = new Lexer(inputReader);

            Assert.Throws <LexerException>(() =>
            {
                var lexems = TestSimpleLexer.getLexerOutput(l);
            });
        }
示例#6
0
文件: Tests.cs 项目: pzhin/MMCS_CS311
        public void TestCommentFileEnd()
        {
            string     text        = @" ts:=623 { }";
            TextReader inputReader = new StringReader(text);
            Lexer      l           = new Lexer(inputReader);

            var lexems = TestSimpleLexer.getLexerOutput(l);

            Assert.IsTrue(lexems.Count == 3);
            CollectionAssert.AreEqual(new LexemList()
            {
                { Tok.ID, "ts" },
                { Tok.ASSIGN, ":=" },
                { Tok.INUM, "623" },
            }.ToList(), lexems);
        }
示例#7
0
文件: Tests.cs 项目: pzhin/MMCS_CS311
        public void TestCommentNextLine()
        {
            string     text        = @" ts:=623 { cmt
                           cmt } id := 22";
            TextReader inputReader = new StringReader(text);
            Lexer      l           = new Lexer(inputReader);

            var lexems = TestSimpleLexer.getLexerOutput(l);

            Assert.AreEqual(6, lexems.Count);
            CollectionAssert.AreEqual(new LexemList()
            {
                { Tok.ID, "ts" },
                { Tok.ASSIGN, ":=" },
                { Tok.INUM, "623" },
                { Tok.ID, "id" },
                { Tok.ASSIGN, ":=" },
                { Tok.INUM, "22" },
            }.ToList(), lexems);
        }
示例#8
0
文件: Tests.cs 项目: pzhin/MMCS_CS311
        public void TestComparisons()
        {
            string     text        = @"><>>=<=+<> > <=";
            TextReader inputReader = new StringReader(text);
            Lexer      l           = new Lexer(inputReader);

            var lexems = TestSimpleLexer.getLexerOutput(l);

            Assert.AreEqual(lexems.Count, 8);
            CollectionAssert.AreEqual(new LexemList()
            {
                { Tok.GT, ">" },
                { Tok.NEQ, "<>" },
                { Tok.GEQ, ">=" },
                { Tok.LEQ, "<=" },
                { Tok.PLUS, "+" },
                { Tok.NEQ, "<>" },
                { Tok.GT, ">" },
                { Tok.LEQ, "<=" }
            }.ToList(), lexems);
        }
示例#9
0
文件: Tests.cs 项目: pzhin/MMCS_CS311
        public void TestKeywords()
        {
            string     text        = @"div mod - and or not notmod anddiv modor *";
            TextReader inputReader = new StringReader(text);
            Lexer      l           = new Lexer(inputReader);

            var lexems = TestSimpleLexer.getLexerOutput(l);

            Assert.IsTrue(lexems.Count == 10);
            CollectionAssert.AreEqual(new LexemList()
            {
                { Tok.DIV, "div" },
                { Tok.MOD, "mod" },
                { Tok.MINUS, "-" },
                { Tok.AND, "and" },
                { Tok.OR, "or" },
                { Tok.NOT, "not" },
                { Tok.ID, "notmod" },
                { Tok.ID, "anddiv" },
                { Tok.ID, "modor" },
                { Tok.MULT, "*" }
            }.ToList(), lexems);
        }