changeset 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
files IBBoard.Ini.Tests.mdp IniFileReaderTest.cs IniLineParserTest.cs TestData/SingleSectionWithMultiLineContent.ini
diffstat 4 files changed, 85 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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 @@
     <File name="TestData/SingleSectionSingleLine.ini" subtype="Code" buildaction="Nothing" copyToOutputDirectory="Always" />
     <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" />
   </Contents>
   <References>
     <ProjectReference type="Project" localcopy="True" refto="IBBoard.Ini" />
--- 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);
+			}
+		}
 	}
 }
--- 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()
--- /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