From b0b6db8681a37a62b0eae1494037c607863d831f Mon Sep 17 00:00:00 2001 From: Edward Rowe Date: Sun, 28 Jun 2020 00:01:04 -0400 Subject: [PATCH] Fixes Issue #24 by adding omitted RichTextTags --- .../Tests/Editor/TextTagParserTests.cs | 60 ++++++++++++++++--- .../RedBlueGames/TextTyper/TextTagParser.cs | 40 ++++++++++++- 2 files changed, 91 insertions(+), 9 deletions(-) diff --git a/Assets/RedBlueGames/TextTyper/Tests/Editor/TextTagParserTests.cs b/Assets/RedBlueGames/TextTyper/Tests/Editor/TextTagParserTests.cs index c0cb439..b6939ff 100644 --- a/Assets/RedBlueGames/TextTyper/Tests/Editor/TextTagParserTests.cs +++ b/Assets/RedBlueGames/TextTyper/Tests/Editor/TextTagParserTests.cs @@ -6,8 +6,45 @@ public class TextTagParserTests { + private static readonly string[] UnityTags = new string[] + { + "b", + "i", + "s", + "u", + "br", + "nobr", + "size", + "color", + "style", + "width", + "align", + "alpha", + "cspace", + "font", + "indent", + "line-height", + "line-indent", + "link", + "lowercase", + "uppercase", + "smallcaps", + "margin", + "mark", + "mspace", + "noparse", + "page", + "pos", + "space", + "sprite", + "sup", + "sub", + "voffset", + "gradient" + }; + [Test] - public void RemoveCustomTags_EmptyString_ReturnsEmpty( ) + public void RemoveCustomTags_EmptyString_ReturnsEmpty() { var textToType = string.Empty; var generatedText = TextTagParser.RemoveCustomTags(textToType); @@ -18,7 +55,7 @@ public void RemoveCustomTags_EmptyString_ReturnsEmpty( ) } [Test] - public void RemoveCustomTags_OnlyUnityRichTextTags_ReturnsUnityTags( ) + public void RemoveCustomTags_OnlyUnityRichTextTags_ReturnsUnityTags() { var textToType = ""; var generatedText = TextTagParser.RemoveCustomTags(textToType); @@ -29,7 +66,7 @@ public void RemoveCustomTags_OnlyUnityRichTextTags_ReturnsUnityTags( ) } [Test] - public void RemoveCustomTags_OnlyCustomRichTextTags_ReturnsEmpty( ) + public void RemoveCustomTags_OnlyCustomRichTextTags_ReturnsEmpty() { var textToType = ""; var generatedText = TextTagParser.RemoveCustomTags(textToType); @@ -40,13 +77,22 @@ public void RemoveCustomTags_OnlyCustomRichTextTags_ReturnsEmpty( ) } [Test] - public void RemoveUnityTags_AllUnityTags_ReturnsNoTags( ) + public void RemoveUnityTags_AllUnityTags_ReturnsNoTags() { - //"b", "i", "size", "color", "style" }; - var textToType = "abcde"; + var builder = new System.Text.StringBuilder(); + var expectedTextBuilder = new System.Text.StringBuilder(); + + for (int i = 0; i < UnityTags.Length; ++i) + { + var tag = UnityTags[i]; + builder.Append($"<{tag}>{i}"); + expectedTextBuilder.Append($"{i}"); + } + + var textToType = builder.ToString(); var generatedText = TextTagParser.RemoveUnityTags(textToType); - var expectedText = "abcde"; + var expectedText = expectedTextBuilder.ToString(); Assert.AreEqual(expectedText, generatedText); } diff --git a/Assets/RedBlueGames/TextTyper/TextTagParser.cs b/Assets/RedBlueGames/TextTyper/TextTagParser.cs index 0dcbac4..80b5845 100644 --- a/Assets/RedBlueGames/TextTyper/TextTagParser.cs +++ b/Assets/RedBlueGames/TextTyper/TextTagParser.cs @@ -19,7 +19,43 @@ public struct CustomTags public const string Animation = "animation"; } - private static readonly string[] UnityTagTypes = new string[] { "b", "i", "size", "color", "style" }; + private static readonly string[] UnityTags = new string[] + { + "b", + "i", + "s", + "u", + "br", + "nobr", + "size", + "color", + "style", + "width", + "align", + "alpha", + "cspace", + "font", + "indent", + "line-height", + "line-indent", + "link", + "lowercase", + "uppercase", + "smallcaps", + "margin", + "mark", + "mspace", + "noparse", + "page", + "pos", + "space", + "sprite", + "sup", + "sub", + "voffset", + "gradient" + }; + private static readonly string[] CustomTagTypes = new string[] { CustomTags.Delay, @@ -70,7 +106,7 @@ public static string RemoveCustomTags(string textWithTags) public static string RemoveUnityTags(string textWithTags) { - return RemoveTags(textWithTags, UnityTagTypes); + return RemoveTags(textWithTags, UnityTags); } private static string RemoveTags(string textWithTags, params string[] tags)