Exemple #1
0
        public void Equals_TwoRunsSame_ReturnsTrue()
        {
            TsString tss1 = CreateTwoRunString();
            TsString tss2 = CreateTwoRunString();

            Assert.That(tss1.Equals(tss2), Is.True);
        }
        public void Serialization_StackedDiacriticsMultipleRuns_ProducesCorrectXML()
        {
            string expectedXML = "<Str>" +
                                 "<Run ws=\"en\" fontsize=\"20000\" fontsizeUnit=\"mpt\" forecolor=\"green\">Stacked diacritics: We</Run>" +
                                 "<Run ws=\"en\" fontsize=\"20000\" fontsizeUnit=\"mpt\" forecolor=\"2f60ff\">" + COMBINING_RING_BELOW + "</Run>" +
                                 "<Run ws=\"en\" fontsize=\"20000\" fontsizeUnit=\"mpt\" forecolor=\"green\">" + COMBINING_GRAVE_ACCENT_BELOW + "</Run>" +
                                 "<Run ws=\"en\" fontsize=\"20000\" fontsizeUnit=\"mpt\" forecolor=\"red\">" + COMBINING_DOUBLE_ACUTE_ACCENT + "</Run>" +
                                 "<Run ws=\"en\" fontsize=\"20000\" fontsizeUnit=\"mpt\" forecolor=\"green\">lc" + COMBINING_LEFT_TACK_BELOW + COMBINING_MINUS_SIGN_BELOW + "o</Run>" +
                                 "<Run ws=\"en\" fontsize=\"20000\" fontsizeUnit=\"mpt\" forecolor=\"blue\">" + COMBINING_CIRCUMFLEX_ACCENT + "</Run>" +
                                 "<Run ws=\"en\" fontsize=\"20000\" fontsizeUnit=\"mpt\" forecolor=\"green\">m" + COMBINING_SEAGULL_BELOW + "</Run>" +
                                 "<Run ws=\"en\" fontsize=\"20000\" fontsizeUnit=\"mpt\" forecolor=\"red\">" + COMBINING_GRAVE_ACCENT + "</Run>" +
                                 "<Run ws=\"en\" fontsize=\"20000\" fontsizeUnit=\"mpt\" forecolor=\"green\">" + COMBINING_DIAERESIS + COMBINING_MACRON + e_WITH_GRAVE + " t" + o_WITH_DIAERESIS + "</Run>" +
                                 "<Run ws=\"en\" fontsize=\"20000\" fontsizeUnit=\"mpt\" forecolor=\"black\">" + COMBINING_CIRCUMFLEX_ACCENT + "</Run>" +
                                 "<Run ws=\"en\" fontsize=\"20000\" fontsizeUnit=\"mpt\" forecolor=\"green\"> W" + o_WITH_DOT_ABOVE + "</Run>" +
                                 "<Run ws=\"en\" fontsize=\"20000\" fontsizeUnit=\"mpt\" forecolor=\"black\">" + COMBINING_INVERTED_BREVE + "</Run>" +
                                 "<Run ws=\"en\" fontsize=\"20000\" fontsizeUnit=\"mpt\" forecolor=\"green\">r" + COMBINING_SQUARE_BELOW + "l</Run>" +
                                 "<Run ws=\"en\" fontsize=\"20000\" fontsizeUnit=\"mpt\" forecolor=\"blue\">" + COMBINING_TILDE + "</Run>" +
                                 "<Run ws=\"en\" fontsize=\"20000\" fontsizeUnit=\"mpt\" forecolor=\"green\">d</Run>" +
                                 "<Run ws=\"en\" fontsize=\"20000\" fontsizeUnit=\"mpt\" forecolor=\"red\">" + COMBINING_DOWN_TACK_BELOW + "</Run>" +
                                 "<Run ws=\"en\" fontsize=\"20000\" fontsizeUnit=\"mpt\" forecolor=\"green\">" + COMBINING_TILDE_BELOW + "P" + a_WITH_DOT_ABOVE + "</Run>" +
                                 "<Run ws=\"en\" fontsize=\"20000\" fontsizeUnit=\"mpt\" forecolor=\"red\">" + COMBINING_OVERLINE + "</Run>" +
                                 "<Run ws=\"en\" fontsize=\"20000\" fontsizeUnit=\"mpt\" forecolor=\"black\">" + COMBINING_DOUBLE_ACUTE_ACCENT + "</Run>" +
                                 "<Run ws=\"en\" fontsize=\"20000\" fontsizeUnit=\"mpt\" forecolor=\"green\">d</Run>" +
                                 "<Run ws=\"en\" fontsize=\"20000\" fontsizeUnit=\"mpt\" forecolor=\"black\">" + COMBINING_ACUTE_ACCENT_BELOW + "</Run>" +
                                 "<Run ws=\"en\" fontsize=\"20000\" fontsizeUnit=\"mpt\" forecolor=\"green\">!</Run>" +
                                 "</Str>";

            TsString tss = CreateStackedDiacriticsInput(singleRun: false);
            string   xml = TsStringSerializer.SerializeTsStringToXml(tss, WritingSystemManager);

            Assert.That(StripNewLines(xml), Is.EqualTo(expectedXML));
        }
Exemple #3
0
        public void FetchChars_IchMinGreaterThanIchLim_Throws()
        {
            TsString tss = CreateTwoRunString();

            using (ArrayPtr rgch = MarshalEx.StringToNative(10, true))
                Assert.That(() => tss.FetchChars(25, 24, rgch), Throws.InstanceOf <ArgumentOutOfRangeException>());
        }
        [TestCase(FwNormalizationMode.knmNFKD, 2, 2, "A" + COMBINING_DIAERESIS + COMBINING_MACRON)] // NFKD: no change
        public void get_NormalizedForm_NFSC_IsBlockedByRunBoundaries(FwNormalizationMode nm, int expectedRunCount, int expectedFirstRunLim, string expectedText)
        {
            // The macron will be in a different run; so while the first two compression
            // schemes produce a single character, NFSC should produce 2.
            string input   = "A" + COMBINING_DIAERESIS + COMBINING_MACRON;
            var    temp    = new TsString(input, EnglishWS);
            var    builder = temp.GetBldr();

            // Make two runs, changing the last character
            builder.SetIntPropValues(2, 3, (int)FwTextPropType.ktptBold, (int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn);
            var tsInput = builder.GetString();

            var actual = tsInput.get_NormalizedForm(nm);

            Assert.That(actual.Text, Is.EqualTo(expectedText));
            Assert.That(actual.RunCount, Is.EqualTo(expectedRunCount));
            var normalProps = tsInput.get_Properties(0);
            var boldProps   = tsInput.get_Properties(1);

            Assert.That(actual.get_Properties(0), Is.EqualTo(normalProps));
            if (expectedRunCount > 1)
            {
                Assert.That(actual.get_LimOfRun(0), Is.EqualTo(expectedFirstRunLim));
                Assert.That(actual.get_Properties(1), Is.EqualTo(boldProps));
            }
        }
        public void NfdAndFixOffsets_WithStackedDiacriticsInMultipleRuns_FixesOffsetsCorrectly()
        {
            TsString input = CreateStackedDiacriticsInput(singleRun: false);

            int[] origOffsets     = { 21, 22, 23, 24, 25 };             // Offsets 26 through end of string are unchanged by this test
            int[] expectedOffsets = { 21, 24, 22, 23, 25 };

            ITsString nfd;

            int[] actualOffsets;
            using (ArrayPtr nativeOffsets = ConvertToNativeArray(origOffsets))
            {
                input.NfdAndFixOffsets(out nfd, nativeOffsets, origOffsets.Length);
                actualOffsets = ConvertToManagedArray(nativeOffsets, origOffsets.Length);
            }
            CollectionAssert.AreEqual(expectedOffsets, actualOffsets);

            // All the new offsets should still point to the same characters that they did before
            for (int i = 0; i < origOffsets.Length; i++)
            {
                int  oldOffset = origOffsets[i];
                int  newOffset = actualOffsets[i];
                char oldCh     = input.Text[oldOffset];
                char newCh     = nfd.Text[newOffset];
                Assert.That(newCh, Is.EqualTo(oldCh),
                            String.Format("Old char '{0}' (U+{1:X4}) at {2} should match new char '{3}' (U+{4:X4}) at {5}, but didn't match.",
                                          oldCh, (int)oldCh, oldOffset, newCh, newOffset, (int)newCh));
            }
        }
Exemple #6
0
        public void Equals_NotSame_ReturnsFalse()
        {
            TsString tss1 = CreateTwoRunString();
            TsString tss2 = CreateOneRunString();

            Assert.That(tss1.Equals(tss2), Is.False);
        }
        public void get_NormalizedForm_NullStrings_NormalizedFormIsSameObjectAsInput(FwNormalizationMode nm)
        {
            TsString nullString = new TsString(null, EnglishWS);
            TsString actual     = (TsString)nullString.get_NormalizedForm(nm);

            Assert.That(actual, Is.SameAs(nullString));
        }
        [TestCase(FwNormalizationMode.knmNFKD, 6, 1, 2, expectedDecomposedTextForReorderingTests)]       // NFKD: same as NFD
        public void get_NormalizedForm_ReorderingDiacriticsAcrossRuns_ShouldKeepCharacterPropertiesIntact(
            FwNormalizationMode nm, int expectedRunCount, int expectedSecondRunMin, int expectedSecondRunLim, string expectedText)
        {
            string input   = "a" + COMBINING_DIAERESIS + COMBINING_DOT_BELOW + a_WITH_DIAERESIS + COMBINING_DOT_BELOW;
            var    temp    = new TsString(input, EnglishWS);
            var    builder = temp.GetBldr();

            // Make three runs, with the underdot having different props from the a and the diaeresis in each case.
            builder.SetIntPropValues(2, 4, (int)FwTextPropType.ktptBold, (int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn);
            var tsInput = builder.GetString();

            Assert.That(tsInput.get_IsNormalizedForm(nm), Is.False);
            var actual = tsInput.get_NormalizedForm(nm);

            Assert.That(actual.Text, Is.EqualTo(expectedText));
            Assert.That(actual.RunCount, Is.EqualTo(expectedRunCount));
            // Second run is a good way to test that all the expected runs are in the right place
            Assert.That(actual.get_MinOfRun(1), Is.EqualTo(expectedSecondRunMin));
            Assert.That(actual.get_LimOfRun(1), Is.EqualTo(expectedSecondRunLim));
            // For all cases, first run of output should be normal, just like first run of input was
            // For all cases, second run of output should be bold, just like second run of input was
            var normalProps = tsInput.get_Properties(0);
            var boldProps   = tsInput.get_Properties(1);

            Assert.That(actual.get_Properties(0), Is.EqualTo(normalProps));
            Assert.That(actual.get_Properties(1), Is.EqualTo(boldProps));
            Assert.That(actual.get_PropertiesAt(0), Is.EqualTo(normalProps));
            Assert.That(actual.get_PropertiesAt(expectedSecondRunMin), Is.EqualTo(boldProps));
            Assert.That(actual.get_PropertiesAt(expectedSecondRunLim - 1), Is.EqualTo(boldProps));
            if (expectedRunCount > 2)
            {
                Assert.That(actual.get_PropertiesAt(expectedSecondRunLim), Is.EqualTo(normalProps));
            }
        }
Exemple #9
0
        public void GetBoundsOfRun_RunIndexOutOfRange_Throws()
        {
            TsString tss = CreateOneRunString();
            int      ichMin, ichLim;

            Assert.That(() => tss.GetBoundsOfRun(1, out ichMin, out ichLim), Throws.InstanceOf <ArgumentOutOfRangeException>());
        }
Exemple #10
0
        public void FetchRunInfoAt_IchOutOfRange_Throws()
        {
            TsString  tss = CreateTwoRunString();
            TsRunInfo tri;

            Assert.That(() => tss.FetchRunInfoAt(37, out tri), Throws.InstanceOf <ArgumentOutOfRangeException>());
        }
Exemple #11
0
        public void Equals_EmptySame_ReturnsTrue()
        {
            TsString tss1 = CreateEmptyString();
            TsString tss2 = CreateEmptyString();

            Assert.That(tss1.Equals(tss2), Is.True);
        }
        public void get_NormalizedForm_NullStrings_AfterNormalizationHaveAlreadyNormalizedFlagSet(FwNormalizationMode nm)
        {
            TsString nullString = new TsString(null, EnglishWS);

            nullString.get_NormalizedForm(nm);             // Don't need result for this test
            Assert.That(nullString.IsAlreadyNormalized(nm), Is.True);
        }
        public void get_NormalizedForm_SplitRuns_ShouldVaryBehaviorBetweenNFCAndNFSC(FwNormalizationMode nm, string expected)
        {
            // Setup
            string input     = "A" + COMBINING_DIAERESIS;
            var    intProps1 = new Dictionary <int, TsIntPropValue>
            {
                { (int)FwTextPropType.ktptWs, new TsIntPropValue((int)FwTextPropVar.ktpvDefault, EnglishWS) },
                { (int)FwTextPropType.ktptBold, new TsIntPropValue((int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn) }
            };
            var intProps2 = new Dictionary <int, TsIntPropValue>
            {
                { (int)FwTextPropType.ktptWs, new TsIntPropValue((int)FwTextPropVar.ktpvDefault, SpanishWS) },
                { (int)FwTextPropType.ktptUnderline, new TsIntPropValue((int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn) }
            };
            var runs = new List <TsRun>();

            runs.Add(new TsRun(1, new TsTextProps(intProps1, null)));
            runs.Add(new TsRun(input.Length, new TsTextProps(intProps2, null)));
            var tsInput = new TsString(input, runs);

            // Exercise
            ITsString actual = tsInput.get_NormalizedForm(nm);

            Assert.That(actual.Text, Is.EqualTo(expected));
            Assert.That(actual.get_IsNormalizedForm(nm), Is.True);
        }
        public void get_IsNormalizedForm_SplitRuns_NFSCIsNotNFC()
        {
            // Setup
            string input     = "A" + COMBINING_DIAERESIS;
            var    intProps1 = new Dictionary <int, TsIntPropValue>
            {
                { (int)FwTextPropType.ktptWs, new TsIntPropValue((int)FwTextPropVar.ktpvDefault, EnglishWS) },
                { (int)FwTextPropType.ktptBold, new TsIntPropValue((int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn) }
            };
            var intProps2 = new Dictionary <int, TsIntPropValue>
            {
                { (int)FwTextPropType.ktptWs, new TsIntPropValue((int)FwTextPropVar.ktpvDefault, SpanishWS) },
                { (int)FwTextPropType.ktptUnderline, new TsIntPropValue((int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn) }
            };
            var runs = new List <TsRun>();

            runs.Add(new TsRun(1, new TsTextProps(intProps1, null)));
            runs.Add(new TsRun(input.Length, new TsTextProps(intProps2, null)));
            var tsInput = new TsString(input, runs);

            // Before calling get_IsNormalizedForm once, we did NOT know that this string was valid NFSC
            Assert.That(tsInput.IsAlreadyNormalized(FwNormalizationMode.knmNFSC), Is.False);

            // Exercise
            Assert.That(tsInput.get_IsNormalizedForm(FwNormalizationMode.knmNFSC), Is.True);

            // We've set the NFSC flag, but NOT the NFKC or NFC flags -- because in some cases (like this one!),
            // a string can be NFSC but not NFC or NFKC.
            Assert.That(tsInput.IsAlreadyNormalized(FwNormalizationMode.knmNFSC), Is.True);
            Assert.That(tsInput.IsAlreadyNormalized(FwNormalizationMode.knmNFKC), Is.False);
            Assert.That(tsInput.IsAlreadyNormalized(FwNormalizationMode.knmNFC), Is.False);
            // And indeed, this string is NOT normalized under either NFC or NFKC.
            Assert.That(tsInput.get_IsNormalizedForm(FwNormalizationMode.knmNFC), Is.False);
            Assert.That(tsInput.get_IsNormalizedForm(FwNormalizationMode.knmNFKC), Is.False);
        }
        public void get_NormalizedForm_NullStrings_AfterCheckingNormalizationHaveAlreadyNormalizedFlagSet(FwNormalizationMode nm)
        {
            TsString nullString = new TsString("", EnglishWS);

            Assert.That(nullString.get_IsNormalizedForm(nm), Is.True);
            Assert.That(nullString.IsAlreadyNormalized(nm), Is.True);
        }
Exemple #16
0
        public void get_PropertiesAt_TwoRuns_ReturnsCorrectProperties()
        {
            TsString     tss = CreateTwoRunString();
            ITsTextProps tps = tss.get_PropertiesAt(20);
            int          var;

            Assert.That(tps.GetIntPropValues((int)FwTextPropType.ktptWs, out var), Is.EqualTo(SpanishWS));
        }
Exemple #17
0
        public void get_PropertiesAt_Empty_ReturnsCorrectProperties()
        {
            TsString     tss = CreateEmptyString();
            ITsTextProps tps = tss.get_PropertiesAt(0);
            int          var;

            Assert.That(tps.GetIntPropValues((int)FwTextPropType.ktptWs, out var), Is.EqualTo(EnglishWS));
        }
        public void get_IsNormalizedForm_SingleRun_NFKDIsAlsoNFD()
        {
            TsString tsInput = new TsString("A" + COMBINING_DIAERESIS, EnglishWS);

            Assert.That(tsInput.get_IsNormalizedForm(FwNormalizationMode.knmNFKD), Is.True);
            Assert.That(tsInput.IsAlreadyNormalized(FwNormalizationMode.knmNFKD), Is.True);
            Assert.That(tsInput.IsAlreadyNormalized(FwNormalizationMode.knmNFD), Is.True);
        }
Exemple #19
0
        public void GetBoundsOfRun_OneRun_ReturnsCorrectBounds()
        {
            TsString tss = CreateOneRunString();
            int      ichMin, ichLim;

            tss.GetBoundsOfRun(0, out ichMin, out ichLim);
            Assert.That(ichMin, Is.EqualTo(0));
            Assert.That(ichLim, Is.EqualTo(15));
        }
        public void get_IsNormalizedForm_SingleRun_NFKCIsAlsoNFSCAndNFC()
        {
            TsString tsInput = new TsString(A_WITH_DIAERESIS, EnglishWS);

            Assert.That(tsInput.get_IsNormalizedForm(FwNormalizationMode.knmNFKC), Is.True);
            Assert.That(tsInput.IsAlreadyNormalized(FwNormalizationMode.knmNFSC), Is.True);
            Assert.That(tsInput.IsAlreadyNormalized(FwNormalizationMode.knmNFKC), Is.True);
            Assert.That(tsInput.IsAlreadyNormalized(FwNormalizationMode.knmNFC), Is.True);
        }
Exemple #21
0
        public void GetBoundsOfRun_TwoRuns_ReturnsCorrectBounds()
        {
            TsString tss = CreateTwoRunString();
            int      ichMin, ichLim;

            tss.GetBoundsOfRun(1, out ichMin, out ichLim);
            Assert.That(ichMin, Is.EqualTo(16));
            Assert.That(ichLim, Is.EqualTo(36));
        }
Exemple #22
0
        public void FetchRunInfo_Empty_ReturnsCorrectRunInfo()
        {
            TsString  tss = CreateEmptyString();
            TsRunInfo tri;

            tss.FetchRunInfo(0, out tri);
            Assert.That(tri, Is.EqualTo(new TsRunInfo {
                ichMin = 0, ichLim = 0, irun = 0
            }));
        }
Exemple #23
0
        public void FetchRunInfoAt_OneRun_ReturnsCorrectRunInfo()
        {
            TsString  tss = CreateOneRunString();
            TsRunInfo tri;

            tss.FetchRunInfoAt(3, out tri);
            Assert.That(tri, Is.EqualTo(new TsRunInfo {
                ichMin = 0, ichLim = 15, irun = 0
            }));
        }
Exemple #24
0
        public void FetchRunInfoAt_TwoRuns_ReturnsCorrectRunInfo()
        {
            TsString  tss = CreateTwoRunString();
            TsRunInfo tri;

            tss.FetchRunInfoAt(18, out tri);
            Assert.That(tri, Is.EqualTo(new TsRunInfo {
                ichMin = 16, ichLim = 36, irun = 1
            }));
        }
Exemple #25
0
        public void GetSubstring_WholeRun_ReturnsCorrectString()
        {
            TsString tss = CreateTwoRunString();

            ITsString substring = tss.GetSubstring(tss.get_MinOfRun(1), tss.get_LimOfRun(1));

            Assert.That(substring.Text, Is.EqualTo(SpanishText));
            Assert.That(substring.RunCount, Is.EqualTo(1));
            Assert.That(substring.get_LimOfRun(0), Is.EqualTo(substring.Length));
            Assert.That(substring.get_WritingSystem(0), Is.EqualTo(SpanishWS));
        }
Exemple #26
0
        public void GetSubstring_PartialRun_ReturnsCorrectString()
        {
            TsString tss = CreateTwoRunString();

            ITsString substring = tss.GetSubstring(tss.get_MinOfRun(1) + 1, tss.get_LimOfRun(1) - 1);

            Assert.That(substring.Text, Is.EqualTo("Esto es una prueba"));
            Assert.That(substring.RunCount, Is.EqualTo(1));
            Assert.That(substring.get_LimOfRun(0), Is.EqualTo(substring.Length));
            Assert.That(substring.get_WritingSystem(0), Is.EqualTo(SpanishWS));
        }
Exemple #27
0
        public void LockText_OneRun_ReturnsCorrectString()
        {
            TsString tss = CreateOneRunString();
            string   text;
            int      len;

            tss.LockText(out text, out len);
            Assert.That(text, Is.EqualTo(EnglishText));
            Assert.That(len, Is.EqualTo(EnglishText.Length));
            tss.UnlockText(text);
        }
Exemple #28
0
        public void LockText_TwoRuns_ReturnsCorrectString()
        {
            TsString tss = CreateTwoRunString();
            string   text;
            int      len;

            tss.LockText(out text, out len);
            Assert.That(text, Is.EqualTo(CombinedText));
            Assert.That(len, Is.EqualTo(CombinedText.Length));
            tss.UnlockText(text);
        }
Exemple #29
0
        public void FetchChars_TwoRuns_ReturnsCorrectString()
        {
            TsString tss = CreateTwoRunString();

            using (ArrayPtr rgch = MarshalEx.StringToNative(11, true))
            {
                tss.FetchChars(25, 36, rgch);
                string str = MarshalEx.NativeToString(rgch, 11, true);
                Assert.That(str, Is.EqualTo("una prueba!"));
            }
        }
Exemple #30
0
        public void LockText_Empty_ReturnsEmptyString()
        {
            TsString tss = CreateEmptyString();
            string   text;
            int      len;

            tss.LockText(out text, out len);
            Assert.That(text, Is.EqualTo(string.Empty));
            Assert.That(len, Is.EqualTo(0));
            tss.UnlockText(text);
        }