public void IpaStatus_SetToNotIpaWhenWasOnlyVariant_FonIpaRemoved()
		{
			var ws = new WritingSystemDefinition();
			ws.Variants.Add("fonipa");
			ws.IpaStatus = IpaStatusChoices.NotIpa;
			Assert.That(ws.Variants, Is.Empty);
		}
		public void IpaStatus_SetToIpaWasAlreadyIpaAndOnyVariant_NoChange()
		{
			var ws = new WritingSystemDefinition();
			ws.IpaStatus = IpaStatusChoices.Ipa;
			ws.Variant = "fonipa";
			Assert.AreEqual("fonipa", ws.Variant);
		}
		public void IpaStatus_SetToIpaWasAlreadyIpaWithOtherVariants_NoChange()
		{
			var ws = new WritingSystemDefinition();
			ws.Variant = "1901-biske-fonipa";
			ws.IpaStatus = IpaStatusChoices.Ipa;
			Assert.AreEqual("1901-biske-fonipa", ws.Variant);
		}
		public void IpaStatus_SetToIpaWhenVariantHasContents_FonIpaAtEnd()
		{
			var ws = new WritingSystemDefinition();
			ws.Variants.AddRange(new VariantSubtag[] {"1901", "biske"});
			ws.IpaStatus = IpaStatusChoices.Ipa;
			Assert.That(ws.Variants, Is.EqualTo(new VariantSubtag[] {"1901", "biske", "fonipa"}));
		}
		public DeleteInputSystemDialog(WritingSystemDefinition wsToDelete,
									   IEnumerable<WritingSystemDefinition> possibleWritingSystemsToConflateWith, bool showHelpButton)
		{
			InitializeComponent();
			if (!showHelpButton)
			{
				_helpButton.Hide();
			}
			_deleteRadioButton.Text = String.Format(_deleteRadioButton.Text, DisplayName(wsToDelete));
			_mergeRadioButton.Text = String.Format(_mergeRadioButton.Text, DisplayName(wsToDelete));
			_wsSelectionComboBox.Items.AddRange(
				possibleWritingSystemsToConflateWith.Where(ws => ws != wsToDelete).Select(ws=>new WritingSystemDisplayAdaptor(ws)).ToArray());
			Choice = Choices.Delete;
			if (_wsSelectionComboBox.Items.Count > 0)
			{
				_wsSelectionComboBox.SelectedIndex = 0;
			}
			_wsSelectionComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
			_okButton.Click += OnOkClicked;
			_cancelButton.Click += OnCancelClicked;
			_deleteRadioButton.CheckedChanged += OnDeleteRadioButtonCheckedChanged;
			_mergeRadioButton.CheckedChanged += OnMergeRadioButtonCheckedChanged;
			_helpButton.Click += OnCustomHelpButtonClicked;
			_deleteRadioButton.Checked = true;
		}
			public TestEnvironment()
			{
				_temporaryFolder = new TemporaryFolder("LiftLexEntryRepositoryTests");
				string filePath = _temporaryFolder.GetTemporaryFile();
				_repository = new LiftLexEntryRepository(filePath);
				_headwordWritingSystem = new WritingSystemDefinition("th") {DefaultCollation = new IcuRulesCollationDefinition("standard")};
			}
		public void Setup()
		{
			_temporaryFolder = new TemporaryFolder();
			string filePath = _temporaryFolder.GetTemporaryFile();
			_repository = new LiftLexEntryRepository(filePath);
			_headwordWritingSystem = new WritingSystemDefinition("th");
		}
		public void IpaStatus_SetToIpaWasAlreadyIpaWithOtherVariants_NoChange()
		{
			var ws = new WritingSystemDefinition();
			ws.Variants.AddRange(new VariantSubtag[] {"1901", "biske", "fonipa"});
			ws.IpaStatus = IpaStatusChoices.Ipa;
			Assert.That(ws.Variants, Is.EqualTo(new VariantSubtag[] {"1901", "biske", "fonipa"}));
		}
		public IEnumerable<IWritingSystemDefinitionSuggestion> GetSuggestions(WritingSystemDefinition primary, IEnumerable<WritingSystemDefinition> existingWritingSystemsForLanguage)
		{
			if (primary.Language == null && primary.Variants.Any(v => !v.IsPrivateUse))
				yield break;

			if (SuppressSuggestionsForMajorWorldLanguages
			   && new[]{"en", "th", "es", "fr", "de", "hi", "id", "vi","my","pt", "fi", "ar", "it","sv", "ja", "ko", "ch", "nl", "ru"}.Contains((string) primary.Language))
				yield break;

			WritingSystemDefinition[] existingWSs = existingWritingSystemsForLanguage.ToArray();

			if (SuggestIpa && IpaSuggestion.ShouldSuggest(existingWSs))
			{
				yield return new IpaSuggestion(_writingSystemFactory, primary);
			}

			if (SuggestVoice && VoiceSuggestion.ShouldSuggest(existingWSs))
			{
				yield return new VoiceSuggestion(_writingSystemFactory, primary);
			}

			if (SuggestDialects)
			{
				yield return new DialectSuggestion(_writingSystemFactory, primary);
			}

			if (SuggestOther)
			{
				yield return new OtherSuggestion(_writingSystemFactory, primary, existingWSs);
			}
		}
		public void Read_ValidXml_SetsAllProperties()
		{
			const string projectSettingsXml =
@"<ProjectLexiconSettings>
  <WritingSystems>
    <WritingSystem id=""qaa-Qaaa-QM-x-kal-Fake-ZG-var1-var2"">
      <Abbreviation>kal</Abbreviation>
      <LanguageName>Kalaba</LanguageName>
      <ScriptName>Fake</ScriptName>
      <RegionName>Zolrog</RegionName>
      <SystemCollation>snarf</SystemCollation>
    </WritingSystem>
    <WritingSystem id=""fr-FR"">
      <SpellCheckingId>fr_FR</SpellCheckingId>
      <LegacyMapping>converter</LegacyMapping>
      <Keyboard>Old Keyboard</Keyboard>
    </WritingSystem>
  </WritingSystems>
</ProjectLexiconSettings>";

			var projectSettingsDataMapper = new ProjectLexiconSettingsWritingSystemDataMapper(new MemorySettingsStore {SettingsElement = XElement.Parse(projectSettingsXml)});

			var ws1 = new WritingSystemDefinition("qaa-Qaaa-QM-x-kal-Fake-ZG-var1-var2");
			projectSettingsDataMapper.Read(ws1);

			Assert.That(ws1.Abbreviation, Is.EqualTo("kal"));
			Assert.That(ws1.Language.Name, Is.EqualTo("Kalaba"));
			Assert.That(ws1.Script.Name, Is.EqualTo("Fake"));
			Assert.That(ws1.Region.Name, Is.EqualTo("Zolrog"));
			Assert.That(ws1.SpellCheckingId, Is.EqualTo(string.Empty));
			Assert.That(ws1.LegacyMapping, Is.EqualTo(string.Empty));
			Assert.That(ws1.Keyboard, Is.EqualTo(string.Empty));
			var scd = new SystemCollationDefinition {LanguageTag = "snarf"};
			Assert.That(ws1.DefaultCollation.ValueEquals(scd), Is.True);

			var ws2 = new WritingSystemDefinition("fr-FR");
			projectSettingsDataMapper.Read(ws2);

			Assert.That(ws2.Abbreviation, Is.EqualTo("fr"));
			Assert.That(ws2.Language.Name, Is.EqualTo("French"));
			Assert.That(ws2.Script.Name, Is.EqualTo("Latin"));
			Assert.That(ws2.Region.Name, Is.EqualTo("France"));
			Assert.That(ws2.Variants, Is.Empty);
			Assert.That(ws2.SpellCheckingId, Is.EqualTo("fr_FR"));
			Assert.That(ws2.LegacyMapping, Is.EqualTo("converter"));
			Assert.That(ws2.Keyboard, Is.EqualTo("Old Keyboard"));

			var ws3 = new WritingSystemDefinition("es");
			projectSettingsDataMapper.Read(ws3);

			Assert.That(ws3.Abbreviation, Is.EqualTo("es"));
			Assert.That(ws3.Language.Name, Is.EqualTo("Spanish"));
			Assert.That(ws3.Script.Name, Is.EqualTo("Latin"));
			Assert.That(ws3.Region, Is.Null);
			Assert.That(ws3.Variants, Is.Empty);
			Assert.That(ws3.SpellCheckingId, Is.EqualTo(string.Empty));
			Assert.That(ws3.LegacyMapping, Is.EqualTo(string.Empty));
			Assert.That(ws3.Keyboard, Is.EqualTo(string.Empty));
		}
		private static WritingSystemDefinition WritingSystemDefinitionForTest(string languageISO, Font font)
		{
			var retval = new WritingSystemDefinition();
			retval.Language = languageISO;
			retval.DefaultFontName = font.Name;
			retval.DefaultFontSize = font.Size;
			return retval;
		}
		public override bool Create(string ietfLanguageTag, out WritingSystemDefinition ws)
		{
			if (_writingSystems.TryGet(ietfLanguageTag, out ws))
				return true;

			ws = ConstructDefinition(ietfLanguageTag);
			return true;
		}
		public virtual void SetUp()
		{
			_writingSystem = new WritingSystemDefinition();
			RepositoryUnderTest = CreateNewStore();
			_writingSystemIdChangedEventArgs = null;
			_writingSystemDeletedEventArgs = null;
			_writingSystemConflatedEventArgs = null;
		}
 public void AllWritingSystems_HasAllWritingSystems_ReturnsAllWritingSystems()
 {
     var ws1 = new WritingSystemDefinition("fr");
     ws1.IsVoice = true;
     RepositoryUnderTest.Set(ws1);
     RepositoryUnderTest.Set(new WritingSystemDefinition("de"));
     RepositoryUnderTest.Set(new WritingSystemDefinition("es"));
     Assert.IsTrue(RepositoryUnderTest.AllWritingSystems.Count() == 3);
 }
		[Test] // ok
		public void GetSuggestions_HasNormalAndIPA_DoesNotIncludeItemToCreateIPA()
		{
			var etr = new WritingSystemDefinition("etr", string.Empty, string.Empty, string.Empty, "edo", false);
			var etrIpa = new WritingSystemDefinition("etr", string.Empty, string.Empty,  "fonipa", "edo", false);
			var list = new List<WritingSystemDefinition>(new[] { etr, etrIpa });
			var suggestor = new WritingSystemSuggestor(new TestWritingSystemFactory());
			IEnumerable<IWritingSystemDefinitionSuggestion> suggestions = suggestor.GetSuggestions(etr, list);

			Assert.That(suggestions.Any(defn => defn is IpaSuggestion), Is.False);
		}
