diff options
author | 2022-11-21 16:52:00 -0800 | |
---|---|---|
committer | 2022-11-21 16:52:00 -0800 | |
commit | 8e36485a76d0ec3406245287c87df7111afee9bc (patch) | |
tree | 9ec948b465ec37edc326e20757f85ae9bc381e3b /test/bun.js/oniguruma-regexp.test.ts | |
parent | 5f2e74bbccd02ae88fda723e3d4415d480f712c3 (diff) | |
download | bun-8e36485a76d0ec3406245287c87df7111afee9bc.tar.gz bun-8e36485a76d0ec3406245287c87df7111afee9bc.tar.zst bun-8e36485a76d0ec3406245287c87df7111afee9bc.zip |
fix oniguruma regex character properties (#1528)
* fix for character properties
* cleanup tests
* cleanup comments
* i - 2 >= 0
Diffstat (limited to '')
-rw-r--r-- | test/bun.js/oniguruma-regexp.test.ts | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/test/bun.js/oniguruma-regexp.test.ts b/test/bun.js/oniguruma-regexp.test.ts index 9fe3d7be8..30dd6e7d2 100644 --- a/test/bun.js/oniguruma-regexp.test.ts +++ b/test/bun.js/oniguruma-regexp.test.ts @@ -3,6 +3,52 @@ import { OnigurumaRegExp } from "bun"; import { expect, it, test } from "bun:test"; import { gc as gcTrace } from "./gc"; +it("character property scripts", () => { + // oniguruma does not support \p{Script=<script value>} + // they are converted to \p{<script value>} internally + const sentence = "A ticket to 大阪 costs ¥2000 👌."; + + const g0 = OnigurumaRegExp("\\p{Emoji_Presentation}", "gu"); + const s0 = sentence.match(g0); + const g1 = RegExp("\\p{Emoji_Presentation}", "gu"); + const s1 = sentence.match(g1); + for (const [i, s] of s0.entries()) { + expect(s === s1[i]).toBe(true); + } + + const g2 = OnigurumaRegExp("\\P{Script_Extensions=Latin}+", "gu"); + const s2 = sentence.match(g2); + const g3 = RegExp("\\P{Script_Extensions=Latin}+", "gu"); + const s3 = sentence.match(g3); + for (const [i, s] of s2.entries()) { + expect(s === s3[i]).toBe(true); + } + + const g4 = OnigurumaRegExp("\\p{Sc}|\\p{P}", "gu"); + const s4 = sentence.match(g4); + const g5 = RegExp("\\p{Sc}|\\p{P}", "gu"); + const s5 = sentence.match(g5); + for (const [i, s] of s4.entries()) { + expect(s === s5[i]).toBe(true); + } + + expect("٢".match(new RegExp("\\p{Script=Thaana}", "u"))).toBe(null); + expect("٢".match(new RegExp("\\p{Script_Extensions=Thaana}", "u"))![0]).toBe( + "٢", + ); + + expect("٢".match(new OnigurumaRegExp("\\p{Thaana}", "u"))).toBe(null); + expect( + "٢".match(new OnigurumaRegExp("\\p{Script_Extensions=Thaana}", "u")), + ).toBe(null); + + let r1 = new OnigurumaRegExp( + "<\\/(?<fullName>(?<name>[-_\\p{Letter}\\p{Number}\\p{script=Deva}\\p{sc=Thai}]{1,32})(?: (?<subcommandOrGroup>[-_\\p{Letter}\\p{Number}\\p{sc=Deva}\\p{sc=Thai}]{1,32}))?(?: (?<subcommand>[-_\\p{Letter}\\p{Number}\\p{sc=Deva}\\p{sc=Thai}]{1,32}))?):(?<id>\\d{17,20})>", + "", + ); + expect(r1 !== null).toBe(true); +}); + it("repeated match and exec calls", () => { for (let i = 0; i < 20000; i++) { let r1 = new OnigurumaRegExp("//.+?/[^?]+", "sg"); |