Skip to content

Commit

Permalink
Allow trailing comma in format macro + fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
derekdreery committed Jan 7, 2020
1 parent 7824352 commit 1e6a511
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/collections/string.rs
Expand Up @@ -95,7 +95,11 @@ macro_rules! format {
let mut s = $crate::collections::String::new_in(bump);
let _ = write!(&mut s, $fmt, $($args),*);
s
}}
}};

( in $bump:expr, $fmt:expr, $($args:expr,)* ) => {
$crate::format!(in $bump, $fmt, $($args),*)
};
}

/// A UTF-8 encoded, growable string.
Expand Down
9 changes: 8 additions & 1 deletion tests/string.rs
@@ -1,5 +1,5 @@
#![cfg(feature = "collections")]
use bumpalo::{collections::String, Bump};
use bumpalo::{collections::String, format, Bump};
use std::fmt::Write;

#[test]
Expand All @@ -10,3 +10,10 @@ fn format_a_bunch_of_strings() {
write!(&mut s, " {}", i).unwrap();
}
}

#[test]
fn trailing_comma_in_format_macro() {
let b = Bump::new();
let v = format![in &b, "{}{}", 1, 2, ];
assert_eq!(v, "12");
}
7 changes: 2 additions & 5 deletions tests/vec.rs 100755 → 100644
@@ -1,8 +1,5 @@
#![cfg(feature = "collections")]
use bumpalo::{
collections::{vec, Vec},
Bump,
};
use bumpalo::{collections::Vec, vec, Bump};
use std::cell::Cell;

#[test]
Expand All @@ -17,7 +14,7 @@ fn push_a_bunch_of_items() {
#[test]
fn trailing_comma_in_vec_macro() {
let b = Bump::new();
let mut v = vec![in b; 1, 2, 3,];
let v = vec![in &b; 1, 2, 3,];
assert_eq!(v, [1, 2, 3]);
}

Expand Down

0 comments on commit 1e6a511

Please sign in to comment.