示例#16
0
		public void Init(WritingSystemDefinition writingSystem, String name)
		{
			WritingSystem = writingSystem;
			_nameForLogging = name;
			if (_nameForLogging == null)
			{
				_nameForLogging = "??";
			}
			Name = name;
		}
		public void SetTwoDefinitions_CountEquals2()
		{
			_writingSystem.Language = "one";
			RepositoryUnderTest.Set(_writingSystem);
			var ws2 = new WritingSystemDefinition();
			ws2.Language = "two";
			RepositoryUnderTest.Set(ws2);

			Assert.AreEqual(2, RepositoryUnderTest.Count);
		}
		[Test] // ok
		public void GetSuggestions_HasNormalAndIPA_DoesNotIncludeItemToCreateIPA()
		{
			var etr = new WritingSystemDefinition("etr", string.Empty, string.Empty, string.Empty, "edo", false);
			var etrIpa = new WritingSystemDefinition("etr", string.Empty, string.Empty,  "fonipa", "edo", false);
			var list = new List<WritingSystemDefinition>(new[] { etr, etrIpa });
			var suggestor = new WritingSystemSuggestor();
			var suggestions = suggestor.GetSuggestions(etr, list);

			Assert.IsFalse(suggestions.Any(defn => ((WritingSystemSuggestion)defn).TemplateDefinition.Variant == "fonipa"));
		}
		public void Save_NewWritingSystem_CreatesLdmlFile()
		{
			using (var e = new TemporaryFolder("GlobalWritingSystemRepositoryTests"))
			{
				var repo = new GlobalWritingSystemRepository(e.Path);
				var ws = new WritingSystemDefinition("en-US");
				repo.Set(ws);
				repo.Save();
				Assert.That(File.Exists(repo.GetFilePathFromLanguageTag("en-US")), Is.True);
			}
		}
		public void IpaStatus_SetToPhonemicOnEntirelyPrivateUseWritingSystem_MarkerForUnlistedLanguageIsInserted()
		{
			var ws = new WritingSystemDefinition("x-private");
			Assert.That(ws.Language, Is.Null);
			Assert.That(ws.Variants, Is.EqualTo(new VariantSubtag[] {"private"}));
			ws.IpaStatus = IpaStatusChoices.IpaPhonemic;
			Assert.That(ws.Language, Is.EqualTo((LanguageSubtag) WellKnownSubtags.UnlistedLanguage));
			Assert.That(ws.Script, Is.Null);
			Assert.That(ws.Region, Is.Null);
			Assert.That(ws.Variants, Is.EqualTo(new VariantSubtag[] {WellKnownSubtags.IpaVariant, WellKnownSubtags.IpaPhonemicPrivateUse, "private"}));
		}
		public void Set_NewWritingSystem_SetsId()
		{
			using (var e = new TemporaryFolder("GlobalWritingSystemRepositoryTests"))
			{
				var repo = new GlobalWritingSystemRepository(e.Path);
				var ws = new WritingSystemDefinition("en-US");
				Assert.That(ws.Id, Is.Null);
				repo.Set(ws);
				Assert.That(ws.Id, Is.EqualTo("en-US"));
			}
		}
