use crate Respond;
use crate::;
use ;
use ;
/// Anything that implements `Match` can be used to constrain when a [`Mock`] is activated.
///
/// `Match` can be used to extend the set of matchers provided out-of-the-box by `wiremock` to
/// cater to your specific testing needs:
/// ```rust
/// use wiremock::{Match, MockServer, Mock, Request, ResponseTemplate};
/// use wiremock::matchers::HeaderExactMatcher;
/// use std::convert::TryInto;
///
/// // Check that a header with the specified name exists and its value has an odd length.
/// pub struct OddHeaderMatcher(http_types::headers::HeaderName);
///
/// impl Match for OddHeaderMatcher {
/// fn matches(&self, request: &Request) -> bool {
/// match request.headers.get(&self.0) {
/// // We are ignoring multi-valued headers for simplicity
/// Some(values) => values[0].as_str().len() % 2 == 1,
/// None => false
/// }
/// }
/// }
///
/// #[async_std::main]
/// async fn main() {
/// // Arrange
/// let mock_server = MockServer::start().await;
///
/// Mock::given(OddHeaderMatcher("custom".try_into().unwrap()))
/// .respond_with(ResponseTemplate::new(200))
/// .mount(&mock_server)
/// .await;
///
/// // Even length
/// let status = surf::get(&mock_server.uri())
/// .header("custom", "even")
/// .await
/// .unwrap()
/// .status();
/// assert_eq!(status, 404);
///
/// // Odd length
/// let status = surf::get(&mock_server.uri())
/// .header("custom", "odd")
/// .await
/// .unwrap()
/// .status();
/// assert_eq!(status, 200);
/// }
/// ```
///
/// Anonymous functions that take a reference to a [`Request`] as input and return a boolean
/// as output automatically implement the `Match` trait.
///
/// The previous example could be rewritten as follows:
/// ```rust
/// use wiremock::{Match, MockServer, Mock, Request, ResponseTemplate};
/// use wiremock::matchers::HeaderExactMatcher;
/// use std::convert::TryInto;
///
/// #[async_std::main]
/// async fn main() {
/// // Arrange
/// let mock_server = MockServer::start().await;
///
/// let header_name: http_types::headers::HeaderName = "custom".try_into().unwrap();
/// // Check that a header with the specified name exists and its value has an odd length.
/// let matcher = move |request: &Request| {
/// match request.headers.get(&header_name) {
/// Some(values) => values[0].as_str().len() % 2 == 1,
/// None => false
/// }
/// };
///
/// Mock::given(matcher)
/// .respond_with(ResponseTemplate::new(200))
/// .mount(&mock_server)
/// .await;
///
/// // Even length
/// let status = surf::get(&mock_server.uri())
/// .header("custom", "even")
/// .await
/// .unwrap()
/// .status();
/// assert_eq!(status, 404);
///
/// // Odd length
/// let status = surf::get(&mock_server.uri())
/// .header("custom", "odd")
/// .await
/// .unwrap()
/// .status();
/// assert_eq!(status, 200);
/// }
/// ```
/// Wrapper around a `Match` trait object.
///
/// We need the wrapper to provide a (fake) implementation of `Debug`,
/// thus allowing us to pass this struct around as a `bastion` message.
/// This is because Rust's closures do not implement `Debug`.
///
/// We wouldn't need this if `bastion` didn't require `Debug` as a trait bound for its Message trait
/// or if Rust automatically implemented `Debug` for closures.
pub ;
/// Given a set of matchers, a `Mock` instructs an instance of [`MockServer`] to return a pre-determined response if the matching conditions are satisfied.
///
/// `Mock`s have to be mounted (or registered) with a [`MockServer`] to become effective.
/// You can use:
///
/// - [`MockServer::register`] or [`Mock::mount`] to activate a **global** `Mock`;
/// - [`MockServer::register_as_scoped`] or [`Mock::mount_as_scoped`] to activate a **scoped** `Mock`.
///
/// Check the respective documentations for more details (or look at the following examples!).
///
/// # Example (using [`register`]):
///
/// ```rust
/// use wiremock::{MockServer, Mock, ResponseTemplate};
/// use wiremock::matchers::method;
///
/// #[async_std::main]
/// async fn main() {
/// // Arrange
/// let mock_server = MockServer::start().await;
///
/// let response = ResponseTemplate::new(200);
///
/// let mock = Mock::given(method("GET")).respond_with(response.clone());
/// // Registering the mock with the mock server - it's now effective!
/// mock_server.register(mock).await;
///
/// // We won't register this mock instead.
/// let unregistered_mock = Mock::given(method("GET")).respond_with(response);
///
/// // Act
/// let status = surf::get(&mock_server.uri())
/// .await
/// .unwrap()
/// .status();
/// assert_eq!(status, 200);
///
/// // This would have matched `unregistered_mock`, but we haven't registered it!
/// // Hence it returns a 404, the default response when no mocks matched on the mock server.
/// let status = surf::post(&mock_server.uri())
/// .await
/// .unwrap()
/// .status();
/// assert_eq!(status, 404);
/// }
/// ```
///
/// # Example (using [`mount`]):
///
/// If you prefer a fluent style, you can use the [`mount`] method on the `Mock` itself
/// instead of [`register`].
/// ```rust
/// use wiremock::{MockServer, Mock, ResponseTemplate};
/// use wiremock::matchers::method;
///
/// #[async_std::main]
/// async fn main() {
/// // Arrange
/// let mock_server = MockServer::start().await;
///
/// Mock::given(method("GET"))
/// .respond_with(ResponseTemplate::new(200))
/// .up_to_n_times(1)
/// // Mounting the mock on the mock server - it's now effective!
/// .mount(&mock_server)
/// .await;
///
/// // Act
/// let status = surf::get(&mock_server.uri())
/// .await
/// .unwrap()
/// .status();
/// assert_eq!(status, 200);
/// }
/// ```
///
/// # Example (using [`mount_as_scoped`]):
///
/// Sometimes you will need a `Mock` to be active within the scope of a function, but not any longer.
/// You can use [`Mock::mount_as_scoped`] to precisely control how long a `Mock` stays active.
///
/// ```rust
/// use wiremock::{MockServer, Mock, ResponseTemplate};
/// use wiremock::matchers::method;
///
/// async fn my_test_helper(mock_server: &MockServer) {
/// let mock_guard = Mock::given(method("GET"))
/// .respond_with(ResponseTemplate::new(200))
/// .expect(1)
/// .named("my_test_helper GET /")
/// .mount_as_scoped(mock_server)
/// .await;
///
/// surf::get(&mock_server.uri())
/// .await
/// .unwrap();
///
/// // `mock_guard` is dropped, expectations are verified!
/// }
///
/// #[async_std::main]
/// async fn main() {
/// // Arrange
/// let mock_server = MockServer::start().await;
/// my_test_helper(&mock_server).await;
///
/// // Act
///
/// // This would have returned 200 if the `Mock` in
/// // `my_test_helper` had not been scoped.
/// let status = surf::get(&mock_server.uri())
/// .await
/// .unwrap()
/// .status();
/// assert_eq!(status, 404);
/// }
/// ```
///
/// [`register`]: MockServer::register
/// [`mount`]: Mock::mount
/// [`mount_as_scoped`]: Mock::mount_as_scoped
/// A fluent builder to construct a [`Mock`] instance given matchers and a [`ResponseTemplate`].
/// Specify how many times we expect a [`Mock`] to match via [`expect`].
/// It is used to set expectations on the usage of a [`Mock`] in a test case.
///
/// You can either specify an exact value, e.g.
/// ```rust
/// use wiremock::Times;
///
/// let times: Times = 10.into();
/// ```
/// or a range
/// ```rust
/// use wiremock::Times;
///
/// // Between 10 and 15 (not included) times
/// let times: Times = (10..15).into();
/// // Between 10 and 15 (included) times
/// let times: Times = (10..=15).into();
/// // At least 10 times
/// let times: Times = (10..).into();
/// // Strictly less than 15 times
/// let times: Times = (..15).into();
/// // Strictly less than 16 times
/// let times: Times = (..=15).into();
/// ```
///
/// [`expect`]: Mock::expect
;
// Implementation notes: this has gone through a couple of iterations before landing to
// what you see now.
//
// The original draft had Times itself as an enum with two variants (Exact and Range), with
// the Range variant generic over `R: RangeBounds<u64>`.
//
// We switched to a generic struct wrapper around a private `R: RangeBounds<u64>` when we realised
// that you would have had to specify a range type when creating the Exact variant
// (e.g. as you do for `Option` when creating a `None` variant).
//
// We achieved the same functionality with a struct wrapper, but exact values had to converted
// to ranges with a single element (e.g. 15 -> 15..16).
// Not the most expressive representation, but we would have lived with it.
//
// We changed once again when we started to update our `MockActor`: we are storing all `Mock`s
// in a vector. Being generic over `R`, the range type leaked into the overall `Mock` (and `MountedMock`)
// type, thus making those generic as well over `R`.
// To store them in a vector all mocks would have had to use the same range internally, which is
// obviously an unreasonable restrictions.
// At the same time, we can't have a Box<dyn RangeBounds<u64>> because `contains` is a generic
// method hence the requirements for object safety are not satisfied.
//
// Thus we ended up creating this master enum that wraps all range variants with the addition
// of the Exact variant.
// If you can do better, please submit a PR.
// We keep them enum private to the crate to allow for future refactoring.
pub
// A quick macro to help easing the implementation pain.
impl_from_for_range!;
impl_from_for_range!;
impl_from_for_range!;
impl_from_for_range!;
impl_from_for_range!;