Skip to content

Commit c4d9f9f

Browse files
Merge pull request #360 from google:coverage
PiperOrigin-RevId: 604258273
2 parents c7d88d1 + e7d2f5d commit c4d9f9f

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Cargo.lock
22
target
3+
coverage

googletest/src/description.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,4 +373,24 @@ mod tests {
373373
)))
374374
)
375375
}
376+
377+
#[test]
378+
fn new_is_empty() -> Result<()> {
379+
verify_that!(Description::new(), predicate(Description::is_empty))
380+
}
381+
382+
#[test]
383+
fn text_is_not_empty() -> Result<()> {
384+
verify_that!(Description::new().text("something"), not(predicate(Description::is_empty)))
385+
}
386+
387+
#[test]
388+
fn new_zero_length() -> Result<()> {
389+
verify_that!(Description::new().len(), eq(0))
390+
}
391+
392+
#[test]
393+
fn text_one_length() -> Result<()> {
394+
verify_that!(Description::new().text("something").len(), eq(1))
395+
}
376396
}

googletest/src/matcher_support/count_elements.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,53 @@ where
3030
}
3131
iterator.count()
3232
}
33+
34+
#[cfg(test)]
35+
mod tests {
36+
37+
use super::*;
38+
use crate::prelude::*;
39+
40+
#[test]
41+
fn count_elements_vec() -> Result<()> {
42+
verify_that!(count_elements(&vec![1, 2, 3]), eq(3))
43+
}
44+
45+
#[test]
46+
fn count_elements_with_unprecised_hint() -> Result<()> {
47+
struct FakeIterator;
48+
49+
impl<'a> Iterator for &'a FakeIterator {
50+
type Item = ();
51+
52+
fn next(&mut self) -> Option<Self::Item> {
53+
None
54+
}
55+
56+
fn size_hint(&self) -> (usize, Option<usize>) {
57+
(0, Some(123))
58+
}
59+
}
60+
61+
verify_that!(count_elements(&FakeIterator), eq(0))
62+
}
63+
64+
#[test]
65+
fn count_elements_with_no_hint() -> Result<()> {
66+
struct FakeIterator;
67+
68+
impl<'a> Iterator for &'a FakeIterator {
69+
type Item = ();
70+
71+
fn next(&mut self) -> Option<Self::Item> {
72+
None
73+
}
74+
75+
fn size_hint(&self) -> (usize, Option<usize>) {
76+
(0, None)
77+
}
78+
}
79+
80+
verify_that!(count_elements(&FakeIterator), eq(0))
81+
}
82+
}

0 commit comments

Comments
 (0)