示例#22
0
		public GeckoBox(WritingSystemDefinition ws, string nameForLogging)
			: this()
		{
			_nameForLogging = nameForLogging;
			if (_nameForLogging == null)
			{
				_nameForLogging = "??";
			}
			Name = _nameForLogging;
			WritingSystem = ws;
		}
		public void FindOrphans_NoOrphansFound_WritingSystemRepoAndFileUntouched()
		{
			using (var e = new TestEnvironment("en", "en"))
			{
				var englishWs = new WritingSystemDefinition("en");
				e.WritingSystemRepository.Set(englishWs);
				WritingSystemOrphanFinder.FindOrphans(e.GetIdsFromFile, e.ReplaceIdInFile, e.WritingSystemRepository);
				Assert.That(e.WritingSystemRepository.Count, Is.EqualTo(1));
				Assert.That(e.WritingSystemRepository.Get("en"), Is.EqualTo(englishWs));
				Assert.That(e.FileContent, Is.EqualTo("|en||en||en|"));
			}
		}
		public void Read_EmptyXml_NothingSet()
		{
			var userSettingsDataMapper = new UserLexiconSettingsWritingSystemDataMapper(new MemorySettingsStore());

			var ws1 = new WritingSystemDefinition("en-US");
			userSettingsDataMapper.Read(ws1);

			Assert.That(ws1.LocalKeyboard, Is.EqualTo(Keyboard.Controller.DefaultKeyboard));
			Assert.That(ws1.DefaultFont, Is.Null);
			Assert.That(ws1.DefaultFontSize, Is.EqualTo(0));
			Assert.That(ws1.IsGraphiteEnabled, Is.True);
		}
		public void GetSuggestions_MajorWorlLanguage_SuggestsOnlyIfSuppressSuggesstionsForMajorWorldLanguagesIsFalse()
		{
			var english = new WritingSystemDefinition("en", string.Empty, string.Empty, string.Empty, "eng", false);
			var list = new List<WritingSystemDefinition>(new[] { english });
			var suggestor = new WritingSystemSuggestor();
			suggestor.SuppressSuggestionsForMajorWorldLanguages =false;
			var suggestions = suggestor.GetSuggestions(english, list);
			Assert.IsTrue(suggestions.Any(defn => ((WritingSystemSuggestion)defn).TemplateDefinition.Variant == "fonipa"));

			suggestor.SuppressSuggestionsForMajorWorldLanguages =true;
			suggestions = suggestor.GetSuggestions(english, list);
			Assert.IsFalse(suggestions.Any(defn => ((WritingSystemSuggestion)defn).TemplateDefinition.Variant == "fonipa"));
		}
		public void FindOrphans_OrphanFoundIsValidRfcTag_WritingsystemIsAddedToWritingSystemRepoAndFileUntouched()
		{
			using (var e = new TestEnvironment("en", "de"))
			{
				var englishWs = new WritingSystemDefinition("en");
				e.WritingSystemRepository.Set(englishWs);
				WritingSystemOrphanFinder.FindOrphans(e.GetIdsFromFile, e.ReplaceIdInFile, e.WritingSystemRepository);
				Assert.That(e.WritingSystemRepository.Count, Is.EqualTo(2));
				Assert.That(e.WritingSystemRepository.Get("en"), Is.EqualTo(englishWs));
				Assert.That(e.WritingSystemRepository.Get("de"), Is.Not.Null);
				Assert.That(e.FileContent, Is.EqualTo("|en||en||de|"));
			}
		}
		public void GetSuggestions_MajorWorlLanguage_SuggestsOnlyIfSuppressSuggesstionsForMajorWorldLanguagesIsFalse()
		{
			var english = new WritingSystemDefinition("en", string.Empty, string.Empty, string.Empty, "eng", false);
			var list = new List<WritingSystemDefinition>(new[] { english });
			var suggestor = new WritingSystemSuggestor(new TestWritingSystemFactory());
			suggestor.SuppressSuggestionsForMajorWorldLanguages = false;
			var suggestions = suggestor.GetSuggestions(english, list);
			Assert.That(suggestions.Any(defn => defn is IpaSuggestion), Is.True);

			suggestor.SuppressSuggestionsForMajorWorldLanguages = true;
			suggestions = suggestor.GetSuggestions(english, list);
			Assert.That(suggestions.Any(defn => defn is IpaSuggestion), Is.False);
		}
		public void Validate_SelfReferencingImport_Valid()
		{
			var ws = new WritingSystemDefinition("en-US");
			ws.Collations.Add(new IcuRulesCollationDefinition("private") {IcuRules = "&B<t<<<T<s<<<S<e<<<E\r\n"});
			var collation = new IcuRulesCollationDefinition("standard")
			{
				OwningWritingSystemDefinition = ws,
				Imports = {new IcuCollationImport("en-US", "private")},
				IcuRules = "&C<k<<<K<x<<<X<i<<<I\r\n"
			};
			string message;
			Assert.That(collation.Validate(out message), Is.True);
			Assert.That(collation.CollationRules, Is.EqualTo("&B<t<<<T<s<<<S<e<<<E\r\n&C<k<<<K<x<<<X<i<<<I\r\n"));
		}
		public IpaSuggestion(IWritingSystemDefinition primary)
		{
			_templateDefinition = new WritingSystemDefinition(primary.Language, "", primary.Region, primary.Variant, "ipa", false)
									  {
										  LanguageName = primary.LanguageName,
										  DefaultFontSize = primary.DefaultFontSize,
										  DefaultFontName = _fontsForIpa.FirstOrDefault(FontExists),
										  IpaStatus = IpaStatusChoices.Ipa,
									  };
			var ipaKeyboard = Keyboard.Controller.AllAvailableKeyboards.FirstOrDefault(k => k.Id.ToLower().Contains("ipa"));
			if (ipaKeyboard != null)
				_templateDefinition.Keyboard = ipaKeyboard.Id;
			this.Label = string.Format("IPA input system for {0}", _templateDefinition.LanguageName);
		}
		public void Validate_ImportInvalidRules_NotValid()
		{
			var ws = new WritingSystemDefinition("en-US");
			ws.Collations.Add(new IcuRulesCollationDefinition("private") {IcuRules = "&&&B<t<<<T<s<<<S<e<<<E\r\n"});
			var collation = new IcuRulesCollationDefinition("standard")
			{
				OwningWritingSystemDefinition = ws,
				Imports = {new IcuCollationImport("en-US", "private")},
				IcuRules = "&C<k<<<K<x<<<X<i<<<I\r\n"
			};
			string message;
			Assert.That(collation.Validate(out message), Is.False);
			Assert.That(message, Is.EqualTo("Unable to import the private collation rules from en-US."));
		}
