aboutsummaryrefslogtreecommitdiff
path: root/integration
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-10-21 04:30:44 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-10-21 04:30:44 -0700
commitf394581ed8e287181d632c0bfefe443c38a3919e (patch)
treeb42ee2a23ce44501c2a1066497f7e229b103ed8c /integration
parent33b0c89e7c00d3b105876071dd8c10df95d8107c (diff)
downloadbun-f394581ed8e287181d632c0bfefe443c38a3919e.tar.gz
bun-f394581ed8e287181d632c0bfefe443c38a3919e.tar.zst
bun-f394581ed8e287181d632c0bfefe443c38a3919e.zip
Add test for non-ascii latin1 characters in strings
Diffstat (limited to 'integration')
-rw-r--r--integration/snippets/latin1-chars-in-regexp.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/integration/snippets/latin1-chars-in-regexp.js b/integration/snippets/latin1-chars-in-regexp.js
new file mode 100644
index 000000000..34a6c4a2a
--- /dev/null
+++ b/integration/snippets/latin1-chars-in-regexp.js
@@ -0,0 +1,46 @@
+// original code:
+// var re_btou = new RegExp(
+// [
+// "[\xC0-\xDF][\x80-\xBF]",
+// "[\xE0-\xEF][\x80-\xBF]{2}",
+// "[\xF0-\xF7][\x80-\xBF]{3}",
+// ].join("|"),
+// "g"
+// );
+
+var re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
+var re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
+var re_btou = new RegExp(
+ [
+ "[\xC0-\xDF][\x80-\xBF]",
+ "[\xE0-\xEF][\x80-\xBF]{2}",
+ "[\xF0-\xF7][\x80-\xBF]{3}",
+ ].join("|"),
+ "g"
+);
+
+const real = [
+ "[\xC0-\xDF][\x80-\xBF]",
+ "[\xE0-\xEF][\x80-\xBF]{2}",
+ "[\xF0-\xF7][\x80-\xBF]{3}",
+]
+ .flatMap((a) => a.split(""))
+ .map((a) => a.codePointAt(0));
+
+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,
+];
+
+export function test() {
+ if (!real.every((point, i) => point === expected[i])) {
+ throw new Error(
+ `test failed.\n\nExpected:\n ${expected.join(
+ " "
+ )}\Received:\n ${real.join(" ")}`
+ );
+ }
+
+ testDone(import.meta.url);
+}