Exemple #1
0
        public void Truncate_CutOffPoint_Umlauts()
        {
            for (var i = 0; i < citiesUtf8.Length; i++)
            {
                AssertLastCityChar(i);
            }

            // test each character to ensure the length jumps correctly each time
            var tests = new List <int[]>
            {
                new[] { 1, 1 }, // Z
                new[] { 2, 7 }, // Z&uuml;
                new[] { 3, 8 },
                new[] { 7, 12 },
                new[] { 8, 17 }, // an &uuml; and &amp;
                new[] { 9, 18 },
                new[] { 10, 19 },
                new[] { 11, 25 }, // two &uuml; and one &amp;
                new[] { 12, 26 },
                new[] { 13, 27 },
                new[] { 15, 29 },
                new[] { 16, 30 },
                new[] { 17, 30 }, // it doesn't get longer
                new[] { 18, 30 }, // it doesn't get longer
                new[] { 19, 30 }, // it doesn't get longer
            };

            foreach (var test in tests)
            {
                Assert.AreEqual(test[1], Truncator.FindCutLength(citiesUmlauts, test[0]),
                                $"looking at length {test[0]}");
            }
        }
Exemple #2
0
        public void Truncate_CutOffPoint_Basic()
        {
            var basicTests = "Some normal text without specials";

            Assert.AreEqual(Truncator.FindCutLength(basicTests, 5), 5);
            Assert.AreEqual(Truncator.FindCutLength(basicTests, 10), 10);
        }
Exemple #3
0
        public void Truncate_CutOffPoint_Nbsp()
        {
            var basicTests = "Dont-Split-Me".Replace("-", "&nbsp;");

            Assert.AreEqual(10, Truncator.FindCutLength(basicTests, 5));
            Assert.AreEqual(15, Truncator.FindCutLength(basicTests, 10));
            Assert.AreEqual(21, Truncator.FindCutLength(basicTests, 11));
            Assert.AreEqual(basicTests.Length, Truncator.FindCutLength(basicTests, basicTests.Length));
        }
Exemple #4
0
        private void AssertLastCityChar(int length)
        {
            var cutLength = Truncator.FindCutLength(citiesUmlauts, length);

            // special case: length 0 means nothing should come back
            if (length == 0)
            {
                Assert.AreEqual(0, cutLength, "on 0 should be 0");
                return;
            }

            var foundChar = citiesUmlauts[cutLength - 1];
            var expected  = citiesUtf8[length - 1];

            // if it's one of the special characters, the real value will be a ; ending the entity
            if (entityPositions.Contains(length))
            {
                expected = ';';
            }
            Assert.AreEqual(expected, foundChar, $"tried on index {length}");
        }