Skip to content

Commit

Permalink
support for nim 0.15
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunc committed Dec 27, 2016
1 parent ba4c5f5 commit ced60f5
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 20 deletions.
8 changes: 4 additions & 4 deletions cucumber.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ skipDirs = @["tests"]

# Dependencies

requires "nim >= 0.13.0"
requires "nim >= 0.15.0"
requires "nre >= 1.0.0"
requires "commandeer >= 0.9.1 & < 0.10.2"
requires "commandeer >= 0.10.5"
requires "tempfile >= 0.1.4"

task tests, "test cucumber_nim features":
task test, "test cucumber_nim features":
exec "nim c -r --verbosity:0 ./tests/run"
setCommand "nop"
8 changes: 4 additions & 4 deletions cucumber/feature.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import sets
from streams import newFileStream, Stream, readLine
from sequtils import mapIt, apply
from sets import toSet, contains
from strutils import split, strip, repeat, `%`, join, capitalize
from strutils import split, strip, repeat, `%`, join, capitalizeAscii
from nre import re, match, captures, `[]`, replace
import options
import "./types"
Expand Down Expand Up @@ -115,7 +115,7 @@ proc newFeature(name: string): Feature =
scenarios: @[]
)
proc newScenario(feature: Feature, text: string) : Scenario =
let description = text.replace(headRE, "").capitalize
let description = text.replace(headRE, "").capitalizeAscii
result = Scenario(
description: description,
parent: feature,
Expand Down Expand Up @@ -174,7 +174,7 @@ proc newLine(line: string, ltype: LineType, number: int): Line =
content: sline.strip)

proc headKey(line: Line) : string =
return capitalize((line.content.match headRE).get.captures[0])
return capitalizeAscii((line.content.match headRE).get.captures[0])

proc nextLine(stream: var LineStream, skipBlankLines : bool = true) : Line =
var text = ""
Expand Down Expand Up @@ -291,7 +291,7 @@ proc readBody(
feature.comments.add comments

const stepTypes = ["And", "Given", "When", "Then"]
let stepTypeRE = re("($1)" % (stepTypes.mapIt ("(?:^$1)" % it)).join("|"))
let stepTypeRE = re("($1)" % mapIt(stepTypes, ("(?:^$1)" % it)).join("|"))

proc addStep(parent: Scenario, steps: var seq[Step], line: Line) : void =
var text = line.content.strip()
Expand Down
2 changes: 1 addition & 1 deletion cucumber/hook.nim
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ proc `[]`*(
defs.items[hookType]

proc hookTypeFor*(hookTypeName: string) : HookType {.procvar.} =
case hookTypeName.toLower
case hookTypeName.toLowerAscii
of "beforeall": result = htBeforeAll
of "afterall": result = htAfterAll
of "beforefeature": result = htBeforeFeature
Expand Down
2 changes: 1 addition & 1 deletion cucumber/macroutil.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import strutils
import sequtils

proc pubName*(prefix: string, aname: string) : NimNode {.compiletime.} =
let name : string = if prefix == nil: aname else: prefix & capitalize(aname)
let name : string = if prefix == nil: aname else: prefix & capitalizeAscii(aname)
result = postfix(newIdentNode(name), "*")
proc toTypeNode(atype: NimNode, isVar: bool = false): NimNode {.compiletime.} =
result = atype
Expand Down
2 changes: 1 addition & 1 deletion cucumber/main.nim
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ proc buildTagFilter(tagStr: string, op: string = "+"): TagFilter =

let tagStr = tagStr.strip
let match = (tagStr.match tagRE).get
let c = toSeq(match.captures.items)
let c = toSeq(match.captures)
let (neg, tag, nextOp, inner) = (c[0], c[1], c[2], c[3])
result = proc (tags: StringSet): bool =
if tag != nil:
Expand Down
12 changes: 6 additions & 6 deletions cucumber/parameter.nim
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

import tables
import macros
from strutils import capitalize, parseInt, toLower
from strutils import capitalizeAscii, parseInt, toLowerAscii
import macroutil
import "./types"

Expand All @@ -39,7 +39,7 @@ type
ResetContext* = proc(ctype: ContextType) : void

proc contextTypeFor*(cname: string) : ContextType =
case cname.substr().toLower
case cname.substr().toLowerAscii
of "global": result = ctGlobal
of "feature": result = ctFeature
of "scenario": result = ctScenario
Expand All @@ -66,10 +66,10 @@ proc resetList*[T](contextList: var ContextList[T], clear: ContextType) :void =
proc ptName*(name: string, suffix: string) : string {.compiletime.} =
var name = name
if name[0..3] == "seq[" and name[^1] == ']':
name = name[0..2] & capitalize(name[4..^2])
ptPrefix & capitalize(name) & capitalize(suffix)
name = name[0..2] & capitalizeAscii(name[4..^2])
ptPrefix & capitalizeAscii(name) & capitalizeAscii(suffix)
proc cttName(name: string) : string {.compiletime.} =
capitalize(name) & "Context"
capitalizeAscii(name) & "Context"

macro declareTypeName(name: static[string], ptype: untyped) : untyped =
result = newVar(
Expand Down Expand Up @@ -254,7 +254,7 @@ DeclareParamType("string", string, parseString, newStringA, r"(.*)")
proc newFloat(): float = 0
const floatPattern = r"((?:[-+]?[0-9]*\.?[0-9]+(?:[eE][-+]?[0-9]+)?)|(?:[Nn][Aa][Nn])|(?:[Ii][Nn][Ff])|(?:-[Ii][Nn][Ff]))"
proc parseFloat*(s: string) : float =
strutils.parseFloat(strutils.toUpper s)
strutils.parseFloat(strutils.toUpperAscii s)
DeclareParamType("float", float, parseFloat, newFloat, floatPattern)

proc newSeqPT*[T]() : seq[T] = newSeq[T]()
Expand Down
9 changes: 7 additions & 2 deletions cucumber/runner.nim
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ iterator count(a, b: int) : int =
yield i

proc runHooks(
hookType: HookType, tags: StringSet, testNode: TestNode,
hookType: HookType, tags: HashSet[string], testNode: TestNode,
options: CucumberOptions): HookResult =
result = HookResult(value: hrSuccess)
let definitions = hookDefinitions[hookType]
Expand All @@ -318,8 +318,13 @@ proc runHooks(

let hookDef = definitions[ihookDef]
if options.verbosity >= 5:
# ???? sets.items missing/broken ... nim 0.15.2?
#let tagiter = sets.items[string](tags)
var tagseq = newSeq[string]()
for t in tags:
tagseq.add t
echo "Check hook $1($2): {$3}?: $4" % [
$hookType, $ihookDef, toSeq(tags.items).join(","), $hookDef.tagFilter(tags)]
$hookType, $ihookDef, tagseq.join(","), $hookDef.tagFilter(tags)]
if not hookDef.tagFilter(tags):
continue
try:
Expand Down
2 changes: 1 addition & 1 deletion cucumber/step.nim
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ proc `[]`*(
defs.items[stepType]

proc stepTypeFor*(stName: string) : StepType {.procvar.} =
case stName.substr().toLower
case stName.substr().toLowerAscii
of "given": return stGiven
of "when": return stWhen
of "then": return stThen
Expand Down

0 comments on commit ced60f5

Please sign in to comment.