3
|
1 // This file (IniSectionParserTest.cs) is a part of the IBBoard.Ini.Tests and is copyright 2009 IBBoard.
|
|
2 //
|
6
|
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.
|
3
|
4
|
|
5 using System;
|
|
6 using NUnit.Framework;
|
|
7
|
|
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 }
|
|
18
|
|
19 [Test()]
|
|
20 public void TestIsLineStartOfNewSectionWithPaddedHeaderReturnsTrue()
|
|
21 {
|
|
22 Assert.IsTrue(IniSectionParser.IsLineStartOfNewSection(" [SomeHeader] "));
|
|
23 }
|
|
24
|
|
25 [Test()]
|
|
26 public void TestIsLineStartOfNewSectionWithNonHeaderReturnsFalse()
|
|
27 {
|
|
28 Assert.IsFalse(IniSectionParser.IsLineStartOfNewSection("SomeNoneHeader"));
|
|
29 }
|
|
30
|
|
31 [Test()]
|
|
32 public void TestIsLineStartOfNewSectionWithHeaderAndExtraCharactersReturnsFalse()
|
|
33 {
|
|
34 Assert.IsFalse(IniSectionParser.IsLineStartOfNewSection("break[SomeHeader]"));
|
|
35 }
|
|
36
|
|
37 [Test()]
|
|
38 public void TestIsLineStartOfNewSectionWithHeaderAndDifferentExtraCharactersReturnsFalse()
|
|
39 {
|
|
40 Assert.IsFalse(IniSectionParser.IsLineStartOfNewSection("[SomeHeader]fail"));
|
|
41 }
|
|
42
|
|
43
|
|
44 [Test()]
|
|
45 public void TestIsStringAnIniSectionForEmptyIniTextReturnsFalse()
|
|
46 {
|
|
47 Assert.IsFalse(IniSectionParser.IsStringAnIniSection(""));
|
|
48 }
|
|
49
|
|
50 [Test()]
|
|
51 public void TestIsStringAnIniSectionForSingleSectionWithoutValuesReturnsTrue()
|
|
52 {
|
|
53 Assert.IsTrue(IniSectionParser.IsStringAnIniSection("[ASection]"));
|
|
54 }
|
|
55
|
|
56 [Test()]
|
|
57 public void TestIsStringAnIniSectionForSingleSectionWithValueReturnsTrue()
|
|
58 {
|
|
59 Assert.IsTrue(IniSectionParser.IsStringAnIniSection("[ASection]\nsomething=fibble"));
|
|
60 }
|
|
61
|
|
62 [Test()]
|
|
63 public void TestIsStringAnIniSectionForSingleSectionWithMultipleValuesReturnsTrue()
|
|
64 {
|
|
65 Assert.IsTrue(IniSectionParser.IsStringAnIniSection("[ASection]\nsomething=fibble\nfobble_key=foo\nabcde=fghij\nfoo9=bar2"));
|
|
66 }
|
|
67
|
|
68 [Test()]
|
|
69 [ExpectedException("IBBoard.Ini.InvalidIniSectionException")]
|
|
70 public void TestCreateSectionThrowsExceptionForEmptyIniText()
|
|
71 {
|
|
72 IniSectionParser.CreateSection("");
|
|
73 }
|
|
74
|
|
75 [Test()]
|
|
76 [ExpectedException("IBBoard.Ini.InvalidIniSectionException")]
|
|
77 public void TestCreateSectionThrowsExceptionForContentWithoutHeader()
|
|
78 {
|
|
79 IniSectionParser.CreateSection("key=something");
|
|
80 }
|
|
81
|
|
82 [Test()]
|
|
83 [ExpectedException("IBBoard.Ini.InvalidIniSectionException")]
|
|
84 public void TestCreateSectionThrowsExceptionForHeaderWithExtraCharacters()
|
|
85 {
|
|
86 IniSectionParser.CreateSection("abc[header]\nkey=something");
|
|
87 }
|
|
88
|
|
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 }
|
|
97
|
|
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 }
|
|
106
|
|
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);
|
|
114
|
|
115 string[] keys = new string[]{"something", "fobble_key", "abcde", "foo9"};
|
|
116
|
|
117 foreach (string key in keys)
|
|
118 {
|
|
119 bool found = false;
|
|
120
|
|
121 foreach (string sectionKey in section.Keys)
|
|
122 {
|
|
123 if (key == sectionKey)
|
|
124 {
|
|
125 found = true;
|
|
126 break;
|
|
127 }
|
|
128 }
|
|
129
|
|
130 Assert.IsTrue(found, "Did not find "+key);
|
|
131 }
|
|
132 }
|
|
133 }
|
|
134 }
|