Exemple #1
0
        public void ReadCustomTest()
        {
            string iniFileContent = "#Section's trailing comment." + Environment.NewLine +
                                    "{Section's name}#Section's leading comment." + Environment.NewLine +
                                    "#Key's trailing comment." + Environment.NewLine +
                                    "Key's name : Key's value#Key's leading comment.";

            IniOptions options = new IniOptions()
            {
                CommentStarter = IniCommentStarter.Hash,
                SectionWrapper = IniSectionWrapper.CurlyBrackets,
                KeyDelimiter   = IniKeyDelimiter.Colon
            };
            IniFile file = IniUtilities.LoadIniFileContent(iniFileContent, options);

            Assert.AreEqual(1, file.Sections.Count);
            Assert.AreEqual("Section's trailing comment.", file.Sections[0].TrailingComment.Text);
            Assert.AreEqual("Section's name", file.Sections[0].Name);
            Assert.AreEqual("Section's leading comment.", file.Sections[0].LeadingComment.Text);

            Assert.AreEqual(1, file.Sections[0].Keys.Count);
            Assert.AreEqual("Key's trailing comment.", file.Sections[0].Keys[0].TrailingComment.Text);
            Assert.AreEqual("Key's name", file.Sections[0].Keys[0].Name);
            Assert.AreEqual("Key's value", file.Sections[0].Keys[0].Value);
            Assert.AreEqual("Key's leading comment.", file.Sections[0].Keys[0].LeadingComment.Text);
        }
Exemple #2
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]);
        }
Exemple #3
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]);
        }
Exemple #4
0
        public void ReadSectionEdgeCasesTest()
        {
            string iniFileContent = "[" + Environment.NewLine +
                                    "]" + Environment.NewLine +
                                    "[]" + Environment.NewLine +
                                    "[;]" + Environment.NewLine +
                                    "[;;]" + Environment.NewLine +
                                    "[[]]" + Environment.NewLine +
                                    "[[]];" + Environment.NewLine +
                                    "[[;]]" + Environment.NewLine +
                                    "[[;]];";

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

            Assert.AreEqual(7, file.Sections.Count);
            Assert.AreEqual(string.Empty, file.Sections[0].Name);
            Assert.AreEqual(";", file.Sections[1].Name);
            Assert.AreEqual(";;", file.Sections[2].Name);
            Assert.AreEqual("[]", file.Sections[3].Name);
            Assert.AreEqual("[]", file.Sections[4].Name);
            Assert.AreEqual(string.Empty, file.Sections[4].LeadingComment.Text);
            Assert.AreEqual("[;]", file.Sections[5].Name);
            Assert.AreEqual("[;]", file.Sections[6].Name);
            Assert.AreEqual(string.Empty, file.Sections[6].LeadingComment.Text);
        }
Exemple #5
0
        public void ReadEmptyLinesTest()
        {
            string iniFileContent = Environment.NewLine +
                                    "  \t  " + Environment.NewLine +
                                    "[Section]" + Environment.NewLine +
                                    Environment.NewLine +
                                    Environment.NewLine +
                                    "  \t  " + Environment.NewLine +
                                    "Key = Value" + Environment.NewLine +
                                    Environment.NewLine +
                                    "  \t  " + Environment.NewLine +
                                    ";" + Environment.NewLine +
                                    "[Section]" + Environment.NewLine +
                                    Environment.NewLine +
                                    "  \t  " + Environment.NewLine +
                                    Environment.NewLine +
                                    ";" + Environment.NewLine +
                                    "Key = Value";

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

            Assert.AreEqual(2, file.Sections[0].LeadingComment.EmptyLinesBefore);
            Assert.AreEqual(3, file.Sections[0].Keys[0].LeadingComment.EmptyLinesBefore);
            Assert.AreEqual(2, file.Sections[1].TrailingComment.EmptyLinesBefore);
            Assert.AreEqual(3, file.Sections[1].Keys[0].TrailingComment.EmptyLinesBefore);
        }
