Skip to content

Commit

Permalink
Move Rejection alongside the types that use it.
Browse files Browse the repository at this point in the history
  • Loading branch information
AltSysrq committed Jan 14, 2018
1 parent cbb3029 commit c81a728
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 65 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

### New Additions

- Added `proptest::strategy::Rejection` which allows you to avoid heap
- Added `proptest::test_runner::Rejection` which allows you to avoid heap
allocation in some places or share allocation with string-interning.

- Added a type alias `proptest::strategy::NewTree<S>` where `S: Strategy`
Expand Down
1 change: 0 additions & 1 deletion src/strategy/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use std::fmt;
use std::sync::Arc;

use strategy::traits::*;
use strategy::rejection::Rejection;
use test_runner::*;

/// `Strategy` and `ValueTree` filter adaptor.
Expand Down
1 change: 0 additions & 1 deletion src/strategy/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use std::sync::Arc;

use strategy::fuse::Fuse;
use strategy::traits::*;
use strategy::Rejection;
use test_runner::*;

/// Adaptor that flattens a `Strategy` which produces other `Strategy`s into a
Expand Down
2 changes: 0 additions & 2 deletions src/strategy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

//! Defines the core traits used by Proptest.

mod rejection;
mod traits;
mod map;
mod filter;
Expand All @@ -19,7 +18,6 @@ mod recursive;
mod shuffle;
mod fuse;

pub use self::rejection::*;
pub use self::traits::*;
pub use self::map::*;
pub use self::filter::*;
Expand Down
57 changes: 0 additions & 57 deletions src/strategy/rejection.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/strategy/statics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
use std::fmt;

use strategy::traits::*;
use strategy::Rejection;
use test_runner::*;

/// Essentially `Fn (&T) -> bool`.
Expand Down
46 changes: 44 additions & 2 deletions src/test_runner.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//-
// Copyright 2017, 2018 Jason Lingle
// Copyright 2017, 2018 The proptest developers
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
Expand All @@ -12,13 +12,14 @@
//! You do not normally need to access things in this module directly except
//! when implementing new low-level strategies.

use std::borrow::Cow;
use std::borrow::{Borrow, Cow};
use std::collections::BTreeMap;
use std::env;
use std::ffi::OsString;
use std::fmt;
use std::fs;
use std::io::{self, BufRead, Write};
use std::ops;
use std::panic::{self, AssertUnwindSafe};
use std::path::{Path, PathBuf};
use std::sync::{Arc, RwLock};
Expand Down Expand Up @@ -284,6 +285,47 @@ impl FailurePersistence {
}
}

/// The reason for why something, such as a generated value, was rejected.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Rejection(Cow<'static, str>);

impl From<&'static str> for Rejection {
fn from(s: &'static str) -> Self {
Rejection(s.into())
}
}

impl From<String> for Rejection {
fn from(s: String) -> Self {
Rejection(s.into())
}
}

impl From<Box<str>> for Rejection {
fn from(s: Box<str>) -> Self {
Rejection(String::from(s).into())
}
}

impl ops::Deref for Rejection {
type Target = str;
fn deref(&self) -> &Self::Target { self.0.deref() }
}

impl AsRef<str> for Rejection {
fn as_ref(&self) -> &str { &*self }
}

impl Borrow<str> for Rejection {
fn borrow(&self) -> &str { &*self }
}

impl fmt::Display for Rejection {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(self.as_ref(), f)
}
}

/// Errors which can be returned from test cases to indicate non-successful
/// completion.
///
Expand Down

0 comments on commit c81a728

Please sign in to comment.