示例#31
0
        private WritingSystemDefinition LoadWritingSystemDefinition()
        {
            if (!ContainsLdmlFile())
            {
                return(null);
            }

            var ldmlAdaptor = new LdmlDataMapper(new WritingSystemFactory());

            var wsFromLdml = new WritingSystemDefinition();

            ldmlAdaptor.Read(LdmlFilePath, wsFromLdml);

            return(wsFromLdml);
        }
示例#32
0
        public void Save_DeletedWritingSystem_RemovesLdmlFile()
        {
            using (var e = CreateTemporaryFolder(TestContext.CurrentContext.Test.Name))
            {
                var repo = new GlobalWritingSystemRepository(e.Path);
                var ws   = new WritingSystemDefinition("en-US");
                repo.Set(ws);
                repo.Save();
                Assert.That(File.Exists(repo.GetFilePathFromLanguageTag("en-US")), Is.True);

                ws.MarkedForDeletion = true;
                repo.Save();
                Assert.That(File.Exists(repo.GetFilePathFromLanguageTag("en-US")), Is.False);
            }
        }
示例#33
0
        public void CopyQuoteMarksIfAppropriate_TargetWsHasNoQuotes_TargetReceivesQuotes()
        {
            var originalBundle = GetGlyssenBundleToBeUsedForProject();
            var project        = new Project(originalBundle);

            project.Status.QuoteSystemStatus = QuoteSystemStatus.UserSet;

            WritingSystemDefinition targetWs       = new WritingSystemDefinition();
            GlyssenDblTextMetadata  targetMetadata = new GlyssenDblTextMetadata();

            project.CopyQuoteMarksIfAppropriate(targetWs, targetMetadata);

            Assert.AreEqual(project.QuoteSystem.AllLevels, targetWs.QuotationMarks);
            Assert.AreEqual(QuoteSystemStatus.UserSet, project.Status.QuoteSystemStatus);
        }
示例#34
0
        public void Setup()
        {
            _projectDir = new ProjectDirectorySetupForTesting("");
            _project    = _projectDir.CreateLoadedProject();
            _project.WritingSystems.Set(WritingSystemDefinition.Parse("fr"));
            _repo  = _project.GetLexEntryRepository();
            _entry = _repo.CreateItem();
            _entry.LexicalForm.SetAlternative("qaa-x-qaa", "apple");


            _project.DefaultPrintingTemplate.GetField(LexSense.WellKnownProperties.Definition).WritingSystemIds.Add("fr");
            _project.DefaultPrintingTemplate.GetField(LexExampleSentence.WellKnownProperties.Translation).WritingSystemIds.Add("fr");

            _project.DefaultPrintingTemplate.GetField(LexEntry.WellKnownProperties.CrossReference).Enabled = true;
        }
示例#35
0
 private static ViewTemplate MakeMasterInventory()
 {
     using (var tempFolder = new TemporaryFolder("ProjectFromViewTemplateTests"))
     {
         IWritingSystemRepository w = LdmlInFolderWritingSystemRepository.Initialize(
             tempFolder.Path,
             OnWritingSystemMigration,
             OnWritingSystemLoadProblem,
             WritingSystemCompatibility.Flex7V0Compatible
             );
         w.Set(WritingSystemDefinition.Parse("aaa"));
         w.Set(WritingSystemDefinition.Parse("aab"));
         return(ViewTemplate.MakeMasterTemplate(w));
     }
 }
        public void GetSuggestions_MajorWorlLanguage_SuggestsOnlyIfSuppressSuggesstionsForMajorWorldLanguagesIsFalse()
        {
            var english   = new WritingSystemDefinition("en", string.Empty, string.Empty, string.Empty, "eng", false);
            var list      = new List <WritingSystemDefinition>(new[] { english });
            var suggestor = new WritingSystemSuggestor();

            suggestor.SuppressSuggestionsForMajorWorldLanguages = false;
            var suggestions = suggestor.GetSuggestions(english, list);

            Assert.IsTrue(suggestions.Any(defn => ((WritingSystemSuggestion)defn).TemplateDefinition.Variant == "fonipa"));

            suggestor.SuppressSuggestionsForMajorWorldLanguages = true;
            suggestions = suggestor.GetSuggestions(english, list);
            Assert.IsFalse(suggestions.Any(defn => ((WritingSystemSuggestion)defn).TemplateDefinition.Variant == "fonipa"));
        }
