Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Js.String.match_ return type #5070

Merged
merged 1 commit into from
Apr 18, 2021
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
2 changes: 1 addition & 1 deletion jscomp/others/js_string.ml
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,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