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
commit e80465dacf
372 changed files with 4486 additions and 4486 deletions

View file

@ -17,7 +17,7 @@ proc echoMatrix(a: TMatrix) =
proc echoMat2(a: TMat2) =
echo TMat2.M
var m = TMatrix[3,3,int](data: [1,2,3,4,5,6,7,8,9])
echoMatrix m

View file

@ -38,7 +38,7 @@ type
proc `[]`*[N, T](f: Bar[N, T], n: range[0..(N - 1)]): T =
assert high(n) == N-1
result = f.bar[n]
var b: Bar[3, int]
echo b[2]

View file

@ -5,7 +5,7 @@ type Deck = object
proc sort(h: var seq[Deck]) =
# works:
h.sort(proc (x, y: Deck): auto =
h.sort(proc (x, y: Deck): auto =
cmp(x.value, y.value))
# fails:
h.sort((x, y: Deck) => cmp(ord(x.value), ord(y.value)))

View file

@ -13,8 +13,8 @@ proc destroyDict[TK, TV](a: PDict[TK, TV]) =
proc newDict[TK, TV](a: TK, b: TV): PDict[TK, TV] =
fakeNew(result, destroyDict[TK, TV])
# Problem: destroyDict is not instantiated when newDict is instantiated!
# Problem: destroyDict is not instantiated when newDict is instantiated!
discard newDict("a", "b")
discard newDict("a", "b")

View file

@ -5,33 +5,33 @@ discard """
# test explicit type instantiation
type
TDict*[TKey, TValue] = object
TDict*[TKey, TValue] = object
data: seq[tuple[k: TKey, v: TValue]]
PDict*[TKey, #with `==`(a, b: TKey): bool
# hash(a: TKey): int,
# hash(a: TKey): int,
TValue] = ref TDict[TKey, TValue]
proc newDict*[TKey, TValue](): PDict[TKey, TValue] =
proc newDict*[TKey, TValue](): PDict[TKey, TValue] =
new(result)
result.data = @[]
proc add*[TKey, TValue](d: PDict[TKey, TValue], k: TKey, v: TValue) =
proc add*[TKey, TValue](d: PDict[TKey, TValue], k: TKey, v: TValue) =
d.data.add((k, v))
iterator items*[Tkey, TValue](d: PDict[TKey, TValue]): tuple[k: TKey,
v: TValue] =
iterator items*[Tkey, TValue](d: PDict[TKey, TValue]): tuple[k: TKey,
v: TValue] =
for k, v in items(d.data): yield (k, v)
var d = newDict[int, string]()
d.add(12, "12")
d.add(13, "13")
for k, v in items(d):
for k, v in items(d):
stdout.write("Key: ", $k, " value: ", v)
var c = newDict[char, string]()
c.add('A', "12")
c.add('B', "13")
for k, v in items(c):
for k, v in items(c):
stdout.write(" Key: ", $k, " value: ", v)

View file

@ -6,30 +6,30 @@ discard """
# test explicit type instantiation
type
TDict*[TKey, TValue] = object
TDict*[TKey, TValue] = object
data: seq[tuple[k: TKey, v: TValue]]
PDict*[TKey, TValue] = ref TDict[TKey, TValue]
proc newDict*[TKey, TValue](): PDict[TKey, TValue] =
proc newDict*[TKey, TValue](): PDict[TKey, TValue] =
new(result)
result.data = @[]
proc add*(d: PDict, k: TKey, v: TValue) =
d.data.add((k, v))
#iterator items*(d: PDict): tuple[k: TKey, v: TValue] =
proc add*(d: PDict, k: TKey, v: TValue) =
d.data.add((k, v))
#iterator items*(d: PDict): tuple[k: TKey, v: TValue] =
# for k, v in items(d.data): yield (k, v)
var d = newDict[int, string]()
d.add(12, "12")
d.add(13, "13")
for k, v in items(d):
for k, v in items(d):
stdout.write("Key: ", $k, " value: ", v)
var c = newDict[char, string]()
c.add('A', "12")
c.add('B', "13")
for k, v in items(c):
for k, v in items(c):
stdout.write(" Key: ", $k, " value: ", v)

View file

@ -9,7 +9,7 @@ type
TBinHeap[T] = object
heap: seq[TNode[T]]
last: int
PBinHeap[T] = ref TBinHeap[T]
proc newBinHeap*[T](heap: var PBinHeap[T], size: int) =
@ -17,7 +17,7 @@ proc newBinHeap*[T](heap: var PBinHeap[T], size: int) =
heap.last = 0
newSeq(heap.heap, size)
#newSeq(heap.seq, size)
proc parent(elem: int): int {.inline.} =
return (elem-1) div 2

View file

@ -1,4 +1,4 @@
type
type
TFoo[T, U, R = int] = object
x: T
y: U
@ -12,7 +12,7 @@ static:
assert type(x1.x) is int
assert type(x1.y) is float
assert type(x1.z) is int
var x2: TFoo[string, R = float, U = seq[int]]
static:

View file

@ -16,7 +16,7 @@ type
min, max: int
PMatcher[T] = ref TMatcher[T]
var
var
m: PMatcher[int]

View file

@ -12,7 +12,7 @@ type
matcher: ref TMatcher[T]
min, max: int
var
var
m: ref TMatcher[int]

View file

@ -1,4 +1,4 @@
type
type
PA[T] = ref TA[T]
TA[T] = object
field: T
@ -20,18 +20,18 @@ foo 23
when false:
# Compiles unless you use var a: PA[string]
type
type
PA = ref TA
TA[T] = object
# Cannot instantiate:
type
type
TA[T] = object
a: PA[T]
PA[T] = ref TA[T]
type
type
PA[T] = ref TA[T]
TA[T] = object

View file

@ -7,7 +7,7 @@ import typetraits
proc typeNameLen(x: typedesc): int {.compileTime.} =
result = x.name.len
macro selectType(a, b: typedesc): typedesc =
result = a
@ -33,7 +33,7 @@ static:
assert high(f1.data2) == 5 # length of MyEnum minus one, because we used T.high
assert high(f2.data1) == 126
assert high(f2.data2) == 3
assert high(f2.data2) == 3
assert high(f1.data3) == 6 # length of MyEnum
assert high(f2.data3) == 4 # length of int8

View file

@ -1,4 +1,4 @@
type
type
TMaybe[T] = object
case empty: bool
of false: value: T

View file

@ -8,7 +8,7 @@ discard """
# https://github.com/Araq/Nim/issues/797
proc foo[T](s:T):string = $s
type IntStringProc = proc(x: int): string
type IntStringProc = proc(x: int): string
var f1 = IntStringProc(foo)
var f2: proc(x: int): string = foo

View file

@ -13,7 +13,7 @@ proc handleThreadFunc(arg: TThreadFuncArgs[int]){.thread.} =
var output = fn()
callback(output)
proc `@||->`*[T](fn: proc(): T {.thread.},
proc `@||->`*[T](fn: proc(): T {.thread.},
callback: proc(val: T){.thread.}): TThread[TThreadFuncArgs[T]] =
var thr: TThread[TThreadFuncArgs[T]]
var args: TThreadFuncArgs[T]
@ -31,7 +31,7 @@ when isMainModule:
return 1
proc callbackFunc(val: int) {.thread.} =
echo($(val))
var thr = (testFunc @||-> callbackFunc)
echo("test")
joinThread(thr)

View file

@ -13,10 +13,10 @@ x32: 3x2 (3x2)'''
type
RectArray*[R, C: static[int], T] = distinct array[R * C, T]
var a23: RectArray[2, 3, int]
var a32: RectArray[3, 2, int]
echo "a23: ", a23.R, "x", a23.C
echo "a32: ", a32.R, "x", a32.C
@ -34,8 +34,8 @@ echo "t32: ", t32.R, "x", t32.C
# Output:
# t32: 3x2
# Everything is still OK. Now let's use the rectangular array inside another
# generic type:
type
@ -62,7 +62,7 @@ var x32 = x23.transpose
echo "x23: ", x23.R, "x", x23.C, " (", x23.theArray.R, "x", x23.theArray.C, ")"
echo "x32: ", x32.R, "x", x32.C, " (", x32.theArray.R, "x", x32.theArray.C, ")"
# Output:
# x23: 2x3 (2x3)
# x32: 3x2 (3x2) <--- this is incorrect. R and C do not match!

View file

@ -35,48 +35,48 @@ proc translation*[T](p: Vector2D[T]): Matrix2x3[T] =
proc scale*[T](v: Vector2D[T]): Matrix2x3[T] =
Matrix2x3[T]([v.x, T(0.0), T(0.0), T(0.0), v.y, T(0.0)])
proc rotation*[T](th: T): Matrix2x3[T] =
let
proc rotation*[T](th: T): Matrix2x3[T] =
let
c = T(cos(th.float))
s = T(sin(th.float))
Matrix2x3[T]([c, -s, T(0.0), s, c, T(0.0)])
proc `*`*[T](a, b: Matrix2x3[T]): Matrix2x3[T] =
proc `*`*[T](a, b: Matrix2x3[T]): Matrix2x3[T] =
# Here we pretend that row 3 is [0,0,0,1] without
# actually storing it in the matrix.
Matrix2x3[T]([a.M11*b.M11 + a.M12*b.M21,
a.M11*b.M12 + a.M12*b.M22,
a.M11*b.M13 + a.M12*b.M23 + a.M13,
Matrix2x3[T]([a.M11*b.M11 + a.M12*b.M21,
a.M11*b.M12 + a.M12*b.M22,
a.M11*b.M13 + a.M12*b.M23 + a.M13,
a.M21*b.M11 + a.M22*b.M21,
a.M21*b.M12 + a.M22*b.M22,
a.M21*b.M13 + a.M22*b.M23 + a.M23])
proc `*`*[T](a: Matrix2x3[T], p: Point2D[T]): Point2D[T] =
let
proc `*`*[T](a: Matrix2x3[T], p: Point2D[T]): Point2D[T] =
let
x = a.M11*p.x + a.M12*p.y + a.M13
y = a.M21*p.x + a.M22*p.y + a.M23
Point2D[T](x: x, y: y)
# making these so things like "line" that need a constructor don't stick out.
# 2x2 determinant: |a b|
# |c d| = ad - bc
# String rendering
#
template ff[S](x: S): string =
template ff[S](x: S): string =
formatFloat(float(x), ffDefault, 0)
proc `$`*[S](p: Point2D[S]): string =
proc `$`*[S](p: Point2D[S]): string =
"P($1, $2)" % [ff(p.x), ff(p.y)]
proc `$`*[S](p: Vector2D[S]): string =
proc `$`*[S](p: Vector2D[S]): string =
"V($1, $2)" % [ff(p.x), ff(p.y)]
proc `$`*[S](m: Matrix2x3[S]): string =
"M($1 $2 $3/$4 $5 $6)" % [ff(m.M11), ff(m.M12), ff(m.M13),
"M($1 $2 $3/$4 $5 $6)" % [ff(m.M11), ff(m.M12), ff(m.M13),
ff(m.M21), ff(m.M22), ff(m.M23)]
#
@ -102,7 +102,7 @@ proc `/`*[S](v: Vector2D[S], sc: S): Vector2D[S] =
proc `/`*[S](sc: S; v: Vector2D[S]): Vector2D[S] =
Vector2D[S](x: sc/v.x, y: sc/v.y)
proc `/`*[S](a, b: Vector2D[S]): Vector2D[S] =
proc `/`*[S](a, b: Vector2D[S]): Vector2D[S] =
Vector2D[S](x: a.x/b.x, y: a.y/b.y)
#proc vec[S](x, y: S): Vector2D[S]
proc vec[S](x, y: S): Vector2D[S] =