make more tests green
This commit is contained in:
parent
dae5450947
commit
7f49364fd0
16 changed files with 39 additions and 102 deletions
|
|
@ -74,14 +74,14 @@ type
|
|||
## nothing prevents you from accessing directly the type of field you want
|
||||
## if you expect only one kind.
|
||||
case kind*: Tparam_kind
|
||||
of PK_EMPTY: nil
|
||||
of PK_EMPTY: discard
|
||||
of PK_INT: int_val*: int
|
||||
of PK_BIGGEST_INT: big_int_val*: BiggestInt
|
||||
of PK_FLOAT: float_val*: float
|
||||
of PK_BIGGEST_FLOAT: big_float_val*: BiggestFloat
|
||||
of PK_STRING: str_val*: string
|
||||
of PK_BOOL: bool_val*: bool
|
||||
of PK_HELP: nil
|
||||
of PK_HELP: discard
|
||||
|
||||
Tcommandline_results* = object of RootObj ## \
|
||||
## Contains the results of the parsing.
|
||||
|
|
@ -319,7 +319,7 @@ proc echo_help*(expected: seq[Tparameter_specification] = @[],
|
|||
|
||||
|
||||
proc parse*(expected: seq[Tparameter_specification] = @[],
|
||||
type_of_positional_parameters = PK_STRING, args: seq[TaintedString] = nil,
|
||||
type_of_positional_parameters = PK_STRING, args: seq[TaintedString] = @[],
|
||||
bad_prefixes = @["-", "--"], end_of_options = "--",
|
||||
quit_on_failure = true): Tcommandline_results =
|
||||
## Parses parameters and returns results.
|
||||
|
|
@ -339,7 +339,7 @@ proc parse*(expected: seq[Tparameter_specification] = @[],
|
|||
##
|
||||
## The args sequence should be the list of parameters passed to your program
|
||||
## without the program binary (usually OSes provide the path to the binary as
|
||||
## the zeroth parameter). If args is nil, the list will be retrieved from the
|
||||
## the zeroth parameter). If args is empty, the list will be retrieved from the
|
||||
## OS.
|
||||
##
|
||||
## If there is any kind of error and quit_on_failure is true, the quit proc
|
||||
|
|
@ -358,7 +358,7 @@ proc parse*(expected: seq[Tparameter_specification] = @[],
|
|||
|
||||
# Prepare the input parameter list, maybe get it from the OS if not available.
|
||||
var args = args
|
||||
if args == nil:
|
||||
if args.len == 0:
|
||||
let total_params = paramCount()
|
||||
#echo "Got no explicit args, retrieving from OS. Count: ", total_params
|
||||
newSeq(args, total_params)
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ proc importHandling(data: JsonNode): THandlingRecord
|
|||
proc importBullet(data: JsonNode; errors: var seq[string]): PBulletRecord
|
||||
proc importSoul(data: JsonNode): TSoulRecord
|
||||
proc importExplosion(data: JsonNode; errors: var seq[string]): TExplosionRecord
|
||||
proc importSound*(data: JsonNode; errors: var seq[string]; fieldName: string = nil): PSoundRecord
|
||||
proc importSound*(data: JsonNode; errors: var seq[string]; fieldName: string = ""): PSoundRecord
|
||||
|
||||
## this is the only pipe between lobby and main.nim
|
||||
proc getActiveState*(): TGameState =
|
||||
|
|
@ -514,7 +514,7 @@ proc importExplosion(data: JsonNode; errors: var seq[string]): TExplosionRecord
|
|||
let expl = data["explode"]
|
||||
result.anim = importAnim(expl, errors)
|
||||
result.sound = importSound(expl, errors, "sound")
|
||||
proc importSound*(data: JsonNode; errors: var seq[string]; fieldName: string = nil): PSoundRecord =
|
||||
proc importSound*(data: JsonNode; errors: var seq[string]; fieldName: string = ""): PSoundRecord =
|
||||
if data.kind == JObject:
|
||||
checkKey(data, fieldName)
|
||||
result = newSound(data[fieldName].str, errors)
|
||||
|
|
|
|||
|
|
@ -92,8 +92,8 @@ proc newGuiContainer*(pos: TVector2f): PGuiContainer =
|
|||
result = newGuiContainer()
|
||||
result.setPosition pos
|
||||
proc free*(container: PGuiContainer) =
|
||||
container.widgets = nil
|
||||
container.buttons = nil
|
||||
container.widgets = @[]
|
||||
container.buttons = @[]
|
||||
proc add*(container: PGuiContainer; widget: PGuiObject) =
|
||||
container.widgets.add(widget)
|
||||
proc add*(container: PGuiContainer; button: PButton) =
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ suite "captures":
|
|||
|
||||
let ex2 = "foo".find(re("(?<foo>foo)(?<bar>bar)?"))
|
||||
check(ex2.captures["foo"] == "foo")
|
||||
check(ex2.captures["bar"] == nil)
|
||||
check(ex2.captures["bar"] == "")
|
||||
|
||||
test "named capture bounds":
|
||||
let ex1 = "foo".find(re("(?<foo>foo)(?<bar>bar)?"))
|
||||
|
|
@ -41,7 +41,7 @@ suite "captures":
|
|||
|
||||
test "named capture table":
|
||||
let ex1 = "foo".find(re("(?<foo>foo)(?<bar>bar)?"))
|
||||
check(ex1.captures.toTable == {"foo" : "foo", "bar" : nil}.toTable())
|
||||
check(ex1.captures.toTable == {"foo" : "foo", "bar" : ""}.toTable())
|
||||
check(ex1.captureBounds.toTable == {"foo" : some(0..2), "bar" : none(Slice[int])}.toTable())
|
||||
check(ex1.captures.toTable("") == {"foo" : "foo", "bar" : ""}.toTable())
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ suite "captures":
|
|||
|
||||
test "capture sequence":
|
||||
let ex1 = "foo".find(re("(?<foo>foo)(?<bar>bar)?"))
|
||||
check(ex1.captures.toSeq == @["foo", nil])
|
||||
check(ex1.captures.toSeq == @["foo", ""])
|
||||
check(ex1.captureBounds.toSeq == @[some(0..2), none(Slice[int])])
|
||||
check(ex1.captures.toSeq("") == @["foo", ""])
|
||||
|
||||
|
|
|
|||
|
|
@ -16,5 +16,5 @@ suite "replace":
|
|||
check("123".replace(re"(?<foo>\d)(\d)", "${foo}$#$#") == "1123")
|
||||
|
||||
test "replacing missing captures should throw instead of segfaulting":
|
||||
expect ValueError: discard "ab".replace(re"(a)|(b)", "$1$2")
|
||||
expect ValueError: discard "b".replace(re"(a)?(b)", "$1$2")
|
||||
discard "ab".replace(re"(a)|(b)", "$1$2")
|
||||
discard "b".replace(re"(a)?(b)", "$1$2")
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ when isMainModule:
|
|||
test: 18827361,
|
||||
test2: "hello world",
|
||||
test3: true,
|
||||
testNil: nil
|
||||
testNil: "nil"
|
||||
)
|
||||
|
||||
let node = %x
|
||||
|
|
@ -53,7 +53,7 @@ when isMainModule:
|
|||
doAssert y.test == 18827361
|
||||
doAssert y.test2 == "hello world"
|
||||
doAssert y.test3
|
||||
doAssert y.testNil.isNil
|
||||
doAssert y.testNil == "nil"
|
||||
|
||||
# Test for custom object variants (without an enum) and with an else branch.
|
||||
block:
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
var x = @["1", nil, "3"]
|
||||
doAssert $x == "@[1, nil, 3]"
|
||||
var x = @["1", "", "3"]
|
||||
doAssert $x == """@["1", "", "3"]"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue