mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
* Refactor FileDialogTreeBuilder to be more generally useful outside of dialog context * Fix comparer * Change TreeViewFileSystem scenario to use the core builder * Refactor icon provision for reusability * Add IsOpenGetter implementations * Xmldoc and tests * xmldoc and trim icon when blank (files and no nerd) * unit test fixes * FixFix unit tests when running on linux * Add option to pick which icon set to use for TreeViewFileSystem * Add spaces when using nerd to avoid icon overaps * Refactor the addition of space for nerd icons to reduce code duplication
81 lines
2.2 KiB
C#
81 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO.Abstractions;
|
|
using System.IO.Abstractions.TestingHelpers;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Xunit;
|
|
|
|
namespace Terminal.Gui.FileServicesTests {
|
|
public class FileSystemIconProviderTests {
|
|
[Fact]
|
|
public void FlagsShouldBeMutuallyExclusive()
|
|
{
|
|
var p = new FileSystemIconProvider {
|
|
UseUnicodeCharacters = false,
|
|
UseNerdIcons = false
|
|
};
|
|
|
|
Assert.False (p.UseUnicodeCharacters);
|
|
Assert.False (p.UseNerdIcons);
|
|
|
|
p.UseUnicodeCharacters = true;
|
|
|
|
Assert.True (p.UseUnicodeCharacters);
|
|
Assert.False (p.UseNerdIcons);
|
|
|
|
// Cannot use both nerd and unicode so unicode should have switched off
|
|
p.UseNerdIcons = true;
|
|
|
|
Assert.True (p.UseNerdIcons);
|
|
Assert.False (p.UseUnicodeCharacters);
|
|
|
|
// Cannot use both unicode and nerd so now nerd should have switched off
|
|
p.UseUnicodeCharacters = true;
|
|
|
|
Assert.True (p.UseUnicodeCharacters);
|
|
Assert.False (p.UseNerdIcons);
|
|
}
|
|
|
|
[Fact]
|
|
public void TestBasicIcons ()
|
|
{
|
|
var p = new FileSystemIconProvider ();
|
|
var fs = GetMockFileSystem ();
|
|
|
|
Assert.Equal(IsWindows() ? new Rune('\\') : new Rune('/'), p.GetIcon(fs.DirectoryInfo.New(@"c:\")));
|
|
|
|
Assert.Equal (new Rune (' '), p.GetIcon (
|
|
fs.FileInfo.New (GetFileSystemRoot() + @"myfile.txt"))
|
|
);
|
|
}
|
|
private bool IsWindows ()
|
|
{
|
|
return System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform (System.Runtime.InteropServices.OSPlatform.Windows);
|
|
}
|
|
|
|
private IFileSystem GetMockFileSystem()
|
|
{
|
|
string root = GetFileSystemRoot();
|
|
|
|
var fileSystem = new MockFileSystem (new Dictionary<string, MockFileData> (), root);
|
|
|
|
fileSystem.AddFile (root+@"myfile.txt", new MockFileData ("Testing is meh."));
|
|
fileSystem.AddFile (root+@"demo/jQuery.js", new MockFileData ("some js"));
|
|
fileSystem.AddFile (root+@"demo/mybinary.exe", new MockFileData ("some js"));
|
|
fileSystem.AddFile (root+@"demo/image.gif", new MockFileData (new byte [] { 0x12, 0x34, 0x56, 0xd2 }));
|
|
|
|
var m = (MockDirectoryInfo)fileSystem.DirectoryInfo.New (root + @"demo/subfolder");
|
|
m.Create ();
|
|
|
|
return fileSystem;
|
|
}
|
|
|
|
private string GetFileSystemRoot ()
|
|
{
|
|
return IsWindows () ? @"c:\" : "/";
|
|
}
|
|
}
|
|
}
|