Пример #1
0
		public void IterateWithForEach()
		{
			MultiTextBase text = new MultiTextBase();
			text["a"] = "alpha";
			text["b"] = "beta";
			text["g"] = "gamma";
			int i = 0;
			foreach (LanguageForm l in text)
			{
				switch (i)
				{
					case 0:
						Assert.AreEqual("a", l.WritingSystemId);
						Assert.AreEqual("alpha", l.Form);
						break;
					case 1:
						Assert.AreEqual("b", l.WritingSystemId);
						Assert.AreEqual("beta", l.Form);
						break;
					case 2:
						Assert.AreEqual("g", l.WritingSystemId);
						Assert.AreEqual("gamma", l.Form);
						break;
				}
				i++;
			}
		}
Пример #2
0
        public static MultiTextBase Create(Dictionary <string, string> forms)
        {
            MultiTextBase m = new MultiTextBase();

            CopyForms(forms, m);
            return(m);
        }
Пример #3
0
        public int CompareTo(object o)
        {
            if (o == null)
            {
                return(1);
            }
            if (!(o is MultiTextBase))
            {
                throw new ArgumentException("Can not compare to objects other than MultiTextBase.");
            }
            MultiTextBase other           = (MultiTextBase)o;
            int           formLengthOrder = this.Forms.Length.CompareTo(other.Forms.Length);

            if (formLengthOrder != 0)
            {
                return(formLengthOrder);
            }
            for (int i = 0; i < Forms.Length; i++)
            {
                int languageFormOrder = Forms[i].CompareTo(other.Forms[i]);
                if (languageFormOrder != 0)
                {
                    return(languageFormOrder);
                }
            }
            return(0);
        }
Пример #4
0
 public LanguageForm(LanguageForm form, MultiTextBase parent)
     : this(form.WritingSystemId, form.Form, parent)
 {
     foreach (var span in form.Spans)
     {
         AddSpan(span.Index, span.Length, span.Lang, span.Class, span.LinkURL);
     }
 }
Пример #5
0
		public void Count()
		{
			MultiTextBase text = new MultiTextBase();
			Assert.AreEqual(0, text.Count);
			text["a"] = "alpha";
			text["b"] = "beta";
			text["g"] = "gamma";
			Assert.AreEqual(3, text.Count);
		}
Пример #6
0
 public void AddLanguageString(string key, string value, string writingSystemId, bool isCollectionValue)
 {
     if(!TextVariables.ContainsKey(key))
     {
         var text = new MultiTextBase();
         TextVariables.Add(key, new NamedMutliLingualValue(text, isCollectionValue));
     }
     TextVariables[key].TextAlternatives.SetAlternative(writingSystemId,value);
 }
Пример #7
0
 public void UpdateGenericLanguageString(string key, string value, bool isCollectionValue)
 {
     var text = new MultiTextBase();
     text.SetAlternative("*", value);
     if(TextVariables.ContainsKey(key))
     {
         TextVariables.Remove(key);
     }
     TextVariables.Add(key, new NamedMutliLingualValue(text, isCollectionValue));
 }
Пример #8
0
        /// <summary>
        /// Will merge the two mt's if they are compatible; if they collide anywhere, leaves the original untouched
        /// and returns false
        /// </summary>
        /// <param name="incoming"></param>
        /// <returns></returns>
        public bool TryMergeIn(MultiTextBase incoming)
        {
            //abort if they collide
            if (!CanBeUnifiedWith(incoming))
            {
                return(false);
            }

            MergeIn(incoming);
            return(true);
        }
Пример #9
0
		public void BasicStuff()
		{
			MultiTextBase text = new MultiTextBase();
			text["foo"] = "alpha";
			Assert.AreSame("alpha", text["foo"]);
			text["foo"] = "beta";
			Assert.AreSame("beta", text["foo"]);
			text["foo"] = "gamma";
			Assert.AreSame("gamma", text["foo"]);
			text["bee"] = "beeeee";
			Assert.AreSame("gamma", text["foo"], "setting a different alternative should not affect this one");
			text["foo"] = null;
			Assert.AreSame(string.Empty, text["foo"]);
		}
Пример #10
0
		public void NullConditions()
		{
			MultiTextBase text = new MultiTextBase();
			Assert.AreSame(string.Empty, text["foo"], "never before heard of alternative should give back an empty string");
			Assert.AreSame(string.Empty, text["foo"], "second time");
			Assert.AreSame(string.Empty, text.GetBestAlternative("fox"));
			text.SetAlternative("zox", "");
			Assert.AreSame(string.Empty, text["zox"]);
			text.SetAlternative("zox", null);
			Assert.AreSame(string.Empty, text["zox"], "should still be empty string after setting to null");
			text.SetAlternative("zox", "something");
			text.SetAlternative("zox", null);
			Assert.AreSame(string.Empty, text["zox"], "should still be empty string after setting something and then back to null");
		}
