SkPDF/Clusterator: a second test

Change-Id: I805672d88f1c913acba58feca3ad950f5d82884d
Reviewed-on: https://skia-review.googlesource.com/117639
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>
diff --git a/src/pdf/SkClusterator.h b/src/pdf/SkClusterator.h
index db47a5d..97aded2 100644
--- a/src/pdf/SkClusterator.h
+++ b/src/pdf/SkClusterator.h
@@ -31,6 +31,13 @@
         uint32_t fGlyphIndex;
         uint32_t fGlyphCount;
         explicit operator bool() const { return fGlyphCount != 0; }
+        bool operator==(const SkClusterator::Cluster& o) {
+            return fUtf8Text       == o.fUtf8Text
+                && fTextByteLength == o.fTextByteLength
+                && fGlyphIndex     == o.fGlyphIndex
+                && fGlyphCount     == o.fGlyphCount;
+        }
+
     };
     Cluster next();
 
diff --git a/tests/PDFPrimitivesTest.cpp b/tests/PDFPrimitivesTest.cpp
index f16c669..372b63a 100644
--- a/tests/PDFPrimitivesTest.cpp
+++ b/tests/PDFPrimitivesTest.cpp
@@ -496,29 +496,44 @@
 }
 
 DEF_TEST(SkPDF_Clusterator, reporter) {
-    const uint32_t clusters[11] = { 3, 2, 2, 1, 0, 4, 4, 7, 6, 6, 5 };
-    const SkGlyphID glyphs[11] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
-    const char text[] = "abcdefgh";
     SkPaint paint;
     paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
-    SkClusterator clusterator(glyphs, sizeof(glyphs), paint, clusters, strlen(text), text);
-    SkClusterator::Cluster expectations[] = {
-        {&text[3], 1, 0, 1},
-        {&text[2], 1, 1, 2},
-        {&text[1], 1, 3, 1},
-        {&text[0], 1, 4, 1},
-        {&text[4], 1, 5, 2},
-        {&text[7], 1, 7, 1},
-        {&text[6], 1, 8, 2},
-        {&text[5], 1, 10, 1},
-        {nullptr, 0, 0, 0},
-    };
-    for (const auto& expectation : expectations) {
-        auto c = clusterator.next();
-        REPORTER_ASSERT(reporter, c.fUtf8Text       == expectation.fUtf8Text);
-        REPORTER_ASSERT(reporter, c.fTextByteLength == expectation.fTextByteLength);
-        REPORTER_ASSERT(reporter, c.fGlyphIndex     == expectation.fGlyphIndex);
-        REPORTER_ASSERT(reporter, c.fGlyphCount     == expectation.fGlyphCount);
+    {
+        const uint32_t clusters[11] = { 3, 2, 2, 1, 0, 4, 4, 7, 6, 6, 5 };
+        const SkGlyphID glyphs[11] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
+        const char text[] = "abcdefgh";
+        SkClusterator clusterator(glyphs, sizeof(glyphs), paint, clusters, strlen(text), text);
+        SkClusterator::Cluster expectations[] = {
+            {&text[3], 1, 0, 1},
+            {&text[2], 1, 1, 2},
+            {&text[1], 1, 3, 1},
+            {&text[0], 1, 4, 1},
+            {&text[4], 1, 5, 2},
+            {&text[7], 1, 7, 1},
+            {&text[6], 1, 8, 2},
+            {&text[5], 1, 10, 1},
+            {nullptr, 0, 0, 0},
+        };
+        for (const auto& expectation : expectations) {
+            REPORTER_ASSERT(reporter, clusterator.next() == expectation);
+        }
+    }
+    {
+        const uint32_t clusters[5] = { 0, 1, 4, 5, 6 };
+        const SkGlyphID glyphs[5] = { 43, 167, 79, 79, 82, };
+        const char text[] = "Ha\xCC\x8A" "llo";
+        SkClusterator clusterator(glyphs, sizeof(glyphs), paint, clusters, strlen(text), text);
+        SkClusterator::Cluster expectations[] = {
+            {&text[0], 1, 0, 1},
+            {&text[1], 3, 1, 1},
+            {&text[4], 1, 2, 1},
+            {&text[5], 1, 3, 1},
+            {&text[6], 1, 4, 1},
+            {nullptr, 0, 0, 0},
+        };
+        for (const auto& expectation : expectations) {
+            REPORTER_ASSERT(reporter, clusterator.next() == expectation);
+        }
     }
 }