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++; } }
public static MultiTextBase Create(Dictionary <string, string> forms) { MultiTextBase m = new MultiTextBase(); CopyForms(forms, m); return(m); }
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); }
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); } }
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); }
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); }
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)); }
/// <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); }
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"]); }
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"); }
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 } } }
/// <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); }
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); }
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); }
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]); } } } }
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]); } } } }
public void CompareTo_MultiTextWithMoreForms_ReturnsLess() { MultiTextBase multiTextBase = new MultiTextBase(); MultiTextBase multiTextBaseToCompare = new MultiTextBase(); multiTextBaseToCompare.SetAlternative("de", "Word 1"); Assert.AreEqual(-1, multiTextBase.CompareTo(multiTextBaseToCompare)); }
public void CompareTo_MultiTextWithFewerForms_ReturnsGreater() { MultiTextBase multiTextBase = new MultiTextBase(); multiTextBase.SetAlternative("de", "Word 1"); MultiTextBase multiTextBaseToCompare = new MultiTextBase(); Assert.AreEqual(1, multiTextBase.CompareTo(multiTextBaseToCompare)); }
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); }
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); }
public void GetOrderedAndFilteredForms_EmptyMultiText_GivesEmptyList() { MultiTextBase x = new MultiTextBase(); LanguageForm[] forms = x.GetOrderedAndFilteredForms(new string[] { "one", "three" }); Assert.AreEqual(0, forms.Length); }
public void GetOrderedAndFilteredForms_EmptyIdList_GivesEmptyList() { MultiTextBase x = new MultiTextBase(); x["one"] = "test"; Assert.AreEqual(0, x.GetOrderedAndFilteredForms(new string[] { }).Length); }
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)); }
public void HasFormWithSameContent_Identity_True() { MultiTextBase x = new MultiTextBase(); x["ws1"] = "testing"; x["ws"] = "test"; x["ws2"] = "testing"; Assert.IsTrue(x.HasFormWithSameContent(x)); }
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)); }
public static bool IsEmpty(MultiTextBase mt) { return(mt == null || mt.Empty); }
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)); }
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")); }
public void HasFormWithSameContent_BothEmpty_True() { MultiTextBase x = new MultiTextBase(); MultiTextBase y = new MultiTextBase(); Assert.IsTrue(x.HasFormWithSameContent(y)); Assert.IsTrue(y.HasFormWithSameContent(x)); }
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)); }
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)); }
public LanguageForm(string writingSystemId, string form, MultiTextBase parent) { _parent = parent; _writingSystemId = writingSystemId; _form = form; }
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)); }
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)); }
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")); }
public NamedMutliLingualValue(MultiTextBase text, bool isCollectionValue) { TextAlternatives = text; IsCollectionValue = isCollectionValue; }
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"); }
public void ClearingAnnotationOfEmptyAlternativeRemovesTheAlternative() { MultiTextBase MultiTextBase = new MultiTextBase(); MultiTextBase.SetAnnotationOfAlternativeIsStarred("zz", true); MultiTextBase.SetAnnotationOfAlternativeIsStarred("zz", false); Assert.IsFalse(MultiTextBase.ContainsAlternative("zz")); }
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)); }
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; }
public void ClearingAnnotationOfNonEmptyAlternative() { MultiTextBase MultiTextBase = new MultiTextBase(); MultiTextBase.SetAnnotationOfAlternativeIsStarred("zz", true); MultiTextBase["zz"] = "hello"; MultiTextBase.SetAnnotationOfAlternativeIsStarred("zz", false); Assert.IsTrue(MultiTextBase.ContainsAlternative("zz")); }