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 diff
     1.1 --- a/IBBoard.Ini.Tests.mdp	Wed Jan 14 19:54:00 2009 +0000
     1.2 +++ b/IBBoard.Ini.Tests.mdp	Wed Jan 14 20:25:58 2009 +0000
     1.3 @@ -22,6 +22,8 @@
     1.4      <File name="TestData/SingleSectionWithContent.ini" subtype="Code" buildaction="Nothing" copyToOutputDirectory="Always" />
     1.5      <File name="TestData/DoubleSectionWithContent.ini" subtype="Code" buildaction="Nothing" copyToOutputDirectory="Always" />
     1.6      <File name="TestData/SingleSectionWithMultiLineContent.ini" subtype="Code" buildaction="Nothing" copyToOutputDirectory="PreserveNewest" />
     1.7 +    <File name="TestData/StartPadded.ini" subtype="Code" buildaction="Nothing" copyToOutputDirectory="PreserveNewest" />
     1.8 +    <File name="TestData/ConsecutiveSection.ini" subtype="Code" buildaction="Nothing" copyToOutputDirectory="PreserveNewest" />
     1.9    </Contents>
    1.10    <References>
    1.11      <ProjectReference type="Project" localcopy="True" refto="IBBoard.Ini" />
     2.1 --- a/IniFileReaderTest.cs	Wed Jan 14 19:54:00 2009 +0000
     2.2 +++ b/IniFileReaderTest.cs	Wed Jan 14 20:25:58 2009 +0000
     2.3 @@ -72,7 +72,7 @@
     2.4  		}
     2.5  		
     2.6  		[Test()]
     2.7 -		public void TestIniFileReaderContainsExpectedSectionForTwoSectionIniTextWithContent()
     2.8 +		public void TestIniFileReaderContainsExpectedSectionsForTwoSectionIniTextWithContent()
     2.9  		{
    2.10  			IniFile file = IniFileReader.ReadFile("[ASection]\nsomething=fibble\n[BSection]\nsomethingElse=fibble");
    2.11  			Assert.AreEqual(2, file.Sections.Length);
    2.12 @@ -87,6 +87,32 @@
    2.13  		}
    2.14  		
    2.15  		[Test()]
    2.16 +		public void TestIniFileReaderContainsExpectedSectionsForTwoConsecutiveSectionSectionsInText()
    2.17 +		{
    2.18 +			IniFile file = IniFileReader.ReadFile("[SectionA]\n[SectionB]");
    2.19 +			Assert.AreEqual(2, file.Sections.Length);
    2.20 +			Assert.IsTrue(file.HasSection("SectionA"));
    2.21 +			Assert.IsNotNull(file["SectionA"]);
    2.22 +			Assert.AreEqual(0, file["SectionA"].Keys.Length);
    2.23 +			Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["SectionA"]);
    2.24 +			Assert.IsTrue(file.HasSection("SectionB"));
    2.25 +			Assert.IsNotNull(file["SectionB"]);
    2.26 +			Assert.AreEqual(0, file["SectionB"].Keys.Length);
    2.27 +			Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["SectionB"]);
    2.28 +		}
    2.29 +		
    2.30 +		[Test()]
    2.31 +		public void TestIniFileReaderContainsExpectedSectionWhenTextPaddedAtStart()
    2.32 +		{
    2.33 +			IniFile file = IniFileReader.ReadFile("\nnon-blank\n[ASection]\nsomething=fibble");
    2.34 +			Assert.AreEqual(1, file.Sections.Length);
    2.35 +			Assert.IsTrue(file.HasSection("ASection"));
    2.36 +			Assert.IsNotNull(file["ASection"]);
    2.37 +			Assert.AreEqual(1, file["ASection"].Keys.Length);
    2.38 +			Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]);
    2.39 +		}
    2.40 +		
    2.41 +		[Test()]
    2.42  		public void TestIniFileReaderReturnsEmptyObjectForEmptyIniFile()
    2.43  		{
    2.44  			IniFile file = IniFileReader.ReadFile(new FileInfo("EmptyFile.ini"));
    2.45 @@ -117,7 +143,7 @@
    2.46  		}
    2.47  		
    2.48  		[Test()]
    2.49 -		public void TestIniFileReaderContainsExpectedSectionForTwoSectionIniFileWithContent()
    2.50 +		public void TestIniFileReaderContainsExpectedSectionsForTwoSectionIniFileWithContent()
    2.51  		{
    2.52  			IniFile file = IniFileReader.ReadFile(new FileInfo("DoubleSectionWithContent.ini"));
    2.53  			Assert.AreEqual(2, file.Sections.Length);
    2.54 @@ -160,5 +186,31 @@
    2.55  				Assert.IsTrue(found, "Did not find "+key);
    2.56  			}
    2.57  		}
    2.58 +		
    2.59 +		[Test()]
    2.60 +		public void TestIniFileReaderContainsExpectedSectionWhenFilePaddedAtStart()
    2.61 +		{
    2.62 +			IniFile file = IniFileReader.ReadFile(new FileInfo("StartPadded.ini"));
    2.63 +			Assert.AreEqual(1, file.Sections.Length);
    2.64 +			Assert.IsTrue(file.HasSection("ASection"));
    2.65 +			Assert.IsNotNull(file["ASection"]);
    2.66 +			Assert.AreEqual(1, file["ASection"].Keys.Length);
    2.67 +			Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]);
    2.68 +		}
    2.69 +		
    2.70 +		[Test()]
    2.71 +		public void TestIniFileReaderContainsExpectedSectionsForTwoConsecutiveSectionSectionsInFile()
    2.72 +		{
    2.73 +			IniFile file = IniFileReader.ReadFile(new FileInfo("ConsecutiveSection.ini"));
    2.74 +			Assert.AreEqual(2, file.Sections.Length);
    2.75 +			Assert.IsTrue(file.HasSection("SectionA"));
    2.76 +			Assert.IsNotNull(file["SectionA"]);
    2.77 +			Assert.AreEqual(0, file["SectionA"].Keys.Length);
    2.78 +			Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["SectionA"]);
    2.79 +			Assert.IsTrue(file.HasSection("SectionB"));
    2.80 +			Assert.IsNotNull(file["SectionB"]);
    2.81 +			Assert.AreEqual(0, file["SectionB"].Keys.Length);
    2.82 +			Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["SectionB"]);
    2.83 +		}
    2.84  	}
    2.85  }
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/TestData/ConsecutiveSection.ini	Wed Jan 14 20:25:58 2009 +0000
     3.3 @@ -0,0 +1,2 @@
     3.4 +[SectionA]
     3.5 +[SectionB]
     3.6 \ No newline at end of file
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/TestData/StartPadded.ini	Wed Jan 14 20:25:58 2009 +0000
     4.3 @@ -0,0 +1,4 @@
     4.4 +
     4.5 +non-blank
     4.6 +[ASection]
     4.7 +something=fibble
     4.8 \ No newline at end of file