| 1 |
// Test inline lower case conversion of ASCII / Latin-1 strings. |
| 2 |
|
| 3 |
function* characters(...ranges) { |
| 4 |
for (let [start, end] of ranges) { |
| 5 |
for (let i = start; i <= end; ++i) { |
| 6 |
yield i; |
| 7 |
} |
| 8 |
} |
| 9 |
} |
| 10 |
|
| 11 |
const ascii_upper = [...characters( |
| 12 |
[0x41, 0x5A], // A..Z |
| 13 |
[0x30, 0x39], // 0..9 |
| 14 |
)]; |
| 15 |
|
| 16 |
const ascii_lower = [...characters( |
| 17 |
[0x61, 0x7A], // a..z |
| 18 |
[0x30, 0x39], // 0..9 |
| 19 |
)]; |
| 20 |
|
| 21 |
const latin1_upper = [...characters( |
| 22 |
[0xC0, 0xDE], // À..Þ |
| 23 |
[0x30, 0x39], // 0..9 |
| 24 |
)]; |
| 25 |
|
| 26 |
const latin1_lower = [...characters( |
| 27 |
[0xDF, 0xFF], // ß..ÿ |
| 28 |
)]; |
| 29 |
|
| 30 |
for (let upper of [ascii_upper, latin1_upper]) { |
| 31 |
let s = String.fromCodePoint(...upper); |
| 32 |
assertEq(isLatin1(s), true); |
| 33 |
assertEq(s, s.toUpperCase()); |
| 34 |
} |
| 35 |
|
| 36 |
for (let lower of [ascii_lower, latin1_lower]) { |
| 37 |
let s = String.fromCodePoint(...lower); |
| 38 |
assertEq(isLatin1(s), true); |
| 39 |
assertEq(s, s.toLowerCase()); |
| 40 |
} |
| 41 |
|
| 42 |
function toRope(s) { |
| 43 |
try { |
| 44 |
return newRope(s[0], s.substring(1)); |
| 45 |
} catch {} |
| 46 |
// newRope can fail when |s| fits into an inline string. In that case simply |
| 47 |
// return the input. |
| 48 |
return s; |
| 49 |
} |
| 50 |
|
| 51 |
for (let i = 0; i <= 32; ++i) { |
| 52 |
let strings = [ascii_upper, ascii_lower, latin1_upper, latin1_lower].flatMap(codePoints => [ |
| 53 |
String.fromCodePoint(...codePoints.slice(0, i)), |
| 54 |
|
| 55 |
// Trailing ASCII upper case character. |
| 56 |
String.fromCodePoint(...codePoints.slice(0, i)) + "A", |
| 57 |
|
| 58 |
// Trailing ASCII lower case character. |
| 59 |
String.fromCodePoint(...codePoints.slice(0, i)) + "a", |
| 60 |
|
| 61 |
// Trailing Latin-1 upper case character. |
| 62 |
String.fromCodePoint(...codePoints.slice(0, i)) + "À", |
| 63 |
|
| 64 |
// Trailing Latin-1 lower case character. |
| 65 |
String.fromCodePoint(...codePoints.slice(0, i)) + "ß", |
| 66 |
]).flatMap(x => [ |
| 67 |
x, |
| 68 |
toRope(x), |
| 69 |
newString(x, {twoByte: true}), |
| 70 |
]); |
| 71 |
|
| 72 |
const expected = strings.map(x => { |
| 73 |
// Prevent Warp compilation when computing the expected results. |
| 74 |
with ({}) ; |
| 75 |
return x.toLowerCase(); |
| 76 |
}); |
| 77 |
|
| 78 |
for (let i = 0; i < 1000; ++i) { |
| 79 |
let idx = i % strings.length; |
| 80 |
let str = strings[idx]; |
| 81 |
|
| 82 |
let actual = str.toLowerCase(); |
| 83 |
if (actual !== expected[idx]) throw new Error(); |
| 84 |
} |
| 85 |
} |