Skip to content

Commit ff57484

Browse files
committed
strv: fix join to take &self and add test
1 parent ae0da09 commit ff57484

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

glib/src/collections/strv.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ impl StrV {
856856
/// Joins the strings into a longer string, with an optional separator
857857
#[inline]
858858
#[doc(alias = "g_strjoinv")]
859-
pub fn join(self, separator: Option<impl IntoGStr>) -> GString {
859+
pub fn join(&self, separator: Option<impl IntoGStr>) -> GString {
860860
separator.run_with_gstr(|separator| unsafe {
861861
from_glib_full(ffi::g_strjoinv(
862862
separator.to_glib_none().0,
@@ -1488,6 +1488,19 @@ mod test {
14881488
});
14891489
}
14901490

1491+
#[test]
1492+
fn test_join() {
1493+
let items = [
1494+
crate::gstr!("str1"),
1495+
crate::gstr!("str2"),
1496+
crate::gstr!("str3"),
1497+
];
1498+
1499+
let strv = StrV::from(&items[..]);
1500+
assert_eq!(strv.join(None::<&str>), "str1str2str3");
1501+
assert_eq!(strv.join(Some(",")), "str1,str2,str3");
1502+
}
1503+
14911504
#[test]
14921505
fn test_contains() {
14931506
let items = [

0 commit comments

Comments
 (0)