mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
Fix SeString serialization/deserialization (#840)
* chore: add SeString JSON conversion test * fix: SeString JSON serialization * chore: add SeString JSON deserialization test * chore: rename tests to abstract format away * chore: fix typos * fix: deserializable SeStrings * chore: add comment to test * chore: use DeserializeConfig in Load
This commit is contained in:
parent
6dcddb1f29
commit
387a820392
3 changed files with 104 additions and 14 deletions
68
Dalamud.Test/Game/Text/SeStringHandling/SeStringTests.cs
Normal file
68
Dalamud.Test/Game/Text/SeStringHandling/SeStringTests.cs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
using System;
|
||||
using Dalamud.Configuration;
|
||||
using Dalamud.Game.Text.SeStringHandling;
|
||||
using Xunit;
|
||||
|
||||
namespace Dalamud.Test.Game.Text.SeStringHandling
|
||||
{
|
||||
public class SeStringTests
|
||||
{
|
||||
private class MockConfig : IPluginConfiguration, IEquatable<MockConfig>
|
||||
{
|
||||
public int Version { get; set; }
|
||||
|
||||
public SeString Text { get; init; }
|
||||
|
||||
public bool Equals(MockConfig other)
|
||||
{
|
||||
if (ReferenceEquals(null, other)) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
return Version == other.Version && Equals(Text.TextValue, other.Text.TextValue);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return Equals(obj as MockConfig);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(Text);
|
||||
}
|
||||
|
||||
public static bool operator ==(MockConfig left, MockConfig right)
|
||||
{
|
||||
return Equals(left, right);
|
||||
}
|
||||
|
||||
public static bool operator !=(MockConfig left, MockConfig right)
|
||||
{
|
||||
return !Equals(left, right);
|
||||
}
|
||||
}
|
||||
|
||||
// Dalamud#779
|
||||
[Fact]
|
||||
public void TestConfigSerializable()
|
||||
{
|
||||
var builder = new SeStringBuilder();
|
||||
var seString = builder.AddText("Some text").Build();
|
||||
var config = new MockConfig { Text = seString };
|
||||
PluginConfigurations.SerializeConfig(config);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestConfigDeserializable()
|
||||
{
|
||||
var builder = new SeStringBuilder();
|
||||
var seString = builder.AddText("Some text").Build();
|
||||
var config = new MockConfig { Text = seString };
|
||||
|
||||
// This relies on the type information being maintained, which is why we're using these
|
||||
// static methods instead of default serialization/deserialization.
|
||||
var configSerialized = PluginConfigurations.SerializeConfig(config);
|
||||
var configDeserialized = (MockConfig)PluginConfigurations.DeserializeConfig(configSerialized);
|
||||
Assert.Equal(config, configDeserialized);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue