-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add specialized predicates #18
Conversation
I think the main remaining predicates that
After that, I'm going to explore ergonomics
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some things I'd like to see addressed before merging, but this is seriously good stuff.
@@ -0,0 +1,101 @@ | |||
use float_cmp::ApproxEq; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New files need a copyright notice - I recommend the following:
// Copyright (c) 2018 The predicates-rs Project Developers.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
I will also plan to go back and modify the notices that list me as the copyright holder and replace with the statement above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally rely on the project-wide license rather than per file.
If you prefer pre-file, we should make sure to get a CONTRIBUTING that mentions that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The recommendation of the FSF (via the GPLv3) is to include the license statement in all source files, and having dealt with way more FOSS licensing BS than I care to think about, I just feel better having the license in all files to avoid any confusion.
I've opened #22 and #23 to track the other changes needed so the whole project is licensed to the "predicates-rs Project Developers" and to make sure we get a CONTRIBUTING document. For this PR I think just adding the statement above is sufficient.
src/predicate/path/existence.rs
Outdated
|
||
/// Creates a new `Predicate` that ensures the path doesn't exist. | ||
/// | ||
/// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra newline here
src/predicate/path/ft.rs
Outdated
}; | ||
metadata | ||
.map(|m| self.ft.eval(&m.file_type())) | ||
.unwrap_or_default() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be more readable with .unwrap_or(false)
- it took me three clicks to recognize that this is the default -> for type boolean -> which means false because false is the default for boolean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In cases like this, I'm on the fence and I just happened to lean the other way :)
src/predicate/path/ft.rs
Outdated
/// | ||
/// # Examples | ||
/// | ||
/// ```ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since all the tests should be false
, wouldn't it be okay to un-ignore
this doctest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it still has some value even if it isn't actually testing true
for anything.
src/predicate/str/difference.rs
Outdated
/// - `"\n" for line-level. | ||
/// | ||
/// Default: `"\n"` | ||
pub fn split<S>(mut self, split: S) -> Self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of forcing a potential allocation, this could use the copy-on-write Cow
type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm always on the fence on allocation vs indirection (Cow
). I'll go ahead and switch it to Cow
.
src/predicate/str/difference.rs
Outdated
/// let predicate_fn = str::diff("Hello World"); | ||
/// assert_eq!(true, predicate_fn.eval("Hello World")); | ||
/// ``` | ||
pub fn diff<S>(orig: S) -> DifferencePredicate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The behavior of this predicate seems backwards to me based on the name. diff
to me sounds like the predicate should be satisfied (return true) when the strings are different. But the behavior seems to be that the result is true when the strings are similar. Is there a better name that could be used for this - maybe like distance
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this has features for edit-distance, as a user, my real care about is showing the diff between the strings once #7 is available and I was going for a name that communicated that.
I can see how the name implies the opposite meaning. What if instead I reversed the behavior of eval
instead? The downside is that almost everyone will now need to not
it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to create two different predicates that handle the two different cases (looking to see if strings differ, looking to see if strings are the same)? The underlying type could easily be shared between two facades with clear naming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eh, sure. Updated.
src/predicate/str/regex.rs
Outdated
} | ||
} | ||
|
||
/// Creates a new `Predicate` that diffs two strings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should actually be something like "applies a regular expression match to a string"
The |
Just force-pushed a fix for everything except |
This will be more helpful when assert-rs#7 is implemented. Fixes assert-rs#9
This is a short term API. Different issues we'll need to consider when evolving this include: - Easy to create predicate - The ability to customize the regex (e.g. case sensitivity, multi-line, ignoring whityespace). - It looks like the flags can be enabled with `(?flag)` inside the regex. Good enough? - How error handling should work. Re-export? A single error type for the whole crate? This is a part of assert-rs#12
Fixed Can't believe I forgot to |
FYI This should now be ready to go (I would have merged it already but you've set up the repo to require approval from a reviewer and I've wanted to respect that and not just disable it) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found some typos - I'll leave it up to you if you want to fix before merging or just tack them onto a different PR. I don't want to hold you up more than I already have.
src/predicate/float/mod.rs
Outdated
|
||
//! Float Predicates | ||
//! | ||
//! This module contains predicates specifiuc to string handling. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: "specifiuc"
src/predicate/float/close.rs
Outdated
impl IsClosePredicate { | ||
/// Set the amount of error allowed. | ||
/// | ||
/// Values `1`-`5` should work in most cases. Some times more control is needed and you will |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: "Some times" -> "Sometimes"
src/predicate/path/mod.rs
Outdated
|
||
//! Path Predicates | ||
//! | ||
//! This module contains predicates specifiuc to the file system. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: specifiuc
src/predicate/str/mod.rs
Outdated
|
||
//! String Predicates | ||
//! | ||
//! This module contains predicates specifiuc to string handling. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another instance of this specifiuc copy-paste ;-)
Particular notes
eval
that tells me why the predicate failed #7 is implemented. Its still nice to have now to help ensure Aneval
that tells me why the predicate failed #7 supports everything it needs