Пример #11
0
 public void MergeIn(MultiTextBase incoming)
 {
     foreach (LanguageForm form in incoming)
     {
         LanguageForm f = Find(form.WritingSystemId);
         if (f != null)
         {
             f.Form = form.Form;
         }
         else
         {
             AddLanguageForm(form);                     //this actually copies the meat of the form
         }
     }
 }
Пример #12
0
 /// <summary>
 /// False if they have different forms on any single writing system. If true, they can be safely merged.
 /// </summary>
 /// <param name="incoming"></param>
 /// <returns></returns>
 public bool CanBeUnifiedWith(MultiTextBase incoming)
 {
     foreach (var form in incoming.Forms)
     {
         if (!ContainsAlternative(form.WritingSystemId))
         {
             continue;                    //no problem, we don't have one of those
         }
         if (GetExactAlternative(form.WritingSystemId) != form.Form)
         {
             return(false);
         }
     }
     return(true);
 }
Пример #13
0
 public bool HasFormWithSameContent(MultiTextBase other)
 {
     if (other.Count == 0 && Count == 0)
     {
         return(true);
     }
     foreach (LanguageForm form in other)
     {
         if (ContainsEqualForm(form))
         {
             return(true);
         }
     }
     return(false);
 }
Пример #14
0
 public bool Equals(MultiTextBase other)
 {
     if (other == null)
     {
         return(false);
     }
     if (other.Count != Count)
     {
         return(false);
     }
     if (!_forms.SequenceEqual(other.Forms))
     {
         return(false);
     }
     return(true);
 }
Пример #15
0
		protected static void CopyForms(Dictionary<string, string> forms, MultiTextBase m)
		{
			if (forms != null && forms.Keys != null)
			{
				foreach (string key in forms.Keys)
				{
					LanguageForm f = m.Find(key);
					if (f != null)
					{
						f.Form = forms[key];
					}
					else
					{
						m.SetAlternative(key, forms[key]);
					}
				}
			}
		}
Пример #16
0
 protected static void CopyForms(Dictionary <string, string> forms, MultiTextBase m)
 {
     if (forms != null && forms.Keys != null)
     {
         foreach (string key in forms.Keys)
         {
             LanguageForm f = m.Find(key);
             if (f != null)
             {
                 f.Form = forms[key];
             }
             else
             {
                 m.SetAlternative(key, forms[key]);
             }
         }
     }
 }
Пример #17
0
		public void CompareTo_MultiTextWithMoreForms_ReturnsLess()
		{
			MultiTextBase multiTextBase = new MultiTextBase();
			MultiTextBase multiTextBaseToCompare = new MultiTextBase();
			multiTextBaseToCompare.SetAlternative("de", "Word 1");
			Assert.AreEqual(-1, multiTextBase.CompareTo(multiTextBaseToCompare));
		}
Пример #18
0
		public void CompareTo_MultiTextWithFewerForms_ReturnsGreater()
		{
			MultiTextBase multiTextBase = new MultiTextBase();
			multiTextBase.SetAlternative("de", "Word 1");
			MultiTextBase multiTextBaseToCompare = new MultiTextBase();
			Assert.AreEqual(1, multiTextBase.CompareTo(multiTextBaseToCompare));
		}
Пример #19
0
		public void SetAlternative_ThreeDifferentLanguages_LanguageFormsAreSortedbyWritingSystem()
		{

			MultiTextBase multiTextBaseToPopulate = new MultiTextBase();
			multiTextBaseToPopulate.SetAlternative("fr", "fr Word3");
			multiTextBaseToPopulate.SetAlternative("de", "de Word1");
			multiTextBaseToPopulate.SetAlternative("en", "en Word2");
			Assert.AreEqual(3, multiTextBaseToPopulate.Forms.Length);
			Assert.AreEqual("de", multiTextBaseToPopulate.Forms[0].WritingSystemId);
			Assert.AreEqual("en", multiTextBaseToPopulate.Forms[1].WritingSystemId);
			Assert.AreEqual("fr", multiTextBaseToPopulate.Forms[2].WritingSystemId);
		}
