Skip to content

Commit

Permalink
Fixes Issue #24 by adding omitted RichTextTags
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardrowe committed Jun 28, 2020
1 parent bb2d531 commit b0b6db8
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 9 deletions.
60 changes: 53 additions & 7 deletions Assets/RedBlueGames/TextTyper/Tests/Editor/TextTagParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -18,7 +55,7 @@ public void RemoveCustomTags_EmptyString_ReturnsEmpty( )
}

[Test]
public void RemoveCustomTags_OnlyUnityRichTextTags_ReturnsUnityTags( )
public void RemoveCustomTags_OnlyUnityRichTextTags_ReturnsUnityTags()
{
var textToType = "<b><i></i></b>";
var generatedText = TextTagParser.RemoveCustomTags(textToType);
Expand All @@ -29,7 +66,7 @@ public void RemoveCustomTags_OnlyUnityRichTextTags_ReturnsUnityTags( )
}

[Test]
public void RemoveCustomTags_OnlyCustomRichTextTags_ReturnsEmpty( )
public void RemoveCustomTags_OnlyCustomRichTextTags_ReturnsEmpty()
{
var textToType = "<delay=5></delay><anim=3></anim><animation=sine></animation>";
var generatedText = TextTagParser.RemoveCustomTags(textToType);
Expand All @@ -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 = "<b>a</b><i>b</i><size=40>c</size><color=red>d</color><style=C1>e</style>";
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}</{tag}>");
expectedTextBuilder.Append($"{i}");
}

var textToType = builder.ToString();
var generatedText = TextTagParser.RemoveUnityTags(textToType);

var expectedText = "abcde";
var expectedText = expectedTextBuilder.ToString();

Assert.AreEqual(expectedText, generatedText);
}
Expand Down
40 changes: 38 additions & 2 deletions Assets/RedBlueGames/TextTyper/TextTagParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b0b6db8

Please sign in to comment.