From f394581ed8e287181d632c0bfefe443c38a3919e Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Thu, 21 Oct 2021 04:30:44 -0700 Subject: Add test for non-ascii latin1 characters in strings --- integration/snippets/latin1-chars-in-regexp.js | 46 ++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 integration/snippets/latin1-chars-in-regexp.js (limited to 'integration/snippets/latin1-chars-in-regexp.js') 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); +} -- cgit v1.2.3