示例#1
0
        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
        private static void AssertThatXmlEquals(XElement expected, XElement actual)
        {
            if (expected == null)
            {
                Assert.IsNull(actual, actual == null ? null : XmlToPo.ComputePathComment(actual, null, null));
                return;
            }
            if (actual == null)
            {
                Assert.Fail($"Expected a node matching {ComputeXPath(expected)}, but was null");
            }

            Assert.AreEqual(expected.Elements().Count(), actual.Elements().Count(),
                            $"Incorrect number of children under {ComputeXPath(expected)}");
            AssertThatXmlStartsWithHelper(expected, actual);
        }
示例#3
0
        public void TestComputeAutoCommentFilePath()
        {
            var result = XmlToPo.ComputeAutoCommentFilePath(@"E:\fwrepo/fw\DistFiles",
                                                            @"E:\fwrepo\fw\DistFiles\Language Explorer\DefaultConfigurations\Dictionary\Hybrid.fwdictconfig");

            Assert.AreEqual(@"/Language Explorer/DefaultConfigurations/Dictionary/Hybrid.fwdictconfig", result);

            result = XmlToPo.ComputeAutoCommentFilePath(@"C:\fwrepo\fw\DistFiles",
                                                        @"E:\fwrepo\fw\DistFiles\Language Explorer\DefaultConfigurations\Dictionary\Hybrid.fwdictconfig");
            Assert.AreEqual(@"E:/fwrepo/fw/DistFiles/Language Explorer/DefaultConfigurations/Dictionary/Hybrid.fwdictconfig", result);

            result = XmlToPo.ComputeAutoCommentFilePath("/home/steve/fwrepo/fw/DistFiles",
                                                        "/home/steve/fwrepo/fw/DistFiles/Language Explorer/Configuration/Parts/LexEntry.fwlayout");
            Assert.AreEqual("/Language Explorer/Configuration/Parts/LexEntry.fwlayout", result);

            result = XmlToPo.ComputeAutoCommentFilePath("/home/john/fwrepo/fw/DistFiles",
                                                        "/home/steve/fwrepo/fw/DistFiles/Language Explorer/Configuration/Parts/LexEntry.fwlayout");
            Assert.AreEqual("/home/steve/fwrepo/fw/DistFiles/Language Explorer/Configuration/Parts/LexEntry.fwlayout", result);
        }
