コード例 #1
0
        public void TestDigitListParse()
        {
            DigitListLexer l = new DigitListLexer("1 2");

            Assert.IsTrue(l.Parse(), "Не пропускает 1 2");
            Assert.AreEqual(l.ParseResult.Count, 2, "неправильно собран список-результат");
            Assert.Contains(1, l.ParseResult);
            Assert.Contains(2, l.ParseResult);

            l = new DigitListLexer("1");
            Assert.IsTrue(l.Parse(), "Не пропускает 1");
            Assert.AreEqual(l.ParseResult.Count, 1, "неправильно собран список-результат");
            Assert.Contains(1, l.ParseResult);

            l = new DigitListLexer("5    6");
            Assert.IsTrue(l.Parse(), "Не пропускает 5    6");
            Assert.AreEqual(l.ParseResult.Count, 2, "неправильно собран список-результат");
            Assert.Contains(5, l.ParseResult);
            Assert.Contains(6, l.ParseResult);
        }
コード例 #2
0
        public void TestDigitListFail()
        {
            DigitListLexer l = new DigitListLexer("12");

            Assert.Throws <LexerException>(() => { l.Parse(); }, "Пропускает 12");

            l = new DigitListLexer(" 1");
            Assert.Throws <LexerException>(() => { l.Parse(); }, "Пропускает пробелы в начале");

            l = new DigitListLexer("1  ");
            Assert.Throws <LexerException>(() => { l.Parse(); }, "Пропускает пробелы в конце");

            l = new DigitListLexer("1, 2");
            Assert.Throws <LexerException>(() => { l.Parse(); }, "Пропускает ,");

            l = new DigitListLexer("1;2");
            Assert.Throws <LexerException>(() => { l.Parse(); }, "Пропускает ;");

            l = new DigitListLexer("1a2");
            Assert.Throws <LexerException>(() => { l.Parse(); }, "Пропускает 1a2");
        }
コード例 #3
0
    public static void Main()
    {
        System.Console.WriteLine("Testing IntLexer:");
        List <string> test_int = new List <string> {
            "1", "123", "+123", "-123", "+a", "+", "+1233f", " "
        };

        foreach (var str in test_int)
        {
            IntLexer L = new IntLexer(str);
            System.Console.WriteLine(System.String.Format("{0} : {1}", str, L.Parse()));
        }

        System.Console.WriteLine("Testing IDLexer:");
        List <string> test_id = new List <string> {
            "a", "a1ad", "a___", "1", "", " "
        };

        foreach (var str in test_id)
        {
            IdLexer L = new IdLexer(str);
            System.Console.WriteLine(System.String.Format("{0} : {1}", str, L.Parse()));
        }

        System.Console.WriteLine("Testing NoZeroIntLexer:");
        List <string> test_nozeroint = new List <string> {
            "1", "123", "+123", "-123", "+0", "0", "-0", " "
        };

        foreach (var str in test_nozeroint)
        {
            NoZeroIntLexer L = new NoZeroIntLexer(str);
            System.Console.WriteLine(System.String.Format("{0} : {1}", str, L.Parse()));
        }


        System.Console.WriteLine("Testing LetterDigitLexer:");
        List <string> test_LetterDigitLexer = new List <string> {
            "a", "a1", "a1a", "1", "a11", "a1aa", "", " "
        };

        foreach (var str in test_LetterDigitLexer)
        {
            LetterDigitLexer L = new LetterDigitLexer(str);
            System.Console.WriteLine(System.String.Format("{0} : {1}", str, L.Parse()));
        }

        System.Console.WriteLine("Testing ListLexer:");
        List <string> test_ListLexer = new List <string> {
            "a", "a,", "a;b", "a,b;", "ab", "", ",", " "
        };

        foreach (var str in test_ListLexer)
        {
            ListLexer L = new ListLexer(str);
            System.Console.WriteLine(System.String.Format("{0} : {1} : {2}", str, L.Parse(), string.Join(",", L.chrs)));
        }


        System.Console.WriteLine("Testing DigitListLexer:");
        List <string> test_DigitListLexer = new List <string> {
            "1", "  1 2    3", "    ", "", "1 2 3 b"
        };

        foreach (var str in test_DigitListLexer)
        {
            DigitListLexer L = new DigitListLexer(str);
            System.Console.WriteLine(System.String.Format("{0} : {1} : {2}", str, L.Parse(), string.Join(",", L.ints)));
        }

        System.Console.WriteLine("Testing GroupLexer:");
        List <string> test_GroupLexer = new List <string> {
            "aa12c23dd1", "aaa12c23dd1", "aa12c232dd1", " ", ""
        };

        foreach (var str in test_GroupLexer)
        {
            GroupLexer L = new GroupLexer(str);
            System.Console.WriteLine(System.String.Format("{0} : {1} : {2}", str, L.Parse(), L.result));
        }


        System.Console.WriteLine("Testing RealLexer:");
        List <string> test_RealLexer = new List <string> {
            "+12", "12", "+0.1", "123.b", " ", ""
        };

        foreach (var str in test_RealLexer)
        {
            RealLexer L = new RealLexer(str);
            System.Console.WriteLine(System.String.Format("{0} : {1}", str, L.Parse()));
        }

        System.Console.WriteLine("Testing StringLexer:");
        List <string> test_StringLexer = new List <string> {
            "'asd'", "''", "a", "'aaa'a", "'aaa", " ", ""
        };

        foreach (var str in test_StringLexer)
        {
            StringLexer L = new StringLexer(str);
            System.Console.WriteLine(System.String.Format("{0} : {1}", str, L.Parse()));
        }


        System.Console.WriteLine("Testing CommentLexer:");
        List <string> test_CommentLexer = new List <string> {
            "/*ddd*/", "/**/", "/*fff", " ", ""
        };

        foreach (var str in test_CommentLexer)
        {
            CommentLexer L = new CommentLexer(str);
            System.Console.WriteLine(System.String.Format("{0} : {1}", str, L.Parse()));
        }
    }