示例#37
0
 public void Get_UpdatedLdmlRemovedByAnotherRepo_ReturnUpdatedDefinition()
 {
     using (var e = CreateTemporaryFolder(TestContext.CurrentContext.Test.Name))
     {
         var repo1 = new GlobalWritingSystemRepository(e.Path);
         var repo2 = new GlobalWritingSystemRepository(e.Path);
         var ws    = new WritingSystemDefinition("en-US");
         repo1.Set(ws);
         repo1.Save();
         Assert.That(repo1.Get("en-US").LanguageTag, Is.EqualTo("en-US"));
         repo2.Remove("en-US");
         ws.WindowsLcid = "test";
         Assert.That(repo1.Get("en-US").WindowsLcid, Is.EqualTo("test"));
     }
 }
        public void GetSuggestions_MajorWorlLanguage_SuggestsOnlyIfSuppressSuggesstionsForMajorWorldLanguagesIsFalse()
        {
            var english   = new WritingSystemDefinition("en", string.Empty, string.Empty, string.Empty, "eng", false);
            var list      = new List <WritingSystemDefinition>(new[] { english });
            var suggestor = new WritingSystemSuggestor(new TestWritingSystemFactory());

            suggestor.SuppressSuggestionsForMajorWorldLanguages = false;
            var suggestions = suggestor.GetSuggestions(english, list);

            Assert.That(suggestions.Any(defn => defn is IpaSuggestion), Is.True);

            suggestor.SuppressSuggestionsForMajorWorldLanguages = true;
            suggestions = suggestor.GetSuggestions(english, list);
            Assert.That(suggestions.Any(defn => defn is IpaSuggestion), Is.False);
        }
 [Test]         // ok
 public void GetTopLevelItems_StoreAlreadyHasAllOsLanguages_DoesNotGiveLanguageChoiceHeader()
 {
     using (var e = new TestEnvironment())
     {
         var en    = new WritingSystemDefinition("en");
         var de    = new WritingSystemDefinition("de");
         var model = e.CreateModel();
         model.Suggestor.OtherKnownWritingSystems = new List <Tuple <string, string> >()
         {
             new Tuple <string, string>("de", string.Empty)
         };
         e.SetDefinitionsInStore(new[] { en, de });
         AssertTreeNodeLabels(model, "English", "German", "", "Add Language");
     }
 }
        public void UpdatesFileNameWhenISOChanges()
        {
            _writingSystem.ISO = "1";
            _writingSystemRepository.StoreDefinition(_writingSystem);
            string path = Path.Combine(_writingSystemRepository.PathToWritingSystems, "1.ldml");

            Assert.IsTrue(File.Exists(path));
            WritingSystemDefinition ws2 = _writingSystemRepository.LoadDefinition("1");

            ws2.ISO = "2";
            _writingSystemRepository.StoreDefinition(ws2);
            Assert.IsFalse(File.Exists(path));
            path = Path.Combine(_writingSystemRepository.PathToWritingSystems, "2.ldml");
            Assert.IsTrue(File.Exists(path));
        }
        public void CanDeleteFileMatchingOneThatWasPreviouslyTrashed()
        {
            _writingSystem.ISO = "blah";
            _writingSystemRepository.StoreDefinition(_writingSystem);
            _writingSystemRepository.DeleteDefinition(_writingSystem);
            AssertFileIsInTrash(_writingSystem);
            WritingSystemDefinition ws2 = new WritingSystemDefinition();

            ws2.ISO = "blah";
            _writingSystemRepository.StoreDefinition(ws2);
            _writingSystemRepository.DeleteDefinition(ws2);
            string path = Path.Combine(_writingSystemRepository.PathToWritingSystems, _writingSystemRepository.GetFileName(_writingSystem));

            Assert.IsFalse(File.Exists(path));
            AssertFileIsInTrash(_writingSystem);
        }
示例#42
0
 private WritingSystemDefinition GetFromFilePath(string filePath)
 {
     try
     {
         WritingSystemDefinition ws = CreateNew();
         var adaptor = new FwLdmlAdaptor();
         adaptor.Read(filePath, ws);
         ws.StoreID  = ((PalasoWritingSystem)ws).RFC5646;
         ws.Modified = false;
         return(ws);
     }
     catch (Exception e)
     {
         throw new ArgumentException("GlobalWritingSystemStore was unable to load the LDML file " + filePath, "filePath", e);
     }
 }
示例#43
0
 public void Read_ReadPrivateUseWsFromFieldWorksLdmlThenNormalLdmlMissingVersion1Element_Throws()
 {
     using (var badFlexLdml = new TempFile())
     {
         using (var version1Ldml = new TempFile())
         {
             WriteVersion0Ldml("x-en", "", "", "x-private", badFlexLdml);
             WriteVersion0Ldml("en", "", "", "", version1Ldml);
             var wsV1    = new WritingSystemDefinition();
             var wsV0    = new WritingSystemDefinition();
             var adaptor = new LdmlDataMapper();
             adaptor.Read(badFlexLdml.Path, wsV0);
             Assert.Throws <ApplicationException>(() => adaptor.Read(version1Ldml.Path, wsV1));
         }
     }
 }
示例#44
0
        public void SaveDefinitionsThenLoad_CountEquals2()
        {
            using (var environment = new TestEnvironment())
            {
                environment.WritingSystem.Language = "one";
                environment.Collection.SaveDefinition(environment.WritingSystem);
                var ws2 = new WritingSystemDefinition
                {
                    Language = "two"
                };
                environment.Collection.SaveDefinition(ws2);
                var newStore = LdmlInFolderWritingSystemRepository.Initialize(environment.TestPath, DummyWritingSystemHandler.onMigration, DummyWritingSystemHandler.onLoadProblem);

                Assert.AreEqual(2, newStore.Count);
            }
        }
        public void NewerThanEmpty_ReturnsNoneNewer()
        {
            var ws1 = new WritingSystemDefinition();

            ws1.Language = "en";
            RepositoryUnderTest.Set(ws1);

            IWritingSystemRepository repository = CreateNewStore();
            int count = 0;

            foreach (WritingSystemDefinition ws in repository.WritingSystemsNewerIn(RepositoryUnderTest.AllWritingSystems))
            {
                count++;
            }
            Assert.AreEqual(0, count);
        }
