Quellcode durchsuchen

Merge pull request #4776 from Gillibald/tests/GlyphRunFindGlyphIndex

Add a test for GlyphRun.FindGlyphIndex
Benedikt Stebner vor 5 Jahren
Ursprung
Commit
fa29ea0521
1 geänderte Dateien mit 50 neuen und 0 gelöschten Zeilen
  1. 50 0
      tests/Avalonia.Visuals.UnitTests/Media/GlyphRunTests.cs

+ 50 - 0
tests/Avalonia.Visuals.UnitTests/Media/GlyphRunTests.cs

@@ -119,6 +119,56 @@ namespace Avalonia.Visuals.UnitTests.Media
             }
             }
         }
         }
 
 
+        [InlineData(new double[] { 10, 10, 10 }, new ushort[] { 0, 0, 0 }, 0)]
+        [InlineData(new double[] { 10, 10, 10 }, new ushort[] { 0, 0, 0 }, 1)]
+        [InlineData(new double[] { 10, 10, 10, 10 }, new ushort[] { 0, 0, 0, 3 }, 0)]
+        [InlineData(new double[] { 10, 10, 10, 10 }, new ushort[] { 3, 0, 0, 0 }, 1)]
+        [InlineData(new double[] { 10, 10, 10, 10, 10 }, new ushort[] { 0, 1, 1, 1, 4 }, 0)]
+        [InlineData(new double[] { 10, 10, 10, 10, 10 }, new ushort[] { 4, 1, 1, 1, 0 }, 1)]
+        [Theory]
+        public void Should_Find_Glyph_Index(double[] advances, ushort[] clusters, int bidiLevel)
+        {
+            using (var glyphRun = CreateGlyphRun(advances, clusters, bidiLevel))
+            {
+                if (glyphRun.IsLeftToRight)
+                {
+                    for (var i = 0; i < clusters.Length; i++)
+                    {
+                        var cluster = clusters[i];
+
+                        var found = glyphRun.FindGlyphIndex(cluster);
+
+                        var expected = i;
+
+                        while (expected - 1 >= 0 && clusters[expected - 1] == cluster)
+                        {
+                            expected--;
+                        }
+
+                        Assert.Equal(expected, found);
+                    }
+                }
+                else
+                {
+                    for (var i = clusters.Length - 1; i > 0; i--)
+                    {
+                        var cluster = clusters[i];
+
+                        var found = glyphRun.FindGlyphIndex(cluster);
+
+                        var expected = i;
+
+                        while (expected + 1 < clusters.Length && clusters[expected + 1] == cluster)
+                        {
+                            expected++;
+                        }
+
+                        Assert.Equal(expected, found);
+                    }
+                }
+            }
+        }
+
         private static GlyphRun CreateGlyphRun(double[] glyphAdvances, ushort[] glyphClusters, int bidiLevel = 0)
         private static GlyphRun CreateGlyphRun(double[] glyphAdvances, ushort[] glyphClusters, int bidiLevel = 0)
         {
         {
             var count = glyphAdvances.Length;
             var count = glyphAdvances.Length;