-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add skeleton of expander, with tests
- Loading branch information
1 parent
6d2929a
commit 32ee790
Showing
3 changed files
with
115 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use crate::parser::{ParsedRoute, RoutePart}; | ||
|
||
/// Represents a collection of expanded, simplified routes, derived from an original route. | ||
#[derive(Debug, PartialEq, Eq)] | ||
pub struct ExpandedRoutes { | ||
pub original: ParsedRoute, | ||
pub routes: Vec<ParsedRoute>, | ||
} | ||
|
||
impl ExpandedRoutes { | ||
pub fn new(route: ParsedRoute) -> Self { | ||
let routes = vec![]; | ||
|
||
Self { | ||
original: route, | ||
routes, | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use std::error::Error; | ||
|
||
#[test] | ||
fn test_expand_users_route() -> Result<(), Box<dyn Error>> { | ||
let route = ParsedRoute::new(b"/users/{id?}")?; | ||
let expanded = ExpandedRoutes::new(route.clone()); | ||
|
||
assert_eq!( | ||
expanded, | ||
ExpandedRoutes { | ||
original: route, | ||
routes: vec![ | ||
ParsedRoute::new(b"/users")?, | ||
ParsedRoute::new(b"/users/{id}")?, | ||
] | ||
} | ||
); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn test_expand_release_route() -> Result<(), Box<dyn Error>> { | ||
let route = ParsedRoute::new(b"/release/v{major}.{minor?}.{patch?}")?; | ||
let expanded = ExpandedRoutes::new(route.clone()); | ||
|
||
assert_eq!( | ||
expanded, | ||
ExpandedRoutes { | ||
original: route, | ||
routes: vec![ | ||
ParsedRoute::new(b"/release/v{major}")?, | ||
ParsedRoute::new(b"/release/v{major}.{minor}")?, | ||
ParsedRoute::new(b"/release/v{major}.{minor}.{patch}")?, | ||
] | ||
} | ||
); | ||
|
||
Ok(()) | ||
} | ||
} |
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