PageRenderTime 8ms CodeModel.GetById 2ms app.highlight 3ms RepoModel.GetById 0ms app.codeStats 0ms

/AvalonEdit/ICSharpCode.AvalonEdit.Tests/Document/TextUtilitiesTests.cs

http://github.com/icsharpcode/ILSpy
C# | 94 lines | 66 code | 11 blank | 17 comment | 0 complexity | 421425aaede2012714cbd162d5358017 MD5 | raw file
 1// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
 2// 
 3// Permission is hereby granted, free of charge, to any person obtaining a copy of this
 4// software and associated documentation files (the "Software"), to deal in the Software
 5// without restriction, including without limitation the rights to use, copy, modify, merge,
 6// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
 7// to whom the Software is furnished to do so, subject to the following conditions:
 8// 
 9// The above copyright notice and this permission notice shall be included in all copies or
10// substantial portions of the Software.
11// 
12// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17// DEALINGS IN THE SOFTWARE.
18
19using System;
20#if NREFACTORY
21using ICSharpCode.NRefactory.Editor;
22#endif
23using NUnit.Framework;
24
25namespace ICSharpCode.AvalonEdit.Document
26{
27	[TestFixture]
28	public class TextUtilitiesTests
29	{
30		#region GetWhitespaceAfter
31		[Test]
32		public void TestGetWhitespaceAfter()
33		{
34			Assert.AreEqual(new SimpleSegment(2, 3), TextUtilities.GetWhitespaceAfter(new StringTextSource("a \t \tb"), 2));
35		}
36		
37		[Test]
38		public void TestGetWhitespaceAfterDoesNotSkipNewLine()
39		{
40			Assert.AreEqual(new SimpleSegment(2, 3), TextUtilities.GetWhitespaceAfter(new StringTextSource("a \t \tb"), 2));
41		}
42		
43		[Test]
44		public void TestGetWhitespaceAfterEmptyResult()
45		{
46			Assert.AreEqual(new SimpleSegment(2, 0), TextUtilities.GetWhitespaceAfter(new StringTextSource("a b"), 2));
47		}
48		
49		[Test]
50		public void TestGetWhitespaceAfterEndOfString()
51		{
52			Assert.AreEqual(new SimpleSegment(2, 0), TextUtilities.GetWhitespaceAfter(new StringTextSource("a "), 2));
53		}
54		
55		[Test]
56		public void TestGetWhitespaceAfterUntilEndOfString()
57		{
58			Assert.AreEqual(new SimpleSegment(2, 3), TextUtilities.GetWhitespaceAfter(new StringTextSource("a \t \t"), 2));
59		}
60		#endregion
61		
62		#region GetWhitespaceBefore
63		[Test]
64		public void TestGetWhitespaceBefore()
65		{
66			Assert.AreEqual(new SimpleSegment(1, 3), TextUtilities.GetWhitespaceBefore(new StringTextSource("a\t \t b"), 4));
67		}
68		
69		[Test]
70		public void TestGetWhitespaceBeforeDoesNotSkipNewLine()
71		{
72			Assert.AreEqual(new SimpleSegment(2, 1), TextUtilities.GetWhitespaceBefore(new StringTextSource("a\n b"), 3));
73		}
74		
75		[Test]
76		public void TestGetWhitespaceBeforeEmptyResult()
77		{
78			Assert.AreEqual(new SimpleSegment(2, 0), TextUtilities.GetWhitespaceBefore(new StringTextSource(" a b"), 2));
79		}
80		
81		[Test]
82		public void TestGetWhitespaceBeforeStartOfString()
83		{
84			Assert.AreEqual(new SimpleSegment(0, 0), TextUtilities.GetWhitespaceBefore(new StringTextSource(" a"), 0));
85		}
86		
87		[Test]
88		public void TestGetWhitespaceBeforeUntilStartOfString()
89		{
90			Assert.AreEqual(new SimpleSegment(0, 2), TextUtilities.GetWhitespaceBefore(new StringTextSource(" \t a"), 2));
91		}
92		#endregion
93	}
94}