1014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// Copyright 2015 the V8 project authors. All rights reserved.
2014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// Use of this source code is governed by a BSD-style license that can be
3014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// found in the LICENSE file.
4014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
5014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdochfunction Test(lower, upper) {
6014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  var lx = lower + "x";
7014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  var ux = upper + "x";
8014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  var lp = lower + "|";
9014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  var uxp = upper + "x|";
10014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  assertEquals(lx, new RegExp(uxp + lp + lower + "cat", "i").exec(lx) + "");
11014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  assertEquals(ux, new RegExp(uxp + lp + lower + "cat", "i").exec(ux) + "");
12014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  assertEquals(lower, new RegExp(lp + uxp + lower + "cat", "i").exec(lx) + "");
13014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  assertEquals(upper, new RegExp(lp + uxp + lower + "cat", "i").exec(ux) + "");
14014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}
15014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
16014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdochfunction TestFail(lower, upper) {
17014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  var lx = lower + "x";
18014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  var ux = upper + "x";
19014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  var lp = lower + "|";
20014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  var uxp = upper + "x|";
21014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  assertEquals(lower, new RegExp(uxp + lp + lower + "cat", "i").exec(lx) + "");
22014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  assertEquals(ux, new RegExp(uxp + lp + lower + "cat", "i").exec(ux) + "");
23014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  assertEquals(lower, new RegExp(lp + uxp + lower + "cat", "i").exec(lx) + "");
24014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  assertEquals(ux, new RegExp(lp + uxp + lower + "cat", "i").exec(ux) + "");
25014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}
26014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
27014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTest("a", "A");
28014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTest("0", "0");
29014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTestFail("a", "b");
30014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// Small and capital o-umlaut
31014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTest(String.fromCharCode(0xf6), String.fromCharCode(0xd6));
32014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// Small and capital kha.
33014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTest(String.fromCharCode(0x445), String.fromCharCode(0x425));
34014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// Small and capital y-umlaut.
35014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTest(String.fromCharCode(0xff), String.fromCharCode(0x178));
36014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// Small and large Greek mu.
37014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTest(String.fromCharCode(0x3bc), String.fromCharCode(0x39c));
38014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// Micron and large Greek mu.
39014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTest(String.fromCharCode(0xb5), String.fromCharCode(0x39c));
40014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// Micron and small Greek mu.
41014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTest(String.fromCharCode(0xb5), String.fromCharCode(0x3bc));
42014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// German double s and capital S. These are not equivalent since one is double.
43014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTestFail(String.fromCharCode(0xdf), "S");
44014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// Small i and Turkish capital dotted I. These are not equivalent due to
45014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// 21.2.2.8.2 section 3g.  One is below 128 and the other is above 127.
46014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTestFail("i", String.fromCharCode(0x130));
47014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// Small dotless i and I. These are not equivalent either.
48014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTestFail(String.fromCharCode(0x131), "I");
49