Beispiel #1
0
        public void GetSetsByStyleTypeTest_Normal()
        {
            List <IUnikodSet> testList = UnicodeSets.GetSetsByStyleType(StyleType.Normal);

            CollectionAssert.AreEquivalent(new List <IUnikodSet>()
            {
                UnicodeSets.LatinNormalUppercaseSet,
                UnicodeSets.LatinNormalLowercaseSet,
                UnicodeSets.NumberNormalSet
            }, testList);
        }
Beispiel #2
0
        public void GetSetByNameTest_Null()
        {
            IUnikodSet test1 = UnicodeSets.GetSetByName("Unused Set Name");
            IUnikodSet test2 = UnicodeSets.GetSetByName(string.Empty);
            IUnikodSet test3 = UnicodeSets.GetSetByName(null);

            Assert.IsNull(test1);
            Assert.IsNull(test2);
            Assert.IsNull(test3);

            Assert.ThrowsException <NullReferenceException>(() => test1.Data.Length);
            Assert.ThrowsException <NullReferenceException>(() => test2.Name.Length);
            Assert.ThrowsException <NullReferenceException>(() => test3.StyleType.ToString());
        }
Beispiel #3
0
        public void GetSetByNameTest_IgnoreCase()
        {
            IUnikodSet test1 = UnicodeSets.GetSetByName("numBer doublE CirclED");
            IUnikodSet test2 = UnicodeSets.GetSetByName("latin fullwidth uppercase");
            IUnikodSet test3 = UnicodeSets.GetSetByName("lisu gLyphS for LATIN UPPERCASE obfuscation");

            Assert.IsInstanceOfType(test1, typeof(NumberSet));
            Assert.IsInstanceOfType(test2, typeof(AlphabetSet));
            Assert.IsInstanceOfType(test3, typeof(AlphabetSet));

            Assert.AreEqual(test1.Name, "Number Double Circled");
            Assert.AreEqual(test2.Name, "Latin Fullwidth Uppercase");
            CollectionAssert.AreEqual(UnicodeSets.LisuGlyphsUppercaseSet.Data, test3.Data);
        }
Beispiel #4
0
        public void GetSetByNameTest_Normal()
        {
            IUnikodSet test1 = UnicodeSets.GetSetByName("Latin Normal Uppercase");
            IUnikodSet test2 = UnicodeSets.GetSetByName("Number Bold");
            IUnikodSet test3 = UnicodeSets.GetSetByName("Latin Modifier(Superscript) Lowercase");

            Assert.IsInstanceOfType(test1, typeof(AlphabetSet));
            Assert.IsInstanceOfType(test2, typeof(NumberSet));
            Assert.IsInstanceOfType(test3, typeof(AlphabetSet));

            Assert.AreEqual(test1.Name, "Latin Normal Uppercase");
            Assert.AreEqual(test2.Name, "Number Bold");
            CollectionAssert.AreEqual(new string[] {
                "ᵃ", "ᵇ", "ᶜ", "ᵈ", "ᵉ",
                "ᶠ", "ᵍ", "ʰ", "ⁱ", "ʲ",
                "ᵏ", "ˡ", "ᵐ", "ⁿ", "ᵒ",
                "ᵖ", null, "ʳ", "ˢ", "ᵗ",
                "ᵘ", "ᵛ", "ʷ", "ˣ", "ʸ",
                "ᶻ"
            }, test3.Data);
        }
Beispiel #5
0
        /// <summary>
        /// Stylize the given styled text string
        /// </summary>
        /// <param name="text">A string text to be stylized</param>
        /// <param name="set">A/Some style set(s) </param>
        /// <returns>Stylized text as `string`</returns>
        public static string Stylize(string text, params IUnikodSet[] set)
        {
            if (text == null)
            {
                return(null);
            }
            else
            {
                StringBuilder builder = new StringBuilder();

                foreach (string character in text.ToUnicodeStringArray())
                {
                    if (char.TryParse(character, out char singleCharacter))
                    {
                        if (char.IsControl(singleCharacter) || char.IsWhiteSpace(singleCharacter))
                        {
                            builder.Append(character);
                            continue;
                        }
                    }

                    bool existInNormalSets    = false;
                    int  index                = -1;
                    Type characterSetType     = null;
                    bool?characterIsUppercase = null;

                    foreach (IUnikodSet normalSet in UnicodeSets.GetSetsByStyleType(StyleType.Normal))
                    {
                        for (int i = 0, normalSetLength = normalSet.Data.Length; i < normalSetLength; i++)
                        {
                            if (normalSet.Data[i].Equals(character))
                            {
                                index             = i;
                                existInNormalSets = true;
                                characterSetType  = normalSet.GetType();

                                if (normalSet is AlphabetSet alphabetSet)
                                {
                                    characterIsUppercase = alphabetSet.LetterCaseType == LetterCaseType.Uppercase;
                                }
                            }
                        }
                    }

                    if (existInNormalSets)
                    {
                        bool found = false;

                        foreach (IUnikodSet targetSet in set)
                        {
                            if (characterSetType == targetSet.GetType())
                            {
                                if (targetSet is AlphabetSet alphabetSet)
                                {
                                    if (alphabetSet.LetterCaseType == LetterCaseType.Uppercase != characterIsUppercase)
                                    {
                                        continue;
                                    }
                                }

                                if (targetSet.Data[index] != null)
                                {
                                    builder.Append(targetSet.Data[index]);
                                    found = true;
                                    break;
                                }
                            }
                        }

                        if (!found)
                        {
                            builder.Append(character);
                        }
                    }
                    else
                    {
                        builder.Append(character);
                    }
                }

                return(builder.ToString());
            }
        }
Beispiel #6
0
 public void AnyShouldHaveCardinality()
 {
     Assert.AreEqual(0x110000, UnicodeSets.Any().Cardinality);
 }