Пример #1
0
        public void TestNormalization()
        {
            String rules = "&a < \u0300\u0315 < A\u0300\u0315 < \u0316\u0315B < \u0316\u0300\u0315";

            String[]          testdata = { "\u1ED9",      "o\u0323\u0302",
                                           "\u0300\u0315",         "\u0315\u0300",
                                           "A\u0300\u0315B",       "A\u0315\u0300B",
                                           "A\u0316\u0315B",       "A\u0315\u0316B",
                                           "\u0316\u0300\u0315",   "\u0315\u0300\u0316",
                                           "A\u0316\u0300\u0315B", "A\u0315\u0300\u0316B",
                                           "\u0316\u0315\u0300",   "A\u0316\u0315\u0300B" };
            RuleBasedCollator coll = null;

            try
            {
                coll = new RuleBasedCollator(rules);
                coll.Decomposition = NormalizationMode.CanonicalDecomposition; //(Collator.CANONICAL_DECOMPOSITION);
            }
            catch (Exception e)
            {
                Warnln("ERROR: in creation of collator using rules " + rules);
                return;
            }

            CollationElementIterator iter = coll.GetCollationElementIterator("testing");

            for (int count = 0; count < testdata.Length; count++)
            {
                iter.SetText(testdata[count]);
                CollationTest.BackAndForth(this, iter);
            }
        }
Пример #2
0
        public void TestSetTextCharacterIterator()
        {
            // Failed in java too
            RuleBasedCollator rbColl = (RuleBasedCollator)ILOG.J2CsMapping.Text.Collator
                                       .GetInstance(new Locale("es", "", "TRADITIONAL"));
            String text = "caa";
            CollationElementIterator iterator = rbColl
                                                .GetCollationElementIterator(text);

            iterator.SetOffset(1);
            NUnit.Framework.Assert.AreEqual(1, iterator.GetOffset());
            iterator.SetText(new StringCharacterIterator("cha"));
            iterator.SetOffset(1);
            NUnit.Framework.Assert.AreEqual(1, iterator.GetOffset());
        }
Пример #3
0
        public void TestDiscontiguous()
        {
            String rulestr = "&z < AB < X\u0300 < ABC < X\u0300\u0315";

            String[] src = { "ADB",                 "ADBC",                 "A\u0315B",       "A\u0315BC",
                             // base character blocked
                             "XD\u0300",            "XD\u0300\u0315",
                             // non blocking combining character
                             "X\u0319\u0300",       "X\u0319\u0300\u0315",
                             // blocking combining character
                             "X\u0314\u0300",       "X\u0314\u0300\u0315",
                             // contraction prefix
                             "ABDC",                "AB\u0315C",            "X\u0300D\u0315",
                             "X\u0300\u0319\u0315", "X\u0300\u031A\u0315",
                             // ends not with a contraction character
                             "X\u0319\u0300D",      "X\u0319\u0300\u0315D",
                             "X\u0300D\u0315D",     "X\u0300\u0319\u0315D",
                             "X\u0300\u031A\u0315D" };
            String[] tgt =  // non blocking combining character
            {
                "A D B",                "A D BC",                "A \u0315 B",       "A \u0315 BC",
                // base character blocked
                "X D \u0300",           "X D \u0300\u0315",
                // non blocking combining character
                "X\u0300 \u0319",       "X\u0300\u0315 \u0319",
                // blocking combining character
                "X \u0314 \u0300",      "X \u0314 \u0300\u0315",
                // contraction prefix
                "AB DC",                "AB \u0315 C",           "X\u0300 D \u0315",
                "X\u0300\u0315 \u0319", "X\u0300 \u031A \u0315",
                // ends not with a contraction character
                "X\u0300 \u0319D",      "X\u0300\u0315 \u0319D",
                "X\u0300 D\u0315D",     "X\u0300\u0315 \u0319D",
                "X\u0300 \u031A\u0315D"
            };
            int count = 0;

            try
            {
                RuleBasedCollator        coll = new RuleBasedCollator(rulestr);
                CollationElementIterator iter
                    = coll.GetCollationElementIterator("");
                CollationElementIterator resultiter
                    = coll.GetCollationElementIterator("");
                while (count < src.Length)
                {
                    iter.SetText(src[count]);
                    int s = 0;
                    while (s < tgt[count].Length)
                    {
                        int e = tgt[count].IndexOf(' ', s);
                        if (e < 0)
                        {
                            e = tgt[count].Length;
                        }
                        String resultstr = tgt[count].Substring(s, e - s); // ICU4N: Corrected 2nd parameter
                        resultiter.SetText(resultstr);
                        int ce = resultiter.Next();
                        while (ce != CollationElementIterator.NULLORDER)
                        {
                            if (ce != iter.Next())
                            {
                                Errln("Discontiguos contraction test mismatch at"
                                      + count);
                                return;
                            }
                            ce = resultiter.Next();
                        }
                        s = e + 1;
                    }
                    iter.Reset();
                    CollationTest.BackAndForth(this, iter);
                    count++;
                }
            }
            catch (Exception e)
            {
                Warnln("Error running discontiguous tests " + e.ToString());
            }
        }
