mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-27 00:07:58 +01:00
* Make AllowedType more flexible * Add test cases for passing empty/null strings to IsAllowed
This commit is contained in:
@@ -94,14 +94,22 @@ namespace Terminal.Gui {
|
||||
/// <inheritdoc/>
|
||||
public bool IsAllowed(string path)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var extension = Path.GetExtension (path);
|
||||
|
||||
if(this.Extensions.Any(e=>path.EndsWith(e, StringComparison.InvariantCultureIgnoreCase))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// There is a requirement to have a particular extension and we have none
|
||||
if (string.IsNullOrEmpty (extension)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.Extensions.Any (e => e.Equals (extension));
|
||||
return this.Extensions.Any (e => e.Equals (extension, StringComparison.InvariantCultureIgnoreCase));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -481,6 +481,37 @@ namespace Terminal.Gui.FileServicesTests {
|
||||
};
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (".csv", null, false)]
|
||||
[InlineData (".csv", "", false)]
|
||||
[InlineData (".csv", "c:\\MyFile.csv", true)]
|
||||
[InlineData (".csv", "c:\\MyFile.CSV", true)]
|
||||
[InlineData (".csv", "c:\\MyFile.csv.bak", false)]
|
||||
public void TestAllowedType_Basic(string allowed, string candidate, bool expected)
|
||||
{
|
||||
Assert.Equal (expected, new AllowedType ("Test", allowed).IsAllowed (candidate));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData ("Dockerfile", "c:\\temp\\Dockerfile", true)]
|
||||
[InlineData ("Dockerfile", "Dockerfile", true)]
|
||||
[InlineData ("Dockerfile", "someimg.Dockerfile", true)]
|
||||
public void TestAllowedType_SpecificFile(string allowed, string candidate, bool expected)
|
||||
{
|
||||
Assert.Equal (expected, new AllowedType ("Test", allowed).IsAllowed (candidate));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (".Designer.cs", "c:\\MyView.Designer.cs", true)]
|
||||
[InlineData (".Designer.cs", "c:\\temp/MyView.Designer.cs", true)]
|
||||
[InlineData(".Designer.cs","MyView.Designer.cs",true)]
|
||||
[InlineData (".Designer.cs", "c:\\MyView.DESIGNER.CS", true)]
|
||||
[InlineData (".Designer.cs", "MyView.cs", false)]
|
||||
public void TestAllowedType_DoubleBarreled (string allowed, string candidate, bool expected)
|
||||
{
|
||||
Assert.Equal (expected, new AllowedType ("Test", allowed).IsAllowed (candidate));
|
||||
}
|
||||
|
||||
[Theory, AutoInitShutdown]
|
||||
[InlineData (true)]
|
||||
[InlineData (false)]
|
||||
|
||||
Reference in New Issue
Block a user