Skip to content

Commit e8a8133

Browse files
committed
test(syntax): use regex literal in test files
necessary to pass syntax roundtrip test since printing has changed
1 parent d0c17c3 commit e8a8133

17 files changed

+48
-49
lines changed

jscomp/syntax/tests/idempotency/nook-exchange/App.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ let make = () => {
6464
let url = ReasonReactRouter.useUrl()
6565
let (showLogin, setShowLogin) = React.useState(() => false)
6666
let itemDetails = {
67-
let result = url.hash |> Js.Re.exec_(%re("/i(-?\d+)(:(\d+))?/g"))
67+
let result = url.hash |> Js.Re.exec_(/i(-?\d+)(:(\d+))?/g)
6868
switch result {
6969
| Some(match_) =>
7070
let captures = Js.Re.captures(match_)

jscomp/syntax/tests/idempotency/nook-exchange/Emoji.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module Styles = {
3131
let emoji = style(list{verticalAlign(#bottom), position(relative), top(px(-2))})
3232
}
3333

34-
let emojiRegex = %re(`/(^|\\s)(\\:[a-zA-Z0-9-_+]+\\:)/g`)
34+
let emojiRegex = /(^|\s)(\:[a-zA-Z0-9-_+]+\:)/g
3535

3636
let parseText = (text: string): React.element => {
3737
let children = []

jscomp/syntax/tests/idempotency/nook-exchange/ImportPage.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ let process = value => {
654654
let resultMap = Js.Dict.empty()
655655
let missingQueries = []
656656
rows->Array.forEach(row => {
657-
let result = row |> Js.Re.exec_(%re("/(.*?) \[(.*?)\]$/g"))
657+
let result = row |> Js.Re.exec_(/(.*?) \[(.*?)\]$/g)
658658
let itemWithVariant = switch result {
659659
| Some(match_) =>
660660
let captures = Js.Re.captures(match_)

jscomp/syntax/tests/idempotency/nook-exchange/Item.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ let loadTranslation: (string, Js.Json.t => unit) => unit = %raw(`function(langua
8282

8383
exception UnexpectedType(string)
8484

85-
let spaceRegex = %re("/\\s/g")
85+
let spaceRegex = /\s/g
8686

8787
exception Unexpected
8888
let jsonToItems = (json: Js.Json.t) => {

jscomp/syntax/tests/idempotency/nook-exchange/ItemFilters.res

+5-5
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ let doesItemMatchCategory = (~item: Item.t, ~category: string) =>
206206
}
207207

208208
let removeAccents = str =>
209-
str |> Js.String.normalizeByForm("NFD") |> Js.String.replaceByRe(%re("/[\u0300-\u036f]/g"), "")
209+
str |> Js.String.normalizeByForm("NFD") |> Js.String.replaceByRe(/[\u0300-\u036f]/g, "")
210210

211211
let doesItemMatchFilters = (~item: Item.t, ~filters: t) =>
212212
switch filters.text {
@@ -218,7 +218,7 @@ let doesItemMatchFilters = (~item: Item.t, ~filters: t) =>
218218
| None => false
219219
} || {
220220
let fragments =
221-
(textLower |> Js.String.splitByRe(%re(`/[\\s-]+/`)))->Belt.Array.keepMap(x => x)
221+
(textLower |> Js.String.splitByRe(/[\s-]+/))->Belt.Array.keepMap(x => x)
222222
fragments->Belt.Array.every(fragment =>
223223
Js.String.toLowerCase(Item.getName(item))
224224
|> removeAccents
@@ -253,8 +253,8 @@ let compareArrays = (a, b) => {
253253

254254
let compareItemsABC = (a: Item.t, b: Item.t) => {
255255
// hack to sort "wooden-" before "wooden "
256-
let aName = Item.getName(a) |> Js.String.replaceByRe(%re("/-/g"), " ")
257-
let bName = Item.getName(b) |> Js.String.replaceByRe(%re("/-/g"), " ")
256+
let aName = Item.getName(a) |> Js.String.replaceByRe(/-/g, " ")
257+
let bName = Item.getName(b) |> Js.String.replaceByRe(/-/g, " ")
258258
int_of_float(Js.String.localeCompare(bName, aName))
259259
}
260260
let compareItemsSellPriceDesc = (a: Item.t, b: Item.t) =>
@@ -798,7 +798,7 @@ let make = (
798798
| "Escape" =>
799799
let url = ReasonReactRouter.dangerouslyGetInitialUrl()
800800
// don't trigger if ItemDetailOverlay is shown
801-
if !(url.hash |> Js.Re.test_(%re("/i(-?\d+)(:(\d+))?/g"))) {
801+
if !(url.hash |> Js.Re.test_(/i(-?\d+)(:(\d+))?/g)) {
802802
onChange({...filters, text: ""})
803803
}
804804
| "/" =>

jscomp/syntax/tests/idempotency/nook-exchange/UserStore.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ let toggleCatalogCheckboxSetting = (~enabled) => {
477477
)
478478
}
479479

480-
let errorQuotationMarksRegex = %re(`/^"(.*)"$/`)
480+
let errorQuotationMarksRegex = /^"(.*)"$/
481481
let register = (~username, ~email, ~password) =>
482482
%Repromise.JsExn({
483483
let response = Fetch.fetchWithInit(

jscomp/syntax/tests/idempotency/pupilfirst/questions/QuestionsShow__QuestionEditor.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ module UpdateQuestionError = {
183183
let handleResponseCB = (id, title) => {
184184
let window = Webapi.Dom.window
185185
let parameterizedTitle =
186-
title |> Js.String.toLowerCase |> Js.String.replaceByRe(%re("/[^0-9a-zA-Z]+/gi"), "-")
186+
title |> Js.String.toLowerCase |> Js.String.replaceByRe(/[^0-9a-zA-Z]+/gi, "-")
187187
let redirectPath = "/questions/" ++ (id ++ ("/" ++ parameterizedTitle))
188188
redirectPath |> Webapi.Dom.Window.setLocation(window)
189189
}

jscomp/syntax/tests/idempotency/pupilfirst/schools/CurriculumEditor__ContentBlockCreator.res

+4-4
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,10 @@ let updateEmbedUrl = (send, event) => {
292292
}
293293

294294
let embedUrlRegexes = [
295-
%re("/https:\\/\\/.*slideshare\\.net/"),
296-
%re("/https:\\/\\/.*vimeo\\.com/"),
297-
%re("/https:\\/\\/.*youtube\\.com/"),
298-
%re("/https:\\/\\/.*youtu\\.be/"),
295+
/https:\/\/.*slideshare\.net/,
296+
/https:\/\/.*vimeo\.com/,
297+
/https:\/\/.*youtube\.com/,
298+
/https:\/\/.*youtu\.be/,
299299
]
300300

301301
let validEmbedUrl = url => Belt.Array.some(embedUrlRegexes, regex => regex->Js.Re.test_(url))

jscomp/syntax/tests/idempotency/pupilfirst/schools/SA_Coaches_CoachEditor.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ let updateEmail = (send, email) => send(UpdateEmail(email, email |> emailInvalid
9494
let updateTitle = (send, title) => send(UpdateTitle(title, title |> nameOrTitleInvalid))
9595

9696
let updateLinkedInUrl = (send, linkedinUrl) => {
97-
let regex = %re(`/(https?)?:?(\\/\\/)?(([w]{3}||\\w\\w)\\.)?linkedin.com(\\w+:{0,1}\\w*@)?(\\S+)(:([0-9])+)?(\\/|\\/([\\w#!:.?+=&%@!\\-\\/]))?/`)
97+
let regex = /(https?)?:?(\/\/)?(([w]{3}||\w\w)\.)?linkedin.com(\w+:{0,1}\w*@)?(\S+)(:([0-9])+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
9898
let hasError = linkedinUrl |> String.length < 1 ? false : !Js.Re.test_(regex, linkedinUrl)
9999
send(UpdateLinkedInUrl(linkedinUrl, hasError))
100100
}

jscomp/syntax/tests/idempotency/pupilfirst/schools/StudentsEditor__StudentInfoForm.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ let updateName = (send, name) => {
2929
}
3030

3131
let updateEmail = (send, email) => {
32-
let regex = %re(`/.+@.+\\..+/i`)
32+
let regex = /.+@.+\..+/i
3333
let hasError = !Js.Re.test_(regex, email)
3434
send(UpdateEmail(email, hasError))
3535
}

jscomp/syntax/tests/idempotency/pupilfirst/shared/EmailUtils.res

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
let regularExpression = %re(
2-
"/^(([^<>()\\[\\]\\.,;:\\s@\"]+(\\.[^<>()\\[\\]\\.,;:\\s@\"]+)*)|(\".+\"))@(([^<>()[\\]\\.,;:\\s@\"]+\\.)+[^<>()[\\]\\.,;:\\s@\"]{2,})$/i"
3-
)
1+
let regularExpression =
2+
/^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i
43
54
let isInvalid = (allowBlank, email) =>
65
if email |> String.trim |> String.length > 0 {

jscomp/syntax/tests/idempotency/reasonml.org/common/App.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ module Url = {
7979
}
8080

8181
let isVersion = str =>
82-
Js.String2.match_(str, %re("/latest|v\\d+(\\.\\d+)?(\\.\\d+)?/"))->Belt.Option.isSome
82+
Js.String2.match_(str, /latest|v\d+(\.\d+)?(\.\d+)?/)->Belt.Option.isSome
8383

8484
let parse = (route: string): t => {
8585
let fullpath = {

jscomp/syntax/tests/idempotency/reasonml.org/components/Markdown.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ module A = {
311311
// Ideally one would check if this link is relative first,
312312
// but it's very unlikely we'd refer to an absolute URL ending
313313
// with .md
314-
let regex = %re("/\\.md(x)?|\\.html$/")
314+
let regex = /\.md(x)?|\.html$/
315315
let href = switch Js.String2.split(href, "#") {
316316
| [pathname, anchor] => Js.String2.replaceByRe(pathname, regex, "") ++ ("#" ++ anchor)
317317
| [pathname] => Js.String2.replaceByRe(pathname, regex, "")

jscomp/syntax/tests/idempotency/wildcards-world-ui/Helper.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ let isPositiveStringInteger = str => {
33

44
// NOTE: This allows leading 0s (which seams to not be a problem for web3 or truffle)
55
// This doesn't check if the number is smaller than 2^256 which is the largest integer ethereum can handle
6-
let f = %re("/^([0-9]\d*)$/")
6+
let f = /^([0-9]\d*)$/
77

88
Js.Re.test_(f, str)
99
}

jscomp/test/js_re_test.res

+13-13
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ let suites = {
44
(
55
"captures",
66
_ => {
7-
let re = %re("/(\d+)-(?:(\d+))?/g")
7+
let re = /(\d+)-(?:(\d+))?/g
88
let str = "3-"
99
switch re->Js.Re.exec_(str) {
1010
| Some(result) =>
@@ -35,15 +35,15 @@ let suites = {
3535
(
3636
"exec_literal",
3737
_ =>
38-
switch %re("/[^.]+/")->Js.Re.exec_("http://xxx.domain.com") {
38+
switch /[^.]+/->Js.Re.exec_("http://xxx.domain.com") {
3939
| Some(res) => Eq(Js.Nullable.return("http://xxx"), Js.Re.captures(res)[0])
4040
| None => FailWith("regex should match")
4141
},
4242
),
4343
(
4444
"exec_no_match",
4545
_ =>
46-
switch %re("/https:\/\/(.*)/")->Js.Re.exec_("http://xxx.domain.com") {
46+
switch /https:\/\/(.*)/->Js.Re.exec_("http://xxx.domain.com") {
4747
| Some(_) => FailWith("regex should not match")
4848
| None => Ok(true)
4949
},
@@ -77,20 +77,20 @@ let suites = {
7777
_ => {
7878
let input = "foobar"
7979

80-
switch %re("/foo/g")->Js.Re.exec_(input) {
80+
switch /foo/g->Js.Re.exec_(input) {
8181
| Some(res) => Eq(input, res |> Js.Re.input)
8282
| None => Fail()
8383
}
8484
},
8585
),
8686
/* es2015 */
87-
("t_flags", _ => Eq("gi", %re("/./ig")->Js.Re.flags)),
88-
("t_global", _ => Eq(true, %re("/./ig")->Js.Re.global)),
89-
("t_ignoreCase", _ => Eq(true, %re("/./ig")->Js.Re.ignoreCase)),
87+
("t_flags", _ => Eq("gi", /./ig->Js.Re.flags)),
88+
("t_global", _ => Eq(true, /./ig->Js.Re.global)),
89+
("t_ignoreCase", _ => Eq(true, /./ig->Js.Re.ignoreCase)),
9090
(
9191
"t_lastIndex",
9292
_ => {
93-
let re = %re("/na/g")
93+
let re = /na/g
9494
let _ =
9595
re->Js.Re.exec_(
9696
"banana",
@@ -101,7 +101,7 @@ let suites = {
101101
(
102102
"t_setLastIndex",
103103
_ => {
104-
let re = %re("/na/g")
104+
let re = /na/g
105105

106106
let before = Js.Re.lastIndex(re)
107107
let () = Js.Re.setLastIndex(re, 42)
@@ -110,11 +110,11 @@ let suites = {
110110
Eq((0, 42), (before, after))
111111
},
112112
),
113-
("t_multiline", _ => Eq(false, %re("/./ig")->Js.Re.multiline)),
114-
("t_source", _ => Eq("f.+o", %re("/f.+o/ig")->Js.Re.source)),
113+
("t_multiline", _ => Eq(false, /./ig->Js.Re.multiline)),
114+
("t_source", _ => Eq("f.+o", /f.+o/ig->Js.Re.source)),
115115
/* es2015 */
116-
("t_sticky", _ => Eq(true, %re("/./yg")->Js.Re.sticky)),
117-
("t_unicode", _ => Eq(false, %re("/./yg")->Js.Re.unicode)),
116+
("t_sticky", _ => Eq(true, /./yg->Js.Re.sticky)),
117+
("t_unicode", _ => Eq(false, /./yg->Js.Re.unicode)),
118118
}
119119
}
120120

jscomp/test/js_string_test.res

+11-11
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ let suites = {
2727
("lastIndexOf", _ => Eq(3, "foobarbaz"->Js.String2.lastIndexOf("bar"))),
2828
("lastIndexOfFrom", _ => Eq(3, "foobarbaz"->Js.String2.lastIndexOfFrom("bar", 4))),
2929
("localeCompare", _ => Eq(0., "foo"->Js.String2.localeCompare("foo"))),
30-
("match", _ => Eq(Some([Some("na"), Some("na")]), "banana"->Js.String2.match_(%re("/na+/g")))),
31-
("match - no match", _ => Eq(None, "banana"->Js.String2.match_(%re("/nanana+/g")))),
30+
("match", _ => Eq(Some([Some("na"), Some("na")]), "banana"->Js.String2.match_(/na+/g))),
31+
("match - no match", _ => Eq(None, "banana"->Js.String2.match_(/nanana+/g))),
3232
(
3333
"match - not found capture groups",
3434
_ => Eq(
3535
Some([Some("hello "), None]),
36-
"hello word"->Js.String2.match_(%re("/hello (world)?/"))->Belt.Option.map(Js.Array.copy),
36+
"hello word"->Js.String2.match_(/hello (world)?/)->Belt.Option.map(Js.Array.copy),
3737
),
3838
),
3939
/* es2015 */
@@ -44,7 +44,7 @@ let suites = {
4444
("replace", _ => Eq("fooBORKbaz", "foobarbaz"->Js.String2.replace("bar", "BORK"))),
4545
(
4646
"replaceByRe",
47-
_ => Eq("fooBORKBORK", "foobarbaz"->Js.String2.replaceByRe(%re("/ba./g"), "BORK")),
47+
_ => Eq("fooBORKBORK", "foobarbaz"->Js.String2.replaceByRe(/ba./g, "BORK")),
4848
),
4949
(
5050
"unsafeReplaceBy0",
@@ -56,7 +56,7 @@ let suites = {
5656
"DORK"
5757
}
5858

59-
Eq("fooBORKDORK", "foobarbaz"->Js.String2.unsafeReplaceBy0(%re("/ba./g"), replace))
59+
Eq("fooBORKDORK", "foobarbaz"->Js.String2.unsafeReplaceBy0(/ba./g, replace))
6060
},
6161
),
6262
(
@@ -69,7 +69,7 @@ let suites = {
6969
"DORK"
7070
}
7171

72-
Eq("fooBORKDORK", "foobarbaz"->Js.String2.unsafeReplaceBy1(%re("/ba./g"), replace))
72+
Eq("fooBORKDORK", "foobarbaz"->Js.String2.unsafeReplaceBy1(/ba./g, replace))
7373
},
7474
),
7575
(
@@ -82,7 +82,7 @@ let suites = {
8282
"DORK"
8383
}
8484

85-
Eq("fooBORKDORK", "foobarbaz"->Js.String2.unsafeReplaceBy2(%re("/ba./g"), replace))
85+
Eq("fooBORKDORK", "foobarbaz"->Js.String2.unsafeReplaceBy2(/ba./g, replace))
8686
},
8787
),
8888
(
@@ -95,10 +95,10 @@ let suites = {
9595
"DORK"
9696
}
9797

98-
Eq("fooBORKDORK", "foobarbaz"->Js.String2.unsafeReplaceBy3(%re("/ba./g"), replace))
98+
Eq("fooBORKDORK", "foobarbaz"->Js.String2.unsafeReplaceBy3(/ba./g, replace))
9999
},
100100
),
101-
("search", _ => Eq(3, "foobarbaz"->Js.String2.search(%re("/ba./g")))),
101+
("search", _ => Eq(3, "foobarbaz"->Js.String2.search(/ba./g))),
102102
("slice", _ => Eq("bar", "foobarbaz"->Js.String2.slice(~from=3, ~to_=6))),
103103
("sliceToEnd", _ => Eq("barbaz", "foobarbaz"->Js.String2.sliceToEnd(~from=3))),
104104
("split", _ => Eq(["foo", "bar", "baz"], "foo bar baz"->Js.String2.split(" "))),
@@ -107,14 +107,14 @@ let suites = {
107107
"splitByRe",
108108
_ => Eq(
109109
[Some("a"), Some("#"), None, Some("b"), Some("#"), Some(":"), Some("c")],
110-
"a#b#:c" |> Js.String.splitByRe(%re("/(#)(:)?/")),
110+
"a#b#:c" |> Js.String.splitByRe(/(#)(:)?/),
111111
),
112112
),
113113
(
114114
"splitByReAtMost",
115115
_ => Eq(
116116
[Some("a"), Some("#"), None],
117-
"a#b#:c" |> Js.String.splitByReAtMost(%re("/(#)(:)?/"), ~limit=3),
117+
"a#b#:c" |> Js.String.splitByReAtMost(/(#)(:)?/, ~limit=3),
118118
),
119119
),
120120
/* es2015 */

jscomp/test/test_regex.res

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
let v = %re("/b/ig")
2-
let r = %re("/Bucklescript是一个程序语言/")
1+
let v = /b/ig
2+
let r = /Bucklescript是一个程序语言/
33

44
/* Js.log(v);;
55
Js.log(r);; */

0 commit comments

Comments
 (0)