Mercurial > repos > IBBoard.Ini.Tests
changeset 2:f880d41804d6
Re #7 - Tests for INI parsing
* Add tests for padding at start of file
* Add tests for consecutive sections with no content
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 14 Jan 2009 20:25:58 +0000 |
parents | c2a0d074b3b5 |
children | 2d2f4084679f |
files | IBBoard.Ini.Tests.mdp IniFileReaderTest.cs TestData/ConsecutiveSection.ini TestData/StartPadded.ini |
diffstat | 4 files changed, 62 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/IBBoard.Ini.Tests.mdp Wed Jan 14 19:54:00 2009 +0000 +++ b/IBBoard.Ini.Tests.mdp Wed Jan 14 20:25:58 2009 +0000 @@ -22,6 +22,8 @@ <File name="TestData/SingleSectionWithContent.ini" subtype="Code" buildaction="Nothing" copyToOutputDirectory="Always" /> <File name="TestData/DoubleSectionWithContent.ini" subtype="Code" buildaction="Nothing" copyToOutputDirectory="Always" /> <File name="TestData/SingleSectionWithMultiLineContent.ini" subtype="Code" buildaction="Nothing" copyToOutputDirectory="PreserveNewest" /> + <File name="TestData/StartPadded.ini" subtype="Code" buildaction="Nothing" copyToOutputDirectory="PreserveNewest" /> + <File name="TestData/ConsecutiveSection.ini" subtype="Code" buildaction="Nothing" copyToOutputDirectory="PreserveNewest" /> </Contents> <References> <ProjectReference type="Project" localcopy="True" refto="IBBoard.Ini" />
--- a/IniFileReaderTest.cs Wed Jan 14 19:54:00 2009 +0000 +++ b/IniFileReaderTest.cs Wed Jan 14 20:25:58 2009 +0000 @@ -72,7 +72,7 @@ } [Test()] - public void TestIniFileReaderContainsExpectedSectionForTwoSectionIniTextWithContent() + public void TestIniFileReaderContainsExpectedSectionsForTwoSectionIniTextWithContent() { IniFile file = IniFileReader.ReadFile("[ASection]\nsomething=fibble\n[BSection]\nsomethingElse=fibble"); Assert.AreEqual(2, file.Sections.Length); @@ -87,6 +87,32 @@ } [Test()] + public void TestIniFileReaderContainsExpectedSectionsForTwoConsecutiveSectionSectionsInText() + { + IniFile file = IniFileReader.ReadFile("[SectionA]\n[SectionB]"); + Assert.AreEqual(2, file.Sections.Length); + Assert.IsTrue(file.HasSection("SectionA")); + Assert.IsNotNull(file["SectionA"]); + Assert.AreEqual(0, file["SectionA"].Keys.Length); + Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["SectionA"]); + Assert.IsTrue(file.HasSection("SectionB")); + Assert.IsNotNull(file["SectionB"]); + Assert.AreEqual(0, file["SectionB"].Keys.Length); + Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["SectionB"]); + } + + [Test()] + public void TestIniFileReaderContainsExpectedSectionWhenTextPaddedAtStart() + { + IniFile file = IniFileReader.ReadFile("\nnon-blank\n[ASection]\nsomething=fibble"); + 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 TestIniFileReaderReturnsEmptyObjectForEmptyIniFile() { IniFile file = IniFileReader.ReadFile(new FileInfo("EmptyFile.ini")); @@ -117,7 +143,7 @@ } [Test()] - public void TestIniFileReaderContainsExpectedSectionForTwoSectionIniFileWithContent() + public void TestIniFileReaderContainsExpectedSectionsForTwoSectionIniFileWithContent() { IniFile file = IniFileReader.ReadFile(new FileInfo("DoubleSectionWithContent.ini")); Assert.AreEqual(2, file.Sections.Length); @@ -160,5 +186,31 @@ Assert.IsTrue(found, "Did not find "+key); } } + + [Test()] + public void TestIniFileReaderContainsExpectedSectionWhenFilePaddedAtStart() + { + IniFile file = IniFileReader.ReadFile(new FileInfo("StartPadded.ini")); + 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 TestIniFileReaderContainsExpectedSectionsForTwoConsecutiveSectionSectionsInFile() + { + IniFile file = IniFileReader.ReadFile(new FileInfo("ConsecutiveSection.ini")); + Assert.AreEqual(2, file.Sections.Length); + Assert.IsTrue(file.HasSection("SectionA")); + Assert.IsNotNull(file["SectionA"]); + Assert.AreEqual(0, file["SectionA"].Keys.Length); + Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["SectionA"]); + Assert.IsTrue(file.HasSection("SectionB")); + Assert.IsNotNull(file["SectionB"]); + Assert.AreEqual(0, file["SectionB"].Keys.Length); + Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["SectionB"]); + } } }