Exemple #6
0
        public void BindValueWithInternalDataTest()
        {
            string iniFileContent = "[Source Section]\n" +
                                    "Source Key 1 = Source Value 1\n" +
                                    "Source Key 2 = Source Value 2\n" +
                                    "Source Key 3 = Source Value 3\n" +

                                    "[Binding Section]\n" +
                                    "Source Key 4 = Source Value 4\n" +
                                    "Test Key 1 = @{Source Section|Source Key 1}\n" +
                                    "Test Key 2-3 = @{Source Section|Source Key 2} and @{Source Section|Source Key 3}\n" +
                                    "Test Key 1-4 = @{Source Section|Source Key 1} and @{Source Key 4}\n" +
                                    "Test Key X = @{Unknown}";

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

            file.ValueBinding.Bind();

            var bindedSection = file.Sections["Binding Section"];

            Assert.AreEqual("Source Value 1", bindedSection.Keys["Test Key 1"].Value);
            Assert.AreEqual("Source Value 2 and Source Value 3", bindedSection.Keys["Test Key 2-3"].Value);
            Assert.AreEqual("Source Value 1 and Source Value 4", bindedSection.Keys["Test Key 1-4"].Value);
            Assert.AreEqual("@{Unknown}", bindedSection.Keys["Test Key X"].Value);
        }
Exemple #7
0
        public void BindValueWithExternalDataTest()
        {
            string iniFileContent = "[Binding Section]\n" +
                                    "Test Key 1 = @{First Tester}\n" +
                                    "Test Key 2-3 = @{Second Tester} and @{Third Tester}\n" +
                                    "Test Key 3-3-4 = {@{Third Tester}, @{Third Tester}, @{Fourth Tester}}\n" +
                                    "Test Key X = @{Unknown}\n" +
                                    "Test Key Nested = @{Nested @{Test}}";

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

            file.ValueBinding.Bind(
                new Dictionary <string, string>()
            {
                { "First Tester", "Source Value 1" },
                { "Second Tester", "Source Value 2" },
                { "Third Tester", "Source Value 3" },
                { "Fourth Tester", "Source Value 4" },
                { "Test", "Tester" }
            });

            var bindedSection = file.Sections["Binding Section"];

            Assert.AreEqual("Source Value 1", bindedSection.Keys["Test Key 1"].Value);
            Assert.AreEqual("Source Value 2 and Source Value 3", bindedSection.Keys["Test Key 2-3"].Value);
            Assert.AreEqual("{Source Value 3, Source Value 3, Source Value 4}", bindedSection.Keys["Test Key 3-3-4"].Value);
            Assert.AreEqual("@{Unknown}", bindedSection.Keys["Test Key X"].Value);
            Assert.AreEqual("@{Nested Tester}", bindedSection.Keys["Test Key Nested"].Value);

            file.ValueBinding.Bind(new KeyValuePair <string, string>("Nested Tester", "Nested Source Value"));
            Assert.AreEqual("Nested Source Value", bindedSection.Keys["Test Key Nested"].Value);
        }
Exemple #8
0
        public void Bug4()
        {
            string iniFileContent = "suffix= LLC © 2016" + Environment.NewLine +
                                    "suffix=LLC © 2016  ";
            IniFile file =
                IniUtilities.LoadIniFileContent(iniFileContent,
                                                new IniOptions()
            {
                Encoding = System.Text.Encoding.UTF8
            });

            Assert.AreEqual(" LLC © 2016", file.Sections[0].Keys[0].Value);
            Assert.AreEqual("LLC © 2016  ", file.Sections[0].Keys[1].Value);

            iniFileContent = "suffix = LLC © 2016" + Environment.NewLine +
                             "suffix =   LLC © 2016  ";
            file = IniUtilities.LoadIniFileContent(iniFileContent,
                                                   new IniOptions()
            {
                Encoding = System.Text.Encoding.UTF8
            });

            Assert.AreEqual("LLC © 2016", file.Sections[0].Keys[0].Value);
            Assert.AreEqual("  LLC © 2016  ", file.Sections[0].Keys[1].Value);
        }
Exemple #9
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]);
        }
Exemple #10
0
        public void Bug5()
        {
            string iniFileContent = "[Section 1]" + Environment.NewLine +
                                    "Key 1.1=Value 1.1";
            IniFile file = IniUtilities.LoadIniFileContent(iniFileContent, new IniOptions());

            Assert.AreEqual("Value 1.1", file.Sections["Section 1"].Keys["Key 1.1"].Value);
        }
