Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions tests/PKForge.Engine.Tests/HaXAbilityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,27 @@ public void OffTableAbilitySurvivesSaveReloadOnGen7()
directory = directory.Parent;
var savePath = Path.Combine(directory!.FullName, "external", "PKHeX", "Tests", "PKHeX.Core.Tests", "TestData", "SM Project 802.main");

using (var session = new SaveEngineSession(File.ReadAllBytes(savePath)))
var haxSavePath = Path.Combine(Path.GetTempPath(), "hax-save.main");
try
{
var slot = session.Snapshot.Slots.First(s => s.Box >= 0 && s.Species is not null);
session.ApplyEdit(slot.Box, slot.Slot, new EntityEdit(Ability: Drought));
Assert.Equal(Drought, session.ReadEntity(slot.Box, slot.Slot).Ability);
File.WriteAllBytes("/tmp/hax-save.main", session.Serialize().ToArray());
}
using (var session = new SaveEngineSession(File.ReadAllBytes(savePath)))
{
var slot = session.Snapshot.Slots.First(s => s.Box >= 0 && s.Species is not null);
session.ApplyEdit(slot.Box, slot.Slot, new EntityEdit(Ability: Drought));
Assert.Equal(Drought, session.ReadEntity(slot.Box, slot.Slot).Ability);
File.WriteAllBytes(haxSavePath, session.Serialize().ToArray());
}

// Reload from disk bytes: the save file itself must carry the edit.
using (var reloaded = new SaveEngineSession(File.ReadAllBytes("/tmp/hax-save.main")))
// Reload from disk bytes: the save file itself must carry the edit.
using (var reloaded = new SaveEngineSession(File.ReadAllBytes(haxSavePath)))
{
var slot = reloaded.Snapshot.Slots.First(s => s.Box >= 0 && s.Species is not null);
Assert.Equal(Drought, reloaded.ReadEntity(slot.Box, slot.Slot).Ability);
}
}
finally
{
var slot = reloaded.Snapshot.Slots.First(s => s.Box >= 0 && s.Species is not null);
Assert.Equal(Drought, reloaded.ReadEntity(slot.Box, slot.Slot).Ability);
File.Delete(haxSavePath);
}
}
}
2 changes: 1 addition & 1 deletion tests/PKForge.Engine.Tests/ShowdownTeamAndBulkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Nonsense line that is not a set field
[Fact]
public void SplitCutsSetsWhereShowdownDoesAndDropsTeamHeaders()
{
var sets = ShowdownTeamService.Split(Team.Replace("\n", "\r\n"));
var sets = ShowdownTeamService.Split(Team.ReplaceLineEndings("\r\n"));
Assert.Equal(3, sets.Count);
Assert.Equal([(ushort)Species.Pikachu, (ushort)Species.Garchomp, (ushort)Species.Bulbasaur], sets.Select(s => s.Set.Species));
Assert.StartsWith("Pikachu @ Light Ball", sets[0].Text, StringComparison.Ordinal);
Expand Down