Skip to content
Merged
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
2 changes: 1 addition & 1 deletion core/string/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ impl JsString {
// We check the size, so this should never panic.
#[allow(clippy::missing_panics_doc)]
pub fn ends_with(&self, needle: JsStr<'_>) -> bool {
self.as_str().starts_with(needle)
self.as_str().ends_with(needle)
}

/// Get the `u16` code unit at index. This does not parse any characters if there
Expand Down
12 changes: 12 additions & 0 deletions core/string/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,3 +553,15 @@ fn trim() {
let base_str = JsString::from(" \u{000B} Hello World \t ");
assert_eq!(base_str.trim(), JsString::from("Hello World"));
}

#[test]
fn starts_with_and_ends_with_basic() {
let basic = JsString::from("abcdef");
let start_needle = JsStr::latin1("abc".as_bytes());
assert!(basic.starts_with(start_needle));
assert!(!basic.ends_with(start_needle));

let end_needle = JsStr::latin1("def".as_bytes());
assert!(!basic.starts_with(end_needle));
assert!(basic.ends_with(end_needle));
}
Loading