Tests for String.setCharAt() breaking string compression.

With string compression, all compressible strings must be
compressed. The internal API String.setCharAt() can break
that invariant when overwriting a non-ASCII character with
an ASCII character, turning an uncompressible string into
a compressible one. It can also truncate a non-ASCII
character written to a compressed string. These regression
tests check the public API that exposes the problem.
Submitting these tests (without a fix) shall prevent us
from enabling string compression before it's ready.

Test: testrunner.py --host -t 021-string2
Test: Manually check that new asserts fail with string compression.
Bug: 31040547
Change-Id: I66f27a73f273f7648acbdf1b601345711f37c85e
diff --git a/test/021-string2/src/Main.java b/test/021-string2/src/Main.java
index 5a43a4f..0dd82ab 100644
--- a/test/021-string2/src/Main.java
+++ b/test/021-string2/src/Main.java
@@ -16,6 +16,7 @@
 
 import junit.framework.Assert;
 import java.lang.reflect.Method;
+import java.util.Locale;
 
 /**
  * more string tests
@@ -120,6 +121,12 @@
 
         testEqualsConstString();
         testConstStringEquals();
+
+        // Regression tests for String.setCharAt() breaking string compression invariants.
+        Locale en_US = new Locale("en", "US");
+        Assert.assertEquals("I", /* Small latin dotless i */ "\u0131".toUpperCase());
+        Assert.assertEquals("abc", "a\u0131c".replace('\u0131', 'b'));
+        Assert.assertEquals("a\u0131c", "abc".replace('b', '\u0131'));
     }
 
     public static void testCompareToAndEquals() {