# HG changeset patch # User IBBoard # Date 1231962840 0 # Node ID c2a0d074b3b5414dc887e28c6749f04c12545337 # Parent ada654b0648c832d091a26badbd35fb8408e7121 Re #7 - Test for INI parsing * Add key length checking to file parsing to ensure section is correctly parsed * Add tests for multi-line section parsing * Add test for line parser parsing padded line diff -r ada654b0648c -r c2a0d074b3b5 IBBoard.Ini.Tests.mdp --- a/IBBoard.Ini.Tests.mdp Mon Jan 12 20:41:45 2009 +0000 +++ b/IBBoard.Ini.Tests.mdp Wed Jan 14 19:54:00 2009 +0000 @@ -21,6 +21,7 @@ + diff -r ada654b0648c -r c2a0d074b3b5 IniFileReaderTest.cs --- a/IniFileReaderTest.cs Mon Jan 12 20:41:45 2009 +0000 +++ b/IniFileReaderTest.cs Wed Jan 14 19:54:00 2009 +0000 @@ -26,6 +26,7 @@ Assert.AreEqual(1, file.Sections.Length); Assert.IsTrue(file.HasSection("ASection")); Assert.IsNotNull(file["ASection"]); + Assert.AreEqual(0, file["ASection"].Keys.Length); Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]); } @@ -36,19 +37,52 @@ Assert.AreEqual(1, file.Sections.Length); Assert.IsTrue(file.HasSection("ASection")); Assert.IsNotNull(file["ASection"]); + Assert.AreEqual(1, file["ASection"].Keys.Length); Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]); } [Test()] + public void TestIniFileReaderContainsExpectedSectionForSingleSectionIniTextWithMultiLineContent() + { + IniFile file = IniFileReader.ReadFile("[ASection]\nsomething=fibble\nfobble_key=foo\nabcde=fghij\nfoo9=bar2"); + Assert.AreEqual(1, file.Sections.Length); + Assert.IsTrue(file.HasSection("ASection")); + IniSection section = file["ASection"]; + Assert.IsNotNull(section); + Assert.AreEqual(4, section.Keys.Length); + Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]); + + string[] keys = new string[]{"something", "fobble_key", "abcde", "foo9"}; + + foreach (string key in keys) + { + bool found = false; + + foreach (string sectionKey in section.Keys) + { + if (key == sectionKey) + { + found = true; + break; + } + } + + Assert.IsTrue(found, "Did not find "+key); + } + } + + [Test()] public void TestIniFileReaderContainsExpectedSectionForTwoSectionIniTextWithContent() { IniFile file = IniFileReader.ReadFile("[ASection]\nsomething=fibble\n[BSection]\nsomethingElse=fibble"); Assert.AreEqual(2, file.Sections.Length); Assert.IsTrue(file.HasSection("ASection")); Assert.IsNotNull(file["ASection"]); + Assert.AreEqual(1, file["ASection"].Keys.Length); Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]); Assert.IsTrue(file.HasSection("BSection")); Assert.IsNotNull(file["BSection"]); + Assert.AreEqual(1, file["BSection"].Keys.Length); Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["BSection"]); } @@ -67,6 +101,7 @@ Assert.AreEqual(1, file.Sections.Length); Assert.IsTrue(file.HasSection("ASection")); Assert.IsNotNull(file["ASection"]); + Assert.AreEqual(0, file["ASection"].Keys.Length); Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]); } @@ -77,6 +112,7 @@ Assert.AreEqual(1, file.Sections.Length); Assert.IsTrue(file.HasSection("ASection")); Assert.IsNotNull(file["ASection"]); + Assert.AreEqual(1, file["ASection"].Keys.Length); Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]); } @@ -87,10 +123,42 @@ Assert.AreEqual(2, file.Sections.Length); Assert.IsTrue(file.HasSection("ASection")); Assert.IsNotNull(file["ASection"]); + Assert.AreEqual(1, file["ASection"].Keys.Length); Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]); Assert.IsTrue(file.HasSection("BSection")); Assert.IsNotNull(file["BSection"]); + Assert.AreEqual(1, file["BSection"].Keys.Length); Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["BSection"]); } + + [Test()] + public void TestIniFileReaderContainsExpectedSectionForSingleSectionIniFileWithMultiLineContent() + { + IniFile file = IniFileReader.ReadFile(new FileInfo("SingleSectionWithMultiLineContent.ini")); + Assert.AreEqual(1, file.Sections.Length); + Assert.IsTrue(file.HasSection("ASection")); + IniSection section = file["ASection"]; + Assert.IsNotNull(section); + Assert.AreEqual(4, section.Keys.Length); + Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]); + + string[] keys = new string[]{"something", "fobble_key", "abcde", "foo9"}; + + foreach (string key in keys) + { + bool found = false; + + foreach (string sectionKey in section.Keys) + { + if (key == sectionKey) + { + found = true; + break; + } + } + + Assert.IsTrue(found, "Did not find "+key); + } + } } } diff -r ada654b0648c -r c2a0d074b3b5 IniLineParserTest.cs --- a/IniLineParserTest.cs Mon Jan 12 20:41:45 2009 +0000 +++ b/IniLineParserTest.cs Wed Jan 14 19:54:00 2009 +0000 @@ -19,6 +19,17 @@ Assert.AreEqual("some_key", keyValuePair.Key); Assert.AreEqual("some_value", keyValuePair.Value); } + + + [Test()] + public void TestIniLineParserReturnsExceptedKeyValuePairForPaddedValidProperty() + { + IIniLine iniLine = IniLineParser.ParseIniLine(" some_key = some_value "); + Assert.IsInstanceOfType(typeof(IniKeyValuePairLine), iniLine); + IniKeyValuePairLine keyValuePair = (IniKeyValuePairLine)iniLine; + Assert.AreEqual("some_key", keyValuePair.Key); + Assert.AreEqual("some_value", keyValuePair.Value); + } [Test()] public void TestIniLineParserReturnsCommentLineForNonProperty() diff -r ada654b0648c -r c2a0d074b3b5 TestData/SingleSectionWithMultiLineContent.ini --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TestData/SingleSectionWithMultiLineContent.ini Wed Jan 14 19:54:00 2009 +0000 @@ -0,0 +1,5 @@ +[ASection] +something=fibble +fobble_key=foo +abcde=fghij +foo9=bar2 \ No newline at end of file