Exemple #11
0
        public void Bug3()
        {
            string iniFileContent = "[sektion]" + Environment.NewLine +
                                    "key=\"Data Source=server;Initial Catalog=catalog;Integrated Security=SSPI\"";
            IniFile file = IniUtilities.LoadIniFileContent(iniFileContent, new IniOptions());

            IniKey key = file.Sections["sektion"].Keys["key"];

            Assert.AreEqual("\"Data Source=server;Initial Catalog=catalog;Integrated Security=SSPI\"", key.Value);
            Assert.IsNull(key.LeadingComment.Text);
        }
Exemple #12
0
        public void BindValueCustomization()
        {
            string iniFileContent = "[Binding Customization Section]\n" +
                                    "Test Key 1 = @{First Tester}\n" +
                                    "Test Key 2-3 = @{Second Tester} and @{Third Tester}\n" +
                                    "Test Key 2-4 = @{Second Tester} and @{Fourth Tester}\n" +
                                    "Test Key X = @{Unknown}";

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

            file.ValueBinding.Binding += (sender, e) =>
            {
                if (!e.IsValueFound)
                {
                    e.Value = "Missing";
                }
                else
                {
                    switch (e.PlaceholderName)
                    {
                    case "First Tester":
                        e.Value = "Custom " + e.Value;
                        break;

                    case "Third Tester":
                        e.Value = null;
                        break;

                    case "Fourth Tester":
                        e.Value = string.Empty;
                        break;
                    }
                }
            };

            file.ValueBinding.Bind(
                new Dictionary <string, string>()
            {
                { "First Tester", "Source Value 1" },
                { "Second Tester", "Source Value 2" },
                { "Third Tester", "Source Value 3" },
                { "Fourth Tester", "Source Value 4" }
            });

            var bindedSection = file.Sections["Binding Customization Section"];

            Assert.AreEqual("Custom Source Value 1", bindedSection.Keys["Test Key 1"].Value);
            Assert.AreEqual("Source Value 2 and @{Third Tester}", bindedSection.Keys["Test Key 2-3"].Value);
            Assert.AreEqual("Source Value 2 and ", bindedSection.Keys["Test Key 2-4"].Value);
            Assert.AreEqual("Missing", bindedSection.Keys["Test Key X"].Value);
        }
Exemple #13
0
        public void ReadUTF8EncodingTest()
        {
            string iniFileContent = "[Καλημέρα κόσμε]" + Environment.NewLine +
                                    "こんにちは 世界 = ¥ £ € $ ¢ ₡ ₢ ₣ ₤ ₥ ₦ ₧ ₨ ₩ ₪ ₫ ₭ ₮ ₯ ₹";

            IniFile file = IniUtilities.LoadIniFileContent(iniFileContent, new IniOptions()
            {
                Encoding = Encoding.UTF8
            });

            Assert.AreEqual("Καλημέρα κόσμε", file.Sections[0].Name);
            Assert.AreEqual("こんにちは 世界", file.Sections[0].Keys[0].Name);
            Assert.AreEqual("¥ £ € $ ¢ ₡ ₢ ₣ ₤ ₥ ₦ ₧ ₨ ₩ ₪ ₫ ₭ ₮ ₯ ₹", file.Sections[0].Keys[0].Value);
        }
Exemple #14
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]);
        }
Exemple #15
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]);
        }
