use googletest::prelude::*;
use std::fmt::{Display, Write};
fn build_text<T: Display>(mut collection: impl Iterator<Item = T>) -> String {
let mut text = String::new();
write!(&mut text, "{}", collection.next().expect("Provided collection without elements"))
.unwrap();
for item in collection {
write!(&mut text, "\n{}", item).unwrap();
}
text
}
#[test]
fn colors_appear_when_no_color_is_no_set_and_force_color_is_set() -> Result<()> {
std::env::remove_var("NO_COLOR");
std::env::set_var("FORCE_COLOR", "1");
let result = verify_that!(build_text(1..50), eq(&build_text(1..51)));
verify_that!(
result,
err(displays_as(contains_substring(
"
Difference(-\x1B[1;31mactual\x1B[0m / +\x1B[1;32mexpected\x1B[0m):
1
2
\x1B[3m<---- 45 common lines omitted ---->\x1B[0m
48
49
+\x1B[1;32m50\x1B[0m"
)))
)
}