diff options
author | Joseph Poirier <jdpoirier@gmail.com> | 2015-01-02 21:47:09 -0600 |
---|---|---|
committer | Joseph Poirier <jdpoirier@gmail.com> | 2015-01-02 21:47:09 -0600 |
commit | efe183861cc8416872e6c1a44f642e6b03049616 (patch) | |
tree | 84fb6bbc5a4f81c1055db9d98492c133886fc846 /tests | |
parent | d15d9f41110a245b2b5a13bd8a882eeb79311acd (diff) | |
parent | 8f82205d12c7546b7369505b54d0157b4909fe6d (diff) | |
download | Nim-efe183861cc8416872e6c1a44f642e6b03049616.tar.gz |
Merge remote-tracking branch 'upstream/devel' into devel
Diffstat (limited to 'tests')
-rw-r--r-- | tests/generics/t1050.nim | 16 | ||||
-rw-r--r-- | tests/metatype/tsemistatic.nim | 8 | ||||
-rw-r--r-- | tests/metatype/tstaticparams.nim | 65 | ||||
-rw-r--r-- | tests/metatype/tusertypeclasses.nim | 27 | ||||
-rw-r--r-- | tests/misc/tvarious.nim | 108 |
5 files changed, 167 insertions, 57 deletions
diff --git a/tests/generics/t1050.nim b/tests/generics/t1050.nim new file mode 100644 index 000000000..a6f9a2482 --- /dev/null +++ b/tests/generics/t1050.nim @@ -0,0 +1,16 @@ +discard """ + msg: "int" + output: "4" +""" + +import typetraits + +type ArrayType[T] = distinct T + +proc arrayItem(a: ArrayType): auto = + static: echo(name(type(a).T)) + result = (type(a).T)(4) + +var arr: ArrayType[int] +echo arrayItem(arr) + diff --git a/tests/metatype/tsemistatic.nim b/tests/metatype/tsemistatic.nim index 0a003be03..a13175ba8 100644 --- a/tests/metatype/tsemistatic.nim +++ b/tests/metatype/tsemistatic.nim @@ -1,9 +1,15 @@ discard """ msg: "static 10\ndynamic\nstatic 20\n" output: "s\nd\nd\ns" - disabled: "true" """ +type + semistatic[T] = + static[T] or T + +template isStatic*(x): expr = + compiles(static(x)) + proc foo(x: semistatic[int]) = when isStatic(x): static: echo "static ", x diff --git a/tests/metatype/tstaticparams.nim b/tests/metatype/tstaticparams.nim index 6d7c569e0..e98a2871f 100644 --- a/tests/metatype/tstaticparams.nim +++ b/tests/metatype/tstaticparams.nim @@ -1,6 +1,6 @@ discard """ file: "tstaticparams.nim" - output: "abracadabra\ntest\n3\n15\n4\n2" + output: "abracadabra\ntest\n3\n15\n4\n2\nfloat\n3\nfloat\nyin\nyang" """ type @@ -56,3 +56,66 @@ type TTestSub[N: static[int]] = TTest[1, N] var z: TTestSub[2] echo z.high + +# issue 1049 +proc matrix_1*[M, N, T](mat: Matrix[M,N,T], a: array[N, int]) = discard +proc matrix_2*[M, N, T](mat: Matrix[M,N,T], a: array[N+1, int]) = discard + +proc matrix_3*[M, N: static[int]; T](mat: Matrix[M,N,T], a: array[N, int]) = discard +proc matrix_4*[M, N: static[int]; T](mat: Matrix[M,N,T], a: array[N+1, int]) = discard + +var + tmat: Matrix[4,4,int] + ar1: array[4, int] + ar2: array[5, int] + +matrix_1(tmat, ar1) +matrix_2(tmat, ar2) +matrix_3(tmat, ar1) +matrix_4(tmat, ar2) + +template reject(x): stmt = + static: assert(not compiles(x)) + +# test with arrays of wrong size +reject matrix_1(tmat, ar2) +reject matrix_2(tmat, ar1) +reject matrix_3(tmat, ar2) +reject matrix_4(tmat, ar1) + +# bug 1820 + +type + T1820_1[T; Y: static[int]] = object + bar: T + +proc intOrFloat*[Y](f: T1820_1[int, Y]) = echo "int" +proc intOrFloat*[Y](f: T1820_1[float, Y]) = echo "float" +proc threeOrFour*[T](f: T1820_1[T, 3]) = echo "3" +proc threeOrFour*[T](f: T1820_1[T, 4]) = echo "4" + +var foo_1: T1820_1[float, 3] + +foo_1.intOrFloat +foo_1.threeOrFour + +type + YinAndYang = enum + Yin, + Yang + + T1820_2[T; Y: static[YinAndYang]] = object + bar: T + +proc intOrFloat*[Y](f: T1820_2[int, Y]) = echo "int" +proc intOrFloat*[Y](f: T1820_2[float, Y]) = echo "float" +proc yinOrYang*[T](f: T1820_2[T, YinAndYang.Yin]) = echo "yin" +proc yinOrYang*[T](f: T1820_2[T, Yang]) = echo "yang" + +var foo_2: T1820_2[float, Yin] +var foo_3: T1820_2[float, YinAndYang.Yang] + +foo_2.intOrFloat +foo_2.yinOrYang +foo_3.yinOrYang + diff --git a/tests/metatype/tusertypeclasses.nim b/tests/metatype/tusertypeclasses.nim index 6e9e4934b..4e5e6221c 100644 --- a/tests/metatype/tusertypeclasses.nim +++ b/tests/metatype/tusertypeclasses.nim @@ -1,5 +1,13 @@ discard """ - output: "Sortable\nSortable\nContainer" + output: '''Sortable +Sortable +Container +true +true +false +false +false +''' """ import typetraits @@ -41,3 +49,20 @@ proc y(x: TObj): int = 10 proc testFoo(x: TFoo) = discard testFoo(TObj(x: 10)) +type + Matrix[Rows, Cols: static[int]; T] = generic M + M.M == Rows + M.N == Cols + M.T is T + + MyMatrix[M, N: static[int]; T] = object + data: array[M*N, T] + +var x: MyMatrix[3, 3, int] + +echo x is Matrix +echo x is Matrix[3, 3, int] +echo x is Matrix[3, 3, float] +echo x is Matrix[4, 3, int] +echo x is Matrix[3, 4, int] + diff --git a/tests/misc/tvarious.nim b/tests/misc/tvarious.nim index 434d25e48..8124b3fc7 100644 --- a/tests/misc/tvarious.nim +++ b/tests/misc/tvarious.nim @@ -1,67 +1,67 @@ -# Test various aspects +# Test various aspects # bug #572 var a=12345678901'u64 - + var x = (x: 42, y: (a: 8, z: 10)) echo x.y - -import - mvarious - -type - PA = ref TA - PB = ref TB - - TB = object - a: PA - - TA = object - b: TB - x: int - -proc getPA(): PA = - var - b: bool - b = not false - return nil + +import + mvarious + +type + PA = ref TA + PB = ref TB + + TB = object + a: PA + + TA = object + b: TB + x: int + +proc getPA(): PA = + var + b: bool + b = not false + return nil # bug #501 proc f(): int = 54 - -var - global: int - -var - s: string - i: int - r: TA - -r.b.a.x = 0 -global = global + 1 -exportme() -write(stdout, "Hallo wie heißt du? ") -write(stdout, getPA().x) -s = readLine(stdin) -i = 0 -while i < s.len: - if s[i] == 'c': write(stdout, "'c' in deinem Namen gefunden\n") - i = i + 1 - -write(stdout, "Du heißt " & s) + +var + global: int + +var + s: string + i: int + r: TA + +r.b.a.x = 0 +global = global + 1 +exportme() +write(stdout, "Hallo wie heißt du? ") +write(stdout, getPA().x) +s = readLine(stdin) +i = 0 +while i < s.len: + if s[i] == 'c': write(stdout, "'c' in deinem Namen gefunden\n") + i = i + 1 + +write(stdout, "Du heißt " & s) # bug #544 -when false: - # yay, fails again - type Bar [T; I:range] = array[I, T] - proc foo*[T; I:range](a, b: Bar[T, I]): Bar[T, I] = - when len(a) != 3: - # Error: constant expression expected - {.fatal:"Dimensions have to be 3".} - #... - block: - var a, b: Bar[int, 0..2] - discard foo(a, b) + +# yay, fails again +type Bar [T; I:range] = array[I, T] +proc foo*[T; I:range](a, b: Bar[T, I]): Bar[T, I] = + when len(a) != 3: + # Error: constant expression expected + {.fatal:"Dimensions have to be 3".} + #... +block: + var a, b: Bar[int, range[0..2]] + discard foo(a, b) # bug #1788 |