/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. using System;
  19. #if NREFACTORY
  20. using ICSharpCode.NRefactory.Editor;
  21. #endif
  22. using NUnit.Framework;
  23. namespace ICSharpCode.AvalonEdit.Document
  24. {
  25. [TestFixture]
  26. public class TextUtilitiesTests
  27. {
  28. #region GetWhitespaceAfter
  29. [Test]
  30. public void TestGetWhitespaceAfter()
  31. {
  32. Assert.AreEqual(new SimpleSegment(2, 3), TextUtilities.GetWhitespaceAfter(new StringTextSource("a \t \tb"), 2));
  33. }
  34. [Test]
  35. public void TestGetWhitespaceAfterDoesNotSkipNewLine()
  36. {
  37. Assert.AreEqual(new SimpleSegment(2, 3), TextUtilities.GetWhitespaceAfter(new StringTextSource("a \t \tb"), 2));
  38. }
  39. [Test]
  40. public void TestGetWhitespaceAfterEmptyResult()
  41. {
  42. Assert.AreEqual(new SimpleSegment(2, 0), TextUtilities.GetWhitespaceAfter(new StringTextSource("a b"), 2));
  43. }
  44. [Test]
  45. public void TestGetWhitespaceAfterEndOfString()
  46. {
  47. Assert.AreEqual(new SimpleSegment(2, 0), TextUtilities.GetWhitespaceAfter(new StringTextSource("a "), 2));
  48. }
  49. [Test]
  50. public void TestGetWhitespaceAfterUntilEndOfString()
  51. {
  52. Assert.AreEqual(new SimpleSegment(2, 3), TextUtilities.GetWhitespaceAfter(new StringTextSource("a \t \t"), 2));
  53. }
  54. #endregion
  55. #region GetWhitespaceBefore
  56. [Test]
  57. public void TestGetWhitespaceBefore()
  58. {
  59. Assert.AreEqual(new SimpleSegment(1, 3), TextUtilities.GetWhitespaceBefore(new StringTextSource("a\t \t b"), 4));
  60. }
  61. [Test]
  62. public void TestGetWhitespaceBeforeDoesNotSkipNewLine()
  63. {
  64. Assert.AreEqual(new SimpleSegment(2, 1), TextUtilities.GetWhitespaceBefore(new StringTextSource("a\n b"), 3));
  65. }
  66. [Test]
  67. public void TestGetWhitespaceBeforeEmptyResult()
  68. {
  69. Assert.AreEqual(new SimpleSegment(2, 0), TextUtilities.GetWhitespaceBefore(new StringTextSource(" a b"), 2));
  70. }
  71. [Test]
  72. public void TestGetWhitespaceBeforeStartOfString()
  73. {
  74. Assert.AreEqual(new SimpleSegment(0, 0), TextUtilities.GetWhitespaceBefore(new StringTextSource(" a"), 0));
  75. }
  76. [Test]
  77. public void TestGetWhitespaceBeforeUntilStartOfString()
  78. {
  79. Assert.AreEqual(new SimpleSegment(0, 2), TextUtilities.GetWhitespaceBefore(new StringTextSource(" \t a"), 2));
  80. }
  81. #endregion
  82. }
  83. }