Verify that table stream read/write is symmetric

This commit is contained in:
Benjamin Popp 2020-05-12 20:06:30 -05:00
parent 185035a93e
commit f55991e85a
2 changed files with 21 additions and 0 deletions

View File

@ -137,6 +137,12 @@ namespace HavenSoft.HexManiac.Core.Models.Runs {
i--;
}
// remove trailing ',' from tokens
for (int i = 0; i < tokens.Count; i++) {
if (!tokens[i].EndsWith(",")) continue;
tokens[i] = tokens[i].Substring(0, tokens[i].Length - 1);
}
return tokens;
}

View File

@ -1,5 +1,6 @@
using HavenSoft.HexManiac.Core;
using HavenSoft.HexManiac.Core.Models;
using HavenSoft.HexManiac.Core.Models.Runs;
using System.Linq;
using Xunit;
@ -101,5 +102,19 @@ namespace HavenSoft.HexManiac.Tests {
var content = Model.Copy(() => ViewPort.CurrentChange, 0, 8);
Assert.Equal(@"^table`plm` 3 Ate, 4 Bumped, 5 Crossed, []", content);
}
[Fact]
public void StreamRunSerializeDeserializeIsSymmetric() {
CreateTextTable(HardcodeTablesModel.PokemonNameTable, 0x100, "Adam", "Bob", "Carl", "Dave");
ViewPort.Edit($"@00 00 00 01 01 02 02 03 03 FF FF @00 ^table[enum.{HardcodeTablesModel.PokemonNameTable} content.]!FFFF ");
var stream = (IStreamRun)Model.GetNextRun(0);
var text = stream.SerializeRun();
Model.ObserveRunWritten(ViewPort.CurrentChange, stream.DeserializeRun(text, ViewPort.CurrentChange));
var result = new byte[] { 0, 0, 1, 1, 2, 2, 3, 3, 255, 255 };
Assert.All(Enumerable.Range(0, result.Length), i => Assert.Equal(Model[i], result[i]));
}
}
}