tests: Trim .nim files trailing whitespace

via OSX: find . -name '*.nim' -exec sed -i '' -E 's/[[:space:]]+$//' {} +
This commit is contained in:
Adam Strzelecki
2015-09-04 23:04:32 +02:00
parent ac9c1cd6b9
commit e80465dacf
372 changed files with 4486 additions and 4486 deletions

View File

@@ -4,23 +4,23 @@ discard """
import tables
proc action1(arg: string) =
proc action1(arg: string) =
echo "action 1 ", arg
proc action2(arg: string) =
proc action2(arg: string) =
echo "action 2 ", arg
proc action3(arg: string) =
proc action3(arg: string) =
echo "action 3 ", arg
proc action4(arg: string) =
proc action4(arg: string) =
echo "action 4 ", arg
var
actionTable = {
"A": action1,
"B": action2,
"C": action3,
"A": action1,
"B": action2,
"C": action3,
"D": action4}.toTable
actionTable["C"]("arg")

View File

@@ -6,7 +6,7 @@ type
proc isPartOf*[S, T](a: S, b: T): TAnalysisResult {.
magic: "IsPartOf", noSideEffect.}
## not yet exported properly.
## not yet exported properly.
template compileTimeAssert(cond: expr) =
when not cond:
@@ -35,30 +35,30 @@ proc p(param1, param2: TC): TC =
local: TC
plocal: ptr TC
plocal2: ptr TA
local.arr <| local
local.arr[0] <| local
local.arr[2] !<| local.arr[1]
plocal2[] ?<| local
param1 ?<| param2
local.arr[0] !<| param1
local.arr !<| param1
local.le[] ?<| param1
param1 !<| local.arr[0]
param1 !<| local.arr
param1 ?<| local.le[]
result !<| local
result <| result
var
a, b: int
x: TC
a <| a
a !<| b

View File

@@ -1,10 +1,10 @@
import mambsym2 # import TExport
type
TExport* = enum x, y, z
TOtherEnum* = enum mDec, mInc, mAssign
proc ha() =
var
x: TExport # no error
discard
import mambsym2 # import TExport
type
TExport* = enum x, y, z
TOtherEnum* = enum mDec, mInc, mAssign
proc ha() =
var
x: TExport # no error
discard

View File

@@ -1,3 +1,3 @@
type
TExport* = enum a, b, c
type
TExport* = enum a, b, c

View File

@@ -1,7 +1,7 @@
import mambsys2 # import TExport
type
TExport* = enum x, y, z
proc foo*(x: int) =
discard
import mambsys2 # import TExport
type
TExport* = enum x, y, z
proc foo*(x: int) =
discard

View File

@@ -1,4 +1,4 @@
type
TExport* = enum x, y, z # exactly the same type!
proc foo*(x: int) = discard
type
TExport* = enum x, y, z # exactly the same type!
proc foo*(x: int) = discard

View File

@@ -3,13 +3,13 @@ discard """
line: 11
errormsg: "ambiguous identifier"
"""
# Test ambiguous symbols
import mambsym1, mambsym2
var
v: TExport #ERROR_MSG ambiguous identifier
v = y
# Test ambiguous symbols
import mambsym1, mambsym2
var
v: TExport #ERROR_MSG ambiguous identifier
v = y

View File

@@ -8,12 +8,12 @@ type
TMyType = object
len: int
data: string
proc len(x: TMyType): int {.inline.} = return x.len
proc x(s: TMyType, len: int) =
writeLine(stdout, len(s))
var
m: TMyType
m.len = 7

View File

@@ -3,13 +3,13 @@ discard """
line: 11
errormsg: "ambiguous identifier"
"""
# Test ambiguous symbols
import mambsym1, times
var
v = mDec #ERROR_MSG ambiguous identifier
writeLine(stdout, ord(v))
# Test ambiguous symbols
import mambsym1, times
var
v = mDec #ERROR_MSG ambiguous identifier
writeLine(stdout, ord(v))

View File

@@ -2,33 +2,33 @@ discard """
file: "tarray.nim"
output: "100124"
"""
# simple check for one dimensional arrays
type
TMyArray = array[0..2, int]
TMyRecord = tuple[x, y: int]
proc sum(a: TMyarray): int =
result = 0
var i = 0
while i < len(a):
inc(result, a[i])
inc(i)
proc sum(a: openarray[int]): int =
result = 0
var i = 0
while i < len(a):
inc(result, a[i])
inc(i)
proc getPos(r: TMyRecord): int =
result = r.x + r.y
write(stdout, sum([1, 2, 3, 4]))
write(stdout, sum([]))
write(stdout, getPos( (x: 5, y: 7) ))
#OUT 10012
# simple check for one dimensional arrays
type
TMyArray = array[0..2, int]
TMyRecord = tuple[x, y: int]
proc sum(a: TMyarray): int =
result = 0
var i = 0
while i < len(a):
inc(result, a[i])
inc(i)
proc sum(a: openarray[int]): int =
result = 0
var i = 0
while i < len(a):
inc(result, a[i])
inc(i)
proc getPos(r: TMyRecord): int =
result = r.x + r.y
write(stdout, sum([1, 2, 3, 4]))
write(stdout, sum([]))
write(stdout, getPos( (x: 5, y: 7) ))
#OUT 10012
# bug #1669
let filesToCreate = ["tempdir/fl1.a", "tempdir/fl2.b",

View File

@@ -9,7 +9,7 @@ type
TObj = object
arr: TMyarray
proc mul(a, b: TMyarray): TMyArray =
result = a
for i in 0..len(a)-1:

View File

@@ -2,9 +2,9 @@ discard """
file: "tarray3.nim"
output: "3"
"""
# simple check for two dimensional arrays
# simple check for two dimensional arrays
const
const
myData = [[1,2,3], [4, 5, 6]]
echo myData[0][2] #OUT 3

View File

@@ -7,7 +7,7 @@ discard """
type
TEnum = enum
eA, eB, eC, eD, eE, eF
const
myMapping: array[TEnum, array[0..1, int]] = [
eA: [1, 2],

View File

@@ -6,7 +6,7 @@ discard """
type
TEnum = enum
eA, eB, eC, eD, eE, eF
const
myMapping: array[TEnum, array[0..1, int]] = [
eA: [1, 2],

View File

@@ -6,7 +6,7 @@ proc `+`*[R, T] (v1, v2: array[R, T]): array[R, T] =
for i in low(v1)..high(v1):
result[i] = v1[i] + v2[i]
var
var
v1: array[0..2, float] = [3.0, 1.2, 3.0]
v2: array[0..1, float] = [2.0, 1.0]
v3 = v1 + v2

View File

@@ -1,13 +1,13 @@
# test another strange bug ... (I hate this compiler; it is much too buggy!)
proc putEnv(key, val: string) =
# XXX: we have to leak memory here, as we cannot
# free it before the program ends (says Borland's
# documentation)
var
env: ptr array[0..500000, char]
env = cast[ptr array[0..500000, char]](alloc(len(key) + len(val) + 2))
for i in 0..len(key)-1: env[i] = key[i]
env[len(key)] = '='
for i in 0..len(val)-1:
env[len(key)+1+i] = val[i]
# test another strange bug ... (I hate this compiler; it is much too buggy!)
proc putEnv(key, val: string) =
# XXX: we have to leak memory here, as we cannot
# free it before the program ends (says Borland's
# documentation)
var
env: ptr array[0..500000, char]
env = cast[ptr array[0..500000, char]](alloc(len(key) + len(val) + 2))
for i in 0..len(key)-1: env[i] = key[i]
env[len(key)] = '='
for i in 0..len(val)-1:
env[len(key)+1+i] = val[i]

View File

@@ -2,12 +2,12 @@ discard """
output: "x == 45ugh"
"""
template myAssert(cond: expr) =
template myAssert(cond: expr) =
when 3 <= 3:
let c = cond.astToStr
if not cond:
echo c, "ugh"
var x = 454
myAssert(x == 45)

View File

@@ -1,31 +1,31 @@
# Test the assignment operator for complex types which need RTTI
type
TRec = object
x, y: int
s: string
seq: seq[string]
arr: seq[seq[array[0..3, string]]]
TRecSeq = seq[TRec]
proc test() =
var
a, b: TRec
a.x = 1
a.y = 2
a.s = "Hallo!"
a.seq = @["abc", "def", "ghi", "jkl"]
a.arr = @[]
setLen(a.arr, 4)
a.arr[0] = @[]
a.arr[1] = @[]
b = a # perform a deep copy here!
b.seq = @["xyz", "huch", "was", "soll"]
writeLine(stdout, len(a.seq))
writeLine(stdout, a.seq[3])
writeLine(stdout, len(b.seq))
writeLine(stdout, b.seq[3])
writeLine(stdout, b.y)
test()
# Test the assignment operator for complex types which need RTTI
type
TRec = object
x, y: int
s: string
seq: seq[string]
arr: seq[seq[array[0..3, string]]]
TRecSeq = seq[TRec]
proc test() =
var
a, b: TRec
a.x = 1
a.y = 2
a.s = "Hallo!"
a.seq = @["abc", "def", "ghi", "jkl"]
a.arr = @[]
setLen(a.arr, 4)
a.arr[0] = @[]
a.arr[1] = @[]
b = a # perform a deep copy here!
b.seq = @["xyz", "huch", "was", "soll"]
writeLine(stdout, len(a.seq))
writeLine(stdout, a.seq[3])
writeLine(stdout, len(b.seq))
writeLine(stdout, b.seq[3])
writeLine(stdout, b.y)
test()

View File

@@ -6,7 +6,7 @@ type
TAny* = object {.pure.}
value*: pointer
rawType: pointer
proc newAny(value, rawType: pointer): TAny =
result.value = value
result.rawType = rawType

View File

@@ -4,7 +4,7 @@ discard """
var t, s: tuple[x: string, c: int]
proc ugh: seq[tuple[x: string, c: int]] =
proc ugh: seq[tuple[x: string, c: int]] =
result = @[("abc", 232)]
t = ugh()[0]

View File

@@ -12,7 +12,7 @@ type
a, b: int
PSomeObj = ref object
a, b: int
var a = TSomeObj(a: 8)
var b = PSomeObj(a: 5)
echo a.a, " ", b.a, " ", a.b, " ", b.b

View File

@@ -50,7 +50,7 @@ proc createServer(port: TPort) {.async.} =
if bindAddr(server.SocketHandle, cast[ptr SockAddr](addr(name)),
sizeof(name).Socklen) < 0'i32:
raiseOSError(osLastError())
discard server.SocketHandle.listen()
while true:
asyncCheck readMessages(await accept(server))

View File

@@ -40,7 +40,7 @@ else:
s = newAsyncSocket()
await s.connect(testHost, testPort)
var ps = await ls.accept()
SocketHandle(ls).close()

View File

@@ -18,7 +18,7 @@ proc main() {.async.} =
let data = await file.readAll()
doAssert data == "foot"
file.close()
# Append test
block:
var file = openAsync(fn, fmAppend)
@@ -29,8 +29,8 @@ proc main() {.async.} =
file.close()
file = openAsync(fn, fmRead)
let data = await file.readAll()
doAssert data == "foot\ntest2"
file.close()
waitFor main()

View File

@@ -10,12 +10,12 @@ disp = newDispatcher()
var msgCount = 0
when defined(ssl):
var ctx = newContext(verifyMode = CVerifyNone,
var ctx = newContext(verifyMode = CVerifyNone,
certFile = "tests/testdata/mycert.pem", keyFile = "tests/testdata/mycert.pem")
var ctx1 = newContext(verifyMode = CVerifyNone)
const
const
swarmSize = 50
messagesToSend = 100

View File

@@ -20,12 +20,12 @@ proc serverRead(s: PAsyncSocket) =
if s.recvFromAsync(data, 9, address, port):
assert address == "127.0.0.1"
msgCount.inc()
discard """
var line = ""
assert s.recvLine(line)
if line == "":
assert(false)
else:
@@ -66,11 +66,11 @@ while true:
if not disp.poll():
break
if (msgCount div messagesToSend) * serverCount == currentClient:
createClient(disp, TPort(10335), false)
createClient(disp, TPort(10336), true)
if msgCount == messagesToSend * serverCount * swarmSize:
break

View File

@@ -44,4 +44,4 @@ when isMainModule:
var b = doBench()
var output = genOutput(b)
writeFile("benchmarkResults.json", pretty(output))

View File

@@ -2,7 +2,7 @@ import os
import strutils
proc fannkuch (n: int): int =
var
var
count: seq[int]
maxFlips = 0
m = n-1
@@ -58,7 +58,7 @@ proc fannkuch (n: int): int =
for i in 0 .. r-1:
perm1[i] = perm1[i+1]
perm1[r] = tmp
dec (count[r])
if count[r] > 0:
break makePerm
@@ -66,4 +66,4 @@ proc fannkuch (n: int): int =
return maxFlips
var n = 10
echo ("Pfannkuchen(" & $n & ") = " & $fannkuch (n))
echo ("Pfannkuchen(" & $n & ") = " & $fannkuch (n))

View File

@@ -51,4 +51,4 @@ proc sort (start, stop: int) =
sort (0, data.len)
echo (data[n div 2 - 1] and 0xFFFF_FFFF'i64, ", ",
data[n div 2] and 0xFFFF_FFFF'i64, ", ",
data[n div 2 + 1] and 0xFFFF_FFFF'i64)
data[n div 2 + 1] and 0xFFFF_FFFF'i64)

View File

@@ -1,5 +1,5 @@
# Module A
var
var
lastId = 0
template genId*: expr =

View File

@@ -6,14 +6,14 @@ discard """
proc p1(x: int8, y: int): int = return x + y
template tempBind(x, y: expr): expr =
template tempBind(x, y: expr): expr =
bind p1
p1(x, y)
p1(x, y)
proc p1(x: int, y: int8): int = return x - y
# This is tricky: the call to ``p1(1'i8, 2'i8)`` should not fail in line 6,
# because it is not ambiguous there. But it is ambiguous after line 8.
# This is tricky: the call to ``p1(1'i8, 2'i8)`` should not fail in line 6,
# because it is not ambiguous there. But it is ambiguous after line 8.
echo tempBind(1'i8, 2'i8) #OUT 3

View File

@@ -8,7 +8,7 @@ discard """
proc p1(x: int8, y: int): int = return x + y
proc p1(x: int, y: int8): int = return x - y
template tempBind(x, y: expr): expr =
template tempBind(x, y: expr): expr =
(bind p1(x, y)) #ERROR_MSG ambiguous call
echo tempBind(1'i8, 2'i8)

View File

@@ -31,14 +31,14 @@ proc newProperty*[T](value: T): TProperty[T] =
proc setter(property: var TProperty[T], v: T) =
property.value = v
# fire event here
var args: TValueEventArgs[T]
args.Property = property
property.EEmitter.emit(property.ValueChanged, args)
prop.setProc = setter
return prop
proc `prop`[T] (p: TProperty[T]): T =
@@ -56,7 +56,7 @@ proc `$`[T] (p: TProperty[T]): string =
proc propertyBind*[T](p1: var TProperty[T], p2: var TProperty[T]) =
p1.Binders.add(p2)
# make handler -> handler[T] so trigger even more generics bugs ...
proc handler(e: TEventArgs) =
type TEA = TValueEventArgs[T]
@@ -77,9 +77,9 @@ proc `->`[T](p1: var TProperty[T], p2: var TProperty[T]) =
when isMainModule:
# Initial value testing
var myProp = newProperty(5)
echo(myProp)
myProp ~= 7 # Temp operator until overloading of '=' is implemented.
echo(myProp)

View File

@@ -6,12 +6,12 @@ discard """
proc `++`*[T: int | float](a, b: T): T =
result = a + b
type
DI = distinct int
DF = distinct float
DS = distinct string
proc `++`(x, y: DI): DI {.borrow.}
proc `++`(x, y: DF): DF {.borrow.}

View File

@@ -8,8 +8,8 @@ type
var
e: TE
case e
of A..D, B..C:
of A..D, B..C:
echo "redundant"
else: nil

View File

@@ -6,7 +6,7 @@ discard """
proc checkDuplicates(myval: int32): bool =
proc checkDuplicates(myval: int32): bool =
case myval
of 0x7B:
echo "this should not compile"

View File

@@ -25,7 +25,7 @@ of "will", "it", "finally", "be", "generated": discard
var z = case i
of 1..5, 8, 9: "aa"
of 6, 7: "bb"
elif x == "Ha":
elif x == "Ha":
"cc"
elif x == "yyy":
write(stdout, x)

View File

@@ -4,13 +4,13 @@ import strutils
var x = 343
case stdin.readline.parseInt
of 0:
of 0:
echo "most common case"
of 1:
of 1:
{.linearScanEnd.}
echo "second most common case"
of 2: echo "unlikely: use branch table"
else:
else:
echo "unlikely too: use branch table"
@@ -18,7 +18,7 @@ case x
of 23: echo "23"
of 343: echo "343"
of 21: echo "21"
else:
else:
{.linearScanEnd.}
echo "default"

View File

@@ -18,21 +18,21 @@ type
FOwnerDocument: PDocument # Read-Only
FParentNode: PNode # Read-Only
prefix*: string # Setting this should change some values... TODO!
PElement* = ref Element
Element = object of Node
FTagName: string # Read-only
PCharacterData = ref CharacterData
CharacterData = object of Node
data*: string
PDocument* = ref Document
Document = object of Node
FImplementation: PDOMImplementation # Read-only
FDocumentElement: PElement # Read-only
PAttr* = ref Attr
PAttr* = ref Attr
Attr = object of Node
FName: string # Read-only
FSpecified: bool # Read-only
@@ -44,22 +44,22 @@ type
PText* = ref Text
Text = object of CharacterData
PComment* = ref Comment
Comment = object of CharacterData
PCDataSection* = ref CDataSection
CDataSection = object of Text
PProcessingInstruction* = ref ProcessingInstruction
ProcessingInstruction = object of Node
data*: string
FTarget: string # Read-only
proc `namespaceURI=`*(n: var PNode, value: string) =
proc `namespaceURI=`*(n: var PNode, value: string) =
n.FNamespaceURI = value
proc main =
proc main =
var n: PNode
new(n)
n.namespaceURI = "test"

View File

@@ -14,7 +14,7 @@ proc p(a: PObj) =
proc q(a: var PObj) =
a.p()
var
var
a: PObj
new(a)
q(a)

View File

@@ -11,7 +11,7 @@ type
status*: TStatusEnum
desc*: string
hash*: string
proc initStatus*(): TStatus =
result.status = sUnknown
result.desc = ""
@@ -49,7 +49,7 @@ proc `$`*(status: TStatusEnum): string =
return "csource generation succeeded"
of sUnknown:
return "unknown"
proc makeCommitPath*(platform, hash: string): string =
return platform / "nim_" & hash.substr(0, 11) # 11 Chars.

View File

@@ -41,7 +41,7 @@ type
proc getInterf(): ITest =
var shared: int
return (setter: proc (x: int) = shared = x,
getter: proc (): int = return shared)

View File

@@ -33,13 +33,13 @@ when true:
for xxxx in 0..9:
var i = 0
proc bx =
if i > 10:
if i > 10:
echo xxxx
return
i += 1
#for j in 0 .. 0: echo i
bx()
bx()
echo i
@@ -50,11 +50,11 @@ when true:
var x = start-1
#let dummy = proc =
# discard start
result = proc (): int =
result = proc (): int =
#var x = 9
for i in 0 .. 0: x = x + 1
return x
var a = accumulator(3)
@@ -69,7 +69,7 @@ when true:
for i in 0..3: echo "py"
py()
outer()
@@ -80,7 +80,7 @@ when true:
if n < 0: result = errorValue
elif n <= 1: result = 1
else: result = n * fac(n-1)
proc px() {.closure.} =
echo "px"
@@ -93,7 +93,7 @@ when true:
"xyz": py
}
mapping[0][1]()
echo fac(3)

View File

@@ -13,7 +13,7 @@ proc main =
for i in 0 .. n-1:
let val = s[i]()
if val != $(i*i): echo "bug ", val
if getOccupiedMem() > 3000_000: quit("still a leak!")
echo "success"

View File

@@ -111,7 +111,7 @@ proc hasKey*[A, B](t: TOrderedTable[A, B], key: A): bool =
## returns true iff `key` is in the table `t`.
result = rawGet(t, key) >= 0
proc rawInsert[A, B](t: var TOrderedTable[A, B],
proc rawInsert[A, B](t: var TOrderedTable[A, B],
data: var TOrderedKeyValuePairSeq[A, B],
key: A, val: B) =
rawInsertImpl()
@@ -128,7 +128,7 @@ proc enlarge[A, B](t: var TOrderedTable[A, B]) =
t.last = -1
while h >= 0:
var nxt = t.data[h].next
if t.data[h].slot == seFilled:
if t.data[h].slot == seFilled:
rawInsert(t, n, t.data[h].key, t.data[h].val)
h = nxt
swap(t.data, n)
@@ -150,16 +150,16 @@ proc initOrderedTable*[A, B](initialSize=64): TOrderedTable[A, B] =
result.last = -1
newSeq(result.data, initialSize)
proc toOrderedTable*[A, B](pairs: openarray[tuple[key: A,
proc toOrderedTable*[A, B](pairs: openarray[tuple[key: A,
val: B]]): TOrderedTable[A, B] =
## creates a new ordered hash table that contains the given `pairs`.
result = initOrderedTable[A, B](nextPowerOfTwo(pairs.len+10))
for key, val in items(pairs): result[key] = val
proc sort*[A, B](t: var TOrderedTable[A,B],
proc sort*[A, B](t: var TOrderedTable[A,B],
cmp: proc (x, y: tuple[key: A, val: B]): int {.closure.}) =
## sorts the ordered table so that the entry with the highest counter comes
## first. This is destructive (with the advantage of being efficient)!
## first. This is destructive (with the advantage of being efficient)!
## You must not modify `t` afterwards!
## You can use the iterators `pairs`, `keys`, and `values` to iterate over
## `t` in the sorted order.
@@ -186,7 +186,7 @@ proc sort*[A, B](t: var TOrderedTable[A,B],
let item1 = (x.key, x.val)
let item2 = (y.key, y.val)
return cmp(item1, item2)
while rawCmp(t.data[j-h], t.data[j]) <= 0:
swap(t.data[j], t.data[j-h])
j = j-h

View File

@@ -10,8 +10,8 @@ type
proc getInterf(): ITest =
var shared1, shared2: int
return (setter: proc (x: int) =
return (setter: proc (x: int) =
shared1 = x
shared2 = x + 10,
getter1: proc (): int = result = shared1,

View File

@@ -3,12 +3,12 @@ discard """
errormsg: "illegal capture 'A'"
"""
proc outer() =
proc outer() =
var A: int
proc ugh[T](x: T) {.cdecl.} =
echo "ugha", A, x
ugh[int](12)
outer()

View File

@@ -17,7 +17,7 @@ proc cbOuter(response: string) {.closure, discardable.} =
var iterVar = fooIter
iterVar().data
yield Future[int](data: foo())
var iterVar2 = cbIter
proc cb2() {.closure.} =
try:

View File

@@ -45,7 +45,7 @@ proc cbOuter() =
proc fooIter() =
echo response
fooIter()
cbIter()
cbOuter()

View File

@@ -2,10 +2,10 @@ discard """
output: "11"
"""
proc p(x, y: int): int =
proc p(x, y: int): int =
result = x + y
echo p((proc (): int =
echo p((proc (): int =
var x = 7
return x)(),
(proc (): int = return 4)())

View File

@@ -2,7 +2,7 @@ import unittest
test "loop variables are captured by copy":
var funcs: seq[proc (): int {.closure.}] = @[]
for i in 0..10:
let ii = i
funcs.add do -> int: return ii * ii

View File

@@ -9,8 +9,8 @@ import strutils
const
myWords = "Angelika Anne Anna Anka Anja".split()
for x in items(myWords):
for x in items(myWords):
write(stdout, x) #OUT AngelikaAnneAnnaAnkaAnja

View File

@@ -4,8 +4,8 @@ discard """
const
myWords = @["Angelika", "Anne", "Anna", "Anka", "Anja"]
for i in 0 .. high(myWords):
for i in 0 .. high(myWords):
write(stdout, myWords[i]) #OUT AngelikaAnneAnnaAnkaAnja

View File

@@ -11,11 +11,11 @@ type
TElem = object
foo: int
bar: string
let
elem1 = TElem(foo: 1, bar: "bar")
elem2 = TElem(foo: 2, bar: "baz")
var tbl2 = initTable[string, TElem]()
tbl2.add("bar", elem1)
tbl2.add("baz", elem2)

View File

@@ -3,7 +3,7 @@
template ignoreExpr(e: expr): stmt {.immediate.} =
discard
# test first class '..' syntactical citizen:
# test first class '..' syntactical citizen:
ignoreExpr x <> 2..4
# test table constructor:
ignoreExpr({:})

View File

@@ -3,28 +3,28 @@ discard """
line: 25
errormsg: "type mismatch"
"""
# Test array, record constructors
type
TComplexRecord = tuple[
s: string,
x, y: int,
z: float,
chars: set[char]]
proc testSem =
var
things: array [0..1, TComplexRecord] = [
(s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
(s: "hi", x: 69, y: 45, z: 1.0, chars: {'a', 'b', 'c'})]
write(stdout, things[0].x)
const
things: array [0..1, TComplexRecord] = [
(s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
(s: "hi", x: 69, y: 45, z: 1.0)] #ERROR
otherThings = [ # the same
(s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
(s: "hi", x: 69, y: 45, z: 1.0, chars: {'a'})]
# Test array, record constructors
type
TComplexRecord = tuple[
s: string,
x, y: int,
z: float,
chars: set[char]]
proc testSem =
var
things: array [0..1, TComplexRecord] = [
(s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
(s: "hi", x: 69, y: 45, z: 1.0, chars: {'a', 'b', 'c'})]
write(stdout, things[0].x)
const
things: array [0..1, TComplexRecord] = [
(s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
(s: "hi", x: 69, y: 45, z: 1.0)] #ERROR
otherThings = [ # the same
(s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
(s: "hi", x: 69, y: 45, z: 1.0, chars: {'a'})]

View File

@@ -2,25 +2,25 @@ discard """
file: "tconstr2.nim"
output: "69"
"""
# Test array, record constructors
type
TComplexRecord = tuple[
s: string,
x, y: int,
z: float,
chars: set[char]]
const
things: array [0..1, TComplexRecord] = [
(s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
(s: "hi", x: 69, y: 45, z: 1.0, chars: {})]
otherThings = [ # the same
(s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
(s: "hi", x: 69, y: 45, z: 1.0, chars: {'a'})]
write(stdout, things[0].x)
#OUT 69
# Test array, record constructors
type
TComplexRecord = tuple[
s: string,
x, y: int,
z: float,
chars: set[char]]
const
things: array [0..1, TComplexRecord] = [
(s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
(s: "hi", x: 69, y: 45, z: 1.0, chars: {})]
otherThings = [ # the same
(s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
(s: "hi", x: 69, y: 45, z: 1.0, chars: {'a'})]
write(stdout, things[0].x)
#OUT 69

View File

@@ -3,7 +3,7 @@ discard """
errormsg: "type mismatch: got (int literal(232))"
"""
proc myGenericProc[T: object|tuple|ptr|ref|distinct](x: T): string =
proc myGenericProc[T: object|tuple|ptr|ref|distinct](x: T): string =
result = $x
type

View File

@@ -3,16 +3,16 @@ discard """
line: 14
errormsg: "undeclared identifier: \'ha\'"
"""
# check for forward label and
# for failure when label is not declared
proc main =
block endLess:
write(stdout, "Muaahh!\N")
break endLess
break ha #ERROR
main()
# check for forward label and
# for failure when label is not declared
proc main =
block endLess:
write(stdout, "Muaahh!\N")
break endLess
break ha #ERROR
main()

View File

@@ -6,7 +6,7 @@ var i = 0
while i < 400:
if i == 10: break
elif i == 3:
elif i == 3:
inc i
continue
inc i
@@ -16,7 +16,7 @@ var j = 0
while j < 300:
for x in 0..34:
if j < 300: continue
if x == 10:
if x == 10:
echo "failure: should never happen"
break
f = "came here"

View File

@@ -2,23 +2,23 @@ discard """
file: "tnestif.nim"
output: "i == 2"
"""
# test nested ifs
var
x, y: int
x = 2
if x == 0:
write(stdout, "i == 0")
if y == 0:
write(stdout, x)
else:
write(stdout, y)
elif x == 1:
write(stdout, "i == 1")
elif x == 2:
write(stdout, "i == 2")
else:
write(stdout, "looks like Python")
#OUT i == 2
# test nested ifs
var
x, y: int
x = 2
if x == 0:
write(stdout, "i == 0")
if y == 0:
write(stdout, x)
else:
write(stdout, y)
elif x == 1:
write(stdout, "i == 1")
elif x == 2:
write(stdout, "i == 2")
else:
write(stdout, "looks like Python")
#OUT i == 2

View File

@@ -3,10 +3,10 @@ discard """
line: 9
errormsg: "statement not allowed after"
"""
# no statement after return
proc main() =
return
echo("huch?") #ERROR_MSG statement not allowed after
# no statement after return
proc main() =
return
echo("huch?") #ERROR_MSG statement not allowed after

View File

@@ -7,7 +7,7 @@ converter p(i: int): bool = return i != 0
if 1:
echo if 4: "foo" else: "barr"
while 0:
while 0:
echo "bar"
var a: array[3, bool]

View File

@@ -11,4 +11,4 @@ proc main() =
thread.createThread(threadMain, 0)
thread.joinThreads()
main()
main()

View File

@@ -1,3 +1,3 @@
# Test for the compiler to be able to compile a Nim file with spaces in it.
echo("Successful")
echo("Successful")

View File

@@ -1,10 +1,10 @@
# Test the discardable pragma
proc p(x, y: int): int {.discardable.} =
proc p(x, y: int): int {.discardable.} =
return x + y
# test that it is inherited from generic procs too:
proc q[T](x, y: T): T {.discardable.} =
proc q[T](x, y: T): T {.discardable.} =
return x + y

View File

@@ -6,7 +6,7 @@ discard """
proc p =
var f: TFile
echo "hi"
open(f, "arg.txt")
p()

View File

@@ -5,7 +5,7 @@ discard """
template Additive(typ: typeDesc): stmt =
proc `+` *(x, y: typ): typ {.borrow.}
proc `-` *(x, y: typ): typ {.borrow.}
# unary operators:
proc `+` *(x: typ): typ {.borrow.}
proc `-` *(x: typ): typ {.borrow.}
@@ -27,7 +27,7 @@ template DefineCurrency(typ, base: expr): stmt {.immediate.} =
Additive(typ)
Multiplicative(typ, base)
Comparable(typ)
proc `$` * (t: typ): string {.borrow.}
DefineCurrency(TDollar, int)

View File

@@ -22,8 +22,8 @@ else:
proc newLit(x: int): PNode {.importc: "newLit", dynlib: dllname.}
proc newOp(k: TNodeKind, a, b: PNode): PNode {.
importc: "newOp", dynlib: dllname.}
proc buildTree(x: int): PNode {.importc: "buildTree", dynlib: dllname.}
importc: "newOp", dynlib: dllname.}
proc buildTree(x: int): PNode {.importc: "buildTree", dynlib: dllname.}
proc eval(n: PNode): int =
case n.k
@@ -36,6 +36,6 @@ proc eval(n: PNode): int =
# Test the GC:
for i in 0..100_000:
discard eval(buildTree(2))
echo "Done"

View File

@@ -10,11 +10,11 @@ type
else: a, b: ref TNode
PNode = ref TNode
proc newLit(x: int): PNode {.exportc: "newLit", dynlib.} =
new(result)
result.x = x
proc newOp(k: TNodeKind, a, b: PNode): PNode {.exportc: "newOp", dynlib.} =
assert a != nil
assert b != nil
@@ -22,13 +22,13 @@ proc newOp(k: TNodeKind, a, b: PNode): PNode {.exportc: "newOp", dynlib.} =
result.k = k
result.a = a
result.b = b
proc buildTree(x: int): PNode {.exportc: "buildTree", dynlib.} =
proc buildTree(x: int): PNode {.exportc: "buildTree", dynlib.} =
result = newOp(nkMul, newOp(nkAdd, newLit(x), newLit(x)), newLit(x))
when false:
# Test the GC:
for i in 0..100_000:
discard buildTree(2)
echo "Done"

View File

@@ -7,11 +7,11 @@ type
TObj = object {.pure, inheritable.}
TObjB = object of TObj
a, b, c: string
IO2Error = ref object of IOError
proc forw: int {. .}
proc lier(): int {.raises: [IO2Error].} =
writeLine stdout, "arg"

View File

@@ -7,9 +7,9 @@ type
TObj = object {.pure, inheritable.}
TObjB = object of TObj
a, b, c: string
EIO2 = ref object of IOError
proc forw: int {.raises: [].}
proc lier(): int {.raises: [IOError].} =

View File

@@ -8,9 +8,9 @@ type
TObjB = object of TObj
a, b, c: string
fn: proc (): int {.tags: [].}
EIO2 = ref object of EIO
proc raiser(): int {.tags: [TObj, FWriteIO].} =
writeLine stdout, "arg"

View File

@@ -8,12 +8,12 @@ type
TObjB = object of TObj
a, b, c: string
fn: proc (): int {.tags: [FReadIO].}
EIO2 = ref object of EIO
proc q() {.tags: [FIO].} =
nil
proc raiser(): int =
writeLine stdout, "arg"
if true:

View File

@@ -6,7 +6,7 @@ discard """
proc p(q: proc() ): proc() {.tags: [], raises: [], closure.} =
return proc () =
q()
let yay = p(proc () = raise newException(EIO, "IO"))
proc main() {.raises: [], tags: [].} = yay()

View File

@@ -3,7 +3,7 @@ type
PMenu = ref object
PMenuItem = ref object
proc createMenuItem*(menu: PMenu, label: string,
proc createMenuItem*(menu: PMenu, label: string,
action: proc (i: PMenuItem, p: pointer) {.cdecl.}) = discard
var s: PMenu
@@ -19,7 +19,7 @@ createMenuItem(s, "Go to definition...",
proc noRaise(x: proc()) {.raises: [].} =
# unknown call that might raise anything, but valid:
x()
proc doRaise() {.raises: [EIO].} =
raise newException(EIO, "IO")

View File

@@ -11,8 +11,8 @@ proc dontcare(x: int): int = return x + global
proc SideEffectLyer(x, y: int): int {.noSideEffect.} = #ERROR_MSG 'SideEffectLyer' can have side effects
return x + y + dontcare(x)
echo SideEffectLyer(1, 3)
echo SideEffectLyer(1, 3)

View File

@@ -8,9 +8,9 @@ var
proc dontcare(x: int): int = return x
proc SideEffectLyer(x, y: int): int {.noSideEffect.} =
proc SideEffectLyer(x, y: int): int {.noSideEffect.} =
return x + y + dontcare(x)
echo SideEffectLyer(1, 3) #OUT 5

View File

@@ -8,9 +8,9 @@ var
proc dontcare(x: int): int {.noSideEffect.} = return x
proc noSideEffect(x, y: int, p: proc (a: int): int {.noSideEffect.}): int {.noSideEffect.} =
proc noSideEffect(x, y: int, p: proc (a: int): int {.noSideEffect.}): int {.noSideEffect.} =
return x + y + dontcare(x)
echo noSideEffect(1, 3, dontcare) #OUT 5

View File

@@ -9,9 +9,9 @@ var
proc dontcare(x: int): int = return x
proc noSideEffect(x, y: int, p: proc (a: int): int {.noSideEffect.}): int {.noSideEffect.} =
proc noSideEffect(x, y: int, p: proc (a: int): int {.noSideEffect.}): int {.noSideEffect.} =
return x + y + dontcare(x)
echo noSideEffect(1, 3, dontcare) #ERROR_MSG type mismatch

View File

@@ -1,8 +1,8 @@
# Test enums
type
E = enum a, b, c, x, y, z
var
en: E
en = a
# Test enums
type
E = enum a, b, c, x, y, z
var
en: E
en = a

View File

@@ -1,14 +1,14 @@
# Test that enum with holes is handled correctly by case statement
type
TEnumHole = enum
TEnumHole = enum
eA = 0,
eB = 4,
eC = 5
var
e: TEnumHole = eB
case e
of eA: echo "A"
of eB: echo "B"

View File

@@ -1,14 +1,14 @@
# Test enum with explicit size
type
TEnumHole {.size: sizeof(int).} = enum
TEnumHole {.size: sizeof(int).} = enum
eA = 0,
eB = 4,
eC = 5
var
e: TEnumHole = eB
case e
of eA: echo "A"
of eB: echo "B"

View File

@@ -12,10 +12,10 @@ type
valueB = strValB & "conc",
valueC,
valueD = (4, "abc")
# test the new "proc body can be an expr" feature:
proc getValue: TMyEnum = valueD
# trick the optimizer with a variable:
var x = getValue()
echo valueA, ord(valueA), valueB, ord(valueB), valueC, valueD, ord(valueD), x

View File

@@ -7,5 +7,5 @@ discard """
type
TE1 = enum eA, eB
TE2 = enum eC, eD
assert eA != eC

View File

@@ -1,18 +1,18 @@
type
# please make sure we have under 32 options (improves code efficiency!)
TOption = enum
optNone, optForceFullMake, optBoehmGC, optRefcGC, optRangeCheck,
optBoundsCheck, optOverflowCheck, optNilCheck, optAssert, optLineDir,
optWarns, optHints, optDeadCodeElim, optListCmd, optCompileOnly,
optSafeCode, # only allow safe code
optStyleCheck, optOptimizeSpeed, optOptimizeSize, optGenDynLib,
optGenGuiApp, optStackTrace
TOptionset = set[TOption]
var
gOptions: TOptionset = {optRefcGC, optRangeCheck, optBoundsCheck,
optOverflowCheck, optAssert, optWarns, optHints, optLineDir, optStackTrace}
compilerArgs: int
gExitcode: int8
type
# please make sure we have under 32 options (improves code efficiency!)
TOption = enum
optNone, optForceFullMake, optBoehmGC, optRefcGC, optRangeCheck,
optBoundsCheck, optOverflowCheck, optNilCheck, optAssert, optLineDir,
optWarns, optHints, optDeadCodeElim, optListCmd, optCompileOnly,
optSafeCode, # only allow safe code
optStyleCheck, optOptimizeSpeed, optOptimizeSize, optGenDynLib,
optGenGuiApp, optStackTrace
TOptionset = set[TOption]
var
gOptions: TOptionset = {optRefcGC, optRangeCheck, optBoundsCheck,
optOverflowCheck, optAssert, optWarns, optHints, optLineDir, optStackTrace}
compilerArgs: int
gExitcode: int8

View File

@@ -21,7 +21,7 @@ try:
stdout.write("E")
stdout.write("C")
raise newException(EsomeotherErr, "bla")
finally:
finally:
echo "caught"
#OUT ECcaught

View File

@@ -4,14 +4,14 @@ discard """
"""
# Test return in try statement:
proc main: int =
proc main: int =
try:
try:
return 1
finally:
echo("came")
return 2
finally:
finally:
echo("here")
return 3

View File

@@ -7,7 +7,7 @@ D'''
"""
# Test break in try statement:
proc main: int =
proc main: int =
try:
block AB:
try:
@@ -16,14 +16,14 @@ proc main: int =
finally:
echo("A")
echo("skipped")
finally:
finally:
block B:
echo("B")
echo("skipped")
echo("C")
finally:
echo("D")
discard main() #OUT ABCD

View File

@@ -4,7 +4,7 @@ discard """
"""
# Test break in try statement:
proc main: bool =
proc main: bool =
while true:
try:
return true

View File

@@ -14,7 +14,7 @@ proc test4() =
discard
# Should cause unhandled exception error,
# but could cause segmentation fault if
# but could cause segmentation fault if
# exceptions are not handled properly.
test4()
raise newException(OSError, "Problem")

View File

@@ -18,6 +18,6 @@ when true:
genErrors("errssor!")
except ESomething:
echo("Error happened")

View File

@@ -7,7 +7,7 @@ try:
raise newException(ValueError, "")
except OverflowError:
echo("Error caught")

View File

@@ -26,16 +26,16 @@ when true:
result.bar = "bar"
echo($newfoo())
proc retInt(x, y: int): int =
proc retInt(x, y: int): int =
if (var yy = 0; yy != 0):
echo yy
else:
echo(try: parseInt("1244") except EINvalidValue: -1)
result = case x
of 23: 3
of 64:
of 64:
case y
of 1: 2
of 2: 3
@@ -79,7 +79,7 @@ semiProblem()
# bug #844
import json
import json
proc parseResponse(): PJsonNode =
result = % { "key1": % { "key2": % "value" } }
for key, val in result["key1"]:

View File

@@ -14,7 +14,7 @@ proc indexOf*(t: typedesc, name: string): int =
for n, x in fieldPairs(d):
if n == name: return i
i.inc
raise newException(EInvalidValue, "No field " & name & " in type " &
raise newException(EInvalidValue, "No field " & name & " in type " &
astToStr(t))
echo TMyTuple.indexOf("b")

View File

@@ -28,7 +28,7 @@ proc p(x: string) = echo "a string: ", x
var x: TMyTuple = ('a', 'b', 5, 6, "abc")
var y: TMyTuple = ('A', 'b', 5, 9, "abc")
for f in fields(x):
for f in fields(x):
p f
for a, b in fields(x, y):

View File

@@ -32,7 +32,7 @@ type
a, b: char
x, y: int
z: string
TEnum = enum enA, enB, enC
TMyCaseObj = object
case myDisc: TEnum
@@ -51,7 +51,7 @@ proc myobj(a, b: char, x, y: int, z: string): TMyObj =
var x = myobj('a', 'b', 5, 6, "abc")
var y = myobj('A', 'b', 5, 9, "abc")
for f in fields(x):
for f in fields(x):
p f
for a, b in fields(x, y):

View File

@@ -8,7 +8,7 @@ import math, strutils
{.emit: """
void printFloats(void) {
double y = 1.234567890123456789;
printf("C double: %.10f, %.10f ", exp(y), cos(y));
}
""".}

View File

@@ -1,9 +1,9 @@
type
TMyObj = object
TMyObj = object
x: int
proc gen*[T](): T =
proc gen*[T](): T =
var d: TMyObj
# access private field here
d.x = 3

View File

@@ -16,7 +16,7 @@ proc free*(some: ref TFoo) =
alive_foos.del alive_foos.find(some.id)
proc newFoo*(): ref TFoo =
new result, free
result.id = foo_counter
alive_foos.add result.id
inc foo_counter
@@ -26,7 +26,7 @@ for i in 0 .. <10:
for i in 0 .. <10:
let f = newFoo()
f.fn = proc =
f.fn = proc =
echo f.id
GC_fullcollect()

Some files were not shown because too many files have changed in this diff Show More