Exemple #16
0
        public void ReadValueEdgeCasesTest()
        {
            string iniFileContent = "[Section]" + Environment.NewLine +
                                    "Key=" + Environment.NewLine +
                                    "Key=;" + Environment.NewLine +
                                    "Key= " + Environment.NewLine +
                                    "Key= ;" + Environment.NewLine +
                                    "Key =" + Environment.NewLine +
                                    "Key =;" + Environment.NewLine +
                                    "Key = " + Environment.NewLine +
                                    "Key = ;" + Environment.NewLine +
                                    "Key=;Test" + Environment.NewLine +
                                    "Key = ;Test";

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

            Assert.IsEmpty(file.Sections[0].Keys[0].Value);
            Assert.IsNull(file.Sections[0].Keys[0].LeadingComment.Text);
            Assert.AreEqual(0, file.Sections[0].Keys[0].LeadingComment.LeftIndentation);
            Assert.IsEmpty(file.Sections[0].Keys[1].Value);
            Assert.IsEmpty(file.Sections[0].Keys[1].LeadingComment.Text);
            Assert.AreEqual(0, file.Sections[0].Keys[1].LeadingComment.LeftIndentation);
            Assert.AreEqual(" ", file.Sections[0].Keys[2].Value);
            Assert.IsNull(file.Sections[0].Keys[2].LeadingComment.Text);
            Assert.AreEqual(0, file.Sections[0].Keys[2].LeadingComment.LeftIndentation);
            Assert.AreEqual(" ", file.Sections[0].Keys[3].Value);
            Assert.IsEmpty(file.Sections[0].Keys[3].LeadingComment.Text);
            Assert.AreEqual(1, file.Sections[0].Keys[3].LeadingComment.LeftIndentation);
            Assert.IsEmpty(file.Sections[0].Keys[4].Value);
            Assert.IsNull(file.Sections[0].Keys[4].LeadingComment.Text);
            Assert.AreEqual(0, file.Sections[0].Keys[4].LeadingComment.LeftIndentation);
            Assert.IsEmpty(file.Sections[0].Keys[5].Value);
            Assert.IsEmpty(file.Sections[0].Keys[5].LeadingComment.Text);
            Assert.AreEqual(0, file.Sections[0].Keys[5].LeadingComment.LeftIndentation);
            Assert.IsEmpty(file.Sections[0].Keys[6].Value);
            Assert.IsNull(file.Sections[0].Keys[6].LeadingComment.Text);
            Assert.AreEqual(0, file.Sections[0].Keys[6].LeadingComment.LeftIndentation);
            Assert.IsEmpty(file.Sections[0].Keys[7].Value);
            Assert.IsEmpty(file.Sections[0].Keys[7].LeadingComment.Text);
            Assert.AreEqual(0, file.Sections[0].Keys[7].LeadingComment.LeftIndentation);
            Assert.IsEmpty(file.Sections[0].Keys[8].Value);
            Assert.AreEqual("Test", file.Sections[0].Keys[8].LeadingComment.Text);
            Assert.AreEqual(0, file.Sections[0].Keys[8].LeadingComment.LeftIndentation);
            Assert.IsEmpty(file.Sections[0].Keys[9].Value);
            Assert.AreEqual("Test", file.Sections[0].Keys[9].LeadingComment.Text);
            Assert.AreEqual(0, file.Sections[0].Keys[9].LeadingComment.LeftIndentation);
        }
Exemple #17
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]);
        }
Exemple #18
0
        public void ReadCommentEdgeCasesTest()
        {
            string iniFileContent = ";" + Environment.NewLine +
                                    ";Section's trailing comment;" + Environment.NewLine +
                                    "[Section]" + Environment.NewLine +
                                    "[Section];" + Environment.NewLine +
                                    "[Section]  ;" + Environment.NewLine +
                                    ";" + Environment.NewLine +
                                    ";Key's trailing comment;" + Environment.NewLine +
                                    "Key = Value  " + Environment.NewLine +
                                    "Key = Value;" + Environment.NewLine +
                                    "Key = Value  ;";

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

            Assert.AreEqual(Environment.NewLine + "Section's trailing comment;", file.Sections[0].TrailingComment.Text);
            Assert.AreEqual("Section", file.Sections[0].Name);
            Assert.IsNull(file.Sections[0].LeadingComment.Text);
            Assert.AreEqual(0, file.Sections[0].LeadingComment.LeftIndentation);

            Assert.AreEqual("Section", file.Sections[1].Name);
            Assert.IsEmpty(file.Sections[1].LeadingComment.Text);
            Assert.AreEqual(0, file.Sections[1].LeadingComment.LeftIndentation);

            Assert.AreEqual("Section", file.Sections[2].Name);
            Assert.IsEmpty(file.Sections[2].LeadingComment.Text);
            Assert.AreEqual(2, file.Sections[2].LeadingComment.LeftIndentation);

            Assert.AreEqual(Environment.NewLine + "Key's trailing comment;", file.Sections[2].Keys[0].TrailingComment.Text);
            Assert.AreEqual("Key", file.Sections[2].Keys[0].Name);
            Assert.AreEqual("Value", file.Sections[2].Keys[0].Value);
            Assert.IsNull(file.Sections[2].Keys[0].LeadingComment.Text);
            Assert.AreEqual(0, file.Sections[2].Keys[0].LeadingComment.LeftIndentation);

            Assert.AreEqual("Key", file.Sections[2].Keys[1].Name);
            Assert.AreEqual("Value", file.Sections[2].Keys[1].Value);
            Assert.IsEmpty(file.Sections[2].Keys[1].LeadingComment.Text);
            Assert.AreEqual(0, file.Sections[2].Keys[1].LeadingComment.LeftIndentation);

            Assert.AreEqual("Key", file.Sections[2].Keys[2].Name);
            Assert.AreEqual("Value", file.Sections[2].Keys[2].Value);
            Assert.IsEmpty(file.Sections[2].Keys[2].LeadingComment.Text);
            Assert.AreEqual(2, file.Sections[2].Keys[2].LeadingComment.LeftIndentation);
        }
