コード例 #1
0
ファイル: XmlToPoTests.cs プロジェクト: limiha/FieldWorks
        public void TestWriteAndReadPoFile()
        {
            var poStrings   = new List <POString>();
            var fwLayoutDoc = XDocument.Parse(FwlayoutData);

            Assert.IsNotNull(fwLayoutDoc.Root);
            XmlToPo.ProcessConfigElement(fwLayoutDoc.Root, "/Language Explorer/Configuration/Parts/LexEntry.fwlayout", poStrings);
            var fwDictConfigDoc = XDocument.Parse(DictConfigData);

            Assert.IsNotNull(fwDictConfigDoc.Root);
            XmlToPo.ProcessFwDictConfigElement(fwDictConfigDoc.Root, "/Language Explorer/DefaultConfigurations/Dictionary/Root.fwdictconfig", poStrings);
            Assert.AreEqual(53, poStrings.Count);
            Assert.AreEqual("Lexeme Form", poStrings[0].MsgIdAsString());
            Assert.AreEqual("modified on: ", poStrings[49].MsgIdAsString());
            poStrings.Sort(POString.CompareMsgIds);
            // SUT
            POString.MergeDuplicateStrings(poStrings);
            Assert.AreEqual(40, poStrings.Count);
            Assert.AreEqual(" - ", poStrings[0].MsgIdAsString());
            Assert.AreEqual("Variants", poStrings[39].MsgIdAsString());
            var sw = new StringWriter();

            XmlToPo.WritePotFile(sw, "/home/testing/fw", poStrings);
            var potFileStr = sw.ToString();

            Assert.IsNotNull(potFileStr);
            var sr      = new StringReader(potFileStr);
            var dictPot = PoToXml.ReadPoFile(sr, null);

            Assert.AreEqual(40, dictPot.Count);
            var listPot = dictPot.ToList();

            Assert.AreEqual(" - ", listPot[0].Value.MsgIdAsString());
            Assert.AreEqual("Variants", listPot[39].Value.MsgIdAsString());

            var posHeadword = dictPot["Headword"];

            Assert.AreEqual(6, posHeadword.AutoComments.Count, "Headword AutoComments");
            Assert.AreEqual("/Language Explorer/Configuration/Parts/LexEntry.fwlayout::/LayoutInventory/layout[\"LexEntry-jtview-CrossRefPub\"]/part[@ref=\"MLHeadWordPub\"]/@label", posHeadword.AutoComments[0]);
            Assert.AreEqual("/Language Explorer/Configuration/Parts/LexEntry.fwlayout::/LayoutInventory/layout[\"LexEntry-jtview-SubentryUnderPub\"]/part[@ref=\"MLHeadWordPub\"]/@label", posHeadword.AutoComments[1]);
            Assert.AreEqual("/Language Explorer/DefaultConfigurations/Dictionary/Root.fwdictconfig:://ConfigurationItem[@name='Main Entry']/ConfigurationItem/@name", posHeadword.AutoComments[2]);
            Assert.AreEqual("/Language Explorer/DefaultConfigurations/Dictionary/Root.fwdictconfig:://ConfigurationItem[@name='MainEntrySubentries']/ConfigurationItem/@name", posHeadword.AutoComments[3]);
            Assert.AreEqual("/Language Explorer/DefaultConfigurations/Dictionary/Root.fwdictconfig:://ConfigurationItem[@name='Minor Entry (Complex Forms)']/ConfigurationItem/@name", posHeadword.AutoComments[4]);
            Assert.AreEqual("(String used 5 times.)", posHeadword.AutoComments[5]);

            var posComma = dictPot[", "];

            Assert.AreEqual(4, posComma.AutoComments.Count, "AutoCommas");
            Assert.AreEqual("/Language Explorer/DefaultConfigurations/Dictionary/Root.fwdictconfig:://ConfigurationItem[@name='Allomorphs']/@between", posComma.AutoComments[0]);
            Assert.AreEqual("(String used 3 times.)", posComma.AutoComments[3]);
        }
