public void GetSections_OnlyBodylessSections()
        {
            string data =
                @"[S1]
[S1.S1]
[S1.S2]
[S1.S2.S1]
[S1.S2.S2]
[S2]
[S2.S1]
[S3]";

            var sections = SectionsFinder.GetSections(data.Split(Global.NL)).ToArray();
            var actualSections = sections.Select(s => s.Section);
            var expectedSections = new[] { null, "S1", "S1.S1", "S1.S2", "S1.S2.S1", "S1.S2.S2", "S2", "S2.S1", "S3" }.Select(sn => new Section(sn));

            var dd = new SectionsFinder.SectionInfo[]
            {
                new SectionsFinder.SectionInfo(null, new string[0], new string[0], new IntInterval(-1, -1), new IntInterval(-1, -1)),
                new SectionsFinder.SectionInfo("S1", new[] { "[S1]" }, new string[0], new IntInterval(0, 0), new IntInterval(-1, -1)),
                new SectionsFinder.SectionInfo("S1.S1", new[] { "[S1.S1]" }, new string[0], new IntInterval(1, 1), new IntInterval(-1, -1)),
                new SectionsFinder.SectionInfo("S1.S2", new[] { "[S1.S2]" }, new string[0], new IntInterval(2, 2), new IntInterval(-1, -1)),
                new SectionsFinder.SectionInfo("S1.S2.S1", new[] { "[S1.S2.S1]" }, new string[0], new IntInterval(3, 3), new IntInterval(-1, -1)),
                new SectionsFinder.SectionInfo("S1.S2.S2", new[] { "[S1.S2.S2]" }, new string[0], new IntInterval(4, 4), new IntInterval(-1, -1)),
                new SectionsFinder.SectionInfo("S2", new[] { "[S2]" }, new string[0], new IntInterval(5, 5), new IntInterval(-1, -1)),
                new SectionsFinder.SectionInfo("S2.S1", new[] { "[S2.S1]" }, new string[0], new IntInterval(6, 6), new IntInterval(-1, -1)),
                new SectionsFinder.SectionInfo("S3", new[] { "[S3]" }, new string[0], new IntInterval(7, 7), new IntInterval(-1, -1)),
            };

            Assert.AreEqual(expectedSections, actualSections);
            Assert.AreEqual(dd, sections);
        }
        public void GetSections()
        {
            string data =
                @"Key=1
[S1]
Key=2
[S1.S1]
Key=3
[S1.S2]
Key=4
[S1.S2.S1]
Key=5
[S2]
Key=6
[S2.S1]
Key=7
[S3]
Key=8";

            var actualSections = SectionsFinder.GetSections(data.Split(Global.NL)).ToArray();

            var expectedSections = new SectionsFinder.SectionInfo[]
            {
                new SectionsFinder.SectionInfo(null, new[] { "Key=1" }, new[] { "Key=1" }, new IntInterval(0, 0), new IntInterval(0, 0)),
                new SectionsFinder.SectionInfo("S1", new[] { "[S1]", "Key=2" }, new[] { "Key=2" }, new IntInterval(1, 2), new IntInterval(2, 2)),
                new SectionsFinder.SectionInfo("S1.S1", new[] { "[S1.S1]", "Key=3" }, new[] { "Key=3" }, new IntInterval(3, 4), new IntInterval(4, 4)),
                new SectionsFinder.SectionInfo("S1.S2", new[] { "[S1.S2]", "Key=4" }, new[] { "Key=4" }, new IntInterval(5, 6), new IntInterval(6, 6)),
                new SectionsFinder.SectionInfo("S1.S2.S1", new[] { "[S1.S2.S1]", "Key=5" }, new[] { "Key=5" }, new IntInterval(7, 8), new IntInterval(8, 8)),
                new SectionsFinder.SectionInfo("S2", new[] { "[S2]", "Key=6" }, new[] { "Key=6" }, new IntInterval(9, 10), new IntInterval(10, 10)),
                new SectionsFinder.SectionInfo("S2.S1", new[] { "[S2.S1]", "Key=7" }, new[] { "Key=7" }, new IntInterval(11, 12), new IntInterval(12, 12)),
                new SectionsFinder.SectionInfo("S3", new[] { "[S3]", "Key=8" }, new[] { "Key=8" }, new IntInterval(13, 14), new IntInterval(14, 14)),
            };

            Assert.AreEqual(expectedSections, actualSections);
        }
        public void GetSections_EmptyAndNotEmptySections()
        {
            string data =
                @"[S1]
[S1.S1]
Key1=1
[S1.S2]
[S1.S2.S1]
[S1.S2.S2]
[S2]
Key2=2
[S2.S1]
[S3]
Key3=3";

            var sections = SectionsFinder.GetSections(data.Split(Global.NL)).ToArray();
            var actualSections = sections.Select(s => s.Section);
            var expectedSections = new[] { null, "S1", "S1.S1", "S1.S2", "S1.S2.S1", "S1.S2.S2", "S2", "S2.S1", "S3" }.Select(sn => new Section(sn));

            var dd = new SectionsFinder.SectionInfo[]
            {
                new SectionsFinder.SectionInfo(null, new string[0], new string[0], new IntInterval(-1, -1), new IntInterval(-1, -1)),
                new SectionsFinder.SectionInfo("S1", new[] { "[S1]" }, new string[0], new IntInterval(0, 0), new IntInterval(-1, -1)),
                new SectionsFinder.SectionInfo("S1.S1", new[] { "[S1.S1]", "Key1=1" }, new [] { "Key1=1" }, new IntInterval(1, 2), new IntInterval(2, 2)),
                new SectionsFinder.SectionInfo("S1.S2", new[] { "[S1.S2]" }, new string[0], new IntInterval(3, 3), new IntInterval(-1, -1)),
                new SectionsFinder.SectionInfo("S1.S2.S1", new[] { "[S1.S2.S1]" }, new string[0], new IntInterval(4, 4), new IntInterval(-1, -1)),
                new SectionsFinder.SectionInfo("S1.S2.S2", new[] { "[S1.S2.S2]" }, new string[0], new IntInterval(5, 5), new IntInterval(-1, -1)),
                new SectionsFinder.SectionInfo("S2", new[] { "[S2]", "Key2=2" }, new [] { "Key2=2" }, new IntInterval(6, 7), new IntInterval(7, 7)),
                new SectionsFinder.SectionInfo("S2.S1", new[] { "[S2.S1]" }, new string[0], new IntInterval(8, 8), new IntInterval(-1, -1)),
                new SectionsFinder.SectionInfo("S3", new[] { "[S3]", "Key3=3" }, new [] { "Key3=3" }, new IntInterval(9, 10), new IntInterval(10, 10)),
            };

            Assert.AreEqual(expectedSections, actualSections);
            Assert.AreEqual(dd, sections);
        }
        public void GetSections_OnlyBodylessSectionsWithWrongHierarchy2()
        {
            string data =
                @"[S1.WRONG]
[S1]
[S1.S2]
[S1.S2]
[S1.S2.S2.WRONG]
[S1.S2.S2]
[S1.S3]
[S2]
[S3]";

            var actualSections   = SectionsFinder.GetSections(data.Split(Global.NL)).ToArray();
            var expectedSections = new SectionsFinder.SectionInfo[]
            {
                new SectionsFinder.SectionInfo(null, new string[0], new string[0], new IntInterval(-1, -1), new IntInterval(-1, -1)),
                new SectionsFinder.SectionInfo("S1", new[] { "[S1]" }, new string[0], new IntInterval(1, 1), new IntInterval(-1, -1)),
                new SectionsFinder.SectionInfo("S1.S2", new[] { "[S1.S2]" }, new string[0], new IntInterval(2, 2), new IntInterval(-1, -1)),
                new SectionsFinder.SectionInfo("S1.S2.S2", new[] { "[S1.S2.S2]" }, new string[0], new IntInterval(5, 5), new IntInterval(-1, -1)),
                new SectionsFinder.SectionInfo("S1.S3", new[] { "[S1.S3]" }, new string[0], new IntInterval(6, 6), new IntInterval(-1, -1)),
                new SectionsFinder.SectionInfo("S2", new[] { "[S2]" }, new string[0], new IntInterval(7), new IntInterval(-1, -1)),
                new SectionsFinder.SectionInfo("S3", new[] { "[S3]" }, new string[0], new IntInterval(8), new IntInterval(-1, -1)),
            };

            Assert.AreEqual(expectedSections, actualSections);
        }
        public void GetSections_OnlyRootSection()
        {
            string data =
                @"Key1=1
Key2=2";

            var actualSections = SectionsFinder.GetSections(data.Split(Global.NL)).ToArray();

            var expectedSections = new SectionsFinder.SectionInfo[]
            {
                new SectionsFinder.SectionInfo(null, new[] { "Key1=1", "Key2=2" }, new[] { "Key1=1", "Key2=2" }, new IntInterval(0, 1), new IntInterval(0, 1)),
            };

            Assert.AreEqual(expectedSections, actualSections);
        }
        public void BuildTree_OnlyGoodSections()
        {
            string data =
                @"
[S1]
[S1.S1]
[S1.S2]
[S1.S2.S1]
[S1.S2.S2]
[S2]
[S2.S1]
[S3]";

            var S1S2S1 = new SectionsTreeBuilder.RootSection(
                new Section("S1.S2.S1"),
                new SectionsTreeBuilder.RootSection[0],
                new string[] { "[S1.S2.S1]" }
                );
            var S1S2S2 = new SectionsTreeBuilder.RootSection(
                new Section("S1.S2.S2"),
                new SectionsTreeBuilder.RootSection[0],
                new string[] { "[S1.S2.S2]" }
                );
            var S1S1 = new SectionsTreeBuilder.RootSection(
                new Section("S1.S1"),
                new SectionsTreeBuilder.RootSection[0],
                new string[] { "[S1.S1]" }
                );
            var S1S2 = new SectionsTreeBuilder.RootSection(
                new Section("S1.S2"),
                new[] { S1S2S1, S1S2S2 },
                new Enumerable <string> {
                "[S1.S2]", S1S2S1.Lines, S1S2S2.Lines
            }
                );
            var S2S1 = new SectionsTreeBuilder.RootSection(
                new Section("S2.S1"),
                new SectionsTreeBuilder.RootSection[0],
                new string[] { "[S2.S1]" }
                );
            var S1 = new SectionsTreeBuilder.RootSection(
                new Section("S1"),
                new[] { S1S1, S1S2 },
                new Enumerable <string> {
                "[S1]", S1S1.Lines, S1S2.Lines
            }
                );
            var S2 = new SectionsTreeBuilder.RootSection(
                new Section("S2"),
                new[] { S2S1 },
                new Enumerable <string> {
                "[S2]", S2S1.Lines
            }
                );
            var S3 = new SectionsTreeBuilder.RootSection(
                new Section("S3"),
                new SectionsTreeBuilder.RootSection[0],
                new string[] { "[S3]" }
                );
            var ROOT = new SectionsTreeBuilder.RootSection(
                new Section(null),
                new[] { S1, S2, S3 },
                new Enumerable <string> {
                S1.Lines, S2.Lines, S3.Lines
            }
                );
            var expectedAllChildren = new[]
            {
                ROOT,
                S1,
                S1S1,
                S1S2,
                S1S2S1,
                S1S2S2,
                S2,
                S2S1,
                S3
            };

            var tree = SectionsTreeBuilder.BuildTree(SectionsFinder.GetSections(data.Split(Global.NL)).ToArray());

            Assert.AreEqual(expectedAllChildren, tree.AllChildren);
        }