Skip to content

Commit f5007a7

Browse files
committed
Decide to go for a different xplat path strategy
1 parent 39816e9 commit f5007a7

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Collections.Generic;
2+
using NUnit.Framework;
3+
4+
namespace System.IO.Abstractions.TestingHelpers.Tests
5+
{
6+
[TestFixture]
7+
public class CrossPlatformExtensionsTests
8+
{
9+
[Test]
10+
public void Should_Convert_Backslashes_To_Slashes_On_Unix()
11+
{
12+
Assert.AreEqual("/test/", XFS.Path(@"\test\", () => true));
13+
}
14+
15+
[Test]
16+
public void Should_Remove_Drive_Letter_On_Unix()
17+
{
18+
Assert.AreEqual("/test/", XFS.Path(@"c:\test\", () => true));
19+
}
20+
}
21+
}

TestingHelpers/CrossPlatformExtensions.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Text.RegularExpressions;
23

34
namespace System.IO.Abstractions.TestingHelpers
45
{
@@ -16,5 +17,25 @@ public static string ForUnix(this string path, string unixPath)
1617

1718
return isUnix ? unixPath : path;
1819
}
20+
21+
public static string Path(string path, Func<bool> isUnixF = null)
22+
{
23+
if (isUnixF == null)
24+
{
25+
isUnixF = () =>
26+
{
27+
int p = (int)Environment.OSVersion.Platform;
28+
return (p == 4) || (p == 6) || (p == 128);
29+
};
30+
}
31+
32+
if (isUnixF())
33+
{
34+
path = Regex.Replace(path, @"^[a-zA-Z]:(?<path>.*)$", "${path}");
35+
path = path.Replace(@"\", "/");
36+
}
37+
38+
return path;
39+
}
1940
}
2041
}

0 commit comments

Comments
 (0)