示例#1
0
 public void TestSectionPositions_2()
 {
     using (var source = _sourceManager.OpenFile("SectionerTests\\TestSources\\white_spaces_test_2.txt"))
     {
         ISectioner sectioner = new Sectioner.Sectioner();
         var sections = sectioner.GetSections(source);
         Assert.Collection(sections,
             x => Assert.Equal(x.Location.GetLocationString(), "white_spaces_test_2.txt: [(1, 3)-(1, 5)]"),
             x => Assert.Equal(x.Location.GetLocationString(), "white_spaces_test_2.txt: [(1, 6)-(1, 7)]"),
             x => Assert.Equal(x.Location.GetLocationString(), "white_spaces_test_2.txt: [(2, 5)-(2, 6)]"),
             x => Assert.Equal(x.Location.GetLocationString(), "white_spaces_test_2.txt: [(3, 1)-(3, 2)]"),
             x => Assert.Equal(x.Location.GetLocationString(), "white_spaces_test_2.txt: [(5, 1)-(5, 2)]"),
             x => Assert.Equal(x.Location.GetLocationString(), "white_spaces_test_2.txt: [(7, 2)-(7, 3)]"));
     }
 }
示例#2
0
        public void TestSectionText_SingleLineComments()
        {
            using (var source = _sourceManager.OpenFile("SectionerTests\\TestSources\\single_line_comment_test.txt"))
            {
                ISectioner sectioner = new Sectioner.Sectioner();
                var sections = sectioner.GetSections(source);

                Assert.Collection(sections,
                    x => Assert.Equal(x.Text, "ada"),
                    x => Assert.Equal(x.Text, "//ddd"),
                    x => Assert.Equal(x.Text, "//das"),
                    x => Assert.Equal(x.Text, "// dsa"),
                    x => Assert.Equal(x.Text, "dada"),
                    x => Assert.Equal(x.Text, "// dsa //"),
                    x => Assert.Equal(x.Text, "//  ddd"),
                    x => Assert.Equal(x.Text, "/"),
                    x => Assert.Equal(x.Text, "d/"),
                    x => Assert.Equal(x.Text, "/"),
                    x => Assert.Equal(x.Text, "/"),
                    x => Assert.Equal(x.Text, "asd"),
                    x => Assert.Equal(x.Text, "//ggg")
                    );
            }
        }
