-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
110 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "human_regex" | ||
version = "0.1.0" | ||
version = "0.1.1" | ||
authors = ["Chris McComb <[email protected]>"] | ||
description = "A regex library for humans" | ||
edition = "2021" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,22 @@ | ||
| ⚠️ This package is under active development and doesn't do much yet. | | ||
| -------------------------------------------------------------------------- | | ||
# Regex for Humans | ||
## About | ||
The goal of this crate is simple: give everybody the power of regular expressions without having | ||
to learn the complicated syntax. It is inspired by [ReadableRegex.jl](https://github.com/jkrumbiegel/ReadableRegex.jl). | ||
|
||
## Example usage | ||
### Matching a date | ||
If you want to match a date of the format `2021-10-30`, you would use the following code to generate a regex: | ||
```rust | ||
let hr = human_regex::HumanRegex::new() | ||
.begin() | ||
.exactly(4, human_regex::DIGIT) | ||
.text("-") | ||
.exactly(2, human_regex::DIGIT) | ||
.text("-") | ||
.exactly(2, human_regex::DIGIT) | ||
.end(); | ||
assert!(hr.is_match("2014-01-01")); | ||
``` | ||
Specifically, this chunk of code would yield the regex `^\d{4}-\d{2}-\d{2}$`, which is exactly what we want! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,31 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
|
||
#[test] | ||
fn check_direct_regex() { | ||
let check_match = human_regex::HumanRegex::new(r"^\d{4}-\d{2}-\d{2}$"); | ||
let check_match = human_regex::HumanRegex::from_regex_string(r"^\d{4}-\d{2}-\d{2}$"); | ||
assert!(check_match.is_match("2014-01-01")) | ||
} | ||
#[test] | ||
fn check_default() { | ||
let check_match = human_regex::HumanRegex::default(); | ||
assert!(check_match.is_match("")) | ||
} | ||
#[test] | ||
fn check_new() { | ||
let check_match = human_regex::HumanRegex::new(); | ||
assert!(check_match.is_match("")) | ||
} | ||
#[test] | ||
fn check_exactly_plus_text() { | ||
let check_match = human_regex::HumanRegex::new() | ||
.begin() | ||
.exactly(4, human_regex::DIGIT) | ||
.text("-") | ||
.exactly(2, human_regex::DIGIT) | ||
.text("-") | ||
.exactly(2, human_regex::DIGIT) | ||
.end(); | ||
assert!(check_match.is_match("2014-01-01")) | ||
} | ||
} |