diff options
author | 2021-10-21 04:30:44 -0700 | |
---|---|---|
committer | 2021-10-21 04:30:44 -0700 | |
commit | f394581ed8e287181d632c0bfefe443c38a3919e (patch) | |
tree | b42ee2a23ce44501c2a1066497f7e229b103ed8c | |
parent | 33b0c89e7c00d3b105876071dd8c10df95d8107c (diff) | |
download | bun-f394581ed8e287181d632c0bfefe443c38a3919e.tar.gz bun-f394581ed8e287181d632c0bfefe443c38a3919e.tar.zst bun-f394581ed8e287181d632c0bfefe443c38a3919e.zip |
Add test for non-ascii latin1 characters in strings
-rw-r--r-- | integration/snippets/latin1-chars-in-regexp.js | 46 |
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); +} |