コード例 #1
0
ファイル: Lexer.cs プロジェクト: Dpopkova/MMCS_CS311
    public static void Test()
    {
        // Тесты для IntNum
        System.Console.WriteLine("Tests for IntNum" + "\n");
        string input = "0";

        System.Console.WriteLine(input + ":");
        Lexer L = new IntNum(input);

        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "";
        System.Console.WriteLine("Empty string:");
        L = new IntNum(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "253";
        System.Console.WriteLine(input + ":");
        L = new IntNum(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "-271273";
        System.Console.WriteLine(input + ":");
        L = new IntNum(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "124-1373";
        System.Console.WriteLine(input + ":");
        L = new IntNum(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        // Тесты для Identifier
        System.Console.WriteLine("\n" + "Tests for Identifier");
        input = "";
        System.Console.WriteLine("Empty string:");
        L = new Identifier(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "a";
        System.Console.WriteLine(input + ":");
        L = new Identifier(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "bnasbh1221bhiu";
        System.Console.WriteLine(input + ":");
        L = new Identifier(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "5";
        System.Console.WriteLine(input + ":");
        L = new Identifier(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "5asbdh28";
        System.Console.WriteLine(input + ":");
        L = new Identifier(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = ";adf22f";
        System.Console.WriteLine(input + ":");
        L = new Identifier(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        // Тесты для Int0
        System.Console.WriteLine("\n" + "Tests for Int0");
        input = "";
        System.Console.WriteLine("Empty string:");
        L = new Int0(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "-724";
        System.Console.WriteLine(input + ":");
        L = new Int0(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "213651";
        System.Console.WriteLine(input + ":");
        L = new Int0(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "abc";
        System.Console.WriteLine(input + ":");
        L = new Int0(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "-012";
        System.Console.WriteLine(input + ":");
        L = new Int0(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "0";
        System.Console.WriteLine(input + ":");
        L = new Int0(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "0931";
        System.Console.WriteLine(input + ":");
        L = new Int0(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        // Тесты для Alternation
        System.Console.WriteLine("\n" + "Tests for Alternation");
        input = "";
        System.Console.WriteLine("Empty string:");
        L = new Alternation(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "a";
        System.Console.WriteLine(input + ":");
        L = new Alternation(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "1";
        System.Console.WriteLine(input + ":");
        L = new Alternation(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "b3n4n6";
        System.Console.WriteLine(input + ":");
        L = new Alternation(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "m2hr4";
        System.Console.WriteLine(input + ":");
        L = new Alternation(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "i8s74g";
        System.Console.WriteLine(input + ":");
        L = new Alternation(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }


        // Тесты для ListOfLetters
        System.Console.WriteLine("\n" + "Tests for ListOfLetters");
        input = "";
        System.Console.WriteLine("Empty string:");
        L = new ListOfLetters(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "v;d:n:";
        System.Console.WriteLine(input + ":");
        L = new ListOfLetters(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = ":n;e;";
        System.Console.WriteLine(input + ":");
        L = new ListOfLetters(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "m";
        System.Console.WriteLine(input + ":");
        L = new ListOfLetters(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "fe:n:";
        System.Console.WriteLine(input + ":");
        L = new ListOfLetters(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "m;:w;w";
        System.Console.WriteLine(input + ":");
        L = new ListOfLetters(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        // Тесты для ListOfNumbers
        System.Console.WriteLine("\n" + "Tests for ListOfNumbers");
        input = "";
        System.Console.WriteLine("Empty string:");
        L = new ListOfNumbers(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "12     636   22 1 523";
        System.Console.WriteLine(input + ":");
        L = new ListOfNumbers(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "  2 4   9";
        System.Console.WriteLine(input + ":");
        L = new ListOfNumbers(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "1; 3";
        System.Console.WriteLine(input + ":");
        L = new ListOfNumbers(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        // Тесты для Groups
        System.Console.WriteLine("\n" + "Tests for Groups");
        input = "";
        System.Console.WriteLine("Empty string:");
        L = new Groups(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "aa12c23dd1";
        System.Console.WriteLine(input + ":");
        L = new Groups(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "aa122c23dd1";
        System.Console.WriteLine(input + ":");
        L = new Groups(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "aa 12v6";
        System.Console.WriteLine(input + ":");
        L = new Groups(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        // Тесты для DoubleLexer
        System.Console.WriteLine("\n" + "Tests for DoubleLexer");
        input = "";
        System.Console.WriteLine("Empty string:");
        L = new DoubleLexer(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "3";
        System.Console.WriteLine(input + ":");
        L = new DoubleLexer(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "5241.32";
        System.Console.WriteLine(input + ":");
        L = new DoubleLexer(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "7265.27.37";
        System.Console.WriteLine(input + ":");
        L = new DoubleLexer(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = ".34";
        System.Console.WriteLine(input + ":");
        L = new DoubleLexer(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "782.";
        System.Console.WriteLine(input + ":");
        L = new DoubleLexer(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        // Тесты для StringInQuotes
        System.Console.WriteLine("\n" + "Tests for StringInQuotes");
        input = "";
        System.Console.WriteLine("Empty string:");
        L = new StringInQuotes(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "'dbj2134;sdh.adsn'";
        System.Console.WriteLine(input + ":");
        L = new StringInQuotes(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "'h6gsf2'sdj1d'";
        System.Console.WriteLine(input + ":");
        L = new StringInQuotes(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "''";
        System.Console.WriteLine(input + ":");
        L = new StringInQuotes(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "'vqhw2";
        System.Console.WriteLine(input + ":");
        L = new StringInQuotes(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "annx'";
        System.Console.WriteLine(input + ":");
        L = new StringInQuotes(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        // Тесты для Comment
        System.Console.WriteLine("\n" + "Tests for Comment");
        input = "";
        System.Console.WriteLine("Empty string:");
        L = new Comment(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "/**/";
        System.Console.WriteLine(input + ":");
        L = new Comment(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "/*jbs.d3d431iu*/";
        System.Console.WriteLine(input + ":");
        L = new Comment(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "/*4odpus";
        System.Console.WriteLine(input + ":");
        L = new Comment(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "an;sjsof*/";
        System.Console.WriteLine(input + ":");
        L = new Comment(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "*/msdc;w";
        System.Console.WriteLine(input + ":");
        L = new Comment(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }
    }