コード例 #2
0
ファイル: XmlToPoTests.cs プロジェクト: limiha/FieldWorks
        public void POString_WriteAndReadLeadingNewlines()
        {
            var poStr = new POString(new [] { "Displayed in a message box.", "/Src/FwResources//FwStrings.resx::kstidFatalError2" },
                                     new[] { @"\n", @"\n", @"In order to protect your data, the FieldWorks program needs to close.\n", @"\n", @"You should be able to restart it normally.\n" });

            Assert.IsNotNull(poStr.MsgId, "First resx string has MsgId data");
            Assert.AreEqual(5, poStr.MsgId.Count, "First resx string has five lines of MsgId data");
            Assert.AreEqual("\\n", poStr.MsgId[0], "First resx string has the expected MsgId data line one");
            Assert.AreEqual("\\n", poStr.MsgId[1], "First resx string has the expected MsgId data line two");
            Assert.AreEqual("In order to protect your data, the FieldWorks program needs to close.\\n", poStr.MsgId[2], "First resx string has the expected MsgId data line three");
            Assert.AreEqual("\\n", poStr.MsgId[3], "First resx string has the expected MsgId data line four");
            Assert.AreEqual("You should be able to restart it normally.\\n", poStr.MsgId[4], "First resx string has the expected MsgId data line five");
            Assert.IsTrue(poStr.HasEmptyMsgStr, "First resx string has no MsgStr data (as expected)");
            Assert.IsNull(poStr.UserComments, "First resx string has no User Comments (as expected)");
            Assert.IsNull(poStr.References, "First resx string has no Reference data (as expected)");
            Assert.IsNull(poStr.Flags, "First resx string.Flags");
            Assert.IsNotNull(poStr.AutoComments, "Third resx string has Auto Comments");
            Assert.AreEqual(2, poStr.AutoComments.Count, "First resx string has two lines of Auto Comments");
            Assert.AreEqual("Displayed in a message box.", poStr.AutoComments[0], "First resx string has the expected Auto Comment line one");
            Assert.AreEqual("/Src/FwResources//FwStrings.resx::kstidFatalError2", poStr.AutoComments[1], "First resx string has the expected Auto Comment line two");

            var sw = new StringWriter();

            // SUT
            poStr.Write(sw);
            poStr.Write(sw);             // write a second to ensure they can be read separately
            var serializedPo = sw.ToString();

            Assert.IsNotNull(serializedPo, "Writing resx strings' po data produced output");
            var poLines = serializedPo.Split(new[] { Environment.NewLine }, 100, StringSplitOptions.None);

            for (var i = 0; i <= 10; i += 10)
            {
                Assert.AreEqual("#. Displayed in a message box.", poLines[0 + i], $"Error line {0 + i}");
                Assert.AreEqual("#. /Src/FwResources//FwStrings.resx::kstidFatalError2", poLines[1 + i], $"Error line {1 + i}");
                Assert.AreEqual("msgid \"\"", poLines[2 + i], $"Error line {2 + i}");
                Assert.AreEqual("\"\\n\"", poLines[3 + i], $"Error line {3 + i}");
                Assert.AreEqual("\"\\n\"", poLines[4 + i], $"Error line {4 + i}");
                Assert.AreEqual("\"In order to protect your data, the FieldWorks program needs to close.\\n\"", poLines[5 + i], $"Error line {5 + i}");
                Assert.AreEqual("\"\\n\"", poLines[6 + i], $"Error line {6 + i}");
                Assert.AreEqual("\"You should be able to restart it normally.\\n\"", poLines[7 + i], $"Error line {7 + i}");
                Assert.AreEqual("msgstr \"\"", poLines[8 + i], $"Error line {8 + i}");
                Assert.AreEqual("", poLines[9 + i], $"Error line {9 + i}");
            }
            Assert.AreEqual("", poLines[20]);
            Assert.AreEqual(21, poLines.Length);

            var sr = new StringReader(serializedPo);
            // SUT
            var poStrA = POString.ReadFromFile(sr);
            var poStrB = POString.ReadFromFile(sr);
            var poStrC = POString.ReadFromFile(sr);

            Assert.IsNotNull(poStrA, "Read first message from leading newline test data");
            Assert.IsNotNull(poStrB, "Read second message from leading newline test data");
            Assert.IsNull(poStrC, "Only two messages in leading newline test data");

            CheckStringList(poStr.MsgId, poStrA.MsgId, "Preserve MsgId in first message from leading newline test data");
            CheckStringList(poStr.MsgStr, poStrA.MsgStr, "Preserve MsgStr in first message from leading newline test data");
            CheckStringList(poStr.UserComments, poStrA.UserComments, "Preserve UserComments in first message from leading newline test data");
            CheckStringList(poStr.References, poStrA.References, "Preserve Reference in first message from leading newline test data");
            CheckStringList(poStr.Flags, poStrA.Flags, "Preserve Flags in first message from leading newline test data");
            CheckStringList(poStr.AutoComments, poStrA.AutoComments, "Preserve AutoComments in first message from leading newline test data");
        }