コード例 #1
0
ファイル: TestUScript.cs プロジェクト: NightOwl888/ICU4N
        public void TestAllCodepointsUsingTry()
        {
            int code;

            for (int i = 0; i <= 0x10ffff; i++)
            {
                code = UScript.GetScript(i);
                if (code == UScript.InvalidCode)
                {
                    Errln("UScript.GetScript for codepoint 0x" + Hex(i) + " failed");
                }

                if (!UScript.TryGetName(code, out string id) || id.IndexOf("INVALID", StringComparison.Ordinal) >= 0)
                {
                    Errln("UScript.GetScript for codepoint 0x" + Hex(i) + " failed");
                }

                if (!UScript.TryGetShortName(code, out string abbr) || abbr.IndexOf("INV", StringComparison.Ordinal) >= 0)
                {
                    Errln("UScript.GetScript for codepoint 0x" + Hex(i) + " failed");
                }
            }
        }
コード例 #2
0
ファイル: TestUScript.cs プロジェクト: NightOwl888/ICU4N
        public void TestScriptNamesUsingTry()
        {
            int v, rev;

            for (int i = 0; i < UScript.CodeLimit; i++)
            {
                if (!UScript.TryGetName(i, out string name) || name.Equals(""))
                {
                    Errln("FAILED: getName for code : " + i);
                }
                if (name != null)
                {
                    /* test reverse mapping */
                    rev = UScript.GetCodeFromName(name);
                    if (rev != (int)i)
                    {
                        Errln("Property round-trip failure: " + i + " -> " +
                              name + " -> " + rev);
                    }
                }
                if (!UScript.TryGetShortName(i, out string shortName) || shortName.Equals(""))
                {
                    Errln("FAILED: getName for code : " + i);
                }
                if (shortName != null)
                {
                    /* test reverse mapping */
                    rev = UScript.GetCodeFromName(shortName);
                    if (rev != (int)i)
                    {
                        Errln("Property round-trip failure: " + i + " -> " +
                              shortName + " -> " + rev);
                    }
                }
            }
        }
コード例 #3
0
        public void TestScriptsUsingTry()
        {
            // get a couple of characters of each script for testing

            StringBuffer testBuffer = new StringBuffer();

            for (int script = 0; script < UScript.CodeLimit; ++script)
            {
                if (UScript.TryGetName(script, out string name))
                {
                    UnicodeSet test  = new UnicodeSet().ApplyPropertyAlias("script", name);
                    int        count = Math.Min(20, test.Count);
                    for (int i = 0; i < count; ++i)
                    {
                        testBuffer.Append(UTF16.ValueOf(test[i]));
                    }
                }
            }
            {
                string test = testBuffer.ToString();
                Logln("Test line: " + test);

                int  inclusion = TestFmwk.GetExhaustiveness();
                bool testedUnavailableScript = false;

                for (int script = 0; script < UScript.CodeLimit; ++script)
                {
                    if (script == UScript.Common || script == UScript.Inherited)
                    {
                        continue;
                    }
                    // if the inclusion rate is not 10, skip all but a small number of items.
                    // Make sure, however, that we test at least one unavailable script
                    if (inclusion < 10 && script != UScript.Latin &&
                        script != UScript.Han &&
                        script != UScript.Hiragana &&
                        testedUnavailableScript
                        )
                    {
                        continue;
                    }

                    if (UScript.TryGetName(script, out string scriptName))
                    {
                        UCultureInfo locale = new UCultureInfo(scriptName);
                        if (locale.Language.Equals("new") || locale.Language.Equals("pau"))
                        {
                            if (logKnownIssue("11171",
                                              "long script name loosely looks like a locale ID with a known likely script"))
                            {
                                continue;
                            }
                        }
                    }
                    Transliterator t;
                    try
                    {
                        t = Transliterator.GetInstance("any-" + scriptName);
                    }
                    catch (Exception e)
                    {
                        testedUnavailableScript = true;
                        Logln("Skipping unavailable: " + scriptName);
                        continue; // we don't handle all scripts
                    }
                    Logln("Checking: " + scriptName);
                    if (t != null)
                    {
                        t.Transform(test); // just verify we don't crash
                    }

                    string shortScriptName = "";
                    if (UScript.TryGetName(script, out scriptName))  // 4-letter script code
                    {
                        try
                        {
                            t = Transliterator.GetInstance("any-" + shortScriptName);
                        }
                        catch (Exception e)
                        {
                            Errln("Transliterator.GetInstance() worked for \"any-" + scriptName +
                                  "\" but not for \"any-" + shortScriptName + '\"');
                        }
                    }
                    t.Transform(test); // just verify we don't crash
                }
            }
        }