Skip to content

Commit 9f4d4de

Browse files
Ryan Mivillelpil
authored andcommitted
simpler doc and remove redundant test
1 parent 0264946 commit 9f4d4de

File tree

2 files changed

+4
-23
lines changed

2 files changed

+4
-23
lines changed

src/gleam/regexp.gleam

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,20 +220,14 @@ pub fn replace(
220220
) -> String
221221

222222
/// Creates a new `String` by replacing all substrings that match the regular
223-
/// expression.
223+
/// expression with the result of applying the function to each match.
224224
///
225225
/// ## Examples
226226
///
227227
/// ```gleam
228-
/// let assert Ok(re) = regexp.from_string("^[A-Z]|([a-z])([A-Z])")
229-
/// let snake_case = fn(match: Match) {
230-
/// case match.submatches {
231-
/// [Some(lower), Some(upper)] -> lower <> "_" <> string.lowercase(upper)
232-
/// _ -> string.lowercase(match.content)
233-
/// }
234-
/// }
235-
/// regexp.replace_map(each: re, in: "TheQuickBrownFox", with: snake_case)
236-
/// // -> "the_quick_brown_fox"
228+
/// let assert Ok(re) = regexp.from_string("\\w+")
229+
/// regexp.replace_map(re, "hello, joe!", fn(m) { string.capitalise(m.content) })
230+
/// // -> "Hello, Joe!"
237231
/// ```
238232
@external(erlang, "gleam_regexp_ffi", "replace_map")
239233
@external(javascript, "../gleam_regexp_ffi.mjs", "replace_map")

test/gleam_regexp_test.gleam

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import gleam/option.{None, Some}
22
import gleam/regexp.{type Match, Match, Options}
3-
import gleam/string
43
import gleeunit
54
import gleeunit/should
65

@@ -219,15 +218,3 @@ pub fn replace_map_1_test() {
219218
regexp.replace_map(re, "'1', '2', '3', '4'", replace)
220219
|> should.equal("one, two, three, '4'")
221220
}
222-
223-
pub fn replace_map_2_test() {
224-
let assert Ok(re) = regexp.from_string("^[A-Z]|([a-z])([A-Z])")
225-
let replace = fn(match: Match) {
226-
case match.submatches {
227-
[Some(lower), Some(upper)] -> lower <> "_" <> string.lowercase(upper)
228-
_ -> string.lowercase(match.content)
229-
}
230-
}
231-
regexp.replace_map(re, "TheQuickBrownFox", replace)
232-
|> should.equal("the_quick_brown_fox")
233-
}

0 commit comments

Comments
 (0)