2018-11-06 23:25:35 +00:00
|
|
|
|
using FluentAssertions;
|
2017-09-06 05:57:45 +00:00
|
|
|
|
using PKHeX.Core;
|
2018-11-06 23:25:35 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using Xunit;
|
2017-09-06 05:57:45 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.Tests.Legality
|
|
|
|
|
{
|
|
|
|
|
public class LegalityTest
|
|
|
|
|
{
|
2018-05-27 22:57:28 +00:00
|
|
|
|
static LegalityTest()
|
|
|
|
|
{
|
|
|
|
|
if (!EncounterEvent.Initialized)
|
|
|
|
|
EncounterEvent.RefreshMGDB();
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-06 23:25:35 +00:00
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData("censor")]
|
|
|
|
|
[InlineData("buttnugget")]
|
|
|
|
|
[InlineData("18넘")]
|
|
|
|
|
public void CensorsBadWords(string badword)
|
2018-11-20 00:14:49 +00:00
|
|
|
|
{
|
|
|
|
|
WordFilter.IsFiltered(badword, out _).Should().BeTrue("the word should have been identified as a bad word");
|
2017-09-06 05:57:45 +00:00
|
|
|
|
}
|
2017-11-18 00:00:22 +00:00
|
|
|
|
|
2018-11-06 23:25:35 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void TestFilesPassOrFailLegalityChecks()
|
2017-11-18 00:00:22 +00:00
|
|
|
|
{
|
|
|
|
|
var folder = Directory.GetCurrentDirectory();
|
|
|
|
|
while (!folder.EndsWith(nameof(Tests)))
|
|
|
|
|
folder = Directory.GetParent(folder).FullName;
|
|
|
|
|
|
|
|
|
|
folder = Path.Combine(folder, "Legality");
|
2018-10-06 02:58:30 +00:00
|
|
|
|
ParseSettings.AllowGBCartEra = true;
|
2017-11-18 00:00:22 +00:00
|
|
|
|
VerifyAll(folder, "Legal", true);
|
2017-11-18 04:02:01 +00:00
|
|
|
|
VerifyAll(folder, "Illegal", false);
|
2017-11-18 00:00:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ReSharper disable once UnusedParameter.Local
|
2018-11-06 23:25:35 +00:00
|
|
|
|
private static void VerifyAll(string folder, string name, bool isValid)
|
2017-11-18 00:00:22 +00:00
|
|
|
|
{
|
|
|
|
|
var path = Path.Combine(folder, name);
|
2018-11-06 23:25:35 +00:00
|
|
|
|
Directory.Exists(path).Should().BeTrue($"the specified test directory at '{path}' should exist");
|
2017-11-18 00:00:22 +00:00
|
|
|
|
var files = Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories);
|
|
|
|
|
foreach (var file in files)
|
|
|
|
|
{
|
|
|
|
|
var fi = new FileInfo(file);
|
2018-11-06 23:25:35 +00:00
|
|
|
|
fi.Should().NotBeNull($"the test file '{file}' should be a valid file");
|
|
|
|
|
PKX.IsPKM(fi.Length).Should().BeTrue($"the test file '{file}' should have a valid file length");
|
2017-11-18 00:00:22 +00:00
|
|
|
|
|
|
|
|
|
var data = File.ReadAllBytes(file);
|
2018-04-21 21:38:18 +00:00
|
|
|
|
var format = PKX.GetPKMFormatFromExtension(file[file.Length - 1], -1);
|
2019-02-15 08:50:23 +00:00
|
|
|
|
format.Should().BeLessOrEqualTo(PKX.Generation, "filename is expected to have a valid extension");
|
2017-11-18 00:00:22 +00:00
|
|
|
|
var pkm = PKMConverter.GetPKMfromBytes(data, prefer: format);
|
2019-02-01 06:01:31 +00:00
|
|
|
|
pkm.Should().NotBeNull($"the PKM '{new FileInfo(file).Name}' should have been loaded");
|
2017-11-18 00:00:22 +00:00
|
|
|
|
|
2018-10-06 02:58:30 +00:00
|
|
|
|
ParseSettings.AllowGBCartEra = fi.DirectoryName.Contains("GBCartEra");
|
|
|
|
|
ParseSettings.AllowGen1Tradeback = fi.DirectoryName.Contains("1 Tradeback");
|
2017-11-18 00:00:22 +00:00
|
|
|
|
var legality = new LegalityAnalysis(pkm);
|
2018-11-06 23:25:35 +00:00
|
|
|
|
legality.Valid.Should().Be(isValid, $"because the file '{fi.Directory.Name}\\{fi.Name}' should be {(isValid ? "Valid" : "Invalid")}");
|
2017-11-18 00:00:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-06 05:57:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|