示例#4
0
        public void TestReadingDetailConfigData()
        {
            var poStrings = new List <POString>();
            var xdoc      = XDocument.Parse(FwlayoutData);

            Assert.IsNotNull(xdoc.Root);
            //SUT
            XmlToPo.ProcessConfigElement(xdoc.Root, "/Language Explorer/Configuration/Parts/LexEntry.fwlayout", poStrings);
            Assert.AreEqual(14, poStrings.Count);
            var postr5 = poStrings[5];

            Assert.IsNotNull(postr5, "Detail Config string[5] has data");
            Assert.IsNotNull(postr5.MsgId, "Detail Config string[5].MsgId");
            Assert.AreEqual(1, postr5.MsgId.Count, "Detail Config string[5].MsgId.Count");
            Assert.AreEqual("Grammatical Info. Details", postr5.MsgId[0], "Detail Config string[5].MsgId[0]");
            Assert.AreEqual("Grammatical Info. Details", postr5.MsgIdAsString(), "Detail Config string[5] is 'Grammatical Info. Details'");
            Assert.IsTrue(postr5.HasEmptyMsgStr, "Detail Config string[5].HasEmptyMsgStr");
            Assert.IsNull(postr5.UserComments, "Detail Config string[5].UserComments");
            Assert.IsNull(postr5.References, "Detail Config string[5].References");
            Assert.IsNull(postr5.Flags, "Detail Config string[5].Flags");
            Assert.IsNotNull(postr5.AutoComments, "Detail Config string[5].AutoComments");
            Assert.AreEqual(1, postr5.AutoComments.Count, "Detail Config string[5].AutoComments.Count");
            Assert.AreEqual(
                "/Language Explorer/Configuration/Parts/LexEntry.fwlayout::/LayoutInventory/layout[\"LexEntry-detail-Normal\"]/part[@ref=\"GrammaticalFunctionsSection\"]/@label",
                postr5.AutoComments[0], "Detail Config string[5].AutoComments[0]");

            var postr8 = poStrings[8];

            Assert.IsNotNull(postr8, "Detail Config string[8] has data");
            Assert.IsNotNull(postr8.MsgId, "Detail Config string[8].MsgId");
            Assert.AreEqual(1, postr8.MsgId.Count, "Detail Config string[8].MsgId.Count");
            Assert.AreEqual("Headword", postr8.MsgId[0], "Detail Config string[8].MsgId[0]");
            Assert.AreEqual("Headword", poStrings[8].MsgIdAsString(), "Detail Config string[8] is 'Headword'");
            Assert.IsTrue(postr8.HasEmptyMsgStr, "Detail Config string[8].HasEmptyMsgStr");
            Assert.IsNull(postr8.UserComments, "Detail Config string[8].UserComments");
            Assert.IsNull(postr8.References, "Detail Config string[8].References");
            Assert.IsNull(postr8.Flags, "Detail Config string[8].Flags");
            Assert.IsNotNull(postr8.AutoComments, "Detail Config string[8].AutoComments");
            Assert.AreEqual(1, postr8.AutoComments.Count, "Detail Config string[8].AutoComments.Count");
            Assert.AreEqual(
                "/Language Explorer/Configuration/Parts/LexEntry.fwlayout::/LayoutInventory/layout[\"LexEntry-jtview-CrossRefPub\"]/part[@ref=\"MLHeadWordPub\"]/@label",
                postr8.AutoComments[0], "Detail Config string[8].AutoComments[0]");

            var postr10 = poStrings[10];

            Assert.IsNotNull(postr10, "Detail Config string[10] has data");
            Assert.IsNotNull(postr10.MsgId, "Detail Config string[10].MsgId");
            Assert.AreEqual(1, postr10.MsgId.Count, "Detail Config string[10].MsgId.Count");
            Assert.AreEqual(" CrossRef:", postr10.MsgId[0], "Detail Config string[10].MsgId[0]");
            Assert.AreEqual(" CrossRef:", poStrings[10].MsgIdAsString(), "Detail Config string[8] is ' CrossRef:'");
            Assert.IsTrue(postr10.HasEmptyMsgStr, "Detail Config string[10].HasEmptyMsgStr");
            Assert.IsNull(postr10.UserComments, "Detail Config string[10].UserComments");
            Assert.IsNull(postr10.References, "Detail Config string[10].References");
            Assert.IsNull(postr10.Flags, "Detail Config string[10].Flags");
            Assert.IsNotNull(postr10.AutoComments, "Detail Config string[10].AutoComments");
            Assert.AreEqual(1, postr10.AutoComments.Count, "Detail Config string[10].AutoComments.Count");
            Assert.AreEqual(
                "/Language Explorer/Configuration/Parts/LexEntry.fwlayout::/LayoutInventory/layout[\"LexEntry-jtview-CrossRefPub\"]/part[@ref=\"MLHeadWordPub\"]/@before",
                postr10.AutoComments[0], "Detail Config string[10].AutoComments[0]");

            var postr11 = poStrings[11];

            Assert.IsNotNull(postr11, "Detail Config string[11] has data");
            Assert.IsNotNull(postr11.MsgId, "Detail Config string[11].MsgId");
            Assert.AreEqual(1, postr11.MsgId.Count, "Detail Config string[11].MsgId.Count");
            Assert.AreEqual("Headword", postr11.MsgId[0], "Detail Config string[11].MsgId[0]");
            Assert.AreEqual("Headword", poStrings[11].MsgIdAsString(), "Detail Config string[8] is 'Headword'");
            Assert.IsTrue(postr11.HasEmptyMsgStr, "Detail Config string[11].HasEmptyMsgStr");
            Assert.IsNull(postr11.UserComments, "Detail Config string[11].UserComments");
            Assert.IsNull(postr11.References, "Detail Config string[11].References");
            Assert.IsNull(postr11.Flags, "Detail Config string[11].Flags");
            Assert.IsNotNull(postr11.AutoComments, "Detail Config string[11].AutoComments");
            Assert.AreEqual(1, postr11.AutoComments.Count, "Detail Config string[11].AutoComments.Count");
            Assert.AreEqual(
                "/Language Explorer/Configuration/Parts/LexEntry.fwlayout::/LayoutInventory/layout[\"LexEntry-jtview-SubentryUnderPub\"]/part[@ref=\"MLHeadWordPub\"]/@label",
                postr11.AutoComments[0], "Detail Config string[11].AutoComments[0]");
        }
