Updated the implementation of Unicode blocks, and added tests.
This commit is contained in:
@@ -64,21 +64,24 @@ namespace UnicodeInformation.Tests
|
||||
Assert.AreEqual("\u00E9", UnicodeInfo.GetDisplayText(0x00E9));
|
||||
}
|
||||
|
||||
private static void AssertChar(int codePoint, UnicodeCategory category, string name)
|
||||
private static void AssertChar(int codePoint, UnicodeCategory category, string name, string block)
|
||||
{
|
||||
var info = UnicodeInfo.GetCharInfo(codePoint);
|
||||
Assert.AreEqual(codePoint, info.CodePoint);
|
||||
Assert.AreEqual(category, info.Category);
|
||||
Assert.AreEqual(name, info.Name);
|
||||
Assert.AreEqual(block, UnicodeInfo.GetBlockName(codePoint));
|
||||
Assert.AreEqual(block, info.Block);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CharacterInfoTest()
|
||||
{
|
||||
AssertChar(0x0041, UnicodeCategory.UppercaseLetter, "LATIN CAPITAL LETTER A");
|
||||
AssertChar(0x1F600, UnicodeCategory.OtherSymbol, "GRINNING FACE");
|
||||
AssertChar(0x00E9, UnicodeCategory.LowercaseLetter, "LATIN SMALL LETTER E WITH ACUTE");
|
||||
AssertChar(0xD4DB, UnicodeCategory.OtherLetter, "HANGUL SYLLABLE PWILH");
|
||||
AssertChar(0x0041, UnicodeCategory.UppercaseLetter, "LATIN CAPITAL LETTER A", "Basic Latin");
|
||||
AssertChar(0x1F600, UnicodeCategory.OtherSymbol, "GRINNING FACE", "Emoticons");
|
||||
AssertChar(0x00E9, UnicodeCategory.LowercaseLetter, "LATIN SMALL LETTER E WITH ACUTE", "Latin-1 Supplement");
|
||||
AssertChar(0xD4DB, UnicodeCategory.OtherLetter, "HANGUL SYLLABLE PWILH", "Hangul Syllables");
|
||||
AssertChar(0x1F574, UnicodeCategory.OtherSymbol, "MAN IN BUSINESS SUIT LEVITATING", "Miscellaneous Symbols and Pictographs");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -141,6 +144,15 @@ namespace UnicodeInformation.Tests
|
||||
Assert.AreEqual("HANGUL SYLLABLE TOLM", UnicodeInfo.GetName(0xD1AA));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void BlockNameTest()
|
||||
{
|
||||
Assert.AreEqual("Basic Latin", UnicodeInfo.GetBlockName(0x0041));
|
||||
Assert.AreEqual("Miscellaneous Technical", UnicodeInfo.GetBlockName(0x2307));
|
||||
Assert.AreEqual("Hangul Syllables", UnicodeInfo.GetBlockName(0xD311));
|
||||
Assert.AreEqual("Miscellaneous Symbols and Pictographs", UnicodeInfo.GetBlockName(0x1F574));
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
[TestMethod]
|
||||
public void UnihanCodePointPackingTest()
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace System.Unicode
|
||||
public string Name { get { return name; } }
|
||||
|
||||
public UnicodeCategory Category { get { return unicodeCharacterData?.Category ?? UnicodeCategory.OtherNotAssigned; } }
|
||||
public string Block { get { return block ?? "No_Block"; } }
|
||||
public string Block { get { return block ?? UnicodeInfo.DefaultBlock; } }
|
||||
public CanonicalCombiningClass CanonicalCombiningClass { get { return unicodeCharacterData?.CanonicalCombiningClass ?? CanonicalCombiningClass.NotReordered; } }
|
||||
public BidirectionalClass BidirectionalClass { get { return unicodeCharacterData?.BidirectionalClass ?? BidirectionalClass.LeftToRight; } }
|
||||
public CompatibilityFormattingTag DecompositionType { get { return unicodeCharacterData?.DecompositionType ?? CompatibilityFormattingTag.Canonical; } }
|
||||
|
||||
@@ -12,7 +12,9 @@ namespace System.Unicode
|
||||
{
|
||||
public static class UnicodeInfo
|
||||
{
|
||||
private static readonly Version unicodeVersion;
|
||||
public const string DefaultBlock = "No_Block";
|
||||
|
||||
private static readonly Version unicodeVersion;
|
||||
private static readonly UnicodeCharacterData[] unicodeCharacterData;
|
||||
private static readonly UnihanCharacterData[] unihanCharacterData;
|
||||
private static readonly UnicodeBlock[] blocks;
|
||||
@@ -250,11 +252,11 @@ namespace System.Unicode
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static string GetBlockName(int codePoint)
|
||||
public static string GetBlockName(int codePoint)
|
||||
{
|
||||
int i = FindBlockIndex(codePoint);
|
||||
|
||||
return i >= 0 ? blocks[i].Name : null;
|
||||
return i >= 0 ? blocks[i].Name : DefaultBlock;
|
||||
}
|
||||
|
||||
public static UnicodeCharInfo GetCharInfo(int codePoint)
|
||||
|
||||
Reference in New Issue
Block a user