Пример #20
0
		public void GetOrderedAndFilteredForms_DropsUnlistedForms()
		{
			MultiTextBase x = new MultiTextBase();
			x["one"] = "1";
			x["two"] = "2";
			x["three"] = "3";
			LanguageForm[] forms = x.GetOrderedAndFilteredForms(new string[] { "one", "three" });
			Assert.AreEqual(2, forms.Length);
			Assert.AreEqual("1", forms[0].Form);
			Assert.AreEqual("3", forms[1].Form);
		}
Пример #21
0
		public void GetOrderedAndFilteredForms_EmptyMultiText_GivesEmptyList()
		{
			MultiTextBase x = new MultiTextBase();
			LanguageForm[] forms = x.GetOrderedAndFilteredForms(new string[] { "one", "three" });
			Assert.AreEqual(0, forms.Length);
		}
Пример #22
0
		public void GetOrderedAndFilteredForms_EmptyIdList_GivesEmptyList()
		{
			MultiTextBase x = new MultiTextBase();
			x["one"] = "test";
			Assert.AreEqual(0, x.GetOrderedAndFilteredForms(new string[] { }).Length);
		}
Пример #23
0
		public void HasFormWithSameContent_DifferentValue_False()
		{
			MultiTextBase x = new MultiTextBase();
			x["ws"] = "test";
			MultiTextBase y = new MultiTextBase();
			y["ws"] = "tests";
			Assert.IsFalse(x.HasFormWithSameContent(y));
			Assert.IsFalse(y.HasFormWithSameContent(x));
		}
Пример #24
0
		public void HasFormWithSameContent_Identity_True()
		{
			MultiTextBase x = new MultiTextBase();
			x["ws1"] = "testing";
			x["ws"] = "test";
			x["ws2"] = "testing";
			Assert.IsTrue(x.HasFormWithSameContent(x));

		}
Пример #25
0
		public void CompareTo_MultiTextWithNonIdenticalFormsAndFirstNonidenticalformIsAlphabeticallyLater_ReturnsLess()
		{
			MultiTextBase multiTextBase = new MultiTextBase();
			multiTextBase.SetAlternative("de", "Word 1");
			MultiTextBase multiTextBaseToCompare = new MultiTextBase();
			multiTextBaseToCompare.SetAlternative("de", "Word 2");
			Assert.AreEqual(-1, multiTextBase.CompareTo(multiTextBaseToCompare));
		}
Пример #26
0
 public static bool IsEmpty(MultiTextBase mt)
 {
     return(mt == null || mt.Empty);
 }
Пример #27
0
 public void UpdateLanguageString(string key,  string value, string writingSystemId,bool isCollectionValue)
 {
     NamedMutliLingualValue namedMutliLingualValue;
     MultiTextBase text;
     if(TextVariables.TryGetValue(key,out namedMutliLingualValue))
         text = namedMutliLingualValue.TextAlternatives;
     else
     {
         text = new MultiTextBase();
     }
     text.SetAlternative(DealiasWritingSystemId(writingSystemId), value);
     TextVariables.Remove(key);
     if(text.Count>0)
         TextVariables.Add(key, new NamedMutliLingualValue(text, isCollectionValue));
 }
Пример #28
0
		public void SetAnnotation()
		{
			MultiTextBase MultiTextBase = new MultiTextBase();
			MultiTextBase.SetAnnotationOfAlternativeIsStarred("zz", true);
			Assert.AreEqual(String.Empty, MultiTextBase.GetExactAlternative("zz"));
			Assert.IsTrue(MultiTextBase.GetAnnotationOfAlternativeIsStarred("zz"));
			MultiTextBase.SetAnnotationOfAlternativeIsStarred("zz", false);
			Assert.IsFalse(MultiTextBase.GetAnnotationOfAlternativeIsStarred("zz"));
		}
Пример #29
0
		public void HasFormWithSameContent_BothEmpty_True()
		{
			MultiTextBase x = new MultiTextBase();
			MultiTextBase y = new MultiTextBase();
			Assert.IsTrue(x.HasFormWithSameContent(y));
			Assert.IsTrue(y.HasFormWithSameContent(x));
		}
Пример #30
0
		public void CompareTo_MultiTextWithNonIdenticalWritingSystemsAndFirstNonidenticalWritingSystemIsAlphabeticallyEarlier_ReturnsGreater()
		{
			MultiTextBase multiTextBase = new MultiTextBase();
			multiTextBase.SetAlternative("en", "Word 1");
			MultiTextBase multiTextBaseToCompare = new MultiTextBase();
			multiTextBaseToCompare.SetAlternative("de", "Word 1");
			Assert.AreEqual(1, multiTextBase.CompareTo(multiTextBaseToCompare));
		}
