aboutsummaryrefslogtreecommitdiff
path: root/integration/snippets/latin1-chars-in-regexp.js
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-10-25 06:17:16 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-10-25 06:17:16 -0700
commiteae70511116b1b08fa11f77332f8a5aa21f7cd50 (patch)
treea26b5af69e3a3dd418a742cfc608924942cb3e3a /integration/snippets/latin1-chars-in-regexp.js
parentadb6be05d1697d15edcddff6536d6dd6368e131e (diff)
downloadbun-eae70511116b1b08fa11f77332f8a5aa21f7cd50.tar.gz
bun-eae70511116b1b08fa11f77332f8a5aa21f7cd50.tar.zst
bun-eae70511116b1b08fa11f77332f8a5aa21f7cd50.zip
Add snapshots for latin1 regexp, add more codepoints to string escapes
Diffstat (limited to 'integration/snippets/latin1-chars-in-regexp.js')
-rw-r--r--integration/snippets/latin1-chars-in-regexp.js47
1 files changed, 36 insertions, 11 deletions
diff --git a/integration/snippets/latin1-chars-in-regexp.js b/integration/snippets/latin1-chars-in-regexp.js
index 34a6c4a2a..9695b9362 100644
--- a/integration/snippets/latin1-chars-in-regexp.js
+++ b/integration/snippets/latin1-chars-in-regexp.js
@@ -19,26 +19,51 @@ var re_btou = new RegExp(
"g"
);
-const real = [
+const encoder = new TextEncoder();
+const realLines = [
"[\xC0-\xDF][\x80-\xBF]",
"[\xE0-\xEF][\x80-\xBF]{2}",
"[\xF0-\xF7][\x80-\xBF]{3}",
-]
- .flatMap((a) => a.split(""))
- .map((a) => a.codePointAt(0));
+];
+const real = realLines.map((input) => Array.from(encoder.encode(input)));
const expected = [
- 91, 192, 45, 223, 93, 91, 128, 45, 191, 93, 91, 224, 45, 239, 93, 91, 128, 45,
- 191, 93, 123, 50, 125, 91, 240, 45, 247, 93, 91, 128, 45, 191, 93, 123, 51,
- 125,
+ [91, 195, 128, 45, 195, 159, 93, 91, 194, 128, 45, 194, 191, 93],
+ [
+ 91, 195, 160, 45, 195, 175, 93, 91, 194, 128, 45, 194, 191, 93, 123, 50,
+ 125,
+ ],
+ [
+ 91, 195, 176, 45, 195, 183, 93, 91, 194, 128, 45, 194, 191, 93, 123, 51,
+ 125,
+ ],
];
+const newlinePreserved = `\n`;
+
export function test() {
- if (!real.every((point, i) => point === expected[i])) {
+ if (
+ !real.every((point, i) => point.every((val, j) => val === expected[i][j]))
+ ) {
+ throw new Error(
+ `test failed
+${JSON.stringify({ expected, real }, null, 2)}`
+ );
+ }
+
+ if (newlinePreserved.length !== 1 || newlinePreserved.charCodeAt(0) !== 10) {
+ throw new Error("Newline was not preserved");
+ }
+
+ const decoder = new TextDecoder("utf8");
+ if (
+ !realLines.every(
+ (line, i) => decoder.decode(Uint8Array.from(expected[i])) === line
+ )
+ ) {
throw new Error(
- `test failed.\n\nExpected:\n ${expected.join(
- " "
- )}\Received:\n ${real.join(" ")}`
+ `test failed. Lines did not match.
+${JSON.stringify({ expected, real }, null, 2)}`
);
}