view IniSectionParserTest.cs @ 12:0be17f8102ed

* Fix unit test paths
author IBBoard <dev@ibboard.co.uk>
date Wed, 07 Nov 2012 20:22:20 +0000
parents 2d2f4084679f
children
line source
1 // This file (IniSectionParserTest.cs) is a part of the IBBoard.Ini.Tests and is copyright 2009 IBBoard.
2 //
3 // 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.
5 using System;
6 using NUnit.Framework;
8 namespace IBBoard.Ini
9 {
10 [TestFixture()]
11 public class IniSectionParserTest
12 {
13 [Test()]
14 public void TestIsLineStartOfNewSectionWithSimpleHeaderReturnsTrue()
15 {
16 Assert.IsTrue(IniSectionParser.IsLineStartOfNewSection("[SomeHeader]"));
17 }
19 [Test()]
20 public void TestIsLineStartOfNewSectionWithPaddedHeaderReturnsTrue()
21 {
22 Assert.IsTrue(IniSectionParser.IsLineStartOfNewSection(" [SomeHeader] "));
23 }
25 [Test()]
26 public void TestIsLineStartOfNewSectionWithNonHeaderReturnsFalse()
27 {
28 Assert.IsFalse(IniSectionParser.IsLineStartOfNewSection("SomeNoneHeader"));
29 }
31 [Test()]
32 public void TestIsLineStartOfNewSectionWithHeaderAndExtraCharactersReturnsFalse()
33 {
34 Assert.IsFalse(IniSectionParser.IsLineStartOfNewSection("break[SomeHeader]"));
35 }
37 [Test()]
38 public void TestIsLineStartOfNewSectionWithHeaderAndDifferentExtraCharactersReturnsFalse()
39 {
40 Assert.IsFalse(IniSectionParser.IsLineStartOfNewSection("[SomeHeader]fail"));
41 }
44 [Test()]
45 public void TestIsStringAnIniSectionForEmptyIniTextReturnsFalse()
46 {
47 Assert.IsFalse(IniSectionParser.IsStringAnIniSection(""));
48 }
50 [Test()]
51 public void TestIsStringAnIniSectionForSingleSectionWithoutValuesReturnsTrue()
52 {
53 Assert.IsTrue(IniSectionParser.IsStringAnIniSection("[ASection]"));
54 }
56 [Test()]
57 public void TestIsStringAnIniSectionForSingleSectionWithValueReturnsTrue()
58 {
59 Assert.IsTrue(IniSectionParser.IsStringAnIniSection("[ASection]\nsomething=fibble"));
60 }
62 [Test()]
63 public void TestIsStringAnIniSectionForSingleSectionWithMultipleValuesReturnsTrue()
64 {
65 Assert.IsTrue(IniSectionParser.IsStringAnIniSection("[ASection]\nsomething=fibble\nfobble_key=foo\nabcde=fghij\nfoo9=bar2"));
66 }
68 [Test()]
69 [ExpectedException("IBBoard.Ini.InvalidIniSectionException")]
70 public void TestCreateSectionThrowsExceptionForEmptyIniText()
71 {
72 IniSectionParser.CreateSection("");
73 }
75 [Test()]
76 [ExpectedException("IBBoard.Ini.InvalidIniSectionException")]
77 public void TestCreateSectionThrowsExceptionForContentWithoutHeader()
78 {
79 IniSectionParser.CreateSection("key=something");
80 }
82 [Test()]
83 [ExpectedException("IBBoard.Ini.InvalidIniSectionException")]
84 public void TestCreateSectionThrowsExceptionForHeaderWithExtraCharacters()
85 {
86 IniSectionParser.CreateSection("abc[header]\nkey=something");
87 }
89 [Test()]
90 public void TestCreateSectionReturnsExpectedSectionForSingleSectionIniText()
91 {
92 IniSection section = IniSectionParser.CreateSection("[ASection]");
93 Assert.IsNotNull(section);
94 Assert.AreEqual(0, section.Keys.Length);
95 Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), section);
96 }
98 [Test()]
99 public void TestCreateSectionReturnsExpectedSectionForSingleSectionIniTextWithContent()
100 {
101 IniSection section = IniSectionParser.CreateSection("[ASection]\nsomething=fibble");
102 Assert.IsNotNull(section);
103 Assert.AreEqual(1, section.Keys.Length);
104 Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), section);
105 }
107 [Test()]
108 public void TestCreateSectionReturnsExpectedSectionForSingleSectionIniTextWithMultiLineContent()
109 {
110 IniSection section = IniSectionParser.CreateSection("[ASection]\nsomething=fibble\nfobble_key=foo\nabcde=fghij\nfoo9=bar2");
111 Assert.IsNotNull(section);
112 Assert.AreEqual(4, section.Keys.Length);
113 Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), section);
115 string[] keys = new string[]{"something", "fobble_key", "abcde", "foo9"};
117 foreach (string key in keys)
118 {
119 bool found = false;
121 foreach (string sectionKey in section.Keys)
122 {
123 if (key == sectionKey)
124 {
125 found = true;
126 break;
127 }
128 }
130 Assert.IsTrue(found, "Did not find "+key);
131 }
132 }
133 }
134 }