-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathPathHelperTests.cs
More file actions
44 lines (40 loc) · 1.62 KB
/
PathHelperTests.cs
File metadata and controls
44 lines (40 loc) · 1.62 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
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.MSBuildCache.Tests;
[TestClass]
public class PathHelperTests
{
[TestMethod]
[DataRow(@"X:\A\B\C", @"X:\A", @"B\C")]
// Lots of .. and .
[DataRow(@"X:\Z\..\A\B\.\C", @"X:\Y\..\D\..\A\.\.", @"B\C")]
// Equal paths
[DataRow(@"X:\A\B\C", @"X:\A\B\C", @"")]
// Drive root
[DataRow(@"X:\A", @"X:\", @"A")]
// Not relative to the base
[DataRow(@"X:\D\E\F", @"X:\A\B\D", null)]
// Different drives
[DataRow(@"X:\A", @"Y:\", null)]
// Trailing slashes
[DataRow(@"X:\A\B\C\", @"X:\A\", @"B\C\")]
[DataRow(@"X:\A\B\C\", @"X:\A", @"B\C\")]
[DataRow(@"X:\A\B\C", @"X:\A\", @"B\C")]
public void MakePathRelative(string path, string basePath, string? expectedResult)
=> Assert.AreEqual(expectedResult, path.MakePathRelativeTo(basePath));
[TestMethod]
[DataRow(@"X:\A\B\C\file.txt", @"X:\A", true)]
// Lots of .. and .
[DataRow(@"X:\Z\..\A\B\.\C\file.txt", @"X:\Y\..\D\..\A\.\.", true)]
// Drive root
[DataRow(@"X:\A\file.txt", @"X:\", true)]
// Not under the dir
[DataRow(@"X:\D\E\F\file.txt", @"X:\A\B\D", false)]
// Different drives
[DataRow(@"X:\A", @"Y:\", false)]
// Trailing slash
[DataRow(@"X:\A\B\C\file.txt", @"X:\A\B\C\", true)]
public void IsUnderDirectory(string filePath, string directoryPath, bool expectedResult)
=> Assert.AreEqual(expectedResult, filePath.IsUnderDirectory(directoryPath));
}