Mercurial > repos > IBBoard.Ini.Tests
changeset 3:2d2f4084679f
Re #7 - Add tests for INI parsing
* Add section parsing test class
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 18 Jan 2009 13:51:47 +0000 |
parents | f880d41804d6 |
children | 59186ab49249 |
files | IBBoard.Ini.Tests.mdp IniFileReaderTest.cs IniSectionParserTest.cs |
diffstat | 3 files changed, 136 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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 @@ -<Project name="IBBoard.Ini.Tests" fileversion="2.0" language="C#" clr-version="Net_2_0" ctype="DotNetProject"> +<Project name="IBBoard.Ini.Tests" fileversion="2.0" language="C#" DefaultNamespace="IBBoard.Ini" clr-version="Net_2_0" ctype="DotNetProject"> <Configurations active="Debug"> <Configuration name="Debug" ctype="DotNetProjectConfiguration"> <Output directory="bin/Debug" assembly="IBBoard.Ini.Tests" /> @@ -24,6 +24,7 @@ <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" /> + <File name="IniSectionParserTest.cs" subtype="Code" buildaction="Compile" /> </Contents> <References> <ProjectReference type="Project" localcopy="True" refto="IBBoard.Ini" />
--- 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()
--- /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); + } + } + } +}