Exemple #19
0
        public void ReadQuotedValue()
        {
            string iniFileContent = "key1 = \"Test;Test\"" + Environment.NewLine +
                                    "key2 = \"Test;Test\";" + Environment.NewLine +
                                    "key3 = \"Test;Test" + Environment.NewLine +
                                    "key4 = \"Test;Test;Test\"Test;Test;Test";

            IniFile    file    = IniUtilities.LoadIniFileContent(iniFileContent, new IniOptions());
            IniSection section = file.Sections[0];

            Assert.AreEqual("\"Test;Test\"", file.Sections[0].Keys[0].Value);
            Assert.IsNull(file.Sections[0].Keys[0].LeadingComment.Text);
            Assert.AreEqual("\"Test;Test\"", file.Sections[0].Keys[1].Value);
            Assert.AreEqual(string.Empty, file.Sections[0].Keys[1].LeadingComment.Text);
            Assert.AreEqual("\"Test", file.Sections[0].Keys[2].Value);
            Assert.AreEqual("Test", file.Sections[0].Keys[2].LeadingComment.Text);
            Assert.AreEqual("\"Test;Test;Test\"Test", file.Sections[0].Keys[3].Value);
            Assert.AreEqual("Test;Test", file.Sections[0].Keys[3].LeadingComment.Text);
        }
Exemple #20
0
        public void ReadDefaultTest()
        {
            string iniFileContent = ";Section's trailing comment." + Environment.NewLine +
                                    "[Section's name];Section's leading comment." + Environment.NewLine +
                                    ";Key's trailing comment." + Environment.NewLine +
                                    "Key's name = Key's value;Key's leading comment.";

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

            Assert.AreEqual(1, file.Sections.Count);
            Assert.AreEqual("Section's trailing comment.", file.Sections[0].TrailingComment.Text);
            Assert.AreEqual("Section's name", file.Sections[0].Name);
            Assert.AreEqual("Section's leading comment.", file.Sections[0].LeadingComment.Text);

            Assert.AreEqual(1, file.Sections[0].Keys.Count);
            Assert.AreEqual("Key's trailing comment.", file.Sections[0].Keys[0].TrailingComment.Text);
            Assert.AreEqual("Key's name", file.Sections[0].Keys[0].Name);
            Assert.AreEqual("Key's value", file.Sections[0].Keys[0].Value);
            Assert.AreEqual("Key's leading comment.", file.Sections[0].Keys[0].LeadingComment.Text);
        }
Exemple #21
0
        public void ReadGlobalSectionTest()
        {
            string iniFileContent = ";Trailing comment1" + Environment.NewLine +
                                    "Key1 = Value1" + Environment.NewLine +
                                    ";Trailing comment2" + Environment.NewLine +
                                    "Key2 = Value2";

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

            Assert.AreEqual(1, file.Sections.Count);
            Assert.AreEqual(IniSection.GlobalSectionName, file.Sections[0].Name);

            Assert.AreEqual(2, file.Sections[0].Keys.Count);
            Assert.AreEqual("Trailing comment1", file.Sections[0].Keys[0].TrailingComment.Text);
            Assert.AreEqual("Key1", file.Sections[0].Keys[0].Name);
            Assert.AreEqual("Value1", file.Sections[0].Keys[0].Value);
            Assert.AreEqual("Trailing comment2", file.Sections[0].Keys[1].TrailingComment.Text);
            Assert.AreEqual("Key2", file.Sections[0].Keys[1].Name);
            Assert.AreEqual("Value2", file.Sections[0].Keys[1].Value);
        }
Exemple #22
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]);
        }