Esempio n. 1
0
        /// <summary/>
        public void UpdateWritingSystemListField_RemovesWsCode()
        {
            int m_wsEn = Cache.WritingSystemFactory.GetWsFromStr("en");
            int m_wsFr = Cache.WritingSystemFactory.GetWsFromStr("fr");

            CoreWritingSystemDefinition enBlz;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "blz", false, false, out enBlz);

            var revIndex = Cache.ServiceLocator.GetInstance <IReversalIndexRepository>().FindOrCreateIndexForWs(m_wsEn);

            var entry1 = SenseOrEntryTests.CreateInterestingLexEntry(Cache);
            var msa1   = Cache.ServiceLocator.GetInstance <IMoStemMsaFactory>().Create();

            entry1.MorphoSyntaxAnalysesOC.Add(msa1);
            entry1.SensesOS.First().MorphoSyntaxAnalysisRA = msa1;

            var entry2 = SenseOrEntryTests.CreateInterestingLexEntry(Cache);
            var msa2   = Cache.ServiceLocator.GetInstance <IMoStemMsaFactory>().Create();

            entry2.MorphoSyntaxAnalysesOC.Add(msa2);
            entry2.SensesOS.First().MorphoSyntaxAnalysisRA = msa2;

            var testEntry = revIndex.FindOrCreateReversalEntry("first");

            testEntry.SensesRS.Add(entry1.SensesOS.First());
            testEntry.SensesRS.Add(entry2.SensesOS.First());

            testEntry.ReversalIndex.WritingSystem = "fr";
            testEntry.ReversalForm.set_String(m_wsFr, "fr");
            WritingSystemServices.UpdateWritingSystemFields(Cache, "fr", "blz");
            Assert.DoesNotThrow(() => WritingSystemServices.UpdateWritingSystemFields(Cache, "fr", null));
            Assert.That(testEntry.ReversalIndex.WritingSystem, Is.EqualTo("blz"));
            Assert.That(testEntry.ReversalIndex.ShortName, Is.EqualTo("Balantak"));
        }
        public void FindAllWritingSystemsWithData_FindsHiddenWritingSystems()
        {
            var wsMgr = Cache.ServiceLocator.WritingSystemManager;

            wsMgr.GetOrSet("en", out var en);
            wsMgr.GetOrSet("fr", out var fr);
            wsMgr.GetOrSet("fr-x-has-no-strings", out _);
            wsMgr.GetOrSet("fr-x-zero-length", out var zeroLength);
            wsMgr.GetOrSet("blz", out var blz);
            wsMgr.GetOrSet("hid", out var hid);
            wsMgr.GetOrSet("hid-x-embedded", out var hidEmbedded);
            wsMgr.GetOrSet("hid-x-edgeCase", out var hidEdgeCase);
            wsMgr.GetOrSet("hid-x-baselineText", out var hidBaseline);
            var entry = SenseOrEntryTests.CreateInterestingLexEntry(Cache);

            entry.CitationForm.set_String(hid.Handle, "Headword");
            entry.CitationForm.set_String(zeroLength.Handle, string.Empty);
            var exampleBldr = new TsStrBldr().Append("Example ", blz.Handle).Append("with embedded WS", hidEmbedded.Handle).Append("!", blz.Handle);
            var example     = Cache.ServiceLocator.GetInstance <ILexExampleSentenceFactory>().Create();

            entry.SensesOS.First().ExamplesOS.Add(example);
            // The Example MultiString has an Edge Case alternative, but no Edge Case text.
            example.Example.set_String(hidEdgeCase.Handle, exampleBldr.GetString());
            // Interlinear texts are monolingual strings.
            AddInterlinearTextToLangProj("Title").ContentsOA.AddNewTextPara(null).Contents = TsStringUtils.MakeString("Content", hidBaseline.Handle);

            // SUT
            var result = WritingSystemServices.FindAllWritingSystemsWithText(Cache);

            Assert.That(new SortedSet <int>(result), Is.EquivalentTo(new[]
            {
                en.Handle, fr.Handle, blz.Handle, hid.Handle, hidEmbedded.Handle, hidEdgeCase.Handle, hidBaseline.Handle
            }));
        }
Esempio n. 3
0
        public void DeleteWritingSystem()
        {
            CoreWritingSystemDefinition wsBlz;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "blz", false, false, out wsBlz);

            var revIndex = Cache.ServiceLocator.GetInstance <IReversalIndexRepository>().FindOrCreateIndexForWs(wsBlz.Handle);

            Cache.LangProject.LexDbOA.ReversalIndexesOC.Add(revIndex);
            var entry1 = SenseOrEntryTests.CreateInterestingLexEntry(Cache);

            var testEntry = revIndex.FindOrCreateReversalEntry("first");

            testEntry.SensesRS.Add(entry1.SensesOS.First());

            testEntry.ReversalIndex.WritingSystem = "blz";
            testEntry.ReversalForm.set_String(wsBlz.Handle, "blz");
            Assert.That(testEntry.ReversalIndex.WritingSystem, Is.EqualTo("blz"));
            WritingSystemServices.DeleteWritingSystem(Cache, wsBlz);
            Assert.IsFalse(testEntry.IsValidObject);
            Assert.IsFalse(Cache.LangProject.LexDbOA.ReversalIndexesOC.Contains(revIndex));
        }
        public void DeleteWritingSystem()
        {
            Cache.ServiceLocator.WritingSystemManager.GetOrSet("fr", out var wsFr);
            Cache.ServiceLocator.WritingSystemManager.GetOrSet("blz", out var wsBlz);

            var revIndex = Cache.ServiceLocator.GetInstance <IReversalIndexRepository>().FindOrCreateIndexForWs(wsBlz.Handle);

            Cache.LangProject.LexDbOA.ReversalIndexesOC.Add(revIndex);
            var lexEntry = SenseOrEntryTests.CreateInterestingLexEntry(Cache);

            lexEntry.CitationForm.set_String(wsBlz.Handle, "Citation");
            var example = Cache.ServiceLocator.GetInstance <ILexExampleSentenceFactory>().Create();

            lexEntry.SensesOS.First().ExamplesOS.Add(example);
            var exampleBldr = new TsStrBldr().Append("Example embedding", wsFr.Handle).Append("Balantak!", wsBlz.Handle);

            example.Example.set_String(wsFr.Handle, exampleBldr.GetString());

            var revEntry = revIndex.FindOrCreateReversalEntry("first");

            revEntry.SensesRS.Add(lexEntry.SensesOS.First());

            revEntry.ReversalIndex.WritingSystem = "blz";
            revEntry.ReversalForm.set_String(wsBlz.Handle, "blz");
            Assert.That(revEntry.ReversalIndex.WritingSystem, Is.EqualTo("blz"));
            // SUT
            WritingSystemServices.DeleteWritingSystem(Cache, wsBlz);
            TsStringUtilsTests.AssertIsNullOrEmpty(lexEntry.CitationForm.get_String(wsBlz.Handle));
            var exampleAfter = example.Example;

            TsStringUtilsTests.AssertIsNullOrEmpty(exampleAfter.get_String(wsBlz.Handle));
            var exampleAfterFr = exampleAfter.get_String(wsFr.Handle);

            Assert.AreEqual("Example embedding", exampleAfterFr.Text);
            Assert.AreEqual(1, exampleAfterFr.RunCount);
            Assert.AreEqual(wsFr.Handle, exampleAfterFr.get_WritingSystemAt(0));
            Assert.IsFalse(revEntry.IsValidObject);
            Assert.IsFalse(Cache.LangProject.LexDbOA.ReversalIndexesOC.Contains(revIndex));
        }