Beispiel #1
0
        public void TestPluralVariantsByType()
        {
            MessageNode msg = MessagePatternUtil.BuildMessageNode(
                "{p,plural,a{A}other{O}=4{iv}b{B}other{U}=2{ii}}");
            ExpectMessageNode expect = new ExpectMessageNode().
                                       ExpectPluralArg("p").
                                       ExpectVariant("a").ExpectTextThatContains("A").FinishVariant().
                                       ExpectVariant("other").ExpectTextThatContains("O").FinishVariant().
                                       ExpectVariant("=4", 4).ExpectTextThatContains("iv").FinishVariant().
                                       ExpectVariant("b").ExpectTextThatContains("B").FinishVariant().
                                       ExpectVariant("other").ExpectTextThatContains("U").FinishVariant().
                                       ExpectVariant("=2", 2).ExpectTextThatContains("ii").FinishVariant().
                                       finishComplexArg();

            if (!expect.Matches(msg))
            {
                return;
            }
            List <VariantNode> numericVariants = new List <VariantNode>();
            List <VariantNode> keywordVariants = new List <VariantNode>();
            VariantNode        other           =
                ((ArgNode)msg.GetContents()[0]).ComplexStyle.
                GetVariantsByType(numericVariants, keywordVariants);

            assertEquals("'other' selector", "other", other.Selector);
            assertEquals("message string of first 'other'", "O", VariantText(other));

            assertEquals("numericVariants.size()", 2, numericVariants.Count);
            VariantNode v = numericVariants[0];

            assertEquals("numericVariants[0] selector", "=4", v.Selector);
            assertEquals("numericVariants[0] selector value", 4.0, v.SelectorValue);
            assertEquals("numericVariants[0] text", "iv", VariantText(v));
            v = numericVariants[1];
            assertEquals("numericVariants[1] selector", "=2", v.Selector);
            assertEquals("numericVariants[1] selector value", 2.0, v.SelectorValue);
            assertEquals("numericVariants[1] text", "ii", VariantText(v));

            assertEquals("keywordVariants.size()", 2, keywordVariants.Count);
            v = keywordVariants[0];
            assertEquals("keywordVariants[0] selector", "a", v.Selector);
            assertFalse("keywordVariants[0].isSelectorNumeric()", v.IsSelectorNumeric);
            assertEquals("keywordVariants[0] text", "A", VariantText(v));
            v = keywordVariants[1];
            assertEquals("keywordVariants[1] selector", "b", v.Selector);
            assertFalse("keywordVariants[1].isSelectorNumeric()", v.IsSelectorNumeric);
            assertEquals("keywordVariants[1] text", "B", VariantText(v));
        }
Beispiel #2
0
            internal bool Matches(MessageNode msg)
            {
                IList <MessageContentsNode> msgContents = msg.GetContents();
                bool ok = assertEquals("different numbers of MessageContentsNode",
                                       contents.Count, msgContents.Count);

                if (ok)
                {
                    //Iterator<MessageContentsNode> msgIter = msgContents.iterator();
                    using (var msgIter = msgContents.GetEnumerator())
                        foreach (ExpectMessageContentsNode ec in contents)
                        {
                            msgIter.MoveNext();
                            ok &= ec.Matches(msgIter.Current);
                        }
                }
                if (!ok)
                {
                    Errln("error in message: " + msg.ToString());
                }
                return(ok);
            }
Beispiel #3
0
        public void TestSelectVariantsByType()
        {
            MessageNode msg = MessagePatternUtil.BuildMessageNode(
                "{s,select,a{A}other{O}b{B}other{U}}");
            ExpectMessageNode expect = new ExpectMessageNode().
                                       ExpectSelectArg("s").
                                       ExpectVariant("a").ExpectTextThatContains("A").FinishVariant().
                                       ExpectVariant("other").ExpectTextThatContains("O").FinishVariant().
                                       ExpectVariant("b").ExpectTextThatContains("B").FinishVariant().
                                       ExpectVariant("other").ExpectTextThatContains("U").FinishVariant().
                                       finishComplexArg();

            if (!expect.Matches(msg))
            {
                return;
            }
            // Check that we can use numericVariants = null.
            IList <VariantNode> keywordVariants = new List <VariantNode>();
            VariantNode         other           =
                ((ArgNode)msg.GetContents()[0]).ComplexStyle.
                GetVariantsByType(null, keywordVariants);

            assertEquals("'other' selector", "other", other.Selector);
            assertEquals("message string of first 'other'", "O", VariantText(other));

            assertEquals("keywordVariants.size()", 2, keywordVariants.Count);
            VariantNode v = keywordVariants[0];

            assertEquals("keywordVariants[0] selector", "a", v.Selector);
            assertFalse("keywordVariants[0].isSelectorNumeric()", v.IsSelectorNumeric);
            assertEquals("keywordVariants[0] text", "A", VariantText(v));
            v = keywordVariants[1];
            assertEquals("keywordVariants[1] selector", "b", v.Selector);
            assertFalse("keywordVariants[1].isSelectorNumeric()", v.IsSelectorNumeric);
            assertEquals("keywordVariants[1] text", "B", VariantText(v));
        }