示例#46
0
        public void NotifyThatLexEntryHasBeenUpdated_LexEntry_CachesAreUpdated()
        {
            LexEntry entryToUpdate = _repository.CreateItem();

            entryToUpdate.LexicalForm.SetAlternative("de", "word 0");
            _repository.SaveItem(entryToUpdate);
            CreateCaches();
            entryToUpdate.LexicalForm.SetAlternative("de", "word 1");
            _repository.NotifyThatLexEntryHasBeenUpdated(entryToUpdate);
            IWritingSystemDefinition writingSystemToMatch = WritingSystemDefinition.Parse("de");
            ResultSet <LexEntry>     headWordResults      = _repository.GetAllEntriesSortedByHeadword(writingSystemToMatch);
            ResultSet <LexEntry>     lexicalFormResults   = _repository.GetAllEntriesSortedByLexicalFormOrAlternative(writingSystemToMatch);

            Assert.AreEqual("word 1", headWordResults[0]["Form"]);
            Assert.AreEqual("word 1", lexicalFormResults[0]["Form"]);
        }
示例#47
0
 [Test]         // ok
 public void GetTopLevelItems_StoreAlreadyHasAllOsLanguages_DoesNotOfferToCreateItAgain()
 {
     using (var e = new TestEnvironment())
     {
         var en    = new WritingSystemDefinition("en");
         var de    = new WritingSystemDefinition("de");
         var green = new WritingSystemDefinition("fr");
         var model = e.CreateModel();
         model.Suggestor.OtherKnownWritingSystems = new[] { de, green };
         e.SetDefinitionsInStore(new[] { en, de });
         AssertTreeNodeLabels(
             model,
             "English", "German", "", "Add Language", "", "Other Languages", "+Add French"                     /*notice, no de*/
             );
     }
 }
 public void AllWritingSystems_LdmlUpdatedByAnotherRepo_ReturnsUpdatedDefinition()
 {
     using (var e = new TemporaryFolder("GlobalWritingSystemRepositoryTests"))
     {
         var repo1 = new GlobalWritingSystemRepository(e.Path);
         var repo2 = new GlobalWritingSystemRepository(e.Path);
         var ws    = new WritingSystemDefinition("en-US");
         repo1.Set(ws);
         repo1.Save();
         Assert.That(ws.WindowsLcid, Is.Empty);
         ws             = repo2.Get("en-US");
         ws.WindowsLcid = "test";
         repo2.Save();
         Assert.That(repo2.AllWritingSystems.First().WindowsLcid, Is.EqualTo("test"));
     }
 }
示例#49
0
        public void CanStoreVariants_CountTwo()
        {
            var ws1 = new WritingSystemDefinition();

            ws1.Language = "en";
            Assert.AreEqual("en", ws1.LanguageTag);
            WritingSystemDefinition ws2 = ws1.Clone();

            ws2.Variants.Add("1901");
            Assert.AreEqual("en-1901", ws2.LanguageTag);

            RepositoryUnderTest.Set(ws1);
            Assert.AreEqual(1, RepositoryUnderTest.Count);
            RepositoryUnderTest.Set(ws2);
            Assert.AreEqual(2, RepositoryUnderTest.Count);
        }
 public void Save_UpdatedWritingSystem_UpdatesLdmlFile()
 {
     using (var e = new TemporaryFolder("GlobalWritingSystemRepositoryTests"))
     {
         var repo = new GlobalWritingSystemRepository(e.Path);
         var ws   = new WritingSystemDefinition("en-US");
         repo.Set(ws);
         repo.Save();
         DateTime modified = File.GetLastWriteTime(repo.GetFilePathFromLanguageTag("en-US"));
         // ensure that last modified timestamp changes
         Thread.Sleep(1000);
         ws.WindowsLcid = "test";
         repo.Save();
         Assert.That(File.GetLastWriteTime(repo.GetFilePathFromLanguageTag("en-US")), Is.Not.EqualTo(modified));
     }
 }
        public void SetAllPossibleAndRemoveOthers_DuplicateIsCreatedFromWsAlreadyInRepoAndWouldBeRenamedToSelf_SetsToRepo()
        {
            Assert.That(_writingSystemRepository.Count, Is.EqualTo(0));
            var ws = new WritingSystemDefinition("en-x-dupl0");

            //reinitialize the model with a prepopulated repo
            _writingSystemRepository.Set(new WritingSystemDefinition("en"));
            _writingSystemRepository.Set(ws);
            _model = new WritingSystemSetupModel(_writingSystemRepository);
            //Now change the Id so it's a duplicate of another ws already in the repo
            ws.Variants.Clear();
            _model.SetAllPossibleAndRemoveOthers();
            Assert.That(_writingSystemRepository.Count, Is.EqualTo(2));
            Assert.That(_writingSystemRepository.Contains("en"));
            Assert.That(_writingSystemRepository.Contains("en-x-dupl0"));
        }
