mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-09 14:32:53 +00:00
made some tests green
This commit is contained in:
@@ -104,7 +104,7 @@ proc guardGlobal(a: PEffects; n: PNode; guard: PSym) =
|
||||
# (var x{.guard: y.}: int)
|
||||
proc guardDotAccess(a: PEffects; n: PNode) =
|
||||
let ri = n.sons[1]
|
||||
internalAssert ri.kind == nkSym and ri.sym.kind == skField
|
||||
if ri.kind != nkSym or ri.sym.kind != skField: return
|
||||
var g = ri.sym.guard
|
||||
if g.isNil or a.isTopLevel: return
|
||||
# fixup guard:
|
||||
|
||||
@@ -448,7 +448,7 @@ proc semConst(c: PContext, n: PNode): PNode =
|
||||
if typ == nil:
|
||||
localError(a.sons[2].info, errConstExprExpected)
|
||||
continue
|
||||
if not typeAllowed(typ, skConst):
|
||||
if not typeAllowed(typ, skConst) and def.kind != nkNilLit:
|
||||
localError(a.info, errXisNoType, typeToString(typ))
|
||||
continue
|
||||
v.typ = typ
|
||||
|
||||
@@ -1342,6 +1342,9 @@ proc semGenericParamList(c: PContext, n: PNode, father: PType = nil): PNode =
|
||||
if def.typ.kind != tyTypeDesc:
|
||||
typ = newTypeWithSons(c, tyStatic, @[def.typ])
|
||||
else:
|
||||
# the following line fixes ``TV2*[T:SomeNumber=TR] = array[0..1, T]``
|
||||
# from manyloc/named_argument_bug/triengine:
|
||||
def.typ = def.typ.skipTypes({tyTypeDesc})
|
||||
if not containsGenericType(def.typ):
|
||||
def = fitNode(c, typ, def)
|
||||
|
||||
|
||||
@@ -142,9 +142,10 @@ type
|
||||
TSOBool: SOBool, TRecvLineResult: RecvLineResult,
|
||||
TReadLineResult: ReadLineResult, ETimeout: TimeoutError].}
|
||||
|
||||
|
||||
let
|
||||
invalidSocket*: Socket = nil ## invalid socket
|
||||
when defined(booting):
|
||||
let invalidSocket*: Socket = nil ## invalid socket
|
||||
else:
|
||||
const invalidSocket*: Socket = nil ## invalid socket
|
||||
|
||||
when defined(windows):
|
||||
let
|
||||
|
||||
@@ -5,13 +5,13 @@ discard """
|
||||
|
||||
#bug #442
|
||||
import scgi, sockets, asyncio, strtabs
|
||||
proc handleSCGIRequest[TScgi: TScgiState | PAsyncScgiState](s: TScgi) =
|
||||
proc handleSCGIRequest[TScgi: ScgiState | AsyncScgiState](s: TScgi) =
|
||||
discard
|
||||
proc handleSCGIRequest(client: PAsyncSocket, headers: PStringTable,
|
||||
proc handleSCGIRequest(client: AsyncSocket, headers: StringTableRef,
|
||||
input: string) =
|
||||
discard
|
||||
|
||||
proc test(handle: proc (client: PAsyncSocket, headers: PStringTable,
|
||||
proc test(handle: proc (client: AsyncSocket, headers: StringTableRef,
|
||||
input: string), b: int) =
|
||||
discard
|
||||
|
||||
|
||||
@@ -76,14 +76,14 @@ type
|
||||
case kind*: Tparam_kind
|
||||
of PK_EMPTY: nil
|
||||
of PK_INT: int_val*: int
|
||||
of PK_BIGGEST_INT: big_int_val*: biggestInt
|
||||
of PK_BIGGEST_INT: big_int_val*: BiggestInt
|
||||
of PK_FLOAT: float_val*: float
|
||||
of PK_BIGGEST_FLOAT: big_float_val*: biggestFloat
|
||||
of PK_BIGGEST_FLOAT: big_float_val*: BiggestFloat
|
||||
of PK_STRING: str_val*: string
|
||||
of PK_BOOL: bool_val*: bool
|
||||
of PK_HELP: nil
|
||||
|
||||
Tcommandline_results* = object of TObject ## \
|
||||
Tcommandline_results* = object of RootObj ## \
|
||||
## Contains the results of the parsing.
|
||||
##
|
||||
## Usually this is the result of the parse() call, but you can inherit from
|
||||
@@ -97,7 +97,7 @@ type
|
||||
## the first name variant for all options to avoid you repeating the test
|
||||
## with different keys.
|
||||
positional_parameters*: seq[Tparsed_parameter]
|
||||
options*: TOrderedTable[string, Tparsed_parameter]
|
||||
options*: OrderedTable[string, Tparsed_parameter]
|
||||
|
||||
|
||||
# - Tparam_kind procs
|
||||
@@ -193,7 +193,7 @@ template new_parsed_parameter*(tkind: Tparam_kind, expr): Tparsed_parameter =
|
||||
|
||||
proc init*(param: var Tcommandline_results;
|
||||
positional_parameters: seq[Tparsed_parameter] = @[];
|
||||
options: TOrderedTable[string, Tparsed_parameter] =
|
||||
options: OrderedTable[string, Tparsed_parameter] =
|
||||
initOrderedTable[string, Tparsed_parameter](4)) =
|
||||
## Initialization helper with default parameters.
|
||||
param.positional_parameters = positional_parameters
|
||||
@@ -231,12 +231,12 @@ template run_custom_proc(parsed_parameter: Tparsed_parameter,
|
||||
## Pass in the string of the parameter triggering the call. If the
|
||||
if not custom_validator.isNil:
|
||||
except:
|
||||
raise_or_quit(EInvalidValue, ("Couldn't run custom proc for " &
|
||||
raise_or_quit(ValueError, ("Couldn't run custom proc for " &
|
||||
"parameter $1:\n$2" % [escape(parameter),
|
||||
getCurrentExceptionMsg()]))
|
||||
let message = custom_validator(parameter, parsed_parameter)
|
||||
if not message.isNil and message.len > 0:
|
||||
raise_or_quit(EInvalidValue, ("Failed to validate value for " &
|
||||
raise_or_quit(ValueError, ("Failed to validate value for " &
|
||||
"parameter $1:\n$2" % [escape(parameter), message]))
|
||||
|
||||
|
||||
@@ -246,50 +246,50 @@ proc parse_parameter(quit_on_failure: bool, param, value: string,
|
||||
##
|
||||
## Pass the parameter string which requires a value and the text the user
|
||||
## passed in for it. It will be parsed according to the param_kind. This proc
|
||||
## will raise (EInvalidValue, EOverflow) if something can't be parsed.
|
||||
## will raise (ValueError, EOverflow) if something can't be parsed.
|
||||
result.kind = param_kind
|
||||
case param_kind:
|
||||
of PK_INT:
|
||||
try: result.int_val = value.parseInt
|
||||
except EOverflow:
|
||||
raise_or_quit(EOverflow, ("parameter $1 requires an " &
|
||||
except OverflowError:
|
||||
raise_or_quit(OverflowError, ("parameter $1 requires an " &
|
||||
"integer, but $2 is too large to fit into one") % [param,
|
||||
escape(value)])
|
||||
except EInvalidValue:
|
||||
raise_or_quit(EInvalidValue, ("parameter $1 requires an " &
|
||||
except ValueError:
|
||||
raise_or_quit(ValueError, ("parameter $1 requires an " &
|
||||
"integer, but $2 can't be parsed into one") % [param, escape(value)])
|
||||
of PK_STRING:
|
||||
result.str_val = value
|
||||
of PK_FLOAT:
|
||||
try: result.float_val = value.parseFloat
|
||||
except EInvalidValue:
|
||||
raise_or_quit(EInvalidValue, ("parameter $1 requires a " &
|
||||
except ValueError:
|
||||
raise_or_quit(ValueError, ("parameter $1 requires a " &
|
||||
"float, but $2 can't be parsed into one") % [param, escape(value)])
|
||||
of PK_BOOL:
|
||||
try: result.bool_val = value.parseBool
|
||||
except EInvalidValue:
|
||||
raise_or_quit(EInvalidValue, ("parameter $1 requires a " &
|
||||
except ValueError:
|
||||
raise_or_quit(ValueError, ("parameter $1 requires a " &
|
||||
"boolean, but $2 can't be parsed into one. Valid values are: " &
|
||||
"y, yes, true, 1, on, n, no, false, 0, off") % [param, escape(value)])
|
||||
of PK_BIGGEST_INT:
|
||||
try:
|
||||
let parsed_len = parseBiggestInt(value, result.big_int_val)
|
||||
if value.len != parsed_len or parsed_len < 1:
|
||||
raise_or_quit(EInvalidValue, ("parameter $1 requires an " &
|
||||
raise_or_quit(ValueError, ("parameter $1 requires an " &
|
||||
"integer, but $2 can't be parsed completely into one") % [
|
||||
param, escape(value)])
|
||||
except EInvalidValue:
|
||||
raise_or_quit(EInvalidValue, ("parameter $1 requires an " &
|
||||
except ValueError:
|
||||
raise_or_quit(ValueError, ("parameter $1 requires an " &
|
||||
"integer, but $2 can't be parsed into one") % [param, escape(value)])
|
||||
of PK_BIGGEST_FLOAT:
|
||||
try:
|
||||
let parsed_len = parseBiggestFloat(value, result.big_float_val)
|
||||
if value.len != parsed_len or parsed_len < 1:
|
||||
raise_or_quit(EInvalidValue, ("parameter $1 requires a " &
|
||||
raise_or_quit(ValueError, ("parameter $1 requires a " &
|
||||
"float, but $2 can't be parsed completely into one") % [
|
||||
param, escape(value)])
|
||||
except EInvalidValue:
|
||||
raise_or_quit(EInvalidValue, ("parameter $1 requires a " &
|
||||
except ValueError:
|
||||
raise_or_quit(ValueError, ("parameter $1 requires a " &
|
||||
"float, but $2 can't be parsed into one") % [param, escape(value)])
|
||||
of PK_EMPTY:
|
||||
discard
|
||||
@@ -298,15 +298,15 @@ proc parse_parameter(quit_on_failure: bool, param, value: string,
|
||||
|
||||
|
||||
template build_specification_lookup():
|
||||
TOrderedTable[string, ptr Tparameter_specification] =
|
||||
OrderedTable[string, ptr Tparameter_specification] =
|
||||
## Returns the table used to keep pointers to all of the specifications.
|
||||
var result {.gensym.}: TOrderedTable[string, ptr Tparameter_specification]
|
||||
var result {.gensym.}: OrderedTable[string, ptr Tparameter_specification]
|
||||
result = initOrderedTable[string, ptr Tparameter_specification](
|
||||
nextPowerOfTwo(expected.len))
|
||||
for i in 0..expected.len-1:
|
||||
for param_to_detect in expected[i].names:
|
||||
if result.hasKey(param_to_detect):
|
||||
raise_or_quit(EInvalidKey,
|
||||
raise_or_quit(KeyError,
|
||||
"Parameter $1 repeated in input specification" % param_to_detect)
|
||||
else:
|
||||
result[param_to_detect] = addr(expected[i])
|
||||
@@ -344,7 +344,7 @@ proc parse*(expected: seq[Tparameter_specification] = @[],
|
||||
##
|
||||
## If there is any kind of error and quit_on_failure is true, the quit proc
|
||||
## will be called with a user error message. If quit_on_failure is false
|
||||
## errors will raise exceptions (usually EInvalidValue or EOverflow) instead
|
||||
## errors will raise exceptions (usually ValueError or EOverflow) instead
|
||||
## for you to catch and handle.
|
||||
|
||||
assert type_of_positional_parameters != PK_EMPTY and
|
||||
@@ -359,7 +359,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:
|
||||
let total_params = ParamCount()
|
||||
let total_params = paramCount()
|
||||
#echo "Got no explicit args, retrieving from OS. Count: ", total_params
|
||||
newSeq(args, total_params)
|
||||
for i in 0..total_params - 1:
|
||||
@@ -387,7 +387,7 @@ proc parse*(expected: seq[Tparameter_specification] = @[],
|
||||
if param.consumes == PK_HELP:
|
||||
echo_help(expected, type_of_positional_parameters,
|
||||
bad_prefixes, end_of_options)
|
||||
raise_or_quit(EInvalidKey, "")
|
||||
raise_or_quit(KeyError, "")
|
||||
|
||||
if param.consumes != PK_EMPTY:
|
||||
if i + 1 < args.len:
|
||||
@@ -396,14 +396,14 @@ proc parse*(expected: seq[Tparameter_specification] = @[],
|
||||
run_custom_proc(parsed, param.custom_validator, arg)
|
||||
i += 1
|
||||
else:
|
||||
raise_or_quit(EInvalidValue, ("parameter $1 requires a " &
|
||||
raise_or_quit(ValueError, ("parameter $1 requires a " &
|
||||
"value, but none was provided") % [arg])
|
||||
result.options[param.names[0]] = parsed
|
||||
break adding_positional_parameter
|
||||
else:
|
||||
for bad_prefix in bad_prefixes:
|
||||
if arg.startsWith(bad_prefix):
|
||||
raise_or_quit(EInvalidValue, ("Found ambiguos parameter '$1' " &
|
||||
raise_or_quit(ValueError, ("Found ambiguos parameter '$1' " &
|
||||
"starting with '$2', put '$3' as the previous parameter " &
|
||||
"if you want to force it as positional parameter.") % [arg,
|
||||
bad_prefix, end_of_options])
|
||||
@@ -415,7 +415,7 @@ proc parse*(expected: seq[Tparameter_specification] = @[],
|
||||
i += 1
|
||||
|
||||
|
||||
proc toString(runes: seq[TRune]): string =
|
||||
proc toString(runes: seq[Rune]): string =
|
||||
result = ""
|
||||
for rune in runes: result.add(rune.toUTF8)
|
||||
|
||||
@@ -424,7 +424,7 @@ proc ascii_cmp(a, b: string): int =
|
||||
## Comparison ignoring non ascii characters, for better switch sorting.
|
||||
let a = filterIt(toSeq(runes(a)), it.isAlpha())
|
||||
# Can't use filterIt twice, github bug #351.
|
||||
let b = filter(toSeq(runes(b)), proc(x: TRune): bool = x.isAlpha())
|
||||
let b = filter(toSeq(runes(b)), proc(x: Rune): bool = x.isAlpha())
|
||||
return system.cmp(toString(a), toString(b))
|
||||
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ task "download", "download game assets":
|
||||
skipAssets = false
|
||||
path = expandFilename("data")
|
||||
path.add DirSep
|
||||
path.add(extractFilename(gameAssets))
|
||||
path.add(extractFilename(GameAssets))
|
||||
if existsFile(path):
|
||||
echo "The file already exists\n",
|
||||
"[R]emove [M]ove [Q]uit [S]kip Source: ", GameAssets
|
||||
@@ -92,7 +92,7 @@ task "download", "download game assets":
|
||||
of "r":
|
||||
removeFile path
|
||||
of "m":
|
||||
moveFile path, path/../(extractFilename(gameAssets)&"-old")
|
||||
moveFile path, path/../(extractFilename(GameAssets)&"-old")
|
||||
of "s":
|
||||
skipAssets = true
|
||||
else:
|
||||
@@ -101,7 +101,7 @@ task "download", "download game assets":
|
||||
echo "Downloading from ", GameAssets
|
||||
if not skipAssets:
|
||||
echo "Downloading to ", path
|
||||
downloadFile gameAssets, path
|
||||
downloadFile GameAssets, path
|
||||
echo "Download finished"
|
||||
|
||||
let targetDir = parentDir(parentDir(path))
|
||||
|
||||
@@ -3,10 +3,10 @@ import
|
||||
tri_engine/config
|
||||
|
||||
type
|
||||
TV2*[T:TNumber=TR] = array[0..1, T]
|
||||
TV3*[T:TNumber=TR] = array[0..2, T]
|
||||
TV4*[T:TNumber=TR] = array[0..3, T]
|
||||
TVT*[T:TNumber=TR] = TV2|TV3|TV4
|
||||
TV2*[T:SomeNumber=TR] = array[0..1, T]
|
||||
TV3*[T:SomeNumber=TR] = array[0..2, T]
|
||||
TV4*[T:SomeNumber=TR] = array[0..3, T]
|
||||
TVT*[T:SomeNumber=TR] = TV2|TV3|TV4
|
||||
#TV2* = array[0..1, TR]
|
||||
#TV3* = array[0..2, TR]
|
||||
#TV4* = array[0..3, TR]
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
discard """
|
||||
output: '''foobarfoobar
|
||||
bazbearbazbear
|
||||
|
||||
1'''
|
||||
cmd: "nim $target --threads:on $options $file"
|
||||
"""
|
||||
|
||||
@@ -18,5 +18,5 @@ type
|
||||
PSDL_Sem = ptr TSDL_Sem
|
||||
TSDL_Sem = TSDL_Semaphore
|
||||
|
||||
proc SDL_CreateSemaphore(initial_value: Int32): PSDL_Sem {.
|
||||
proc SDL_CreateSemaphore(initial_value: int32): PSDL_Sem {.
|
||||
importc: "SDL_CreateSemaphore".}
|
||||
|
||||
Reference in New Issue
Block a user