-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathStringExtensionsTests.cs
More file actions
128 lines (103 loc) · 3.96 KB
/
StringExtensionsTests.cs
File metadata and controls
128 lines (103 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using NUnit.Framework;
namespace System.IO.Abstractions.TestingHelpers.Tests
{
using XFS = MockUnixSupport;
[TestFixture]
public class StringExtensionsTests
{
[Test]
public void SplitLines_InputWithOneLine_ShouldReturnOnlyOneLine()
{
var input = "This is row one";
var expected = new[] { "This is row one" };
var result = input.SplitLines();
Assert.That(result, Is.EquivalentTo(expected));
}
[Test]
public void SplitLines_InputWithTwoLinesSeparatedWithLf_ShouldReturnBothLines()
{
var input = "This is row one\nThis is row two";
var expected = new[] { "This is row one", "This is row two" };
var result = input.SplitLines();
Assert.That(result, Is.EquivalentTo(expected));
}
[Test]
public void SplitLines_InputWithTwoLinesSeparatedWithCr_ShouldReturnBothLines()
{
var input = "This is row one\rThis is row two";
var expected = new[] { "This is row one", "This is row two" };
var result = input.SplitLines();
Assert.That(result, Is.EquivalentTo(expected));
}
[Test]
public void SplitLines_InputWithTwoLinesSeparatedWithCrLf_ShouldReturnBothLines()
{
var input = "This is row one\r\nThis is row two";
var expected = new[] { "This is row one", "This is row two" };
var result = input.SplitLines();
Assert.That(result, Is.EquivalentTo(expected));
}
[Test]
public void SplitLines_InputWithTwoLinesSeparatedWithAllLineEndings_ShouldReturnAllLines()
{
var input = "one\r\ntwo\rthree\nfour";
var expected = new[] { "one", "two", "three", "four" };
var result = input.SplitLines();
Assert.That(result, Is.EquivalentTo(expected));
}
[Test]
[WindowsOnly(WindowsSpecifics.Drives)]
public void TrimSlashes_DriveRoot_PreserveTrailingSlash()
{
Assert.That(@"c:\".TrimSlashes(), Is.EqualTo(@"c:\"));
}
[Test]
[WindowsOnly(WindowsSpecifics.Drives)]
public void TrimSlashes_DriveRoot_AppendsTrailingSlash()
{
Assert.That(@"c:".TrimSlashes(), Is.EqualTo(@"c:\"));
}
[Test]
[WindowsOnly(WindowsSpecifics.Drives)]
public void TrimSlashes_DriveRoot_TrimsExcessTrailingSlash()
{
Assert.That(@"c:\\".TrimSlashes(), Is.EqualTo(@"c:\"));
}
[Test]
[WindowsOnly(WindowsSpecifics.Drives)]
public void TrimSlashes_DriveRoot_NormalizeAlternateSlash()
{
Assert.That(@"c:/".TrimSlashes(), Is.EqualTo(@"c:\"));
}
[Test]
[WindowsOnly(WindowsSpecifics.Drives)]
public void TrimSlashes_RootedPath_TrimsAllTrailingSlashes()
{
Assert.That(@"c:\x\".TrimSlashes(), Is.EqualTo(@"c:\x"));
}
[Test]
public void TrimSlashes_RootedPath_DoNotAlterPathWithoutTrailingSlashes()
{
Assert.That(XFS.Path(@"c:\x").TrimSlashes(), Is.EqualTo(XFS.Path(@"c:\x")));
}
[Test]
[UnixOnly(UnixSpecifics.SlashRoot)]
public void TrimSlashes_SlashRoot_TrimsExcessTrailingSlash()
{
Assert.That("//".TrimSlashes(), Is.EqualTo("/"));
}
[Test]
[UnixOnly(UnixSpecifics.SlashRoot)]
public void TrimSlashes_SlashRoot_PreserveSlashRoot()
{
Assert.That("/".TrimSlashes(), Is.EqualTo("/"));
}
[TestCase(@"\\unc\folder\file.txt", @"\\unc\folder\file.txt")]
[TestCase(@"//unc/folder/file.txt", @"\\unc\folder\file.txt")]
[WindowsOnly(WindowsSpecifics.UNCPaths)]
public void NormalizeSlashes_KeepsUNCPathPrefix(string path, string expectedValue)
{
Assert.That(path.NormalizeSlashes(), Is.EqualTo(expectedValue));
}
}
}