47 lines
1.5 KiB
C#
47 lines
1.5 KiB
C#
using FluentAssertions;
|
|
using FreeCode.Tools;
|
|
using FreeCode.Tests.Unit.Helpers;
|
|
using Xunit;
|
|
|
|
namespace FreeCode.Tests.Unit.Tools;
|
|
|
|
public sealed class GlobToolTests : IDisposable
|
|
{
|
|
private readonly string _tempDirectory = Path.Combine(Path.GetTempPath(), "free-code-tests", Guid.NewGuid().ToString("N"));
|
|
private readonly GlobTool _sut = new();
|
|
|
|
public GlobToolTests()
|
|
{
|
|
Directory.CreateDirectory(Path.Combine(_tempDirectory, "sub"));
|
|
File.WriteAllText(Path.Combine(_tempDirectory, "alpha.txt"), "a");
|
|
File.WriteAllText(Path.Combine(_tempDirectory, "sub", "beta.txt"), "b");
|
|
File.WriteAllText(Path.Combine(_tempDirectory, "sub", "gamma.cs"), "c");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ExecuteAsync_FindsMatchingFiles()
|
|
{
|
|
var result = await _sut.ExecuteAsync(new GlobToolInput("**/*.txt", _tempDirectory), TestHelper.CreateContext());
|
|
|
|
result.IsError.Should().BeFalse();
|
|
result.Data.Matches.Should().ContainSingle(path => path.EndsWith("beta.txt", StringComparison.Ordinal));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ExecuteAsync_WithNoMatches_ReturnsEmpty()
|
|
{
|
|
var result = await _sut.ExecuteAsync(new GlobToolInput("**/*.md", _tempDirectory), TestHelper.CreateContext());
|
|
|
|
result.IsError.Should().BeFalse();
|
|
result.Data.Matches.Should().BeEmpty();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
if (Directory.Exists(_tempDirectory))
|
|
{
|
|
Directory.Delete(_tempDirectory, recursive: true);
|
|
}
|
|
}
|
|
}
|