Normalize string to fix test case on Unix (#1841)

This commit is contained in:
Benjin Dubishar
2023-02-01 14:30:28 -08:00
committed by GitHub
parent 07e4225259
commit 2e950f54bd
3 changed files with 24 additions and 1 deletions

View File

@@ -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."),
};
}
}
}