Beispiel #1
0
        public void WriteLeftIndentionTest()
        {
            IniOptions options = new IniOptions()
            {
                Encoding = Encoding.UTF8
            };
            IniFile file = new IniFile(options);

            file.Sections.Add(
                new IniSection(file, "Section",
                               new IniKey(file, "Key")
            {
                LeftIndentation = 2,
                TrailingComment = { Text = string.Empty, LeftIndentation = 4 },
                LeadingComment  = { Text = string.Empty, LeftIndentation = 2 }
            })
            {
                LeftIndentation = 2,
                TrailingComment = { Text = string.Empty, LeftIndentation = 4 },
                LeadingComment  = { Text = string.Empty, LeftIndentation = 2 }
            });

            string[] lines = IniUtilities.SaveIniFileContent(file, options);
            Assert.AreEqual("    ;", lines[0]);
            Assert.AreEqual("  [Section]  ;", lines[1]);
            Assert.AreEqual("    ;", lines[2]);
            Assert.AreEqual("  Key=  ;", lines[3]);
        }
Beispiel #2
0
        public void WriteEmptyLinesTest()
        {
            IniOptions options = new IniOptions()
            {
                Encoding = Encoding.UTF8
            };
            IniFile file = new IniFile(options);

            file.Sections.Add(
                new IniSection(file, "Section",
                               new IniKey(file, "Key")
            {
                TrailingComment = { Text = string.Empty, EmptyLinesBefore = 2 },
                LeadingComment  = { Text = string.Empty, EmptyLinesBefore = 1 }
            })
            {
                TrailingComment = { Text = string.Empty, EmptyLinesBefore = 2 },
                LeadingComment  = { Text = string.Empty, EmptyLinesBefore = 1 }
            });

            string[] lines = IniUtilities.SaveIniFileContent(file, options);
            Assert.IsEmpty(lines[0]);
            Assert.IsEmpty(lines[1]);
            Assert.AreEqual(";", lines[2]);
            Assert.IsEmpty(lines[3]);
            Assert.AreEqual("[Section];", lines[4]);
            Assert.IsEmpty(lines[5]);
            Assert.IsEmpty(lines[6]);
            Assert.AreEqual(";", lines[7]);
            Assert.IsEmpty(lines[8]);
            Assert.AreEqual("Key=;", lines[9]);
        }
Beispiel #3
0
        public void Bug1()
        {
            string iniFileContent = "[Segment [A]]" + Environment.NewLine +
                                    "[Segment [A]];[Comment];" + Environment.NewLine +

                                    "[Segment [A][1]]" + Environment.NewLine +
                                    "[Segment [A][1]]  ;[Comment][1];" + Environment.NewLine +

                                    "[Segment;A]" + Environment.NewLine +
                                    "[Segment[A;B]]" + Environment.NewLine +
                                    "[Segment[A;B]];" + Environment.NewLine +
                                    "[Segment[A;B]]    ;[Comment];" + Environment.NewLine +

                                    "[Segment[A;B]]AB;Invalid comment" + Environment.NewLine +
                                    "[Segment[A;B]][[;Invalid comment" + Environment.NewLine +
                                    "[Segment[A;B;]";

            IniOptions options = new IniOptions();
            IniFile    file    = IniUtilities.LoadIniFileContent(iniFileContent, options);

            Assert.AreEqual("Segment [A]", file.Sections[0].Name);
            Assert.AreEqual("Segment [A]", file.Sections[1].Name);
            Assert.AreEqual("[Comment];", file.Sections[1].LeadingComment.Text);

            Assert.AreEqual("Segment [A][1]", file.Sections[2].Name);
            Assert.AreEqual("Segment [A][1]", file.Sections[3].Name);
            Assert.AreEqual("[Comment][1];", file.Sections[3].LeadingComment.Text);
            Assert.AreEqual(2, file.Sections[3].LeadingComment.LeftIndentation);

            Assert.AreEqual("Segment;A", file.Sections[4].Name);
            Assert.AreEqual(null, file.Sections[4].LeadingComment.Text);
            Assert.AreEqual("Segment[A;B]", file.Sections[5].Name);
            Assert.AreEqual(null, file.Sections[5].LeadingComment.Text);
            Assert.AreEqual("Segment[A;B]", file.Sections[6].Name);
            Assert.AreEqual(string.Empty, file.Sections[6].LeadingComment.Text);
            Assert.AreEqual("Segment[A;B]", file.Sections[7].Name);
            Assert.AreEqual("[Comment];", file.Sections[7].LeadingComment.Text);
            Assert.AreEqual(4, file.Sections[7].LeadingComment.LeftIndentation);

            Assert.AreEqual("Segment[A;B]", file.Sections[8].Name);
            Assert.AreEqual(null, file.Sections[8].LeadingComment.Text);
            Assert.AreEqual("Segment[A;B]", file.Sections[9].Name);
            Assert.AreEqual(null, file.Sections[9].LeadingComment.Text);
            Assert.AreEqual("Segment[A;B;", file.Sections[10].Name);

            string[] lines = IniUtilities.SaveIniFileContent(file, options);

            Assert.AreEqual("[Segment [A]]", lines[0]);
            Assert.AreEqual("[Segment [A]];[Comment];", lines[1]);
            Assert.AreEqual("[Segment [A][1]]", lines[2]);
            Assert.AreEqual("[Segment [A][1]]  ;[Comment][1];", lines[3]);
            Assert.AreEqual("[Segment;A]", lines[4]);
            Assert.AreEqual("[Segment[A;B]]", lines[5]);
            Assert.AreEqual("[Segment[A;B]];", lines[6]);
            Assert.AreEqual("[Segment[A;B]]    ;[Comment];", lines[7]);
            Assert.AreEqual("[Segment[A;B]]", lines[8]);
            Assert.AreEqual("[Segment[A;B]]", lines[9]);
            Assert.AreEqual("[Segment[A;B;]", lines[10]);
        }
