Beispiel #1
0
        void CheckHeader(POCatalog catalog, bool expectComments, bool expectInfoHeaders)
        {
            if (expectInfoHeaders)
            {
                Assert.Equal(12, catalog.Headers.Count);

                Assert.Equal("8bit", catalog.Headers["Content-Transfer-Encoding"]);
                Assert.Equal("text/plain; charset=UTF-8", catalog.Headers["Content-Type"]);
                Assert.Equal("", catalog.Headers["Language-Team"]);
                Assert.Equal("nplurals=2; plural=(n != 1);", catalog.Headers["Plural-Forms"]);
                Assert.Equal("", catalog.Headers["PO-Revision-Date"]);
                Assert.Equal("2018-06-22 07:01+0200", catalog.Headers["POT-Creation-Date"]);
                Assert.Equal("", catalog.Headers["Project-Id-Version"]);
                Assert.Equal("", catalog.Headers["Report-Msgid-Bugs-To"]);
                Assert.Equal("1.0", catalog.Headers["MIME-Version"]);
                Assert.Equal("Poedit 2.0.8", catalog.Headers["X-Generator"]);
                Assert.Equal("", catalog.Headers["Last-Translator"]);
                Assert.Equal("en_US", catalog.Headers["Language"]);
            }
            else
            {
                Assert.Null(catalog.Headers);
            }

            Assert.Equal("UTF-8", catalog.Encoding);
            Assert.Equal("en_US", catalog.Language);
            Assert.Equal(2, catalog.PluralFormCount);
            Assert.Equal("(n != 1)", catalog.PluralFormSelector);
            Assert.Equal(0, catalog.GetPluralFormIndex(1));
            Assert.Equal(1, catalog.GetPluralFormIndex(2));
            Assert.Equal(1, catalog.GetPluralFormIndex(5));

            if (expectComments)
            {
                Assert.Equal(1, catalog.HeaderComments.Count);

                var comments = catalog.HeaderComments;
                Assert.Equal(POCommentKind.Translator, comments[0].Kind);
                Assert.Equal("header comment", ((POTranslatorComment)comments[0]).Text);
            }
            else
            {
                Assert.Null(catalog.HeaderComments);
            }
        }
Beispiel #2
0
        private void CheckHeader(POCatalog catalog, bool expectComments, bool expectInfoHeaders, bool expectOrderedHeaders)
        {
            if (expectInfoHeaders)
            {
                Assert.Equal(12, catalog.Headers.Count);

                Assert.Equal("8bit", catalog.Headers["Content-Transfer-Encoding"]);
                Assert.Equal("text/plain; charset=UTF-8", catalog.Headers["Content-Type"]);
                Assert.Equal("", catalog.Headers["Language-Team"]);
                Assert.Equal("nplurals=2; plural=(n != 1);", catalog.Headers["Plural-Forms"]);
                Assert.Equal("", catalog.Headers["PO-Revision-Date"]);
                Assert.Equal("2018-06-22 07:01+0200", catalog.Headers["POT-Creation-Date"]);
                Assert.Equal("", catalog.Headers["Project-Id-Version"]);
                Assert.Equal("", catalog.Headers["Report-Msgid-Bugs-To"]);
                Assert.Equal("1.0", catalog.Headers["MIME-Version"]);
                Assert.Equal("Poedit 2.0.8", catalog.Headers["X-Generator"]);
                Assert.Equal("", catalog.Headers["Last-Translator"]);
                Assert.Equal("en_US", catalog.Headers["Language"]);
            }
            else
            {
                Assert.Null(catalog.Headers);
            }

            if (expectOrderedHeaders)
            {
#if USE_COMMON
                Assert.IsAssignableFrom <Karambolo.Common.Collections.IOrderedDictionary <string, string> >(catalog.Headers);

                Assert.Equal(new[] { "Content-Transfer-Encoding", "Content-Type", "Language", "Language-Team", "Last-Translator", "MIME-Version",
                                     "Plural-Forms", "PO-Revision-Date", "POT-Creation-Date", "Project-Id-Version", "Report-Msgid-Bugs-To", "X-Generator" },
                             catalog.Headers.Keys);
#else
                Assert.True(false, "Compact version doesn't include PreserveHeadersOrder.");
#endif
            }

            Assert.Equal("UTF-8", catalog.Encoding);
            Assert.Equal("en_US", catalog.Language);
            Assert.Equal(2, catalog.PluralFormCount);
            Assert.Equal("(n != 1)", catalog.PluralFormSelector);

#if USE_HIME
            Assert.Equal(0, catalog.GetPluralFormIndex(1));
            Assert.Equal(1, catalog.GetPluralFormIndex(2));
            Assert.Equal(1, catalog.GetPluralFormIndex(5));
#else
            Assert.Equal(0, catalog.GetPluralFormIndex(1));
            Assert.Equal(0, catalog.GetPluralFormIndex(2));
            Assert.Equal(0, catalog.GetPluralFormIndex(5));
#endif

            if (expectComments)
            {
                Assert.Equal(1, catalog.HeaderComments.Count);

                IList <POComment> comments = catalog.HeaderComments;
                Assert.Equal(POCommentKind.Translator, comments[0].Kind);
                Assert.Equal("header comment", ((POTranslatorComment)comments[0]).Text);
            }
            else
            {
                Assert.Null(catalog.HeaderComments);
            }
        }