|
| 1 | +using System.IO; |
| 2 | +using System.Linq; |
| 3 | +using FluentAssertions; |
| 4 | +using KS.RustAnalyzer.TestAdapter.Cargo; |
| 5 | +using KS.RustAnalyzer.Tests.Common; |
| 6 | +using Xunit; |
| 7 | + |
| 8 | +namespace KS.RustAnalyzer.TestAdapter.UnitTests.Cargo; |
| 9 | + |
| 10 | +public class ManifestExtensionsTests |
| 11 | +{ |
| 12 | + [Theory] |
| 13 | + [InlineData(@"not_a_project\src\main.rs", "not_a_project", @"not_a_project\Cargo.toml", false)] |
| 14 | + [InlineData(@"not_a_project\src", "not_a_project", @"not_a_project\Cargo.toml", false)] |
| 15 | + [InlineData(@"hello_library\src\lib.rs", "hello_library", @"hello_library\Cargo.toml", true)] |
| 16 | + [InlineData(@"hello_library\Cargo.toml", "hello_library", @"hello_library\Cargo.toml", true)] |
| 17 | + [InlineData(@"hello_workspace\main\src\main.rs", "hello_workspace", @"hello_workspace\main\Cargo.toml", true)] |
| 18 | + [InlineData(@"hello_workspace\main\src", "hello_workspace", @"hello_workspace\main\Cargo.toml", true)] |
| 19 | + [InlineData(@"hello_workspace\main\Cargo.toml", "hello_workspace", @"hello_workspace\main\Cargo.toml", true)] |
| 20 | + [InlineData(@"workspace_with_example\lib\examples\eg1.rs", "workspace_with_example", @"workspace_with_example\lib\Cargo.toml", true)] |
| 21 | + [InlineData(@"c:\workspace_with_example\lib\examples\eg1.rs", "workspace_with_example", null, false)] |
| 22 | + public void GetContainingManifestOrThisTests(string fileOrFolder, string workspaceRootx, string parentCargoRelPath, bool foundParentManifest) |
| 23 | + { |
| 24 | + string path = Path.Combine(TestHelpers.ThisTestRoot, fileOrFolder); |
| 25 | + var workspaceRoot = Path.Combine(TestHelpers.ThisTestRoot, workspaceRootx); |
| 26 | + var found = path.TryGetParentManifestOrThisUnderWorkspace(workspaceRoot, out string parentCargoPath); |
| 27 | + |
| 28 | + found.Should().Be(foundParentManifest); |
| 29 | + var expectedParentManifestpath = found ? Path.Combine(TestHelpers.ThisTestRoot, parentCargoRelPath) : null; |
| 30 | + parentCargoPath.Should().Be(expectedParentManifestpath); |
| 31 | + } |
| 32 | + |
| 33 | + [Theory] |
| 34 | + [InlineData(@"not_a_project\src\main.rs", "not_a_project", false)] |
| 35 | + [InlineData(@"hello_library\src\lib.rs", "hello_library", false)] |
| 36 | + [InlineData(@"hello_library\Cargo.toml", "hello_library", false)] |
| 37 | + [InlineData(@"hello_workspace\main\src\main.rs", "hello_workspace", false)] |
| 38 | + [InlineData(@"hello_workspace\main\Cargo.toml", "hello_workspace", true)] |
| 39 | + [InlineData(@"workspace_with_example\lib\examples\eg1.rs", "workspace_with_example", true)] |
| 40 | + [InlineData(@"workspace_with_example\lib\examples\eg2\main.rs", "workspace_with_example", true)] |
| 41 | + [InlineData(@"workspace_with_example\lib\examples\eg2\utils.rs", "workspace_with_example", false)] |
| 42 | + [InlineData(@"does_not_exist\workspace_with_example\lib\examples\eg1.rs", "does_not_exist", false)] |
| 43 | + public void CanHaveExecutableTargetsTests(string relativePath, string relWorkspaceRoot, bool canHaveExecutableTargets) |
| 44 | + { |
| 45 | + var filePath = Path.Combine(TestHelpers.ThisTestRoot, relativePath); |
| 46 | + var workspaceRoot = Path.Combine(TestHelpers.ThisTestRoot, relWorkspaceRoot); |
| 47 | + |
| 48 | + var res = filePath.CanHaveExecutableTargets(workspaceRoot); |
| 49 | + |
| 50 | + res.Should().Be(canHaveExecutableTargets); |
| 51 | + } |
| 52 | +} |
0 commit comments