Skip to content

Commit b9b821e

Browse files
JosephTLyonslpil
authored andcommitted
Fix string.drop_end to handle zero gracefully
1 parent 3f3b9d4 commit b9b821e

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/gleam/string.gleam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ pub fn drop_start(from string: String, up_to num_graphemes: Int) -> String {
248248
/// ```
249249
///
250250
pub fn drop_end(from string: String, up_to num_graphemes: Int) -> String {
251-
case num_graphemes < 0 {
251+
case num_graphemes <= 0 {
252252
True -> string
253253
False -> slice(string, 0, length(string) - num_graphemes)
254254
}

test/gleam/string_test.gleam

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ pub fn drop_start_test() {
356356
assert string.drop_start("gleam", up_to: 6) == ""
357357

358358
assert string.drop_start("gleam", up_to: -2) == "gleam"
359+
360+
assert string.drop_start("gleam", up_to: 0) == "gleam"
359361
}
360362

361363
pub fn drop_start_3499_test() {
@@ -369,6 +371,8 @@ pub fn drop_end_test() {
369371
assert string.drop_end("gleam", up_to: 5) == ""
370372

371373
assert string.drop_end("gleam", up_to: -2) == "gleam"
374+
375+
assert string.drop_end("gleam", up_to: 0) == "gleam"
372376
}
373377

374378
pub fn pad_start_test() {

0 commit comments

Comments
 (0)