public void CloneCopiesImports() { var original = new IcuRulesCollationDefinition("standard"); original.Imports.Add(new IcuCollationImport("en-US", "standard")); original.Imports.Add(new IcuCollationImport("zh-Hans-CN", "pinyin")); var copy = (IcuRulesCollationDefinition) original.Clone(); Assert.That(copy.Imports, Is.EqualTo(new[] {new IcuCollationImport("en-US", "standard"), new IcuCollationImport("zh-Hans-CN", "pinyin")})); }
public void CloneCopiesImports() { var original = new IcuRulesCollationDefinition("standard"); original.Imports.Add(new IcuCollationImport("en-US", "standard")); original.Imports.Add(new IcuCollationImport("zh-Hans-CN", "pinyin")); var copy = (IcuRulesCollationDefinition)original.Clone(); Assert.That(copy.Imports, Is.EqualTo(new[] { new IcuCollationImport("en-US", "standard"), new IcuCollationImport("zh-Hans-CN", "pinyin") })); }
public void Validate_NonSelfReferencingImport_WritingSystemFactoryNotSet_NotValid() { var collation = new IcuRulesCollationDefinition("standard") { Imports = {new IcuCollationImport("en-US", "other")}, 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 other collation rules from en-US.")); }
public void Validate_NonSelfReferencingImport_WritingSystemFactoryNotSet_NotValid() { var collation = new IcuRulesCollationDefinition("standard") { Imports = { new IcuCollationImport("en-US", "other") }, 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 other collation rules from en-US.")); }
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 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.")); }
public void Validate_NonSelfReferencingImport_Valid() { var ws = new WritingSystemDefinition("en-US"); ws.Collations.Add(new IcuRulesCollationDefinition("other") {IcuRules = "&B<t<<<T<s<<<S<e<<<E\r\n"}); var wsFactory = new TestWritingSystemFactory(); wsFactory.WritingSystems.Add(ws); var collation = new IcuRulesCollationDefinition("standard") { WritingSystemFactory = wsFactory, Imports = {new IcuCollationImport("en-US", "other")}, 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")); }
private bool ValidateSortRules() { CollationDefinition cd; switch (_model.CurrentCollationRulesType) { case "CustomIcu": { cd = new IcuRulesCollationDefinition((IcuRulesCollationDefinition)_model.CurrentDefinition.DefaultCollation) { IcuRules = _sortRulesTextBox.Text }; break; } case "CustomSimple": { cd = new SimpleRulesCollationDefinition((SimpleRulesCollationDefinition)_model.CurrentDefinition.DefaultCollation) { SimpleRules = _sortRulesTextBox.Text }; break; } default: { return(false); } } string message; const string prefixToMessage = "SORT RULES WILL NOT BE SAVED\r\n"; if (!cd.Validate(out message)) { _testSortResult.Text = prefixToMessage + (message ?? String.Empty); _testSortResult.ForeColor = Color.Red; return(false); } if (_testSortResult.Text.StartsWith(prefixToMessage)) { _testSortResult.Text = String.Empty; _testSortResult.ForeColor = Color.Black; } return(true); }
public void ValueEqualsComparesImports() { var first = new IcuRulesCollationDefinition("standard"); first.Imports.Add(new IcuCollationImport("en-US", "standard")); first.Imports.Add(new IcuCollationImport("zh-Hans-CN", "pinyin")); var second = new IcuRulesCollationDefinition("standard"); Assert.That(first.ValueEquals(second), Is.False, "collations with empty imports should not equal one with some"); second.Imports.Add(new IcuCollationImport("en-US", "standard")); Assert.That(first.ValueEquals(second), Is.False, "collations with different length import lists should not be equal"); second.Imports.Add(new IcuCollationImport("zh-Hans-CN", "pinyin")); Assert.That(first.ValueEquals(second), Is.True, "collations with same import lists should be equal"); second.Imports.Clear(); second.Imports.Add(new IcuCollationImport("en-US", "standard")); second.Imports.Add(new IcuCollationImport("fr-FR", "standard")); Assert.That(first.ValueEquals(second), Is.False, "collations with same-length lists of different imports should not be equal"); }
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.")); }
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 void ValidateSortRules_ValidOtherLanguage_IsTrue() { var enWS = new WritingSystemDefinition("en"); var cd = new IcuRulesCollationDefinition("standard") { IcuRules = "&b<a<c" }; string message; Assert.That(cd.Validate(out message), Is.True); enWS.DefaultCollation = cd; _writingSystemRepository.WritingSystemFactory.WritingSystems.Add(enWS); _model.AddNew(); _model.CurrentIso = "pt"; _model.CurrentCollationRulesType = "OtherLanguage"; _model.CurrentCollationRules = "en"; Assert.That(_model.ValidateCurrentSortRules(out message), Is.True); }
public void Validate_NonSelfReferencingImport_Valid() { var ws = new WritingSystemDefinition("en-US"); ws.Collations.Add(new IcuRulesCollationDefinition("other") { IcuRules = "&B<t<<<T<s<<<S<e<<<E\r\n" }); var wsFactory = new TestWritingSystemFactory(); wsFactory.WritingSystems.Add(ws); var collation = new IcuRulesCollationDefinition("standard") { WritingSystemFactory = wsFactory, Imports = { new IcuCollationImport("en-US", "other") }, 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 void Roundtrip_LdmlInvalidStandardCollation() { using (var environment = new TestEnvironment()) { const string icuRules = "&&&B<t<<<T<s<<<S<e<<<E\r\n\t\t\t\t&C<k<<<K<x<<<X<i<<<I\r\n\t\t\t\t&D<q<<<Q<r<<<R\r\n\t\t\t\t&G<o<<<O\r\n\t\t\t\t&W<h<<<H"; var cd = new IcuRulesCollationDefinition("standard") { IcuRules = icuRules, CollationRules = icuRules, IsValid = false }; var wsToLdml = new WritingSystemDefinition("aa", "Latn", "", ""); wsToLdml.Collations.Add(cd); var ldmlAdaptor = new LdmlDataMapper(new TestWritingSystemFactory()); ldmlAdaptor.Write(environment.FilePath("test.ldml"), wsToLdml, null); XElement ldmlElem = XElement.Load(environment.FilePath("test.ldml")); XElement collationsElem = ldmlElem.Element("collations"); XElement defaultCollationElem = collationsElem.Element("defaultCollation"); XElement collationElem = collationsElem.Element("collation"); Assert.That((string)defaultCollationElem, Is.EqualTo("standard")); Assert.That((string)collationElem.Attribute("type"), Is.EqualTo("standard")); Assert.That((string)collationElem, Is.EqualTo(icuRules.Replace("\r\n", "\n"))); // Verify comment written about being unable to parse ICU rule const string expectedComment = "'Unable to parse the ICU rules with ICU version'"; AssertThatXmlIn.File(environment.FilePath("test.ldml")) .HasAtLeastOneMatchForXpath(string.Format("/ldml/collations/collation/comment()[contains(.,{0})]", expectedComment)); var wsFromLdml = new WritingSystemDefinition(); ldmlAdaptor.Read(environment.FilePath("test.ldml"), wsFromLdml); Assert.That(wsFromLdml.Collations.First().ValueEquals(cd)); } }
public void Roundtrip_LdmlIcuCollationWithImports() { using (var environment = new TestEnvironment()) { const string icuRules = "&B<t<<<T<s<<<S<e<<<E\n\t\t\t\t&C<k<<<K<x<<<X<i<<<I\n\t\t\t\t&D<q<<<Q<r<<<R\n\t\t\t\t&G<o<<<O\n\t\t\t\t&W<h<<<H"; var cd = new IcuRulesCollationDefinition("standard") { Imports = {new IcuCollationImport("my", "standard")}, CollationRules = icuRules, IsValid = true }; var wsToLdml = new WritingSystemDefinition("aa", "Latn", "", ""); wsToLdml.Collations.Add(cd); var wsFactory = new TestWritingSystemFactory {WritingSystems = { new WritingSystemDefinition("my") { Collations = {new IcuRulesCollationDefinition("standard") {IcuRules = icuRules, CollationRules = icuRules, IsValid = true}} } }}; var ldmlAdaptor = new LdmlDataMapper(wsFactory); ldmlAdaptor.Write(environment.FilePath("test.ldml"), wsToLdml, null); XElement ldmlElem = XElement.Load(environment.FilePath("test.ldml")); XElement collationsElem = ldmlElem.Element("collations"); XElement defaultCollationElem = collationsElem.Element("defaultCollation"); XElement collationElem = collationsElem.Element("collation"); XElement crElem = collationElem.Element("cr"); XElement importElem = collationElem.Element("import"); Assert.That((string) defaultCollationElem, Is.EqualTo("standard")); Assert.That((string) collationElem.Attribute("type"), Is.EqualTo("standard")); Assert.That(crElem, Is.Null); Assert.That((string) importElem.Attribute("source"), Is.EqualTo("my")); Assert.That((string) importElem.Attribute("type"), Is.EqualTo("standard")); var wsFromLdml = new WritingSystemDefinition(); ldmlAdaptor.Read(environment.FilePath("test.ldml"), wsFromLdml); Assert.That(wsFromLdml.Collations.First().ValueEquals(cd)); Assert.That(wsFromLdml.DefaultCollation.ValueEquals(cd)); } }
public void Roundtrip_LdmlStandardCollation() { using (var environment = new TestEnvironment()) { const string icuRules = "&B<t<<<T<s<<<S<e<<<E\r\n\t\t\t\t&C<k<<<K<x<<<X<i<<<I\r\n\t\t\t\t&D<q<<<Q<r<<<R\r\n\t\t\t\t&G<o<<<O\r\n\t\t\t\t&W<h<<<H"; var cd = new IcuRulesCollationDefinition("standard") { IcuRules = icuRules, CollationRules = icuRules, IsValid = true }; var wsToLdml = new WritingSystemDefinition("aa", "Latn", "", ""); wsToLdml.Collations.Add(cd); var ldmlAdaptor = new LdmlDataMapper(new TestWritingSystemFactory()); ldmlAdaptor.Write(environment.FilePath("test.ldml"), wsToLdml, null); XElement ldmlElem = XElement.Load(environment.FilePath("test.ldml")); XElement collationsElem = ldmlElem.Element("collations"); XElement defaultCollationElem = collationsElem.Element("defaultCollation"); XElement collationElem = collationsElem.Element("collation"); Assert.That((string)defaultCollationElem, Is.EqualTo("standard")); Assert.That((string) collationElem.Attribute("type"), Is.EqualTo("standard")); Assert.That((string) collationElem, Is.EqualTo(icuRules.Replace("\r\n", "\n"))); var wsFromLdml = new WritingSystemDefinition(); ldmlAdaptor.Read(environment.FilePath("test.ldml"), wsFromLdml); Assert.That(wsFromLdml.Collations.First().ValueEquals(cd)); } }