示例#52
0
        public override bool Validate(out string message)
        {
            if (IsValid)
            {
                message = null;
                return(true);
            }

            var sb = new StringBuilder();

            foreach (IcuCollationImport import in _imports)
            {
                bool importSuccessful      = false;
                WritingSystemDefinition ws = null;
                if (OwningWritingSystemDefinition != null && OwningWritingSystemDefinition.LanguageTag.StartsWith(import.LanguageTag) && OwningWritingSystemDefinition.Collations.Contains(import.Type))
                {
                    ws = OwningWritingSystemDefinition;
                }
                else if (WritingSystemFactory != null && (OwningWritingSystemDefinition == null || OwningWritingSystemDefinition.LanguageTag != import.LanguageTag))
                {
                    WritingSystemFactory.Create(import.LanguageTag, out ws);
                }
                CollationDefinition cd;
                if (ws != null && ws.Collations.TryGet(import.Type, out cd))
                {
                    var    rcd = cd as RulesCollationDefinition;
                    string importMessage;
                    if (rcd != null && rcd.Validate(out importMessage))
                    {
                        sb.Append(rcd.CollationRules);
                        importSuccessful = true;
                    }
                }

                if (!importSuccessful)
                {
                    message = string.Format("Unable to import the {0} collation rules from {1}.", string.IsNullOrEmpty(import.Type) ? "default" : import.Type, import.LanguageTag);
                    return(false);
                }
            }

            sb.Append(_icuRules);

            CollationRules = sb.ToString();

            return(base.Validate(out message));
        }
 public void Get_UpdatedLdmlUpdatedByAnotherRepo_ReturnLastUpdatedDefinition()
 {
     using (var e = new TemporaryFolder("GlobalWritingSystemRepositoryTests"))
     {
         var repo1 = new GlobalWritingSystemRepository(e.Path);
         var repo2 = new GlobalWritingSystemRepository(e.Path);
         var ws    = new WritingSystemDefinition("en-US");
         repo1.Set(ws);
         repo1.Save();
         Assert.That(repo1.Get("en-US").LanguageTag, Is.EqualTo("en-US"));
         WritingSystemDefinition ws2 = repo2.Get("en-US");
         ws2.WindowsLcid = "test2";
         repo2.Save();
         ws.WindowsLcid = "test1";
         Assert.That(repo1.Get("en-US").WindowsLcid, Is.EqualTo("test1"));
     }
 }
示例#54
0
        public void Get_CaseDifferingWritingSystems_DoesNotThrow(string id)
        {
            using (var temporaryFolder = CreateTemporaryFolder("Get_CaseDifferingWritingSystems_DoesNotThrow"))
            {
                // Setup
                var repo = new GlobalWritingSystemRepository(temporaryFolder.Path);
                var ws   = new WritingSystemDefinition("en-US");
                repo.Set(ws);
                repo.Save();
                // Now we simulate that the user did a S/R which added a WS that differs by case
                File.Copy(Path.Combine(temporaryFolder.Path, "3", ws.Id + ".ldml"),
                          Path.Combine(temporaryFolder.Path, "3", ws.Id.ToLower() + ".ldml"));

                // SUT/Verify
                Assert.That(() => repo.Get(id), Throws.Nothing);
            }
        }
        /// <summary>
        /// Gets a ResultSet containing all entries sorted by lexical form for a given writing system.
        /// If a lexical form for a given writingsystem does not exist we substitute one from another writingsystem.
        /// Use "Form" to access the lexical form in a RecordToken.
        /// </summary>
        /// <param name="writingSystemDefinition"></param>
        /// <returns></returns>
        public ResultSet <LexEntry> GetAllEntriesSortedByLexicalFormOrAlternative(WritingSystemDefinition writingSystemDefinition)
        {
            if (writingSystemDefinition == null)
            {
                throw new ArgumentNullException("writingSystemDefinition");
            }
            string cacheName = String.Format("sortedByLexicalFormOrAlternative_{0}", writingSystemDefinition.LanguageTag);

            if (_caches[cacheName] == null)
            {
                var lexicalFormWithAlternativeQuery = new DelegateQuery <LexEntry>(
                    delegate(LexEntry entryToQuery)
                {
                    IDictionary <string, object> tokenFieldsAndValues = new Dictionary <string, object>();
                    string lexicalform         = entryToQuery.LexicalForm[writingSystemDefinition.LanguageTag];
                    string writingSystemOfForm = writingSystemDefinition.LanguageTag;
                    if (lexicalform == "")
                    {
                        lexicalform = entryToQuery.LexicalForm.GetBestAlternative(writingSystemDefinition.LanguageTag);
                        foreach (LanguageForm form in entryToQuery.LexicalForm.Forms)
                        {
                            if (form.Form == lexicalform)
                            {
                                writingSystemOfForm = form.WritingSystemId;
                            }
                        }
                        if (lexicalform == "")
                        {
                            lexicalform = null;
                        }
                    }
                    tokenFieldsAndValues.Add("Form", lexicalform);
                    tokenFieldsAndValues.Add("WritingSystem", writingSystemOfForm);
                    return(new[] { tokenFieldsAndValues });
                });
                ResultSet <LexEntry> itemsMatching = _decoratedDataMapper.GetItemsMatching(lexicalFormWithAlternativeQuery);

                var sortOrder = new SortDefinition[1];
                sortOrder[0] = new SortDefinition("Form", writingSystemDefinition.DefaultCollation.Collator);

                _caches.Add(cacheName, new ResultSetCache <LexEntry>(this, sortOrder, itemsMatching, lexicalFormWithAlternativeQuery));
            }
            ResultSet <LexEntry> resultsFromCache = _caches[cacheName].GetResultSet();

            return(resultsFromCache);
        }
示例#56
0
            public EnvironmentForTest()
            {
                _projectDir = new ProjectDirectorySetupForTesting("");
                var project = _projectDir.CreateLoadedProject();

                _outputFile           = new TempFile();
                Repo                  = new LexEntryRepository(_projectDir.PathToLiftFile);
                WritingSystemIds      = new List <string>(new[] { Red, Green, Blue, Voice });
                HeadwordWritingSystem = WritingSystemDefinition.Parse(Red);
                project.WritingSystems.Set(HeadwordWritingSystem);
                project.WritingSystems.Set(WritingSystemDefinition.Parse(Green));
                project.WritingSystems.Set(WritingSystemDefinition.Parse(Blue));
                project.WritingSystems.Set(WritingSystemDefinition.Parse(Voice));

                Template = new ViewTemplate
                {
                    new Field(
                        LexEntry.WellKnownProperties.Citation,
                        "LexEntry",
                        new[] { Blue, Red, Voice }),
                    new Field(
                        LexEntry.WellKnownProperties.LexicalUnit,
                        "LexEntry",
                        new[] { Red, Green, Blue, Voice }),
                    new Field(
                        LexEntry.WellKnownProperties.BaseForm,
                        "LexEntry",
                        WritingSystemIds),
                    new Field(
                        "brother",
                        "LexEntry",
                        WritingSystemIds)
                };

                var visibleCustom = new Field(
                    "VisibleCustom",
                    "LexEntry",
                    WritingSystemIds,
                    Field.MultiplicityType.ZeroOr1,
                    "MultiText"
                    );

                visibleCustom.Visibility  = CommonEnumerations.VisibilitySetting.Visible;
                visibleCustom.DisplayName = "VisibleCustom";
                Template.Add(visibleCustom);
            }
        public void Read_EmptyXml_NothingSet()
        {
            var projectSettingsDataMapper = new ProjectLexiconSettingsWritingSystemDataMapper(new MemorySettingsStore());

            var ws1 = new WritingSystemDefinition("en-US");

            projectSettingsDataMapper.Read(ws1);

            Assert.That(ws1.Abbreviation, Is.EqualTo("en"));
            Assert.That(ws1.Language.Name, Is.EqualTo("English"));
            Assert.That(ws1.Script.Name, Is.EqualTo("Latin"));
            Assert.That(ws1.Region.Name, Is.EqualTo("United States"));
            Assert.That(ws1.Variants, Is.Empty);
            Assert.That(ws1.SpellCheckingId, Is.EqualTo(string.Empty));
            Assert.That(ws1.LegacyMapping, Is.EqualTo(string.Empty));
            Assert.That(ws1.Keyboard, Is.EqualTo(string.Empty));
        }
