From b003aee14833000ffe90e751cd869eb3e3b5eafa Mon Sep 17 00:00:00 2001 From: Smooth Operator Date: Thu, 18 Jan 2024 21:32:59 -0500 Subject: [PATCH] apparently we're doing ~= and ^= now (#169) * apparently we're doing ~= and ^= now * whoops --- src/nimph/requirement.nim | 12 +++++++----- tests/test.nim | 19 ++++++++++++++++++- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/nimph/requirement.nim b/src/nimph/requirement.nim index 65da6ff..e26528a 100644 --- a/src/nimph/requirement.nim +++ b/src/nimph/requirement.nim @@ -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 = @@ -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 diff --git a/tests/test.nim b/tests/test.nim index 503e0be..5c058fa 100644 --- a/tests/test.nim +++ b/tests/test.nim @@ -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) @@ -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 @@ -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"