Mercurial > repos > IBBoard.Ini.Tests
view IniSectionParserTest.cs @ 13:48b646dd1dc2 default tip
* Automated clean-up of .csproj file
* Ignore generated files
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 07 Nov 2012 20:23:16 +0000 |
parents | 4f281289bcdd |
children |
line wrap: on
line source
// 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, either version 3 of the License or (at your option) any later version. 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); } } } }