Пример #31
0
		public void HasFormWithSameContent_OneEmpty_False()
		{
			MultiTextBase x = new MultiTextBase();
			MultiTextBase y = new MultiTextBase();
			y["ws"] = "test";
			y.SetAnnotationOfAlternativeIsStarred("ws", true);
			Assert.IsFalse(x.HasFormWithSameContent(y));
			Assert.IsFalse(y.HasFormWithSameContent(x));
		}
Пример #32
0
 public LanguageForm(string writingSystemId, string form, MultiTextBase parent)
 {
     _parent          = parent;
     _writingSystemId = writingSystemId;
     _form            = form;
 }
Пример #33
0
		public void HasFormWithSameContent_SameContent_True()
		{
			MultiTextBase x = new MultiTextBase();
			x["ws1"] = "testing";
			x["ws"] = "test";
			x["ws2"] = "testing";
			MultiTextBase y = new MultiTextBase();
			x["ws1"] = "testin";
			y["ws"] = "test";
			Assert.IsTrue(x.HasFormWithSameContent(y));
			Assert.IsTrue(y.HasFormWithSameContent(x));
		}
Пример #34
0
		public void CompareTo_IdenticalMultiText_ReturnsEqual()
		{
			MultiTextBase multiTextBase = new MultiTextBase();
			multiTextBase.SetAlternative("de", "Word 1");
			MultiTextBase multiTextBaseToCompare = new MultiTextBase();
			multiTextBaseToCompare.SetAlternative("de", "Word 1");
			Assert.AreEqual(0, multiTextBase.CompareTo(multiTextBaseToCompare));
		}
Пример #35
0
		public void EmptyingTextOfFlaggedAlternativeDoesNotDeleteIfFlagged()
		{
			// REVIEW: not clear really what behavior we want here, since user deletes via clearing text
			MultiTextBase MultiTextBase = new MultiTextBase();
			MultiTextBase["zz"] = "hello";
			MultiTextBase.SetAnnotationOfAlternativeIsStarred("zz", true);
			MultiTextBase["zz"] = "";
			Assert.IsTrue(MultiTextBase.ContainsAlternative("zz"));
		}
Пример #36
0
 public NamedMutliLingualValue(MultiTextBase text, bool isCollectionValue)
 {
     TextAlternatives = text;
     IsCollectionValue = isCollectionValue;
 }
Пример #37
0
		public void AnnotationOfMisssingAlternative()
		{
			MultiTextBase MultiTextBase = new MultiTextBase();
			Assert.IsFalse(MultiTextBase.GetAnnotationOfAlternativeIsStarred("zz"));
			Assert.IsFalse(MultiTextBase.ContainsAlternative("zz"), "should not cause the creation of the alt");
		}
Пример #38
0
		public void ClearingAnnotationOfEmptyAlternativeRemovesTheAlternative()
		{
			MultiTextBase MultiTextBase = new MultiTextBase();
			MultiTextBase.SetAnnotationOfAlternativeIsStarred("zz", true);
			MultiTextBase.SetAnnotationOfAlternativeIsStarred("zz", false);
			Assert.IsFalse(MultiTextBase.ContainsAlternative("zz"));
		}
Пример #39
0
		public void ContainsEqualForm_DifferentStarred_False()
		{
			MultiTextBase x = new MultiTextBase();
			x["ws"] = "test";
			LanguageForm form = new LanguageForm();
			form.WritingSystemId = "ws";
			form.Form = "test";
			form.IsStarred = true;
			Assert.IsFalse(x.ContainsEqualForm(form));
		}
Пример #40
0
 public MultiTextBase GetBookSetting(string key)
 {
     var result = new MultiTextBase();
     foreach(XmlElement e in RawDom.SafeSelectNodes("//div[@id='bloomDataDiv']/div[@data-book='" + key + "']"))
     {
         var lang = e.GetAttribute("lang");
         result.SetAlternative(lang ?? "", e.InnerXml);
     }
     return result;
 }
Пример #41
0
		public void ClearingAnnotationOfNonEmptyAlternative()
		{
			MultiTextBase MultiTextBase = new MultiTextBase();
			MultiTextBase.SetAnnotationOfAlternativeIsStarred("zz", true);
			MultiTextBase["zz"] = "hello";
			MultiTextBase.SetAnnotationOfAlternativeIsStarred("zz", false);
			Assert.IsTrue(MultiTextBase.ContainsAlternative("zz"));
		}