Пример #1
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)"));
            }
        }
Пример #2
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));
            }
        }
Пример #3
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'));
            }
        }
Пример #4
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)");
            }
        }
Пример #5
0
        public void TestEndOfFile_StringSection()
        {
            using (var source = new StringSource("\"aaa"))
            {
                ISectioner sectioner = new Sectioner.Sectioner();

                Assert.Throws<EndOfFileInStringException>(() => sectioner.GetSections(source).ForEach(x => { }));
            }
        }
Пример #6
0
 public void TestEndOfFile_MultiLineCommentSection()
 {
     using (var source = new StringSource("/*aaa"))
     {
         ISectioner sectioner = new Sectioner.Sectioner();
         Assert.Throws<EndOfFileInMultilineCommentException>(() => sectioner.GetSections(source).ForEach(x => { }));
     }
 }
Пример #7
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");
                    }
                );
            }
        }