Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/assertions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
#![allow(clippy::wrong_self_convention, clippy::return_self_not_must_use)]

use crate::spec::{CollectFailures, DebugRepresentation, GetFailures, Represent, Spec};
use crate::std::ops::RangeBounds;
use crate::std::string::String;
use crate::std::{ops::RangeBounds, string::String};

/// Assert whether two values are equal or not.
///
Expand Down
3 changes: 1 addition & 2 deletions src/boolean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use crate::spec::{
DiffFormat, Expectation, Expecting, Expression, FailingStrategy, Invertible, Represent,
Represented, Spec,
};
use crate::std::format;
use crate::std::string::String;
use crate::std::{format, string::String};

impl<D, R> AssertBoolean for Spec<'_, bool, D, R>
where
Expand Down
6 changes: 4 additions & 2 deletions src/char/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ use crate::spec::{
DiffFormat, DisplayRepresentation, Expectation, Expecting, Expression, FailingStrategy,
Invertible, Represent, Spec,
};
use crate::std::format;
use crate::std::string::{String, ToString};
use crate::std::{
format,
string::{String, ToString},
};

impl<D, R> AssertChar for Spec<'_, char, D, R>
where
Expand Down
4 changes: 1 addition & 3 deletions src/char_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ use crate::properties::CharCountProperty;
use crate::spec::{
DiffFormat, Expectation, Expecting, Expression, FailingStrategy, Represent, Represented, Spec,
};
use crate::std::format;
use crate::std::ops::RangeBounds;
use crate::std::string::String;
use crate::std::{format, ops::RangeBounds, string::String};

impl<S, D, R> AssertHasCharCount<usize, D> for Spec<'_, S, D, R>
where
Expand Down
9 changes: 6 additions & 3 deletions src/colored/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,13 @@ pub use with_colored_feature::{
};

use crate::spec::{DiffFormat, DisplayRepresentation, Highlight, Represent, Represented};
use crate::std::format;
use crate::std::string::{String, ToString};
use crate::std::vec::Vec;
use crate::std::{
format,
string::{String, ToString},
vec::Vec,
};
use hashbrown::HashSet;

