diff options
author | Adam Strzelecki <ono@java.pl> | 2015-09-04 23:04:32 +0200 |
---|---|---|
committer | Adam Strzelecki <ono@java.pl> | 2015-09-04 23:04:32 +0200 |
commit | e80465dacf50f260abec30ae57d37b298c93fd83 (patch) | |
tree | 393394f8353a4adb49f95e6f13da1fd41681b7b3 /tests/generics | |
parent | ac9c1cd6b980d4f00eeb52d1109d8e2c8cd21213 (diff) | |
download | Nim-e80465dacf50f260abec30ae57d37b298c93fd83.tar.gz |
tests: Trim .nim files trailing whitespace
via OSX: find . -name '*.nim' -exec sed -i '' -E 's/[[:space:]]+$//' {} +
Diffstat (limited to 'tests/generics')
-rw-r--r-- | tests/generics/t1056.nim | 2 | ||||
-rw-r--r-- | tests/generics/t1789.nim | 2 | ||||
-rw-r--r-- | tests/generics/tconfusing_arrow.nim | 2 | ||||
-rw-r--r-- | tests/generics/tdictdestruct.nim | 4 | ||||
-rw-r--r-- | tests/generics/texplicitgeneric1.nim | 24 | ||||
-rw-r--r-- | tests/generics/texplicitgeneric2.nim | 20 | ||||
-rw-r--r-- | tests/generics/tgeneric1.nim | 4 | ||||
-rw-r--r-- | tests/generics/tgenericdefaults.nim | 4 | ||||
-rw-r--r-- | tests/generics/tgenericmatcher.nim | 2 | ||||
-rw-r--r-- | tests/generics/tgenericmatcher2.nim | 2 | ||||
-rw-r--r-- | tests/generics/tgenericrefs.nim | 8 | ||||
-rw-r--r-- | tests/generics/tgenericshardcases.nim | 4 | ||||
-rw-r--r-- | tests/generics/tgenericvariant.nim | 2 | ||||
-rw-r--r-- | tests/generics/tinferredgenericprocs.nim | 2 | ||||
-rw-r--r-- | tests/generics/tthread_generic.nim | 4 | ||||
-rw-r--r-- | tests/generics/twrong_field_caching.nim | 10 | ||||
-rw-r--r-- | tests/generics/twrong_floatlit_type.nim | 46 |
17 files changed, 71 insertions, 71 deletions
diff --git a/tests/generics/t1056.nim b/tests/generics/t1056.nim index b1fe25894..de8bde8ef 100644 --- a/tests/generics/t1056.nim +++ b/tests/generics/t1056.nim @@ -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 diff --git a/tests/generics/t1789.nim b/tests/generics/t1789.nim index 188db88f6..c3fe336af 100644 --- a/tests/generics/t1789.nim +++ b/tests/generics/t1789.nim @@ -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] diff --git a/tests/generics/tconfusing_arrow.nim b/tests/generics/tconfusing_arrow.nim index 6a5a9d682..f63a874e0 100644 --- a/tests/generics/tconfusing_arrow.nim +++ b/tests/generics/tconfusing_arrow.nim @@ -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))) diff --git a/tests/generics/tdictdestruct.nim b/tests/generics/tdictdestruct.nim index 17ded4853..228d93e66 100644 --- a/tests/generics/tdictdestruct.nim +++ b/tests/generics/tdictdestruct.nim @@ -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") diff --git a/tests/generics/texplicitgeneric1.nim b/tests/generics/texplicitgeneric1.nim index d54044368..ac0197c1a 100644 --- a/tests/generics/texplicitgeneric1.nim +++ b/tests/generics/texplicitgeneric1.nim @@ -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) diff --git a/tests/generics/texplicitgeneric2.nim b/tests/generics/texplicitgeneric2.nim index 95461d023..c4af17b7b 100644 --- a/tests/generics/texplicitgeneric2.nim +++ b/tests/generics/texplicitgeneric2.nim @@ -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) = + +proc add*(d: PDict, k: TKey, v: TValue) = d.data.add((k, v)) - -#iterator items*(d: PDict): tuple[k: TKey, v: TValue] = + +#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) diff --git a/tests/generics/tgeneric1.nim b/tests/generics/tgeneric1.nim index 5d20a864b..5349f8f1d 100644 --- a/tests/generics/tgeneric1.nim +++ b/tests/generics/tgeneric1.nim @@ -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 diff --git a/tests/generics/tgenericdefaults.nim b/tests/generics/tgenericdefaults.nim index ad96f1851..a4c90a884 100644 --- a/tests/generics/tgenericdefaults.nim +++ b/tests/generics/tgenericdefaults.nim @@ -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: diff --git a/tests/generics/tgenericmatcher.nim b/tests/generics/tgenericmatcher.nim index edd0c4cf1..2edf46187 100644 --- a/tests/generics/tgenericmatcher.nim +++ b/tests/generics/tgenericmatcher.nim @@ -16,7 +16,7 @@ type min, max: int PMatcher[T] = ref TMatcher[T] -var +var m: PMatcher[int] diff --git a/tests/generics/tgenericmatcher2.nim b/tests/generics/tgenericmatcher2.nim index aa2f9dbb3..6832f80b7 100644 --- a/tests/generics/tgenericmatcher2.nim +++ b/tests/generics/tgenericmatcher2.nim @@ -12,7 +12,7 @@ type matcher: ref TMatcher[T] min, max: int -var +var m: ref TMatcher[int] diff --git a/tests/generics/tgenericrefs.nim b/tests/generics/tgenericrefs.nim index a44b96af9..245789caf 100644 --- a/tests/generics/tgenericrefs.nim +++ b/tests/generics/tgenericrefs.nim @@ -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 diff --git a/tests/generics/tgenericshardcases.nim b/tests/generics/tgenericshardcases.nim index e3b805db6..72a2f4ec2 100644 --- a/tests/generics/tgenericshardcases.nim +++ b/tests/generics/tgenericshardcases.nim @@ -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 diff --git a/tests/generics/tgenericvariant.nim b/tests/generics/tgenericvariant.nim index 0150cda8d..348d3da6e 100644 --- a/tests/generics/tgenericvariant.nim +++ b/tests/generics/tgenericvariant.nim @@ -1,4 +1,4 @@ -type +type TMaybe[T] = object case empty: bool of false: value: T diff --git a/tests/generics/tinferredgenericprocs.nim b/tests/generics/tinferredgenericprocs.nim index 12adfe965..5cbeabb94 100644 --- a/tests/generics/tinferredgenericprocs.nim +++ b/tests/generics/tinferredgenericprocs.nim @@ -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 diff --git a/tests/generics/tthread_generic.nim b/tests/generics/tthread_generic.nim index fdd11d9d1..d34b24628 100644 --- a/tests/generics/tthread_generic.nim +++ b/tests/generics/tthread_generic.nim @@ -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) diff --git a/tests/generics/twrong_field_caching.nim b/tests/generics/twrong_field_caching.nim index 595c58eb7..667ffbbe5 100644 --- a/tests/generics/twrong_field_caching.nim +++ b/tests/generics/twrong_field_caching.nim @@ -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! diff --git a/tests/generics/twrong_floatlit_type.nim b/tests/generics/twrong_floatlit_type.nim index 2db8b4353..c1830cd5a 100644 --- a/tests/generics/twrong_floatlit_type.nim +++ b/tests/generics/twrong_floatlit_type.nim @@ -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] = |