2021-06-30 03:58:06 +00:00
|
|
|
|
using System;
|
2021-04-19 01:29:02 +00:00
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using PKHeX.Core;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.Tests.PKM
|
|
|
|
|
{
|
|
|
|
|
public class StringTests
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Gen7ZHLengthCorrect()
|
|
|
|
|
{
|
|
|
|
|
StringConverter7ZH.Gen7_ZHRaw.Length.Should().Be(StringConverter7ZH.Gen7_ZHLength);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void EncodesOTNameCorrectly()
|
|
|
|
|
{
|
|
|
|
|
const string name_fabian = "Fabian♂";
|
|
|
|
|
var pkm = new PK7 { OT_Name = name_fabian };
|
|
|
|
|
var byte_fabian = new byte[]
|
|
|
|
|
{
|
|
|
|
|
0x46, 0x00, // F
|
|
|
|
|
0x61, 0x00, // a
|
|
|
|
|
0x62, 0x00, // b
|
|
|
|
|
0x69, 0x00, // i
|
|
|
|
|
0x61, 0x00, // a
|
|
|
|
|
0x6E, 0x00, // n
|
|
|
|
|
0x8E, 0xE0, // ♂
|
|
|
|
|
0x00, 0x00, // \0 terminator
|
|
|
|
|
};
|
|
|
|
|
CheckStringGetSet(nameof(pkm.OT_Name), name_fabian, pkm.OT_Name, byte_fabian, pkm.OT_Trash);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void EncodesNicknameCorrectly()
|
|
|
|
|
{
|
|
|
|
|
const string name_nidoran = "ニドラン♀";
|
|
|
|
|
var pkm = new PK7 { Nickname = name_nidoran };
|
|
|
|
|
var byte_nidoran = new byte[]
|
|
|
|
|
{
|
|
|
|
|
0xCB, 0x30, // ニ
|
|
|
|
|
0xC9, 0x30, // ド
|
|
|
|
|
0xE9, 0x30, // ラ
|
|
|
|
|
0xF3, 0x30, // ン
|
|
|
|
|
0x40, 0x26, // ♀
|
|
|
|
|
0x00, 0x00, // \0 terminator
|
|
|
|
|
};
|
|
|
|
|
CheckStringGetSet(nameof(pkm.Nickname), name_nidoran, pkm.Nickname, byte_nidoran, pkm.Nickname_Trash);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-30 03:58:06 +00:00
|
|
|
|
private static void CheckStringGetSet(string check, string instr, string outstr, ReadOnlySpan<byte> indata, ReadOnlySpan<byte> outdata)
|
2021-04-19 01:29:02 +00:00
|
|
|
|
{
|
|
|
|
|
instr.Should().BeEquivalentTo(outstr);
|
|
|
|
|
|
2021-05-10 06:33:54 +00:00
|
|
|
|
outdata = outdata[..indata.Length];
|
2021-04-19 01:29:02 +00:00
|
|
|
|
|
|
|
|
|
indata.SequenceEqual(outdata).Should()
|
2021-06-30 03:58:06 +00:00
|
|
|
|
.BeTrue($"expected {check} to set properly, instead got {Hex(outdata)}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string Hex(ReadOnlySpan<byte> outdata)
|
|
|
|
|
{
|
|
|
|
|
var sb = new System.Text.StringBuilder(outdata.Length);
|
|
|
|
|
foreach (var b in outdata)
|
|
|
|
|
sb.AppendFormat("{0:X2}, ", b);
|
|
|
|
|
return sb.ToString();
|
2021-04-19 01:29:02 +00:00
|
|
|
|
}
|
Revise 4->5 encode table (Half-width symbols)
Manually transferred from English Pt to English B
All revised indexes were the result in Black.
Differences that were not incorporated:
0EE=09794 ♂, not 09325 ⑭
0EF=09792 ♀, not 09326 ⑮
0F2=00215 ×, not 09319 ⑧
0F3=00247 ÷, not 09320 ⑨
Full-width and half-width symbols I think are related to full-width games, which English isn't. Probably has different handling for other language, plus it'd result in other duplicates of the half-width symbols.
Revise not-found char glyph to return ? instead of {terminator}, to match the game's behavior. Again, this might be language specific, but whatever.
Make the Convert char methods public, add a few unit tests.
Closes #3172
Co-Authored-By: Lusamine <30205550+Lusamine@users.noreply.github.com>
2021-06-12 02:38:34 +00:00
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(0x0F5, 0xFF5E)] // ~
|
|
|
|
|
[InlineData(0x0FA, 0x2660)] // ♠
|
|
|
|
|
[InlineData(0x0FB, 0x2663)] // ♣
|
|
|
|
|
[InlineData(0x0FC, 0x2665)] // ♥
|
|
|
|
|
[InlineData(0x0FD, 0x2666)] // ♦
|
|
|
|
|
[InlineData(0x0FE, 0x2605)] // ★
|
|
|
|
|
[InlineData(0x105, 0x266A)] // ♪
|
|
|
|
|
public static void Encode45(ushort g4, char g5)
|
|
|
|
|
{
|
|
|
|
|
StringConverter4.ConvertChar2ValueG4(g5).Should().Be(g4);
|
|
|
|
|
StringConverter4.ConvertValue2CharG4(g4).Should().Be(g5);
|
|
|
|
|
}
|
2021-04-19 01:29:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|