diff options
author | inoas <mail@inoas.com> | 2023-05-29 12:34:28 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-29 13:34:28 +0100 |
commit | f8945cba4b9ed2d5490cdf13be1c441fcf81d33f (patch) | |
tree | c1ebe5990396082d6f4621fb2e5a5c78080a7540 /test | |
parent | 940401f74cd2a35f7639ad8116a91d8af06925c0 (diff) | |
download | gleam_stdlib-f8945cba4b9ed2d5490cdf13be1c441fcf81d33f.tar.gz gleam_stdlib-f8945cba4b9ed2d5490cdf13be1c441fcf81d33f.zip |
Fix repeated `regex.check()` calls on the same regex on target javascript (#459)
Diffstat (limited to 'test')
-rw-r--r-- | test/gleam/regex_test.gleam | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/test/gleam/regex_test.gleam b/test/gleam/regex_test.gleam index eb84013..d97c8fa 100644 --- a/test/gleam/regex_test.gleam +++ b/test/gleam/regex_test.gleam @@ -27,7 +27,7 @@ pub fn compile_test() { regex.check(re, "abc\n123") |> should.be_true - // For Erlang: This test will only passes if unicode and ucp flags are set + // On target Erlang this test will only pass if unicode and ucp flags are set let assert Ok(re) = regex.compile("\\s", options) // Em space == U+2003 == " " == used below regex.check(re, " ") @@ -42,6 +42,28 @@ pub fn check_test() { regex.check(re, "boo") |> should.be_false + + re + |> regex.check(content: "foo") + |> should.be_true + + "boo" + |> regex.check(with: re) + |> should.be_false + + // On target JavaScript internal `RegExp` objects are stateful when they + // have the global or sticky flags set (e.g., /foo/g or /foo/y). + // These following tests make sure that our implementation circumvents this. + let assert Ok(re) = regex.from_string("^-*[0-9]+") + + regex.check(re, "1") + |> should.be_true + + regex.check(re, "12") + |> should.be_true + + regex.check(re, "123") + |> should.be_true } pub fn split_test() { |