#[cfg(feature = "colored")]
use with_colored_feature::{
configured_diff_format_impl, mark_diff_impl, mark_missing_impl, mark_unexpected_impl,
Expand Down
22 changes: 12 additions & 10 deletions src/derived_spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,18 @@ use crate::spec::{
Location, PanicOnFail, Represent, Represented, RepresentedAs, RepresentedBy, Satisfies,
SoftPanic, Spec,
};
use crate::std::borrow::{Cow, ToOwned};
use crate::std::boxed::Box;
use crate::std::error::Error;
use crate::std::fmt;
use crate::std::fmt::{Debug, Display};
use crate::std::format;
use crate::std::ops::RangeBounds;
use crate::std::slice;
use crate::std::string::{String, ToString};
use crate::std::vec::Vec;
use crate::std::{
borrow::{Cow, ToOwned},
boxed::Box,
error::Error,
fmt,
fmt::{Debug, Display},
format,
ops::RangeBounds,
slice,
string::{String, ToString},
vec::Vec,
};
use hashbrown::HashSet;

/// A `DerivedSpec` does assertions on a derived subject while keeping track
Expand Down
25 changes: 16 additions & 9 deletions src/derived_spec/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::prelude::*;
use crate::std::string::{String, ToString};
use crate::std::vec;
use crate::std::vec::Vec;
use crate::std::{
string::{String, ToString},
vec,
vec::Vec,
};
#[cfg(feature = "bigdecimal")]
use bigdecimal::BigDecimal;
#[cfg(feature = "float-cmp")]
Expand Down Expand Up @@ -939,6 +941,8 @@ fn extracting_ref_vec_contains_all_in_order() {

mod iterator_all_elements {
use super::*;
#[cfg(feature = "std")]
use crate::assert_panic_message;

#[derive(Debug, Clone)]
struct Person {
Expand Down Expand Up @@ -988,16 +992,19 @@ mod iterator_all_elements {
});
}

#[cfg(feature = "std")]
#[test]
#[should_panic = "expected numbers.val[1] to be not equal to 4\n but was: 4\n expected: not 4\n"]
fn assert_each_element_of_an_iterator_panics_if_one_assertion_fails() {
let subject = Numbers(vec![2, 4, 6, 8, 10]);

assert_that(subject)
.named("numbers")
.extracting_ref("val", |numbers| &numbers.0)
.is_not_empty()
.each_element(|e| e.is_not_equal_to(4));
assert_panic_message!(
assert_that(subject)
.named("numbers")
.extracting_ref("val", |numbers| &numbers.0)
.is_not_empty()
.each_element(|e| e.is_not_equal_to(4)),
"expected numbers.val[1] to be not equal to 4\n but was: 4\n expected: not 4\n"
);
}

#[test]
Expand Down
3 changes: 1 addition & 2 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ pub use fake_env::*;

#[cfg(test)]
mod fake_env {
use crate::std::cell::RefCell;
use crate::std::env::VarError;
use crate::std::{cell::RefCell, env::VarError};
use fakeenv::EnvStore;

thread_local! {
Expand Down
8 changes: 5 additions & 3 deletions src/equality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ use crate::spec::{
DiffFormat, Expectation, Expecting, Expression, FailingStrategy, Invertible, Represent,
Represented, Spec,
};
use crate::std::fmt::{Debug, Display};
use crate::std::format;
use crate::std::string::{String, ToString};
use crate::std::{
fmt::{Debug, Display},
format,
string::{String, ToString},
};

impl<S, E, D, R> AssertEquality<E> for Spec<'_, S, D, R>
where
Expand Down
8 changes: 5 additions & 3 deletions src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ use crate::spec::{
DebugRepresentation, DiffFormat, DisplayRepresentation, Expectation, Expecting, Expression,
FailingStrategy, Invertible, Represent, Spec,
};
use crate::std::error::Error;
use crate::std::format;
use crate::std::string::{String, ToString};
use crate::std::{
error::Error,
format,
string::{String, ToString},
};

impl<'a, S, D, R> AssertErrorHasSource for Spec<'a, S, D, R>
where
Expand Down
8 changes: 5 additions & 3 deletions src/error/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::prelude::*;
use crate::std::error::Error;
use crate::std::fmt::{self, Display};
use crate::std::vec::Vec;
use crate::std::{
error::Error,
fmt::{self, Display},
vec::Vec,
};

#[derive(Debug)]
struct SuperError {
Expand Down
3 changes: 1 addition & 2 deletions src/expectations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#![allow(missing_docs)]
#![warn(clippy::return_self_not_must_use)]

use crate::std::marker::PhantomData;
use crate::std::{string::String, vec::Vec};
use crate::std::{marker::PhantomData, string::String, vec::Vec};
use hashbrown::HashSet;
#[cfg(feature = "regex")]
use regex::Regex;
Expand Down
5 changes: 1 addition & 4 deletions src/iterator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ use crate::spec::{
DiffFormat, DisplayRepresentation, Expectation, Expecting, Expression, FailingStrategy,
GetFailures, Invertible, PanicOnFail, Represent, Represented, RepresentedBy, Spec,
};
use crate::std::borrow::ToOwned;
use crate::std::cmp::Ordering;
use crate::std::mem;
use crate::std::{format, string::String, vec, vec::Vec};
use crate::std::{borrow::ToOwned, cmp::Ordering, format, mem, string::String, vec, vec::Vec};
use hashbrown::HashSet;

impl<'a, S, T, E, D, R> AssertIteratorContains<E> for Spec<'a, S, D, R>
Expand Down
18 changes: 11 additions & 7 deletions src/iterator/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#[cfg(feature = "std")]
use crate::assert_panic_message;
use crate::prelude::*;
use crate::std::string::String;
use crate::std::{vec, vec::Vec};
use crate::std::{string::String, vec, vec::Vec};

#[derive(Debug)]
struct CustomCollection<T> {
Expand Down Expand Up @@ -295,15 +296,18 @@ mod all_elements {
.each_element(|person| person.extracting("name", |p| &p.name).starts_with('J'));
}

#[cfg(feature = "std")]
#[test]
#[should_panic = "expected numbers [1] to be not equal to 4\n but was: 4\n expected: not 4\n"]
fn assert_each_element_of_an_iterator_panics_if_one_assertion_fails() {
let subject = [2, 4, 6, 8, 10];

assert_that(subject)
.named("numbers")
.is_not_empty()
.each_element(|e| e.is_not_equal_to(4));
assert_panic_message!(
assert_that(subject)
.named("numbers")
.is_not_empty()
.each_element(|e| e.is_not_equal_to(4)),
"expected numbers [1] to be not equal to 4\n but was: 4\n expected: not 4\n"
);
}

#[test]
Expand Down
3 changes: 1 addition & 2 deletions src/length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ use crate::spec::{
DiffFormat, Expectation, Expecting, Expression, FailingStrategy, Invertible, Represent,
Represented, Spec,
};
use crate::std::ops::RangeBounds;
use crate::std::{format, string::String};
use crate::std::{format, ops::RangeBounds, string::String};

impl<S, D, R> AssertEmptiness for Spec<'_, S, D, R>
where
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,7 @@ pub mod assertions;
pub mod colored;
pub mod derived_spec;
pub mod expectations;
pub mod panic;
pub mod prelude;
pub mod properties;
#[cfg(feature = "recursive")]
Expand Down Expand Up @@ -1147,7 +1148,7 @@ mod order;
#[cfg(feature = "std")]
mod os_sting;
#[cfg(feature = "panic")]
mod panic;
mod panic_assertion;
mod predicate;
mod range;
mod representation;
Expand Down
10 changes: 3 additions & 7 deletions src/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ use crate::spec::{
DiffFormat, Expectation, Expecting, Expression, FailingStrategy, Invertible, Represent,
Represented, Spec,
};
use crate::std::format;
use crate::std::string::String;
use crate::std::vec::Vec;
use crate::std::{format, string::String, vec::Vec};
use hashbrown::HashSet;

impl<S, E, D, R> AssertMapContainsKey<E> for Spec<'_, S, D, R>
Expand Down Expand Up @@ -579,8 +577,7 @@ mod hashbrown_impls {
#[cfg(feature = "std")]
mod std_hashmap_impls {
use crate::properties::MapProperties;
use crate::std::collections::HashMap;
use crate::std::iter::Iterator;
use crate::std::{collections::HashMap, iter::Iterator};

impl<K, V, H> MapProperties for HashMap<K, V, H> {
type Key = K;
Expand Down Expand Up @@ -636,8 +633,7 @@ mod std_hashmap_impls {

mod btree_map_impls {
use crate::properties::MapProperties;
use crate::std::collections::BTreeMap;
use crate::std::iter::Iterator;
use crate::std::{collections::BTreeMap, iter::Iterator};

impl<K, V> MapProperties for BTreeMap<K, V> {
type Key = K;
Expand Down
13 changes: 4 additions & 9 deletions src/map/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
mod hashbrown {
use crate::prelude::*;
use crate::std::format;
use crate::std::vec::Vec;
use crate::std::{format, vec::Vec};
use hashbrown::HashMap;

#[test]
Expand Down Expand Up @@ -402,8 +401,7 @@ mod hashbrown {
#[cfg(feature = "std")]
mod std_hash_map {
use crate::prelude::*;
use crate::std::collections::HashMap;
use crate::std::format;
use crate::std::{collections::HashMap, format};

#[test]
fn hashmap_is_empty() {
Expand Down Expand Up @@ -730,9 +728,7 @@ mod std_hash_map {

mod btree_map {
use crate::prelude::*;
use crate::std::collections::BTreeMap;
use crate::std::format;
use crate::std::vec::Vec;
use crate::std::{collections::BTreeMap, format, vec::Vec};

#[test]
fn btree_map_is_empty() {
Expand Down Expand Up @@ -1055,8 +1051,7 @@ mod btree_map {
#[cfg(feature = "colored")]
mod colored {
use crate::prelude::*;
use crate::std::format;
use crate::std::vec::Vec;
use crate::std::{format, vec::Vec};
use hashbrown::HashMap;

#[test]
Expand Down
8 changes: 5 additions & 3 deletions src/mapping.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::assertions::{AssertDebugString, AssertDisplayString};
use crate::spec::{DebugRepresentation, FailingStrategy, Spec};
use crate::std::fmt::{Debug, Display};
use crate::std::format;
use crate::std::string::{String, ToString};
use crate::std::{
fmt::{Debug, Display},
format,
string::{String, ToString},
};

impl<'a, S, D, R> AssertDebugString for Spec<'a, S, D, R>
where
Expand Down
3 changes: 1 addition & 2 deletions src/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ use crate::spec::{
DiffFormat, DisplayRepresentation, Expectation, Expecting, Expression, FailingStrategy,
Invertible, Represent, Represented, Spec,
};
use crate::std::format;
use crate::std::string::String;
use crate::std::{format, string::String};

impl<S, D, R> AssertSignum for Spec<'_, S, D, R>
where
Expand Down
4 changes: 2 additions & 2 deletions src/option/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ where
let value_representation = self.representation().clone();
self.mapping(|subject| match subject {
None => {
panic!("expected the subject to be `Some(_)`, but was `None`")
crate::panic::trigger_panic("expected the subject to be `Some(_)`, but was `None`")
},
Some(value) => value,
})
Expand All @@ -67,7 +67,7 @@ where
let value_representation = self.representation().clone();
self.mapping(|subject| match subject {
None => {
panic!("expected the subject to be `Some(_)`, but was `None`")
crate::panic::trigger_panic("expected the subject to be `Some(_)`, but was `None`")
},
Some(value) => value,
})
Expand Down
Loading
Loading