Skip to content
Open
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
22 changes: 22 additions & 0 deletions test/gleam/string_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,33 @@ pub fn split_once_empty_test() {
assert string.split_once("", ",") == Error(Nil)
}

// An empty pattern matches the zero-width gap at the start.
pub fn split_once_empty_pattern_test() {
assert string.split_once("Gleam", "") == Ok(#("", "Gleam"))
}

pub fn split_once_empty_pattern_empty_string_test() {
assert string.split_once("", "") == Ok(#("", ""))
}

pub fn replace_test() {
assert string.replace("Gleam,Erlang,Elixir", ",", "++")
== "Gleam++Erlang++Elixir"
}

// An empty pattern matches the gap around every grapheme.
pub fn replace_empty_pattern_test() {
assert string.replace("ab", "", "-") == "-a-b-"
}

pub fn replace_empty_pattern_empty_string_test() {
assert string.replace("", "", "-") == "-"
}

pub fn replace_empty_pattern_grapheme_test() {
assert string.replace("👩‍👩‍👦‍👦x", "", "-") == "-👩‍👩‍👦‍👦-x-"
}

pub fn append_test() {
assert string.append("Test", " Me") == "Test Me"
}
Expand Down
29 changes: 29 additions & 0 deletions test/gleam/string_tree_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,35 @@ pub fn split_multi_string_test() {
]
}

// An empty pattern splits between every grapheme.
pub fn split_empty_pattern_test() {
assert "abc"
|> string_tree.from_string
|> string_tree.split("")
== [
string_tree.from_string("a"),
string_tree.from_string("b"),
string_tree.from_string("c"),
]
}

// An empty pattern substitutes around every grapheme.
pub fn replace_empty_pattern_test() {
assert "ab"
|> string_tree.from_string
|> string_tree.replace(each: "", with: "-")
|> string_tree.to_string
== "-a-b-"
}

pub fn replace_empty_pattern_empty_string_test() {
assert ""
|> string_tree.from_string
|> string_tree.replace(each: "", with: "-")
|> string_tree.to_string
== "-"
}

pub fn is_equal_different_structure_test() {
assert string_tree.is_equal(
string_tree.from_string("12"),
Expand Down
Loading