Beispiel #4
0
        public void WriteGlobalSectionTest()
        {
            IniOptions options = new IniOptions();
            IniFile    file    = new IniFile(options);

            file.Sections.Add(
                new IniSection(file, IniSection.GlobalSectionName,
                               new IniKey(file, "Key1", "Value1"),
                               new IniKey(file, "Key2", "Value2")));

            string[] lines = IniUtilities.SaveIniFileContent(file, options);
            Assert.AreEqual("Key1=Value1", lines[0]);
            Assert.AreEqual("Key2=Value2", lines[1]);
        }
Beispiel #5
0
        public void WriteUTF8EncodingTest()
        {
            IniOptions options = new IniOptions()
            {
                Encoding = Encoding.UTF8
            };
            IniFile file = new IniFile(options);

            file.Sections.Add(new IniSection(file, "Καλημέρα κόσμε"));
            file.Sections.Add(new IniSection(file, "こんにちは 世界"));

            string[] lines = IniUtilities.SaveIniFileContent(file, options);
            Assert.AreEqual("[Καλημέρα κόσμε]", lines[0]);
            Assert.AreEqual("[こんにちは 世界]", lines[1]);
        }
Beispiel #6
0
        public void WriteCustomTest()
        {
            IniOptions options = new IniOptions()
            {
                KeyDelimiter            = IniKeyDelimiter.Colon,
                KeySpaceAroundDelimiter = true,
                SectionWrapper          = IniSectionWrapper.Parentheses
            };
            IniFile file = new IniFile(options);

            file.Sections.Add(
                new IniSection(file, "Section",
                               new IniKey(file, "Key", "Value")));

            string[] lines = IniUtilities.SaveIniFileContent(file, options);
            Assert.AreEqual("(Section)", lines[0]);
            Assert.AreEqual("Key : Value", lines[1]);
        }
Beispiel #7
0
        public void WriteDefaultTest()
        {
            IniOptions options = new IniOptions();
            IniFile    file    = new IniFile(options);

            file.Sections.Add(
                new IniSection(file, "Section",
                               new IniKey(file, "Key", "Value")
            {
                TrailingComment = { Text = "Trailing comment" },
                LeadingComment  = { Text = "Leading comment" }
            })
            {
                TrailingComment = { Text = "Trailing comment" },
                LeadingComment  = { Text = "Leading comment" }
            });

            string[] lines = IniUtilities.SaveIniFileContent(file, options);
            Assert.AreEqual(";Trailing comment", lines[0]);
            Assert.AreEqual("[Section];Leading comment", lines[1]);
            Assert.AreEqual(";Trailing comment", lines[2]);
            Assert.AreEqual("Key=Value;Leading comment", lines[3]);
        }