示例#3
0
        public void TestSectionPositions_SingleLineComments()
        {
            using (var source = _sourceManager.OpenFile("SectionerTests\\TestSources\\single_line_comment_test.txt"))
            {
                ISectioner sectioner = new Sectioner.Sectioner();
                var sections = sectioner.GetSections(source);

                Assert.Collection(sections,
                    x => Assert.Equal(x.Location.GetLocationString(), "single_line_comment_test.txt: [(1, 1)-(1, 4)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "single_line_comment_test.txt: [(1, 4)-(1, 9)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "single_line_comment_test.txt: [(2, 1)-(2, 6)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "single_line_comment_test.txt: [(3, 1)-(3, 7)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "single_line_comment_test.txt: [(4, 2)-(4, 6)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "single_line_comment_test.txt: [(4, 7)-(4, 16)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "single_line_comment_test.txt: [(6, 2)-(6, 9)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "single_line_comment_test.txt: [(7, 1)-(7, 2)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "single_line_comment_test.txt: [(7, 3)-(7, 5)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "single_line_comment_test.txt: [(8, 1)-(8, 2)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "single_line_comment_test.txt: [(8, 3)-(8, 4)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "single_line_comment_test.txt: [(9, 1)-(9, 4)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "single_line_comment_test.txt: [(9, 4)-(9, 9)]")
                    );
            }
        }
示例#4
0
 void TestFirstSimpleCase()
 {
     using (var source = _sourceManager.OpenFile("LexerTests\\TestSources\\first_simple_test.txt"))
     {
         ISectioner sectioner = new Sectioner.Sectioner();
         var sections = sectioner.GetSections(source);
         ILexer lexer = new Lexer.Lexer();
         lexer.AddRecognizer(new SingleCharTokenRecognizer('+', TokenEnum.Code_Plus));
         lexer.AddRecognizer(new IdTokenRecognizer());
         var tokens = lexer.GetTokens(sections);
         Assert.Collection(tokens,
             x => Assert.Equal(x.Code, TokenEnum.Code_Identifier),
             x => Assert.Equal(x.Code, TokenEnum.Code_Plus),
             x => Assert.Equal(x.Code, TokenEnum.Code_Identifier),
             x => Assert.Equal(x.Code, TokenEnum.Code_Plus),
             x => Assert.Equal(x.Code, TokenEnum.Code_Identifier));
         Assert.Collection(tokens,
             x => Assert.Equal(x.Text, "a"),
             x => Assert.Equal(x.Text, "+"),
             x => Assert.Equal(x.Text, "b"),
             x => Assert.Equal(x.Text, "+"),
             x => Assert.Equal(x.Text, "c"));
         Assert.Collection(tokens,
             x => Assert.Equal(x.Length, 1),
             x => Assert.Equal(x.Length, 1),
             x => Assert.Equal(x.Length, 1),
             x => Assert.Equal(x.Length, 1),
             x => Assert.Equal(x.Length, 1));
         Assert.Collection(tokens,
             x => Assert.Equal(x.Location.GetLocationString(), "first_simple_test.txt: (1, 1)"),
             x => Assert.Equal(x.Location.GetLocationString(), "first_simple_test.txt: (1, 2)"),
             x => Assert.Equal(x.Location.GetLocationString(), "first_simple_test.txt: (1, 3)"),
             x => Assert.Equal(x.Location.GetLocationString(), "first_simple_test.txt: (1, 4)"),
             x => Assert.Equal(x.Location.GetLocationString(), "first_simple_test.txt: (1, 5)"));
     }
 }
示例#5
0
        public void TestGetSectionsTwice_FileSource()
        {
            using (var source = new FileSource("SectionerTests\\TestSources\\white_spaces_test.txt"))
            {
                ISectioner sectioner = new Sectioner.Sectioner();
                Assert.Collection(sectioner.GetSections(source),
                    x => Assert.IsType<StandardSection>(x),
                    x => Assert.IsType<StandardSection>(x),
                    x => Assert.IsType<StandardSection>(x),
                    x => Assert.IsType<StandardSection>(x),
                    x => Assert.IsType<StandardSection>(x),
                    x => Assert.IsType<StandardSection>(x),
                    x => Assert.IsType<StandardSection>(x));

                Assert.Collection(sectioner.GetSections(source),
                    x => Assert.IsType<StandardSection>(x),
                    x => Assert.IsType<StandardSection>(x),
                    x => Assert.IsType<StandardSection>(x),
                    x => Assert.IsType<StandardSection>(x),
                    x => Assert.IsType<StandardSection>(x),
                    x => Assert.IsType<StandardSection>(x),
                    x => Assert.IsType<StandardSection>(x));
            }
        }
示例#6
0
        public void TestGetSectionsTwice_StringSource()
        {
            using (var source = new StringSource("a a a a"))
            {
                ISectioner sectioner = new Sectioner.Sectioner();
                Assert.Collection(sectioner.GetSections(source),
                    x => Assert.IsType<StandardSection>(x),
                    x => Assert.IsType<StandardSection>(x),
                    x => Assert.IsType<StandardSection>(x),
                    x => Assert.IsType<StandardSection>(x));

                Assert.Collection(sectioner.GetSections(source),
                    x => Assert.IsType<StandardSection>(x),
                    x => Assert.IsType<StandardSection>(x),
                    x => Assert.IsType<StandardSection>(x),
                    x => Assert.IsType<StandardSection>(x));
            }
        }
示例#7
0
        public void TestCharPositions()
        {
            using (var source = new StringSource("abc abc \r\n abd"))
            {
                ISectioner sectioner = new Sectioner.Sectioner();
                var sections = sectioner.GetSections(source);
                var list = new List<string>();

                foreach (var s in sections)
                {
                    list.AddRange(s.Text.Select((x, i) => s.CreateLocation(i).GetLocationString()));
                }
                Assert.Collection(list,
                        x => Assert.Equal(x, "<string_source>: (1, 1)"),
                        x => Assert.Equal(x, "<string_source>: (1, 2)"),
                        x => Assert.Equal(x, "<string_source>: (1, 3)"),
                        x => Assert.Equal(x, "<string_source>: (1, 5)"),
                        x => Assert.Equal(x, "<string_source>: (1, 6)"),
                        x => Assert.Equal(x, "<string_source>: (1, 7)"),
                        x => Assert.Equal(x, "<string_source>: (2, 2)"),
                        x => Assert.Equal(x, "<string_source>: (2, 3)"),
                        x => Assert.Equal(x, "<string_source>: (2, 4)"));
            }
        }
示例#8
0
        public void TestCharInfo_Char()
        {
            using (var source = new StringSource("abc abc \r\n abd"))
            {
                ISectioner sectioner = new Sectioner.Sectioner();
                var sections = sectioner.GetSections(source);

                Assert.Collection(sections.SelectMany(x => x.Text),
                    x => Assert.Equal(x, 'a'),
                    x => Assert.Equal(x, 'b'),
                    x => Assert.Equal(x, 'c'),
                    x => Assert.Equal(x, 'a'),
                    x => Assert.Equal(x, 'b'),
                    x => Assert.Equal(x, 'c'),
                    x => Assert.Equal(x, 'a'),
                    x => Assert.Equal(x, 'b'),
                    x => Assert.Equal(x, 'd'));
            }
        }
示例#9
0
        public void TestSectionPositions_MultiLineComments()
        {
            using (var source = _sourceManager.OpenFile("SectionerTests\\TestSources\\multi_line_comment_test.txt"))
            {
                ISectioner sectioner = new Sectioner.Sectioner();
                var sections = sectioner.GetSections(source);

                Assert.Collection(sections,
                    x => Assert.Equal(x.Location.GetLocationString(), "multi_line_comment_test.txt: [(1, 1)-(1, 10)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "multi_line_comment_test.txt: [(2, 1)-(4, 8)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "multi_line_comment_test.txt: [(5, 2)-(7, 8)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "multi_line_comment_test.txt: [(8, 1)-(8, 2)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "multi_line_comment_test.txt: [(8, 2)-(10, 8)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "multi_line_comment_test.txt: [(11, 1)-(13, 8)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "multi_line_comment_test.txt: [(13, 8)-(13, 11)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "multi_line_comment_test.txt: [(14, 1)-(16, 8)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "multi_line_comment_test.txt: [(16, 8)-(16, 13)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "multi_line_comment_test.txt: [(17, 1)-(17, 10)]")
                    );
            }
        }
示例#10
0
        public void TestSectionTypes_Strings()
        {
            using (var source = _sourceManager.OpenFile("SectionerTests\\TestSources\\string_tests.txt"))
            {
                ISectioner sectioner = new Sectioner.Sectioner();
                var sections = sectioner.GetSections(source);

                Assert.Collection(sections,
                    x => Assert.IsType<StringSection>(x),
                    x => Assert.IsType<StringSection>(x),
                    x => Assert.IsType<StringSection>(x),
                    x => Assert.IsType<StringSection>(x),
                    x => Assert.IsType<StringSection>(x),
                    x => Assert.IsType<StringSection>(x),
                    x => Assert.IsType<StringSection>(x),
                    x => Assert.IsType<StringSection>(x),
                    x => Assert.IsType<StringSection>(x),
                    x => Assert.IsType<StandardSection>(x),
                    x => Assert.IsType<StringSection>(x),
                    x => Assert.IsType<SingleLineCommentSection>(x),
                    x => Assert.IsType<StringSection>(x),
                    x => Assert.IsType<MultiLineCommentSection>(x)
                    );
            }
        }
示例#11
0
        public void TestSectionPositions_Strings()
        {
            using (var source = _sourceManager.OpenFile("SectionerTests\\TestSources\\string_tests.txt"))
            {
                ISectioner sectioner = new Sectioner.Sectioner();
                var sections = sectioner.GetSections(source);

                Assert.Collection(sections,
                    x => Assert.Equal(x.Location.GetLocationString(), "string_tests.txt: [(1, 1)-(1, 3)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "string_tests.txt: [(2, 1)-(2, 6)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "string_tests.txt: [(3, 1)-(3, 10)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "string_tests.txt: [(4, 1)-(4, 10)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "string_tests.txt: [(5, 1)-(5, 18)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "string_tests.txt: [(6, 1)-(6, 9)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "string_tests.txt: [(7, 1)-(7, 6)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "string_tests.txt: [(7, 6)-(7, 11)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "string_tests.txt: [(8, 1)-(8, 6)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "string_tests.txt: [(8, 6)-(8, 9)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "string_tests.txt: [(9, 1)-(9, 6)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "string_tests.txt: [(9, 6)-(9, 16)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "string_tests.txt: [(10, 1)-(10, 6)]"),
                    x => Assert.Equal(x.Location.GetLocationString(), "string_tests.txt: [(10, 6)-(11, 10)]")
                    );
            }
        }
示例#12
0
        public void TestSectionText_Strings()
        {
            using (var source = _sourceManager.OpenFile("SectionerTests\\TestSources\\string_tests.txt"))
            {
                ISectioner sectioner = new Sectioner.Sectioner();
                var sections = sectioner.GetSections(source);

                Assert.Collection(sections,
                    x => Assert.Equal(x.Text, "\"\""),
                    x => Assert.Equal(x.Text, "\"abc\""),
                    x => Assert.Equal(x.Text, "\"abc abc\""),
                    x => Assert.Equal(x.Text, "\"abc \\\\ \""),
                    x => Assert.Equal(x.Text, "\"abc /* daads */\""),
                    x => Assert.Equal(x.Text, "\"abc \\\"\""),
                    x => Assert.Equal(x.Text, "\"abc\""),
                    x => Assert.Equal(x.Text, "\"abc\""),
                    x => Assert.Equal(x.Text, "\"abc\""),
                    x => Assert.Equal(x.Text, "abc"),
                    x => Assert.Equal(x.Text, "\"abc\""),
                    x => Assert.Equal(x.Text, "// comment"),
                    x => Assert.Equal(x.Text, "\"abc\""),
                    x => Assert.Equal(x.Text, "/*\r\ncomment*/")
                    );
            }
        }
示例#13
0
        public void TestEndOfFile_StringSection()
        {
            using (var source = new StringSource("\"aaa"))
            {
                ISectioner sectioner = new Sectioner.Sectioner();

                Assert.Throws<EndOfFileInStringException>(() => sectioner.GetSections(source).ForEach(x => { }));
            }
        }
示例#14
0
 public void TestEndOfFile_MultiLineCommentSection()
 {
     using (var source = new StringSource("/*aaa"))
     {
         ISectioner sectioner = new Sectioner.Sectioner();
         Assert.Throws<EndOfFileInMultilineCommentException>(() => sectioner.GetSections(source).ForEach(x => { }));
     }
 }
示例#15
0
        public void TestEndOfFile_SingleLineCommentSection()
        {
            using (var source = new StringSource("//aaa"))
            {
                ISectioner sectioner = new Sectioner.Sectioner();
                var sections = sectioner.GetSections(source);

                Assert.Collection(sections,
                    x =>
                    {
                        Assert.IsType<SingleLineCommentSection>(x);
                        Assert.Equal(x.Location.GetLocationString(), "<string_source>: [(1, 1)-(1, 6)]");
                        Assert.Equal(x.Text, "//aaa");
                    }
                );
            }
        }
示例#16
0
        public void TestEndOfLine_StringCommentSection()
        {
            using (var source = new StringSource("\"aaa\r\n"))
            {
                ISectioner sectioner = new Sectioner.Sectioner();

                var e = Assert.Throws<EndOfLineInStringException>(() => sectioner.GetSections(source).ForEach(x => { }));
                Assert.Equal(e.Message, "End of line reached inside string constant at <string_source>: (1, 5)");
            }
        }
示例#17
0
        public void TestSectionText_MultiLineComments()
        {
            using (var source = _sourceManager.OpenFile("SectionerTests\\TestSources\\multi_line_comment_test.txt"))
            {
                ISectioner sectioner = new Sectioner.Sectioner();
                var sections = sectioner.GetSections(source);

                Assert.Collection(sections,
                    x => Assert.Equal(x.Text, "/* aaa */"),
                    x => Assert.Equal(x.Text, "/* bbb\r\nccc\r\nddddd*/"),
                    x => Assert.Equal(x.Text, "/* bbb\r\nccc\r\nddddd*/"),
                    x => Assert.Equal(x.Text, "a"),
                    x => Assert.Equal(x.Text, "/* bbb\r\nccc\r\nddddd*/"),
                    x => Assert.Equal(x.Text, "/* bbb\r\nccc\r\nddddd*/"),
                    x => Assert.Equal(x.Text, "ala"),
                    x => Assert.Equal(x.Text, "/* bbb\r\nccc\r\nddddd*/"),
                    x => Assert.Equal(x.Text, "//ala"),
                    x => Assert.Equal(x.Text, "/* rrr */")
                    );
            }
        }