public void XHTMLExportGetDigraphMapsFromICUSortRules_TertiaryIgnorableDoesNotCrash()
        {
            var ws = Cache.LangProject.DefaultVernacularWritingSystem;

            ws.SortRules = "&[last tertiary ignorable] = \\";
            ws.SortUsing = WritingSystemDefinition.SortRulesType.CustomICU;

            var    exporter = new ConfiguredExport(null, null, 0);
            string output;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    exporter.Initialize(Cache, null, writer, null, "xhtml", null, "dicBody");
                    Dictionary <string, string> mapChars = null;
                    Set <string> ignoreSet = null;
                    Set <string> data      = null;
                    Assert.DoesNotThrow(() => data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet));
                    // The second test catches the real world scenario, GetDigraphs is actually called many times, but the first time
                    // is the only one that should trigger the algorithm, afterward the information is cached in the exporter.
                    Assert.DoesNotThrow(() => data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet));
                    Assert.AreEqual(mapChars.Count, 0, "Too many characters found equivalents");
                    Assert.AreEqual(ignoreSet.Count, 1, "Ignorable character not parsed from rule");
                }
            }
        }
        public void XHTMLExportGetDigraphMapsFromICUSortRules_TestSecondaryTertiaryShouldNotGenerateHeader()
        {
            var ws = Cache.LangProject.DefaultVernacularWritingSystem;

            ws.SortRules = "&b << az / c <<< AZ / C" + Environment.NewLine + "&f << gz";
            ws.SortUsing = WritingSystemDefinition.SortRulesType.CustomICU;

            var    exporter = new ConfiguredExport(null, null, 0);
            string output;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    exporter.Initialize(Cache, null, writer, null, "xhtml", null, "dicBody");
                    Dictionary <string, string> mapChars;
                    Set <string> ignoreSet;
                    var          data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet);
                    Assert.AreEqual(data.Count, 0, "Header created for two wedges");
                    Assert.AreEqual(mapChars.Count, 3, "Too many characters found equivalents");
                    Assert.AreEqual(mapChars["az"], "b");
                    Assert.AreEqual(mapChars["AZ"], "b");
                    // Rules following the '/' rule should not be skipped LT-18309
                    Assert.AreEqual(mapChars["gz"], "f");
                }
            }
        }
        public void XHTMLExportGetDigraphMapsFromICUSortRules_BeforeRuleSecondaryIgnored()
        {
            var ws = Cache.LangProject.DefaultVernacularWritingSystem;

            ws.SortRules = "& [before 2] a < aa <<< Aa <<< AA";
            ws.SortUsing = WritingSystemDefinition.SortRulesType.CustomICU;

            var    exporter = new ConfiguredExport(null, null, 0);
            string output;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    exporter.Initialize(Cache, null, writer, null, "xhtml", null, "dicBody");
                    Dictionary <string, string> mapChars = null;
                    Set <string> ignoreSet = null;
                    Set <string> data      = null;
                    Assert.DoesNotThrow(() => data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet));
                    Assert.AreEqual(data.Count, 0, "No characters should be generated by a before 2 rule");
                    Assert.AreEqual(mapChars.Count, 0, "The rule should have been ignored, no characters ought to have been mapped");
                    Assert.AreEqual(ignoreSet.Count, 0, "Ignorable character incorrectly parsed from rule");
                }
            }
        }
        public void XHTMLExportGetDigraphMapsFromICUSortRules_BeforeRulePrimaryGetsADigraph()
        {
            var ws = Cache.LangProject.DefaultVernacularWritingSystem;

            ws.SortRules = "& [before 1] a < aa <<< Aa <<< AA";
            ws.SortUsing = WritingSystemDefinition.SortRulesType.CustomICU;

            var    exporter = new ConfiguredExport(null, null, 0);
            string output;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    exporter.Initialize(Cache, null, writer, null, "xhtml", null, "dicBody");
                    Dictionary <string, string> mapChars = null;
                    Set <string> ignoreSet = null;
                    Set <string> data      = null;
                    Assert.DoesNotThrow(() => data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet));
                    Assert.AreEqual(data.Count, 1, "Wrong number of character mappings found");
                    Assert.AreEqual(mapChars.Count, 2, "Wrong number of character mappings found");
                    Assert.AreEqual(ignoreSet.Count, 0, "Ignorable character incorrectly parsed from rule");
                }
            }
        }
        public void XHTMLExportGetDigraphMapsFromICUSortRules_UnicodeTertiaryIgnorableWorks()
        {
            var ws = Cache.LangProject.DefaultVernacularWritingSystem;

            ws.SortRules = "&[last tertiary ignorable] = \\uA78C";
            ws.SortUsing = WritingSystemDefinition.SortRulesType.CustomICU;

            var    exporter = new ConfiguredExport(null, null, 0);
            string output;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    exporter.Initialize(Cache, null, writer, null, "xhtml", null, "dicBody");
                    Dictionary <string, string> mapChars = null;
                    Set <string> ignoreSet = null;
                    Set <string> data      = null;
                    Assert.DoesNotThrow(() => data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet));
                    Assert.AreEqual(mapChars.Count, 0, "Too many characters found equivalents");
                    Assert.AreEqual(ignoreSet.Count, 1, "Ignorable character not parsed from rule");
                    Assert.IsTrue(ignoreSet.Contains('\uA78C'.ToString(CultureInfo.InvariantCulture)));
                }
            }
        }
