1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 04:53:29 +01:00

added tests for ensuring genericfont correctness compared to regular font

This commit is contained in:
Ell 2021-04-19 14:30:03 +02:00
parent 8078d41724
commit 60bc320604

View file

@ -1,5 +1,7 @@
using System.Text.RegularExpressions;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MLEM.Extensions;
using MLEM.Font;
using MLEM.Formatting;
using MLEM.Formatting.Codes;
@ -117,5 +119,34 @@ namespace Tests {
Assert.AreEqual(ret.AllCodes.Length, 12);
}
[Test]
public void TestConsistency() {
void CompareSizes(string s) {
var spriteFont = ((GenericSpriteFont) this.font).Font;
Assert.AreEqual(spriteFont.MeasureString(s), this.font.MeasureString(s));
}
CompareSizes("This is a very simple test string");
CompareSizes("This\n is a very\nsimple test string");
CompareSizes("\nThis is a very simple test string");
CompareSizes("This is a very simple test string\n");
CompareSizes("This is a very simple test string\n\n\n\n\n");
}
[Test]
public void TestSpecialCharacters() {
void CompareSizes(string s) {
var spriteFont = ((GenericSpriteFont) this.font).Font;
Assert.AreNotEqual(spriteFont.MeasureString(s), this.font.MeasureString(s));
}
CompareSizes($"This is a very simple{GenericFont.Nbsp}test string");
CompareSizes($"This is a very simple{GenericFont.OneEmSpace}test string");
CompareSizes($"This is a very simple{GenericFont.Zwsp}test string");
Assert.AreEqual(new Vector2(this.font.LineHeight, this.font.LineHeight), this.font.MeasureString(GenericFont.OneEmSpace.ToCachedString()));
Assert.AreEqual(new Vector2(0, this.font.LineHeight), this.font.MeasureString(GenericFont.Zwsp.ToCachedString()));
}
}
}