Пример #4
0
        public void TestSetText(/* char* par */)
        {
            RuleBasedCollator        en_us = (RuleBasedCollator)Collator.GetInstance(new CultureInfo("en-US"));
            CollationElementIterator iter1 = en_us.GetCollationElementIterator(test1);
            CollationElementIterator iter2 = en_us.GetCollationElementIterator(test2);

            // Run through the second iterator just to exercise it
            int c = iter2.Next();
            int i = 0;

            while (++i < 10 && c != CollationElementIterator.NULLORDER)
            {
                try
                {
                    c = iter2.Next();
                }
                catch (Exception e)
                {
                    Errln("iter2.Next() returned an error.");
                    break;
                }
            }

            // Now set it to point to the same string as the first iterator
            try
            {
                iter2.SetText(test1);
            }
            catch (Exception e)
            {
                Errln("call to iter2->setText(test1) failed.");
                return;
            }
            assertEqual(iter1, iter2);

            iter1.Reset();
            //now use the overloaded setText(ChracterIterator&, UErrorCode) function to set the text
            CharacterIterator chariter = new StringCharacterIterator(test1);

            try
            {
                iter2.SetText(chariter);
            }
            catch (Exception e)
            {
                Errln("call to iter2->setText(chariter(test1)) failed.");
                return;
            }
            assertEqual(iter1, iter2);

            iter1.Reset();
            //now use the overloaded setText(ChracterIterator&, UErrorCode) function to set the text
            UCharacterIterator uchariter = UCharacterIterator.GetInstance(test1);

            try
            {
                iter2.SetText(uchariter);
            }
            catch (Exception e)
            {
                Errln("call to iter2->setText(uchariter(test1)) failed.");
                return;
            }
            assertEqual(iter1, iter2);
        }
Пример #5
0
        public void TestMaxExpansion(/* char* par */)
        {
            int               unassigned = 0xEFFFD;
            String            rule       = "&a < ab < c/aba < d < z < ch";
            RuleBasedCollator coll       = null;

            try
            {
                coll = new RuleBasedCollator(rule);
            }
            catch (Exception e)
            {
                Warnln("Fail to create RuleBasedCollator");
                return;
            }
            char   ch  = (char)0;
            String str = ch + "";

            CollationElementIterator iter = coll.GetCollationElementIterator(str);

            while (ch < 0xFFFF)
            {
                int count = 1;
                ch++;
                str = ch + "";
                iter.SetText(str);
                int order = iter.Previous();

                // thai management
                if (order == 0)
                {
                    order = iter.Previous();
                }

                while (iter.Previous() != CollationElementIterator.NULLORDER)
                {
                    count++;
                }

                if (iter.GetMaxExpansion(order) < count)
                {
                    Errln("Failure at codepoint " + ch + ", maximum expansion count < " + count);
                }
            }

            // testing for exact max expansion
            ch = (char)0;
            while (ch < 0x61)
            {
                str = ch + "";
                iter.SetText(str);
                int order = iter.Previous();

                if (iter.GetMaxExpansion(order) != 1)
                {
                    Errln("Failure at codepoint 0x" + (ch).ToHexString()
                          + " maximum expansion count == 1");
                }
                ch++;
            }

            ch  = (char)0x63;
            str = ch + "";
            iter.SetText(str);
            int temporder = iter.Previous();

            if (iter.GetMaxExpansion(temporder) != 3)
            {
                Errln("Failure at codepoint 0x" + (ch).ToHexString()
                      + " maximum expansion count == 3");
            }

            ch  = (char)0x64;
            str = ch + "";
            iter.SetText(str);
            temporder = iter.Previous();

            if (iter.GetMaxExpansion(temporder) != 1)
            {
                Errln("Failure at codepoint 0x" + (ch).ToHexString()
                      + " maximum expansion count == 1");
            }

            str = UChar.ToString(unassigned);
            iter.SetText(str);
            temporder = iter.Previous();

            if (iter.GetMaxExpansion(temporder) != 2)
            {
                Errln("Failure at codepoint 0x" + (ch).ToHexString()
                      + " maximum expansion count == 2");
            }


            // testing jamo
            ch  = (char)0x1165;
            str = ch + "";
            iter.SetText(str);
            temporder = iter.Previous();

            if (iter.GetMaxExpansion(temporder) > 3)
            {
                Errln("Failure at codepoint 0x" + (ch).ToHexString()
                      + " maximum expansion count < 3");
            }

            // testing special jamo &a<\u1165
            rule = "\u0026\u0071\u003c\u1165\u002f\u0071\u0071\u0071\u0071";

            try
            {
                coll = new RuleBasedCollator(rule);
            }
            catch (Exception e)
            {
                Errln("Fail to create RuleBasedCollator");
                return;
            }
            iter = coll.GetCollationElementIterator(str);

            temporder = iter.Previous();

            if (iter.GetMaxExpansion(temporder) != 6)
            {
                Errln("Failure at codepoint 0x" + (ch).ToHexString()
                      + " maximum expansion count == 6");
            }
        }