Skip to content

Commit 7468bfe

Browse files
committed
Support trailing commas in the shorthand element_are! and unordered_elements_are! syntax.
The library consequently supports trailing commas wherever comma-separated items are provided. The shorthand syntax for `elements_are!` and `unordered_elements_are!` did not support this. Thus the following would not compile: ``` verify_that!(vec![1, 2], [eq(1), eq(2),]) verify_that!(vec![1, 2], {eq(1), eq(2),}) ``` This change adds support for trailing commas, making the developer experience more consistent within the library and with the Rust language in general.
1 parent 911fe63 commit 7468bfe

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

googletest/src/assertions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,15 @@
120120
/// not supported; see [Rust by Example](https://doc.rust-lang.org/rust-by-example/primitives/tuples.html#tuples).
121121
#[macro_export]
122122
macro_rules! verify_that {
123-
($actual:expr, [$($expecteds:expr),+]) => {
123+
($actual:expr, [$($expecteds:expr),+ $(,)?]) => {
124124
$crate::assertions::internal::check_matcher(
125125
&$actual,
126126
$crate::elements_are![$($expecteds),+],
127127
stringify!($actual),
128128
$crate::internal::source_location::SourceLocation::new(file!(), line!(), column!()),
129129
)
130130
};
131-
($actual:expr, {$($expecteds:expr),+}) => {
131+
($actual:expr, {$($expecteds:expr),+ $(,)?}) => {
132132
$crate::assertions::internal::check_matcher(
133133
&$actual,
134134
$crate::unordered_elements_are![$($expecteds),+],

integration_tests/src/integration_tests.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ mod tests {
3636
verify_that!(vec![1, 2], {eq(2), eq(1)})
3737
}
3838

39+
#[test]
40+
fn verify_that_with_short_elements_are_syntax_supports_trailing_comma() -> Result<()> {
41+
verify_that!(vec![1, 2], [eq(1), eq(2),])
42+
}
43+
44+
#[test]
45+
fn verify_that_with_short_unordered_elements_are_syntax_supports_trailing_comma() -> Result<()>
46+
{
47+
verify_that!(vec![1, 2], {eq(2), eq(1),})
48+
}
49+
3950
#[test]
4051
fn should_pass_with_assert_that() -> Result<()> {
4152
let value = 2;

0 commit comments

Comments
 (0)