# HG changeset patch # User IBBoard # Date 1232286707 0 # Node ID 2d2f4084679f9f20b71266a27e5b5d19a72c2065 # Parent f880d41804d69a42c50263489ce3073049cb0d72 Re #7 - Add tests for INI parsing * Add section parsing test class diff -r f880d41804d6 -r 2d2f4084679f IBBoard.Ini.Tests.mdp --- a/IBBoard.Ini.Tests.mdp Wed Jan 14 20:25:58 2009 +0000 +++ b/IBBoard.Ini.Tests.mdp Sun Jan 18 13:51:47 2009 +0000 @@ -1,4 +1,4 @@ - + @@ -24,6 +24,7 @@ + diff -r f880d41804d6 -r 2d2f4084679f IniFileReaderTest.cs --- a/IniFileReaderTest.cs Wed Jan 14 20:25:58 2009 +0000 +++ b/IniFileReaderTest.cs Sun Jan 18 13:51:47 2009 +0000 @@ -17,7 +17,6 @@ IniFile file = IniFileReader.ReadFile(""); Assert.AreEqual(0, file.Sections.Length); } - [Test()] public void TestIniFileReaderContainsExpectedSectionForSingleSectionIniText() diff -r f880d41804d6 -r 2d2f4084679f IniSectionParserTest.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/IniSectionParserTest.cs Sun Jan 18 13:51:47 2009 +0000 @@ -0,0 +1,134 @@ +// This file (IniSectionParserTest.cs) is a part of the IBBoard.Ini.Tests and is copyright 2009 IBBoard. +// +// The file and the library/program it is in are licensed under the GNU LGPL license. Please see COPYING.LGPL for more information and the full license. + +using System; +using NUnit.Framework; + +namespace IBBoard.Ini +{ + [TestFixture()] + public class IniSectionParserTest + { + [Test()] + public void TestIsLineStartOfNewSectionWithSimpleHeaderReturnsTrue() + { + Assert.IsTrue(IniSectionParser.IsLineStartOfNewSection("[SomeHeader]")); + } + + [Test()] + public void TestIsLineStartOfNewSectionWithPaddedHeaderReturnsTrue() + { + Assert.IsTrue(IniSectionParser.IsLineStartOfNewSection(" [SomeHeader] ")); + } + + [Test()] + public void TestIsLineStartOfNewSectionWithNonHeaderReturnsFalse() + { + Assert.IsFalse(IniSectionParser.IsLineStartOfNewSection("SomeNoneHeader")); + } + + [Test()] + public void TestIsLineStartOfNewSectionWithHeaderAndExtraCharactersReturnsFalse() + { + Assert.IsFalse(IniSectionParser.IsLineStartOfNewSection("break[SomeHeader]")); + } + + [Test()] + public void TestIsLineStartOfNewSectionWithHeaderAndDifferentExtraCharactersReturnsFalse() + { + Assert.IsFalse(IniSectionParser.IsLineStartOfNewSection("[SomeHeader]fail")); + } + + + [Test()] + public void TestIsStringAnIniSectionForEmptyIniTextReturnsFalse() + { + Assert.IsFalse(IniSectionParser.IsStringAnIniSection("")); + } + + [Test()] + public void TestIsStringAnIniSectionForSingleSectionWithoutValuesReturnsTrue() + { + Assert.IsTrue(IniSectionParser.IsStringAnIniSection("[ASection]")); + } + + [Test()] + public void TestIsStringAnIniSectionForSingleSectionWithValueReturnsTrue() + { + Assert.IsTrue(IniSectionParser.IsStringAnIniSection("[ASection]\nsomething=fibble")); + } + + [Test()] + public void TestIsStringAnIniSectionForSingleSectionWithMultipleValuesReturnsTrue() + { + Assert.IsTrue(IniSectionParser.IsStringAnIniSection("[ASection]\nsomething=fibble\nfobble_key=foo\nabcde=fghij\nfoo9=bar2")); + } + + [Test()] + [ExpectedException("IBBoard.Ini.InvalidIniSectionException")] + public void TestCreateSectionThrowsExceptionForEmptyIniText() + { + IniSectionParser.CreateSection(""); + } + + [Test()] + [ExpectedException("IBBoard.Ini.InvalidIniSectionException")] + public void TestCreateSectionThrowsExceptionForContentWithoutHeader() + { + IniSectionParser.CreateSection("key=something"); + } + + [Test()] + [ExpectedException("IBBoard.Ini.InvalidIniSectionException")] + public void TestCreateSectionThrowsExceptionForHeaderWithExtraCharacters() + { + IniSectionParser.CreateSection("abc[header]\nkey=something"); + } + + [Test()] + public void TestCreateSectionReturnsExpectedSectionForSingleSectionIniText() + { + IniSection section = IniSectionParser.CreateSection("[ASection]"); + Assert.IsNotNull(section); + Assert.AreEqual(0, section.Keys.Length); + Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), section); + } + + [Test()] + public void TestCreateSectionReturnsExpectedSectionForSingleSectionIniTextWithContent() + { + IniSection section = IniSectionParser.CreateSection("[ASection]\nsomething=fibble"); + Assert.IsNotNull(section); + Assert.AreEqual(1, section.Keys.Length); + Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), section); + } + + [Test()] + public void TestCreateSectionReturnsExpectedSectionForSingleSectionIniTextWithMultiLineContent() + { + IniSection section = IniSectionParser.CreateSection("[ASection]\nsomething=fibble\nfobble_key=foo\nabcde=fghij\nfoo9=bar2"); + Assert.IsNotNull(section); + Assert.AreEqual(4, section.Keys.Length); + Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), section); + + 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); + } + } + } +}