Skip to content

Commit

Permalink
apparently we're doing ~= and ^= now (#169)
Browse files Browse the repository at this point in the history
* apparently we're doing ~= and ^= now

* whoops
  • Loading branch information
disruptek authored Jan 19, 2024
1 parent d95fc20 commit b003aee
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/nimph/requirement.nim
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,14 @@ proc newRequirement*(id: string; operator: Operator; spec: string): Requirement

proc newRequirement(id: string; operator: string; spec: string): Requirement =
## parse a requirement with the given operator from a string
var
op = Equal
# using "" to mean "==" was retarded and i refuse to map my Equal
# enum to "" in capitulation; nil carborundum illegitimi
if operator != "":
op = parseEnum[Operator](operator)
let op =
case operator
of "": Equal # nimble wuz here
of "~=": Tilde # nimble wuz here
of "^=": Caret # nimble wuz here
else: parseEnum[Operator](operator)
result = newRequirement(id, op, spec)

iterator orphans*(parent: Requirement): Requirement =
Expand All @@ -201,7 +203,7 @@ proc parseRequires*(input: string): Option[Requires] =
white <- {'\t', ' '}
url <- +Alnum * "://" * +(1 - white - ending - '#')
name <- url | +(Alnum | '_')
ops <- ">=" | "<=" | ">" | "<" | "==" | "~" | "^" | 0
ops <- ">=" | "<=" | ">" | "<" | "==" | "~=" | "~" | "^=" | "^" | 0
dstar <- +Digit | '*'
ver <- (dstar * ('.' * dstar)[0..2]) | "any version"
ending <- (*white * "," * *white) | (*white * "&" * *white) | !1
Expand Down
19 changes: 18 additions & 1 deletion tests/test.nim
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ block:
text9 = "git://github.com/disruptek/bump.git"
text10 = "pigs 2.*"
text11 = "dogs ^3.2"
text15 = "dogs ^=3.2"
text12 = "owls ~4"
text16 = "owls ~= 4"
text13 = "owls any version"
text14 = "owls >=1.0.0 &< 2"
parsed1 = parseRequires(text1)
Expand All @@ -114,6 +116,8 @@ block:
parsed12 = parseRequires(text12)
parsed13 = parseRequires(text13)
parsed14 = parseRequires(text14)
parsed15 = parseRequires(text15)
parsed16 = parseRequires(text16)
check parsed1.isSome
check parsed2.isSome
check parsed3.isSome
Expand All @@ -138,9 +142,22 @@ block:
check req.identity == "pigs"
for req in parsed11.get.values:
check req.identity == "dogs"
for req in parsed15.get.values:
check req.identity == "dogs"
check req.isSatisfiedBy newRelease"3.2.4"
check req.isSatisfiedBy newRelease"3.2.0"
check req.isSatisfiedBy newRelease"3.3.0"
check not req.isSatisfiedBy newRelease"3.1.0"
check not req.isSatisfiedBy newRelease"3.1.9"
check not req.isSatisfiedBy newRelease"4.0.0"
for req in parsed12.get.values:
check req.identity == "owls"
check not req.isSatisfiedBy newRelease"1.8.8"
for req in parsed16.get.values:
check req.identity == "owls"
check req.isSatisfiedBy newRelease"4.0.0"
check req.isSatisfiedBy newRelease"4.2.0"
check not req.isSatisfiedBy newRelease"5.0.0"
check not req.isSatisfiedBy newRelease"3.9.0"
for req in parsed13.get.values:
check $req.release == anyRelease
check req.isSatisfiedBy newRelease"1.8.8"
Expand Down

0 comments on commit b003aee

Please sign in to comment.