Skip to content

Commit

Permalink
Add some dos directory resolving tests (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
JorisVanEijden authored and maximilien-noal committed Jul 6, 2023
1 parent 7320705 commit 15786a6
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
106 changes: 106 additions & 0 deletions src/Spice86.Tests/DosPathResolverTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
namespace Spice86.Tests;

using FluentAssertions;

using Moq;

using Spice86.Core.CLI;
using Spice86.Core.Emulator.OperatingSystem;
using Spice86.Shared.Interfaces;
using Spice86.Shared.Utils;

using Xunit;

public class DosPathResolverTests {
private static readonly string MountPoint = Path.GetFullPath(@"Resources\MountPoint");

[Theory]
[InlineData(@"bar", @"/foo/bar")]
[InlineData(@"bar/", @"/foo/bar/")]
[InlineData(@"bar\", @"/foo/bar/")]
[InlineData(@"BAR", @"/foo/bar")]
[InlineData(@".\bAr", @"/foo/bar")]
[InlineData(@".\bAr\nothere", @"")]
[InlineData(@".", @"/foo")]
[InlineData(@".\", @"/foo")]
[InlineData(@"..\", @"")]
[InlineData(@"..", @"")]
[InlineData(@"d:\foo\bar", @"/foo/bar")]
[InlineData(@"d:bar", @"/foo/bar")]
public void SetCurrentDir(string newCurrentDir, string expected) {
// Arrange
DosPathResolver dosPathResolver = ArrangeDosPathResolver('D', @"foo");

// Act
dosPathResolver.SetCurrentDir(newCurrentDir);

// Assert
string actual = dosPathResolver.CurrentHostDirectory.Replace(ConvertUtils.ToSlashPath(MountPoint), "");
Assert.Equal(expected, actual);
}

[Theory]
[InlineData(@"bar")]
[InlineData(@"BAR")]
[InlineData(@"BAR\")]
[InlineData(@"BAR/")]
[InlineData(@"../foo/BAR")]
[InlineData(@"..\foo\BAR")]
[InlineData(@"./BAR")]
[InlineData(@".\BAR")]
[InlineData(@"D:BAR")]
[InlineData(@"D:BAR\")]
[InlineData(@"D:BAR/")]
[InlineData(@"D:\bar\..\Foo")]
public void RelativePaths(string dosPath) {
// Arrange
DosPathResolver dosPathResolver = ArrangeDosPathResolver('D', @"foo");

// Act
string? actual = dosPathResolver.TryGetFullHostPath(dosPath);

// Assert
actual.Should().NotBeNull($"'{dosPath}' should be resolvable");
Directory.Exists(actual).Should().BeTrue();
}

[Theory]
[InlineData(@"\FoO")]
[InlineData(@"/FOo")]
[InlineData(@"/fOO/")]
[InlineData(@"/Foo\")]
[InlineData(@"\FoO\")]
[InlineData(@"D:\FoO\BAR\")]
public void AbsolutePaths(string dosPath) {
// Arrange
DosPathResolver dosPathResolver = ArrangeDosPathResolver('D', @"foo");
string? actual = dosPathResolver.TryGetFullHostPath(dosPath);

// Assert
actual.Should().NotBeNull($"'{dosPath}' should be resolvable");
Directory.Exists(actual).Should().BeTrue();
}

[Theory]
[InlineData(@"E:\FolDeR")]
[InlineData(@"bAr")]
public void MultipleDrives(string dosPath) {
// Arrange
DosPathResolver dosPathResolver = ArrangeDosPathResolver('D', @"foo");
dosPathResolver.DriveMap.Add('E', new MountedFolder('E', Path.GetFullPath(@"Resources\MountPoint\drive2")));
string? actual = dosPathResolver.TryGetFullHostPath(dosPath);

// Assert
actual.Should().NotBeNull($"'{dosPath}' should be resolvable");
Directory.Exists(actual).Should().BeTrue();
}

private static DosPathResolver ArrangeDosPathResolver(char currentDriveLetter, string currentDosPath) {
var loggerService = new Mock<ILoggerService>();
var configuration = new Configuration {CDrive = MountPoint};
var dosPathResolver = new DosPathResolver(loggerService.Object, configuration);
dosPathResolver.DriveMap.Add(currentDriveLetter, new MountedFolder(currentDriveLetter, MountPoint));
dosPathResolver.SetCurrentDir(currentDosPath);
return dosPathResolver;
}
}
2 changes: 2 additions & 0 deletions src/Spice86.Tests/Resources/MountPoint/drive2/folder/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Lorem ipsum dolor sit amet
consectetur adipiscing elit
2 changes: 2 additions & 0 deletions src/Spice86.Tests/Resources/MountPoint/foo/bar/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Lorem ipsum dolor sit amet
consectetur adipiscing elit

0 comments on commit 15786a6

Please sign in to comment.