Example #6
0
        public void XHTMLExportGetDigraphMapsFirstCharactersFromICUSortRules()
        {
            CoreWritingSystemDefinition ws = Cache.LangProject.DefaultVernacularWritingSystem;

            ws.DefaultCollation = new IcuRulesCollationDefinition("standard")
            {
                IcuRules = "&b < az << a < c <<< ch"
            };

            var    exporter = new ConfiguredExport(null, null, 0);
            string output;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    exporter.Initialize(Cache, m_propertyTable, writer, null, "xhtml", null, "dicBody");
                    Dictionary <string, string> mapChars;
                    ISet <string> ignoreSet;
                    var           data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet);
                    Assert.AreEqual(mapChars.Count, 2, "Too many characters found equivalents");
                    Assert.AreEqual(mapChars["a"], "az");
                    Assert.AreEqual(mapChars["ch"], "c");
                }
            }
        }
Example #7
0
        public void XHTMLExportGetDigraphMapsFirstCharactersFromSortRulesWithNoMapping()
        {
            var ws = Cache.LangProject.DefaultVernacularWritingSystem;

            ws.DefaultCollation = new SimpleRulesCollationDefinition("standard")
            {
                SimpleRules = "b" + Environment.NewLine + "ñe ñ"
            };

            var    exporter = new ConfiguredExport(null, null, 0);
            string output;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    exporter.Initialize(Cache, m_propertyTable, writer, null, "xhtml", null, "dicBody");
                    Dictionary <string, string> mapChars;
                    ISet <string> ignoreSet;
                    var           data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet);
                    Assert.AreEqual(data.Count, 2, "Two Digraphs should be returned");
                    Assert.AreEqual(mapChars["ñ"], "ñe");
                }
            }
        }
Example #8
0
        public void XHTMLExportGetDigraphMapsFromICUSortRules_BeforeRuleCombinedWithNormalRuleWorks()
        {
            CoreWritingSystemDefinition ws = Cache.LangProject.DefaultVernacularWritingSystem;

            ws.DefaultCollation = new IcuRulesCollationDefinition("standard")
            {
                IcuRules = "& a < bb & [before 1] a < aa"
            };

            var    exporter = new ConfiguredExport(null, null, 0);
            string output;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    exporter.Initialize(Cache, m_propertyTable, writer, null, "xhtml", null, "dicBody");
                    Dictionary <string, string> mapChars = null;
                    ISet <string> ignoreSet = null;
                    ISet <string> data      = null;
                    Assert.DoesNotThrow(() => data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet));
                    Assert.AreEqual(data.Count, 2, "The [before 1] rule should have added one additional character");
                }
            }
        }
Example #9
0
        public void XHTMLExportGetDigraphMapsFromICUSortRules_TertiaryIgnorableMixedSpacingWorks()
        {
            CoreWritingSystemDefinition ws = Cache.LangProject.DefaultVernacularWritingSystem;

            ws.DefaultCollation = new IcuRulesCollationDefinition("standard")
            {
                IcuRules = "&[last tertiary ignorable]= '!'\r\n&[last tertiary ignorable] ='?'"
            };

            var    exporter = new ConfiguredExport(null, null, 0);
            string output;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    exporter.Initialize(Cache, m_propertyTable, writer, null, "xhtml", null, "dicBody");
                    Dictionary <string, string> mapChars = null;
                    ISet <string> ignoreSet = null;
                    ISet <string> data      = null;
                    Assert.DoesNotThrow(() => data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet));
                    Assert.AreEqual(mapChars.Count, 0, "Too many characters found equivalents");
                    Assert.AreEqual(ignoreSet.Count, 2, "Ignorable character not parsed from rule");
                    CollectionAssert.AreEquivalent(ignoreSet, new[] { "!", "?" });
                }
            }
        }
        public void XHTMLExportGetDigraphMapsFirstCharactersFromOtherSortRules()
        {
            var ws = Cache.LangProject.DefaultVernacularWritingSystem;

            ws.SortRules = "fr";
            ws.SortUsing = WritingSystemDefinition.SortRulesType.OtherLanguage;

            var    exporter = new ConfiguredExport(null, null, 0);
            string output;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    exporter.Initialize(Cache, null, writer, null, "xhtml", null, "dicBody");
                    Dictionary <string, string> mapChars;
                    Set <string> ignoreSet;
                    var          data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet);
                    Assert.AreEqual(mapChars.Count, 0, "No equivalents expected");
                }
            }
        }
        public void XHTMLExportGetDigraphMapsFirstCharactersFromToolboxSortRules()
        {
            var ws = Cache.LangProject.DefaultVernacularWritingSystem;

            ws.SortRules = "b" + Environment.NewLine + "az a" + Environment.NewLine + "c ch";
            ws.SortUsing = WritingSystemDefinition.SortRulesType.CustomSimple;

            var    exporter = new ConfiguredExport(null, null, 0);
            string output;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    exporter.Initialize(Cache, null, writer, null, "xhtml", null, "dicBody");
                    Dictionary <string, string> mapChars;
                    Set <string> ignoreSet;
                    var          data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet);
                    Assert.AreEqual(mapChars.Count, 2, "Too many characters found equivalents");
                    Assert.AreEqual(mapChars["a"], "az");
                    Assert.AreEqual(mapChars["ch"], "c");
                }
            }
        }