Skip to content

Commit

Permalink
Merge pull request #5070 from renatoalencar/fix/js_string-match_
Browse files Browse the repository at this point in the history
Fix Js.String.match_ return type
  • Loading branch information
bobzhang authored Apr 18, 2021
2 parents 100da8a + 5ae4b1b commit b525837
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion jscomp/others/js_string.ml
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ external localeCompare : t -> float = "localeCompare" [@@bs.send.pipe: t]
]}
*)
external match_ : Js_re.t -> t array option = "match" [@@bs.send.pipe: t] [@@bs.return {null_to_opt}]
external match_ : Js_re.t -> t option array option = "match" [@@bs.send.pipe: t] [@@bs.return {null_to_opt}]

(** [normalize str] returns the normalized Unicode string using Normalization Form Canonical (NFC) Composition.
Expand Down
2 changes: 1 addition & 1 deletion jscomp/others/js_string2.ml
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ external localeCompare : t -> t -> float = "localeCompare" [@@bs.send]
]}
*)
external match_ : t -> Js_re.t -> t array option = "match" [@@bs.send] [@@bs.return {null_to_opt}]
external match_ : t -> Js_re.t -> t option array option = "match" [@@bs.send] [@@bs.return {null_to_opt}]

(** [normalize str] returns the normalized Unicode string using Normalization Form Canonical (NFC) Composition.
Expand Down
5 changes: 4 additions & 1 deletion jscomp/test/js_string_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,14 @@ let suites = Mt.[
);

"match", (fun _ ->
Eq(Some [| "na"; "na" |], "banana" |. Js.String2.match_ [%re "/na+/g"])
Eq(Some [| Some "na"; Some "na" |], "banana" |. Js.String2.match_ [%re "/na+/g"])
);
"match - no match", (fun _ ->
Eq(None, "banana" |. Js.String2.match_ [%re "/nanana+/g"])
);
"match - not found capture groups", (fun _ ->
Eq(Some [| Some "hello "; None |], "hello word" |. Js.String2.match_ [%re "/hello (world)?/"] |. Belt.Option.map Js.Array.copy )
);

(* es2015 *)
"normalize", (fun _ ->
Expand Down

0 comments on commit b525837

Please sign in to comment.