示例#5
0
        public void TestReadingDictConfigData()
        {
            var poStrings = new List <POString>();
            var xdoc      = XDocument.Parse(DictConfigData);

            Assert.IsNotNull(xdoc.Root);
            //SUT
            XmlToPo.ProcessFwDictConfigElement(xdoc.Root, "/Language Explorer/DefaultConfigurations/Dictionary/Root.fwdictconfig", poStrings);
            Assert.AreEqual(39, poStrings.Count);
            var postr0 = poStrings[0];

            Assert.IsNotNull(postr0, "fwdictconfig string[0] has data");
            Assert.IsNotNull(postr0.MsgId, "fwdictconfig string[0].MsgId");
            Assert.AreEqual(1, postr0.MsgId.Count, "fwdictconfig string[0].MsgId.Count");
            Assert.AreEqual("Root-based (complex forms as subentries)", postr0.MsgId[0], "fwdictconfig string[0].MsgId[0]");
            Assert.AreEqual("Root-based (complex forms as subentries)", postr0.MsgIdAsString(), "fwdictconfig string[0] is 'Root-based (complex forms as subentries)'");
            Assert.IsTrue(postr0.HasEmptyMsgStr, "fwdictconfig string[0].HasEmptyMsgStr");
            Assert.IsNull(postr0.UserComments, "fwdictconfig string[0].UserComments");
            Assert.IsNull(postr0.References, "fwdictconfig string[0].References");
            Assert.IsNull(postr0.Flags, "fwdictconfig string[0].Flags");
            Assert.IsNotNull(postr0.AutoComments, "fwdictconfig string[0].AutoComments");
            Assert.AreEqual(1, postr0.AutoComments.Count, "fwdictconfig string[0].AutoComments.Count");
            Assert.AreEqual("/Language Explorer/DefaultConfigurations/Dictionary/Root.fwdictconfig:://DictionaryConfiguration/@name",
                            postr0.AutoComments[0], "fwdictconfig string[0].AutoComments[0]");

            var postr5 = poStrings[5];

            Assert.IsNotNull(postr5, "fwdictconfig string[5] has data");
            Assert.IsNotNull(postr5.MsgId, "fwdictconfig string[5].MsgId");
            Assert.AreEqual(1, postr5.MsgId.Count, "fwdictconfig string[5].MsgId.Count");
            Assert.AreEqual("Grammatical Info.", postr5.MsgId[0], "fwdictconfig string[5].MsgId[0]");
            Assert.AreEqual("Grammatical Info.", postr5.MsgIdAsString(), "fwdictconfig string[5] is 'Grammatical Info.'");
            Assert.IsTrue(postr5.HasEmptyMsgStr, "fwdictconfig string[5].HasEmptyMsgStr");
            Assert.IsNull(postr5.UserComments, "fwdictconfig string[5].UserComments");
            Assert.IsNull(postr5.References, "fwdictconfig string[5].References");
            Assert.IsNull(postr5.Flags, "fwdictconfig string[5].Flags");
            Assert.IsNotNull(postr5.AutoComments, "fwdictconfig string[5].AutoComments");
            Assert.AreEqual(1, postr5.AutoComments.Count, "fwdictconfig string[5].AutoComments.Count");
            Assert.AreEqual("/Language Explorer/DefaultConfigurations/Dictionary/Root.fwdictconfig:://ConfigurationItem[@name='Senses']/ConfigurationItem/@name",
                            postr5.AutoComments[0], "fwdictconfig string[5].AutoComments[0]");

            var postr34 = poStrings[34];

            Assert.IsNotNull(postr34, "fwdictconfig string[34] has data");
            Assert.IsNotNull(postr34.MsgId, "fwdictconfig string[34].MsgId");
            Assert.AreEqual(1, postr34.MsgId.Count, "fwdictconfig string[34].MsgId.Count");
            Assert.AreEqual("Date Modified", postr34.MsgId[0], "fwdictconfig string[34].MsgId[0]");
            Assert.AreEqual("Date Modified", postr34.MsgIdAsString(), "fwdictconfig string[34] is 'Date Modified'");
            Assert.IsTrue(postr34.HasEmptyMsgStr, "fwdictconfig string[34].HasEmptyMsgStr");
            Assert.IsNull(postr34.UserComments, "fwdictconfig string[34].UserComments");
            Assert.IsNull(postr34.References, "fwdictconfig string[34].References");
            Assert.IsNull(postr34.Flags, "fwdictconfig string[34].Flags");
            Assert.IsNotNull(postr34.AutoComments, "fwdictconfig string[34].AutoComments");
            Assert.AreEqual(1, postr34.AutoComments.Count, "fwdictconfig string[34].AutoComments.Count");
            Assert.AreEqual("/Language Explorer/DefaultConfigurations/Dictionary/Root.fwdictconfig:://ConfigurationItem[@name='Minor Entry (Complex Forms)']/ConfigurationItem/@name",
                            postr34.AutoComments[0], "fwdictconfig string[34].AutoComments[0]");

            var postr35 = poStrings[35];

            Assert.IsNotNull(postr35, "fwdictconfig string[35] has data");
            Assert.IsNotNull(postr35.MsgId, "fwdictconfig string[35].MsgId");
            Assert.AreEqual(1, postr35.MsgId.Count, "fwdictconfig string[35].MsgId.Count");
            Assert.AreEqual("modified on: ", postr35.MsgId[0], "fwdictconfig string[35].MsgId[0]");
            Assert.AreEqual("modified on: ", postr35.MsgIdAsString(), "fwdictconfig string[35] is 'modified on: '");
            Assert.IsTrue(postr35.HasEmptyMsgStr, "fwdictconfig string[35].HasEmptyMsgStr");
            Assert.IsNull(postr35.UserComments, "fwdictconfig string[35].UserComments");
            Assert.IsNull(postr35.References, "fwdictconfig string[35].References");
            Assert.IsNull(postr35.Flags, "fwdictconfig string[35].Flags");
            Assert.IsNotNull(postr35.AutoComments, "fwdictconfig string[35].AutoComments");
            Assert.AreEqual(1, postr35.AutoComments.Count, "fwdictconfig string[35].AutoComments.Count");
            Assert.AreEqual("/Language Explorer/DefaultConfigurations/Dictionary/Root.fwdictconfig:://ConfigurationItem[@name='Date Modified']/@before",
                            postr35.AutoComments[0], "fwdictconfig string[35].AutoComments[0]");

            var postr38 = poStrings[38];

            Assert.IsNotNull(postr38, "string[38]");
            Assert.IsNotNull(postr38.MsgId, "string[38].MsgId");
            Assert.AreEqual(1, postr38.MsgId.Count, "fwdictconfig string[38].MsgId.Count");
            Assert.AreEqual("Subsubentries", postr38.MsgId[0], "fwdictconfig string[38].MsgId[0]");
            Assert.AreEqual("Subsubentries", postr38.MsgIdAsString(), "fwdictconfig string[38].MsgIdAsString()");
            Assert.IsTrue(postr38.HasEmptyMsgStr, "fwdictconfig string[38].MsgStr");
            Assert.IsNull(postr38.UserComments, "fwdictconfig string[38].UserComments");
            Assert.IsNull(postr38.References, "fwdictconfig string[38].References");
            Assert.IsNull(postr38.Flags, "fwdictconfig string[38].Flags");
            Assert.IsNotNull(postr38.AutoComments, "fwdictconfig string[38].AutoComments");
            Assert.AreEqual(1, postr38.AutoComments.Count, "fwdictconfig string[38].AutoComments.Count");
            Assert.AreEqual("/Language Explorer/DefaultConfigurations/Dictionary/Root.fwdictconfig:://ConfigurationItem[@name='MainEntrySubentries']/ConfigurationItem/@name",
                            postr38.AutoComments[0], "fwdictconfig string[38].AutoComments[0]");

            Assert.False(poStrings.Any(poStr => poStr.MsgIdAsString() == "MainEntrySubentries"), "Shared Items' labels should not be translatable");
        }