Index: test/mjsunit/string-case.js |
diff --git a/test/mjsunit/string-case.js b/test/mjsunit/string-case.js |
index 13dcd3ea815615f6c2591eb9fcbbdf982147f4c9..84992164d82b7738f6822a454b6168f564d18d1a 100644 |
--- a/test/mjsunit/string-case.js |
+++ b/test/mjsunit/string-case.js |
@@ -25,4 +25,56 @@ |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+// Flags: --random-seed=17 |
+ |
assertEquals("ΚΟΣΜΟΣ ΚΟΣΜΟΣ".toLowerCase(), "κοσμος κοσμος"); |
+ |
+var A_CODE = "A".charCodeAt(0); |
+var Z_CODE = "Z".charCodeAt(0); |
+var a_CODE = "a".charCodeAt(0); |
+var z_CODE = "z".charCodeAt(0); |
+ |
+function charCodeToLower(charCode) { |
+ if (A_CODE <= charCode && charCode <= Z_CODE) { |
+ return charCode + a_CODE - A_CODE; |
+ } |
+ return charCode; |
+} |
+ |
+function charCodeToUpper(charCode) { |
+ if (a_CODE <= charCode && charCode <= z_CODE) { |
+ return charCode - (a_CODE - A_CODE); |
+ } |
+ return charCode; |
+} |
+ |
+function generator(i, j) { |
+ return Math.min(0x7f, i + j); |
+} |
+ |
+function randomGenerator(i, j) { |
antonm
2010/10/26 17:17:33
I don't think you have to declare unused arguments
Vitaly Repeshko
2010/10/26 18:14:48
Obsolete.
|
+ return Math.round(0x7f * Math.random()); |
+} |
+ |
+function test(generator, length) { |
+ for (var i = 0; i < 0x7f; i++) { |
+ var str = ""; |
+ var strLower = ""; |
+ var strUpper = ""; |
+ for (var j = 0; j < length; j++) { |
+ var c = generator(i, j); |
+ str += String.fromCharCode(c); |
+ strLower += String.fromCharCode(charCodeToLower(c)); |
+ strUpper += String.fromCharCode(charCodeToUpper(c)); |
+ } |
+ assertEquals(strLower, str.toLowerCase()); |
+ assertEquals(strUpper, str.toUpperCase()); |
+ } |
+} |
+ |
+for (var i = 1; i <= 1024; i <<= 1); { |
+ for (var j = 0; j < 10; j++) { |
+ test(generator, i + j); |
antonm
2010/10/26 17:17:33
I am slightly concerned that string pattern for th
Vitaly Repeshko
2010/10/26 18:14:48
You're right. I dropped the half-baked determinist
|
+ test(randomGenerator, i + j); |
+ } |
+} |