Mercurial > repos > IBBoard.Ini.Tests
diff IniFileReaderTest.cs @ 1:c2a0d074b3b5
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
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 14 Jan 2009 19:54:00 +0000 |
parents | ada654b0648c |
children | f880d41804d6 |
line wrap: on
line diff
--- 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); + } + } } }