mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
Normalize string to fix test case on Unix (#1841)
This commit is contained in:
@@ -76,5 +76,25 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Normalizes Windows, Unix, and mixed paths to the same slash direction, specified by <paramref name="separatorType"/>
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="separatorType">Win32NT for \, Unix for /</param>
|
||||
/// <returns></returns>
|
||||
public static string NormalizePath(string path, PlatformID separatorType)
|
||||
{
|
||||
return separatorType switch
|
||||
{
|
||||
PlatformID.Win32NT => path.Contains('/')
|
||||
? String.Join('\\', path.Split('/', StringSplitOptions.RemoveEmptyEntries))
|
||||
: path,
|
||||
PlatformID.Unix => path.Contains('\\')
|
||||
? String.Join('/', path.Split('\\', StringSplitOptions.RemoveEmptyEntries))
|
||||
: path,
|
||||
_ => throw new ArgumentException($"{nameof(separatorType)} must be either {PlatformID.Win32NT} or {PlatformID.Unix}, but {separatorType} was passed."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user