示例#58
0
        public void GeckoListBox_TestGetRectangle()
        {
            _countOfItemsDrawn     = 0;
            _itemToNotDrawYetDrawn = false;
            IWritingSystemDefinition ws  = WritingSystemDefinition.Parse("fr");
            IWritingSystemDefinition ws2 = WritingSystemDefinition.Parse("en");

            _listBox = new GeckoListBox();
            _listBox.FormWritingSystem    = ws;
            _listBox.MeaningWritingSystem = ws2;
            _listBox.Name = "ControlUnderTest";
            Assert.IsNotNull(_listBox);

            String volvo  = "Volvo";
            String saab   = "Saab";
            String toyota = "Toyota";

            _listBox.AddItem(volvo);
            _listBox.AddItem(saab);
            _listBox.AddItem(toyota);

            _listBox.ItemDrawer = GeckoListBox_TestDrawItem;
            _listBox.ListCompleted();

            Application.DoEvents();

            _window.Controls.Add(_listBox);
            _window.Show();
            ControlTester t = new ControlTester("ControlUnderTest", _window);

            Application.DoEvents();
            Rectangle r = _listBox.GetItemRectangle(1);

            Application.DoEvents();

            using (MouseController mc = new MouseController(t))
            {
                mc.Click(r.Right + 5, r.Top + 5);
            }

            Application.DoEvents();
            Application.DoEvents();

            Assert.AreEqual(1, _listBox.SelectedIndex);
            Assert.AreSame(_listBox.SelectedItem, saab);
        }
示例#59
0
        public void RoundtripKnownKeyboards()
        {
            var ldmlAdaptor = new LdmlDataMapper();

            Keyboard.Controller = new MyKeyboardController();

            const string sortRules            = "(A̍ a̍)";
            var          wsWithKnownKeyboards = new WritingSystemDefinition();
            var          keyboard1            = new DefaultKeyboardDefinition();

            keyboard1.Locale          = "en-US";
            keyboard1.Layout          = "MyFavoriteKeyboard";
            keyboard1.OperatingSystem = PlatformID.MacOSX;             // pick something that for sure won't be our default
            wsWithKnownKeyboards.AddKnownKeyboard(keyboard1);

            var keyboard2 = new DefaultKeyboardDefinition();

            keyboard2.Locale          = "en-GB";
            keyboard2.Layout          = "SusannasFavoriteKeyboard";
            keyboard2.OperatingSystem = PlatformID.Unix;
            wsWithKnownKeyboards.AddKnownKeyboard(keyboard2);

            var wsFromLdml = new WritingSystemDefinition();

            using (var tempFile = new TempFile())
            {
                ldmlAdaptor.Write(tempFile.Path, wsWithKnownKeyboards, null);
                ldmlAdaptor.Read(tempFile.Path, wsFromLdml);
            }

            var knownKeyboards = wsFromLdml.KnownKeyboards.ToList();

            Assert.That(knownKeyboards, Has.Count.EqualTo(2), "restored WS should have known keyboards");
            var keyboard1FromLdml = knownKeyboards[0];

            Assert.That(keyboard1FromLdml.Layout, Is.EqualTo("MyFavoriteKeyboard"));
            Assert.That(keyboard1FromLdml.Locale, Is.EqualTo("en-US"));
            Assert.That(keyboard1FromLdml.OperatingSystem, Is.EqualTo(PlatformID.MacOSX));
            Assert.That(keyboard1FromLdml, Is.InstanceOf <MyKeyboardDefn>(), "Reader should have used controller to create keyboard defn");

            var keyboard2FromLdml = knownKeyboards[1];

            Assert.That(keyboard2FromLdml.Layout, Is.EqualTo("SusannasFavoriteKeyboard"));
            Assert.That(keyboard2FromLdml.Locale, Is.EqualTo("en-GB"));
            Assert.That(keyboard2FromLdml.OperatingSystem, Is.EqualTo(PlatformID.Unix));
        }
        public void CanSetVariantToExistingLDML()
        {
            _writingSystem.ISO          = "blah";
            _writingSystem.Abbreviation = "bl";            //crucially, abbreviation isn't part of the name of the file
            _writingSystemRepository.StoreDefinition(_writingSystem);

            //here, the task is not to overwrite what was in ther already
            WritingSystemDefinition ws2 = new WritingSystemDefinition();

            ws2         = _writingSystemRepository.LoadDefinition("blah");
            ws2.Variant = "piglatin";
            _writingSystemRepository.StoreDefinition(ws2);
            string path = Path.Combine(_writingSystemRepository.PathToWritingSystems, _writingSystemRepository.GetFileName(ws2));

            AssertXmlFile.AtLeastOneMatch(path, "ldml/identity/variant[@type='piglatin']");
            AssertXmlFile.AtLeastOneMatch(path, "ldml/special/palaso:abbreviation[@value='bl']", LdmlAdaptor.MakeNameSpaceManager());
        }