bovender framework
C# framework that implements MVVM and more
MultilineTest.cs
1 /* MultilineTest.cs
2  * part of Daniel's XL Toolbox NG
3  *
4  * Copyright 2014-2018 Daniel Kraus
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 using System;
19 using System.Collections.Generic;
20 using System.Linq;
21 using System.Text;
22 using NUnit.Framework;
23 using Bovender.Text;
24 
25 namespace Bovender.UnitTests.Text
26 {
27  [TestFixture]
29  {
30  Multiline _multiline;
31 
32  [SetUp]
33  public void SetUp()
34  {
35  _multiline = new Multiline();
36  }
37 
38  [Test]
39  public void EmptyText()
40  {
41  Assert.AreEqual(String.Empty, _multiline.Text);
42  }
43 
44  [Test]
45  public void NormalLines()
46  {
47  _multiline.AddLine("Hello");
48  _multiline.AddLine("World");
49  Assert.AreEqual("Hello World", _multiline.Text);
50  }
51 
52  [Test]
53  public void LinesWithSpaceAtEnd()
54  {
55  _multiline.AddLine("Hello ");
56  _multiline.AddLine("World");
57  Assert.AreEqual("Hello World", _multiline.Text);
58  }
59 
60  [Test]
61  public void LinesWithLineBreaksAtEnd()
62  {
63  _multiline.AddLine("Hello\r\n\r\n\r\n");
64  _multiline.AddLine("World");
65  Assert.AreEqual("Hello World", _multiline.Text);
66  }
67 
68  [Test]
69  public void EmptyLinesInbetween()
70  {
71  _multiline.AddLine("Hello");
72  _multiline.AddLine("");
73  _multiline.AddLine("World");
74  Assert.AreEqual(3, _multiline.NumberOfLines);
75  }
76 
77  [Test]
78  public void UnorderedListItems()
79  {
80  _multiline.AddLine("Hello");
81  _multiline.AddLine("- This is an unordered list item");
82  _multiline.AddLine(" - and this is one with more indent");
83  _multiline.AddLine("* List item with asterisk");
84  _multiline.AddLine("World");
85  Assert.AreEqual(5, _multiline.NumberOfLines);
86  }
87 
88  [Test]
89  public void UnorderedListItemsSeveralLines()
90  {
91  _multiline.AddLine("Hello");
92  _multiline.AddLine(" - This is an unordered list item with indent");
93  _multiline.AddLine(" that continues into the next line.");
94  _multiline.AddLine(" * And this is another one");
95  _multiline.AddLine(" that also continues into the next line.");
96  _multiline.AddLine("World");
97  Assert.AreEqual(4, _multiline.NumberOfLines);
98  }
99 
100  [Test]
101  public void OrderedListItems()
102  {
103  _multiline.AddLine("Hello");
104  _multiline.AddLine("1. This is an unordered list item");
105  _multiline.AddLine(" 19) and this is one with more indent");
106  _multiline.AddLine("World");
107  Assert.AreEqual(4, _multiline.NumberOfLines);
108  }
109 
110  [Test]
111  public void IndentedLines()
112  {
113  _multiline.AddLine("The first two lines");
114  _multiline.AddLine("share the same indent.");
115  _multiline.AddLine(" Then there are two lines");
116  _multiline.AddLine(" that are indented by two spaces.");
117  _multiline.AddLine("And finally a line without indent.");
118  Assert.AreEqual(3, _multiline.NumberOfLines);
119  }
120 
121  [Test]
122  public void UnixLineSeparator()
123  {
124  _multiline.Add("This\nis\na\nUnix\ntext");
125  Assert.AreEqual("This is a Unix text", _multiline.Text);
126  }
127 
128  [Test]
129  public void MixedLineSeparators()
130  {
131  string[] lines = new string[]
132  {
133  "This test string", // 0
134  "has several lines with", // 1
135  "various different", // 2
136  "line endings, but mostly", // 3
137  "Windows-style line endings", // 4
138  "which consist of a sequence", // 5
139  "of CR+LF." // 6
140  };
141  string expected = String.Join(" ", lines);
142  string testText =
143  lines[0] + "\r\n" +
144  lines[1] + "\n" +
145  lines[2] + "\n" +
146  lines[3] + "\r\n" +
147  lines[4] + "\r\n" +
148  lines[5] + "\r" +
149  lines[6];
150  _multiline.Add(testText);
151  Assert.AreEqual(expected, _multiline.Text);
152  }
153 
154  [Test]
155  public void IgnoreComments()
156  {
157  _multiline.IgnoreHashedComments = true;
158  _multiline.AddLine("This line ends # with a comment");
159  _multiline.AddLine("# This line should be completeley ignored");
160  _multiline.AddLine("beautifully.");
161  Assert.AreEqual("This line ends beautifully.", _multiline.Text);
162  }
163  }
164 }
Represents a text with multiple lines.
Definition: Multiline.cs:31
bool IgnoreHashedComments
Indicates whether or not to ignore comments that are marked with a hash (#).
Definition: Multiline.cs:63
void AddLine(string line)
Adds an individual line.
Definition: Multiline.cs:99
string Text
Gets the multiline text as a single string.
Definition: Multiline.cs:39
void Add(string text)
Adds text to the multiline text.
Definition: Multiline.cs:75