Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Fable.Transforms/Replacements.Util.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,7 @@ let (|RegexFlags|_|) e =
| 8 -> Some [] // Compiled flag (ignored)
| 16 -> Some [ RegexSingleline ]
| 256 -> Some [] // ECMAScript flag (ignored)
| 1024 -> Some [] // NonBacktracking flag (ignored)
| _ -> None
| Operation(Binary(BinaryOrBitwise, flags1, flags2), _, _, _) ->
match getFlags flags1, getFlags flags2 with
Expand Down
5 changes: 3 additions & 2 deletions src/fable-library-dart/RegExp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ RegExp create(String pattern, [int options = 0]) {
// * Compiled: 0x0008 (ignored)
// * Singleline: 0x0010
// * ECMAScript: 0x0100 (ignored)
if ((options & ~(1 ^ 2 ^ 8 ^ 16 ^ 256)) != 0) {
// * NonBacktracking: 0x0400 (ignored)
if ((options & ~(1 ^ 2 ^ 8 ^ 16 ^ 256 ^ 1024)) != 0) {
throw Exception(
'RegexOptions only supports: IgnoreCase, Multiline, Compiled, Singleline and ECMAScript');
'RegexOptions only supports: IgnoreCase, Multiline, Compiled, Singleline, ECMAScript and NonBacktracking');
}
return RegExp(pattern,
unicode: true,
Expand Down
3 changes: 2 additions & 1 deletion src/fable-library-rust/src/RegExp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ pub mod RegExp_ {
// * Singleline: 0x0010
// * IgnorePatternWhitespace: 0x0020
// * ECMAScript: 0x0100 (ignored)
if ((options & !(1 | 2 | 8 | 16 | 32 | 256)) != 0) {
// * NonBacktracking: 0x0400 (ignored)
if ((options & !(1 | 2 | 8 | 16 | 32 | 256 | 1024)) != 0) {
panic!("Unsupported Regex Option");
}
let regex_ = regex::RegexBuilder::new(pat.as_str())
Expand Down
5 changes: 3 additions & 2 deletions src/fable-library-ts/RegExp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ export function create(pattern: string, options = 0) {
// * Compiled: 0x0008 (ignored)
// * Singleline: 0x0010
// * ECMAScript: 0x0100 (ignored)
if ((options & ~(1 ^ 2 ^ 8 ^ 16 ^ 256)) !== 0) {
throw new Exception("RegexOptions only supports: IgnoreCase, Multiline, Compiled, Singleline and ECMAScript");
// * NonBacktracking: 0x0400 (ignored)
if ((options & ~(1 ^ 2 ^ 8 ^ 16 ^ 256 ^ 1024)) !== 0) {
throw new Exception("RegexOptions only supports: IgnoreCase, Multiline, Compiled, Singleline, ECMAScript and NonBacktracking");
}
// Set always global and unicode flags for compatibility with dotnet, see #2925
let flags = "gu";
Expand Down
8 changes: 8 additions & 0 deletions tests/Beam/RegexTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ let ``test Regex.Unescape works`` () =

// --- Options ---

[<Fact>]
let ``test RegexOptions.NonBacktracking is accepted`` () =
let options = RegexOptions.NonBacktracking ||| RegexOptions.IgnoreCase
let r = Regex("ab", options)
r.IsMatch("xABx") |> equal true
Regex.IsMatch("aaab", "(a+)*b", RegexOptions.NonBacktracking) |> equal true
Regex.Replace("a1b2", "\\d", "-", RegexOptions.NonBacktracking) |> equal "a-b-"

[<Fact>]
let ``test Regex.Options works`` () =
let r = Regex("\\d+", RegexOptions.IgnoreCase ||| RegexOptions.Multiline)
Expand Down
7 changes: 7 additions & 0 deletions tests/Dart/src/RegexTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ let tests() =
let r = Regex("[a-z]", options)
int r.Options |> equal 257

testCase "RegexOptions.NonBacktracking is accepted" <| fun _ ->
let options = RegexOptions.NonBacktracking ||| RegexOptions.IgnoreCase
let r = Regex("ab", options)
r.IsMatch("xABx") |> equal true
Regex.IsMatch("aaab", "(a+)*b", RegexOptions.NonBacktracking) |> equal true
Regex.Replace("a1b2", "\\d", "-", RegexOptions.NonBacktracking) |> equal "a-b-"

testCase "Regex.IsMatch with IgnoreCase and Multiline works" <| fun _ ->
let str = "ab\ncd"
let option1 = RegexOptions.IgnoreCase
Expand Down
7 changes: 7 additions & 0 deletions tests/Js/Main/RegexTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ let tests =
let r = Regex("[a-z]", options)
int r.Options |> equal 257

testCase "RegexOptions.NonBacktracking is accepted" <| fun _ ->
let options = RegexOptions.NonBacktracking ||| RegexOptions.IgnoreCase
let r = Regex("ab", options)
r.IsMatch("xABx") |> equal true
Regex.IsMatch("aaab", "(a+)*b", RegexOptions.NonBacktracking) |> equal true
Regex.Replace("a1b2", "\\d", "-", RegexOptions.NonBacktracking) |> equal "a-b-"

testCase "Regex.IsMatch with IgnoreCase and Multiline works" <| fun _ ->
let str = "ab\ncd"
let option1 = RegexOptions.IgnoreCase
Expand Down
8 changes: 8 additions & 0 deletions tests/Python/TestRegex.fs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ let ``test Literal regex works with whitespace characters`` () = // See #2635
Regex("\\t").IsMatch("foo\tbar") |> equal true
Regex(@"\\t").IsMatch("foo\tbar") |> equal false

[<Fact>]
let ``test RegexOptions.NonBacktracking is accepted`` () =
let options = RegexOptions.NonBacktracking ||| RegexOptions.IgnoreCase
let r = Regex("ab", options)
r.IsMatch("xABx") |> equal true
Regex.IsMatch("aaab", "(a+)*b", RegexOptions.NonBacktracking) |> equal true
Regex.Replace("a1b2", "\\d", "-", RegexOptions.NonBacktracking) |> equal "a-b-"

[<Fact>]
let ``test Regex.Options works`` () =
let option1 = int RegexOptions.IgnoreCase
Expand Down
8 changes: 8 additions & 0 deletions tests/Rust/tests/src/RegexTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ let ``Literal regex works with whitespace characters`` () = // See #2635
Regex("\\t").IsMatch("foo\tbar") |> equal true
Regex(@"\\t").IsMatch("foo\tbar") |> equal false

[<Fact>]
let ``RegexOptions.NonBacktracking is accepted`` () =
let options = RegexOptions.NonBacktracking ||| RegexOptions.IgnoreCase
let r = Regex("ab", options)
r.IsMatch("xABx") |> equal true
Regex.IsMatch("aaab", "(a+)*b", RegexOptions.NonBacktracking) |> equal true
Regex.Replace("a1b2", "\\d", "-", RegexOptions.NonBacktracking) |> equal "a-b-"

[<Fact>]
let ``Regex.Options works`` () =
let option1 = RegexOptions.IgnoreCase
Expand Down
Loading