Skip to content

Commit

Permalink
simpler doc and remove redundant test
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmiville authored and lpil committed Feb 5, 2025
1 parent 0264946 commit 9f4d4de
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 23 deletions.
14 changes: 4 additions & 10 deletions src/gleam/regexp.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -220,20 +220,14 @@ pub fn replace(
) -> String

/// Creates a new `String` by replacing all substrings that match the regular
/// expression.
/// expression with the result of applying the function to each match.
///
/// ## Examples
///
/// ```gleam
/// let assert Ok(re) = regexp.from_string("^[A-Z]|([a-z])([A-Z])")
/// let snake_case = fn(match: Match) {
/// case match.submatches {
/// [Some(lower), Some(upper)] -> lower <> "_" <> string.lowercase(upper)
/// _ -> string.lowercase(match.content)
/// }
/// }
/// regexp.replace_map(each: re, in: "TheQuickBrownFox", with: snake_case)
/// // -> "the_quick_brown_fox"
/// let assert Ok(re) = regexp.from_string("\\w+")
/// regexp.replace_map(re, "hello, joe!", fn(m) { string.capitalise(m.content) })
/// // -> "Hello, Joe!"
/// ```
@external(erlang, "gleam_regexp_ffi", "replace_map")
@external(javascript, "../gleam_regexp_ffi.mjs", "replace_map")
Expand Down
13 changes: 0 additions & 13 deletions test/gleam_regexp_test.gleam
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import gleam/option.{None, Some}
import gleam/regexp.{type Match, Match, Options}
import gleam/string
import gleeunit
import gleeunit/should

Expand Down Expand Up @@ -219,15 +218,3 @@ pub fn replace_map_1_test() {
regexp.replace_map(re, "'1', '2', '3', '4'", replace)
|> should.equal("one, two, three, '4'")
}

pub fn replace_map_2_test() {
let assert Ok(re) = regexp.from_string("^[A-Z]|([a-z])([A-Z])")
let replace = fn(match: Match) {
case match.submatches {
[Some(lower), Some(upper)] -> lower <> "_" <> string.lowercase(upper)
_ -> string.lowercase(match.content)
}
}
regexp.replace_map(re, "TheQuickBrownFox", replace)
|> should.equal("the_quick_brown_fox")
}

0 comments on commit 9f4d4de

Please sign in to comment.