lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject [1/2] lucenenet git commit: different approach to recasing test strings
Date Mon, 29 Dec 2014 10:16:39 GMT
Repository: lucenenet
Updated Branches:
  refs/heads/master 11917175d -> febdd0ff3


different approach to recasing test strings


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/6cfc4fe8
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/6cfc4fe8
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/6cfc4fe8

Branch: refs/heads/master
Commit: 6cfc4fe83ef1a1958e311b34fb86a159782ef2e5
Parents: 1191717
Author: Laimonas Simutis <laimis@gmail.com>
Authored: Sun Dec 28 21:24:12 2014 -0500
Committer: Laimonas Simutis <laimis@gmail.com>
Committed: Sun Dec 28 21:24:12 2014 -0500

----------------------------------------------------------------------
 src/Lucene.Net.TestFramework/Util/TestUtil.cs | 36 ++++++++++++++--------
 1 file changed, 23 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6cfc4fe8/src/Lucene.Net.TestFramework/Util/TestUtil.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Util/TestUtil.cs b/src/Lucene.Net.TestFramework/Util/TestUtil.cs
index 5dadc39..7250cdb 100644
--- a/src/Lucene.Net.TestFramework/Util/TestUtil.cs
+++ b/src/Lucene.Net.TestFramework/Util/TestUtil.cs
@@ -678,15 +678,15 @@ namespace Lucene.Net.Util
                             switch (NextInt(random, 0, 3))
                             {
                                 case 0:
-                                    sb.Append(RandomlyRecaseCodePoints(random, "script"));
+                                    sb.Append(RandomlyRecaseString(random, "script"));
                                     break;
 
                                 case 1:
-                                    sb.Append(RandomlyRecaseCodePoints(random, "style"));
+                                    sb.Append(RandomlyRecaseString(random, "style"));
                                     break;
 
                                 case 2:
-                                    sb.Append(RandomlyRecaseCodePoints(random, "br"));
+                                    sb.Append(RandomlyRecaseString(random, "br"));
                                     break;
                                 // default: append nothing
                             }
@@ -704,26 +704,36 @@ namespace Lucene.Net.Util
         /// <summary>
         /// Randomly upcases, downcases, or leaves intact each code point in the given string
         /// </summary>
-        public static string RandomlyRecaseCodePoints(Random random, string str)
+        public static string RandomlyRecaseString(Random random, string str)
         {
             var builder = new StringBuilder();
             int pos = 0;
             while (pos < str.Length)
             {
-                int codePoint = Character.CodePointAt(str, pos);
-                pos += Character.CharCount(codePoint);
+                string toRecase;
+
+                // check if the next char sequence is a surrogate pair
+                if (pos + 1 < str.Length && char.IsSurrogatePair(str[pos], str[pos+1]))
+                {
+                    toRecase = str.Substring(pos, 2);
+                }
+                else
+                {
+                    toRecase = str.Substring(pos, 1);
+                }
+
+                pos += toRecase.Length;
+
                 switch (NextInt(random, 0, 2))
                 {
                     case 0:
-                        builder.Append(char.ToUpper((char)codePoint));
+                        builder.Append(toRecase.ToUpper());
                         break;
-
                     case 1:
-                        builder.Append(char.ToLower((char)codePoint));
+                        builder.Append(toRecase.ToLower());
                         break;
-
-                    case 2: // leave intact
-                        builder.Append((char)codePoint);
+                    case 2:
+                        builder.Append(toRecase);
                         break;
                 }
             }
@@ -1415,7 +1425,7 @@ namespace Lucene.Net.Util
             if (random.Next(17) == 0)
             {
                 // mix up case
-                string mixedUp = TestUtil.RandomlyRecaseCodePoints(random, sb.ToString());
+                string mixedUp = TestUtil.RandomlyRecaseString(random, sb.ToString());
                 Assert.True(mixedUp.Length == sb.Length, "Lengths are not the same: mixedUp
= " + mixedUp + ", length = " + mixedUp.Length + ", sb = " + sb + ", length = " + sb.Length);
                 return mixedUp;
             }


Mime
View raw message