Add cleaner cleaning tests

This commit is contained in:
Matt Nadareski
2020-12-18 23:06:28 -08:00
parent 518ec31c25
commit 1cee8adc59
3 changed files with 179 additions and 1 deletions

View File

@@ -123,7 +123,7 @@ namespace SabreTools.Filtering
/// <summary>
/// Logging object
/// </summary>
private Logger logger = new Logger();
private readonly Logger logger = new Logger();
#endregion
@@ -140,6 +140,10 @@ namespace SabreTools.Filtering
ExcludeMachineFields ??= new List<MachineField>();
ExcludeDatItemFields ??= new List<DatItemField>();
// If the list is null or empty, just return
if (fields == null || fields.Count == 0)
return;
foreach (string field in fields)
{
// If we don't even have a possible field name
@@ -186,6 +190,10 @@ namespace SabreTools.Filtering
MachineFilter ??= new MachineFilter();
DatItemFilter ??= new DatItemFilter();
// If the list is null or empty, just return
if (filters == null || filters.Count == 0)
return;
foreach (string filterPair in filters)
{
(string field, string value, bool negate) = ProcessFilterPair(filterPair);

View File

@@ -0,0 +1,169 @@
using System.Collections.Generic;
using SabreTools.Filtering;
using Xunit;
namespace SabreTools.Test.Filtering
{
public class CleanerPopulationTests
{
[Fact]
public void PopulateExclusionNullListTest()
{
// Setup the list
List<string> exclusions = null;
// Setup the cleaner
var cleaner = new Cleaner();
cleaner.PopulateExclusionsFromList(exclusions);
// Check the exclusion lists
Assert.Empty(cleaner.ExcludeDatHeaderFields);
Assert.Empty(cleaner.ExcludeMachineFields);
Assert.Empty(cleaner.ExcludeDatItemFields);
}
[Fact]
public void PopulateExclusionEmptyListTest()
{
// Setup the list
List<string> exclusions = new List<string>();
// Setup the cleaner
var cleaner = new Cleaner();
cleaner.PopulateExclusionsFromList(exclusions);
// Check the exclusion lists
Assert.Empty(cleaner.ExcludeDatHeaderFields);
Assert.Empty(cleaner.ExcludeMachineFields);
Assert.Empty(cleaner.ExcludeDatItemFields);
}
[Fact]
public void PopulateExclusionHeaderFieldTest()
{
// Setup the list
List<string> exclusions = new List<string>
{
"header.datname",
};
// Setup the cleaner
var cleaner = new Cleaner();
cleaner.PopulateExclusionsFromList(exclusions);
// Check the exclusion lists
Assert.Single(cleaner.ExcludeDatHeaderFields);
Assert.Empty(cleaner.ExcludeMachineFields);
Assert.Empty(cleaner.ExcludeDatItemFields);
}
[Fact]
public void PopulateExclusionMachineFieldTest()
{
// Setup the list
List<string> exclusions = new List<string>
{
"machine.name",
};
// Setup the cleaner
var cleaner = new Cleaner();
cleaner.PopulateExclusionsFromList(exclusions);
// Check the exclusion lists
Assert.Empty(cleaner.ExcludeDatHeaderFields);
Assert.Single(cleaner.ExcludeMachineFields);
Assert.Empty(cleaner.ExcludeDatItemFields);
}
[Fact]
public void PopulateExclusionDatItemFieldTest()
{
// Setup the list
List<string> exclusions = new List<string>
{
"item.name",
};
// Setup the cleaner
var cleaner = new Cleaner();
cleaner.PopulateExclusionsFromList(exclusions);
// Check the exclusion lists
Assert.Empty(cleaner.ExcludeDatHeaderFields);
Assert.Empty(cleaner.ExcludeMachineFields);
Assert.Single(cleaner.ExcludeDatItemFields);
}
[Fact]
public void PopulateFilterNullListTest()
{
// Setup the list
List<string> filters = null;
// Setup the cleaner
var cleaner = new Cleaner();
cleaner.PopulateFiltersFromList(filters);
// Check the filters
Assert.NotNull(cleaner.MachineFilter);
Assert.NotNull(cleaner.DatItemFilter);
}
[Fact]
public void PopulateFilterEmptyListTest()
{
// Setup the list
List<string> filters = new List<string>();
// Setup the cleaner
var cleaner = new Cleaner();
cleaner.PopulateFiltersFromList(filters);
// Check the filters
Assert.NotNull(cleaner.MachineFilter);
Assert.NotNull(cleaner.DatItemFilter);
}
[Fact]
public void PopulateFilterMachineFieldTest()
{
// Setup the list
List<string> filters = new List<string>
{
"machine.name:foo",
"!machine.name:bar",
};
// Setup the cleaner
var cleaner = new Cleaner();
cleaner.PopulateFiltersFromList(filters);
// Check the filters
Assert.Contains("foo", cleaner.MachineFilter.Name.PositiveSet);
Assert.Contains("bar", cleaner.MachineFilter.Name.NegativeSet);
Assert.NotNull(cleaner.DatItemFilter);
}
[Fact]
public void PopulateFilterDatItemFieldTest()
{
// Setup the list
List<string> filters = new List<string>
{
"item.name:foo",
"!item.name:bar"
};
// Setup the cleaner
var cleaner = new Cleaner();
cleaner.PopulateFiltersFromList(filters);
// Check the filters
Assert.NotNull(cleaner.MachineFilter);
Assert.Contains("foo", cleaner.DatItemFilter.Name.PositiveSet);
Assert.Contains("bar", cleaner.DatItemFilter.Name.NegativeSet);
}
}
}

View File

@@ -7,6 +7,7 @@
<ItemGroup>
<ProjectReference Include="..\SabreTools.Core\SabreTools.Core.csproj" />
<ProjectReference Include="..\SabreTools.Filtering\SabreTools.Filtering.csproj" />
<ProjectReference Include="..\SabreTools.IO\SabreTools.IO.csproj" />
<ProjectReference Include="..\SabreTools.Skippers\SabreTools.Skippers.csproj" />
</ItemGroup>