Skip to content

Commit

Permalink
Merge pull request #29 from udoprog/wildcard
Browse files Browse the repository at this point in the history
Parse wildcard as an empty set of predicates
  • Loading branch information
steveklabnik authored Nov 24, 2017
2 parents 240ada6 + 7558089 commit dfe41d5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 60 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "semver-parser"
version = "0.7.0"
version = "0.8.0"
authors = ["Steve Klabnik <steve@steveklabnik.com>"]
license = "MIT/Apache-2.0"
repository = "https://github.com/steveklabnik/semver-parser"
Expand Down
66 changes: 7 additions & 59 deletions src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,23 +131,15 @@ pub struct VersionReq {
///
/// # Examples
///
/// Parsing wildcard predicate and checking that its `op` is `WildcardVersion::Major`:
/// Parsing wildcard predicate and checking that its predicates are empty.
///
/// ```
/// use semver_parser::range;
///
/// # fn try_main() -> Result<(), String> {
/// let r = range::parse("*")?;
///
/// assert_eq!(range::Predicate {
/// op: range::Op::Wildcard(range::WildcardVersion::Major),
/// major: 0,
/// minor: None,
/// patch: None,
/// pre: Vec::new(),
/// },
/// r.predicates[0]
/// );
/// assert!(r.predicates.is_empty());
/// # Ok(())
/// # }
/// #
Expand All @@ -159,8 +151,6 @@ pub struct VersionReq {
/// [`Predicate`]: ./struct.Predicate.html
#[derive(PartialOrd,PartialEq,Debug)]
pub enum WildcardVersion {
/// Wildcard major version `*.2.3`.
Major,
/// Wildcard minor version `1.*.3`.
Minor,
/// Wildcard patch version `1.2.*`.
Expand Down Expand Up @@ -477,13 +467,7 @@ pub fn parse(ranges: &str) -> Result<VersionReq, String> {
|| (ranges == "x")
|| (ranges == "X") {
return Ok(VersionReq {
predicates: vec![Predicate {
op: Op::Wildcard(WildcardVersion::Major),
major: 0,
minor: None,
patch: None,
pre: Vec::new(),
}],
predicates: vec![],
});
}

Expand Down Expand Up @@ -683,61 +667,25 @@ mod tests {
#[test]
fn test_parsing_blank() {
let r = range::parse("").unwrap();

assert_eq!(Predicate {
op: Op::Wildcard(WildcardVersion::Major),
major: 0,
minor: None,
patch: None,
pre: Vec::new(),
},
r.predicates[0]
);
assert!(r.predicates.is_empty());
}

#[test]
fn test_parsing_wildcard() {
let r = range::parse("*").unwrap();

assert_eq!(Predicate {
op: Op::Wildcard(WildcardVersion::Major),
major: 0,
minor: None,
patch: None,
pre: Vec::new(),
},
r.predicates[0]
);
assert!(r.predicates.is_empty());
}

#[test]
fn test_parsing_x() {
let r = range::parse("x").unwrap();

assert_eq!(Predicate {
op: Op::Wildcard(WildcardVersion::Major),
major: 0,
minor: None,
patch: None,
pre: Vec::new(),
},
r.predicates[0]
);
assert!(r.predicates.is_empty());
}

#[test]
fn test_parsing_capital_x() {
let r = range::parse("X").unwrap();

assert_eq!(Predicate {
op: Op::Wildcard(WildcardVersion::Major),
major: 0,
minor: None,
patch: None,
pre: Vec::new(),
},
r.predicates[0]
);
assert!(r.predicates.is_empty());
}

#[test]
Expand Down

0 comments on commit dfe41d5

Please sign in to comment.