diff --git a/testament/categories.nim b/testament/categories.nim index 59ce70315a..429330677c 100644 --- a/testament/categories.nim +++ b/testament/categories.nim @@ -247,8 +247,7 @@ proc jsTests(r: var TResults, cat: Category, options: string) = "exception/texcsub", "exception/tfinally", "exception/tfinally2", "exception/tfinally3", "exception/tunhandledexc", - "actiontable/tactiontable", "method/tmultim1", - "method/tmultim3", "method/tmultim4", + "actiontable/tactiontable", "method/tmultimjs", "varres/tvarres0", "varres/tvarres3", "varres/tvarres4", "varres/tvartup", "misc/tints", "misc/tunsignedinc", "async/tjsandnativeasync"]: diff --git a/tests/ccgbugs/tcodegenbug1.nim b/tests/ccgbugs/tcodegenbug1.nim index 012a4de47e..ebdc571448 100644 --- a/tests/ccgbugs/tcodegenbug1.nim +++ b/tests/ccgbugs/tcodegenbug1.nim @@ -8,7 +8,7 @@ obj = (inner: (kind: Just, id: 7)) # bug #6960 -import future +import sugar type Kind = enum None, Just, Huge Inner = object diff --git a/tests/concepts/trandom_vars.nim b/tests/concepts/trandom_vars.nim index a236cebad1..861e876a7d 100644 --- a/tests/concepts/trandom_vars.nim +++ b/tests/concepts/trandom_vars.nim @@ -30,7 +30,7 @@ proc map[A, B](x: RandomVar[A], f: proc(a: A): B): ClosureVar[B] = result.f = inner -import future +import sugar proc fakeRandom(): Random = result.random = () => 0.5 diff --git a/tests/generics/tunique_type.nim b/tests/generics/tunique_type.nim index ccb367ac8a..1150dea49f 100644 --- a/tests/generics/tunique_type.nim +++ b/tests/generics/tunique_type.nim @@ -11,7 +11,7 @@ discard """ ## because it's more efficient than using procedure pointers and less ## verbose than defining a new callable type for every invocation of `map`. -import future +import sugar import macros import strutils diff --git a/tests/iter/tpermutations.nim b/tests/iter/tpermutations.nim index a3b3833231..5149eb9c2f 100644 --- a/tests/iter/tpermutations.nim +++ b/tests/iter/tpermutations.nim @@ -1,5 +1,5 @@ -import sequtils, future +import sequtils, sugar iterator permutations*[T](ys: openarray[T]): tuple[perm: seq[T], sign: int] = var diff --git a/tests/magics/t8693.nim b/tests/magics/t8693.nim deleted file mode 100644 index 71468116b9..0000000000 --- a/tests/magics/t8693.nim +++ /dev/null @@ -1,35 +0,0 @@ -discard """ - output: '''true -false -true -false -false -true -true -false -true -true -false -true -true -false -''' -""" - -type Foo = int | float - -proc bar(t1, t2: typedesc): bool = - echo (t1 is t2) - (t2 is t1) - -proc bar[T](x: T, t2: typedesc): bool = - echo (T is t2) - (t2 is T) - -echo bar(int, Foo) -echo bar(4, Foo) -echo bar(any, int) -echo bar(int, any) -echo bar(Foo, Foo) -echo bar(any, Foo) -echo bar(Foo, any) diff --git a/tests/magics/tlowhigh.nim b/tests/magics/tlowhigh.nim deleted file mode 100644 index 60ed13c993..0000000000 --- a/tests/magics/tlowhigh.nim +++ /dev/null @@ -1,24 +0,0 @@ -discard """ - file: "tlowhigh.nim" - output: "10" -""" -# Test the magic low() and high() procs - -type - myEnum = enum e1, e2, e3, e4, e5 - -var - a: array[myEnum, int] - -for i in low(a) .. high(a): - a[i] = 0 - -proc sum(a: openarray[int]): int = - result = 0 - for i in low(a)..high(a): - inc(result, a[i]) - -write(stdout, sum([1, 2, 3, 4])) -#OUT 10 - - diff --git a/tests/magics/tmagics.nim b/tests/magics/tmagics.nim new file mode 100644 index 0000000000..d13a036bdf --- /dev/null +++ b/tests/magics/tmagics.nim @@ -0,0 +1,45 @@ +discard """ + output: ''' +true +true +false +true +true +false +true +''' +""" + +block tlowhigh: + type myEnum = enum e1, e2, e3, e4, e5 + var a: array[myEnum, int] + + for i in low(a) .. high(a): + a[i] = 0 + + proc sum(a: openarray[int]): int = + result = 0 + for i in low(a)..high(a): + inc(result, a[i]) + + doAssert sum([1, 2, 3, 4]) == 10 + + +block t8693: + type Foo = int | float + + proc bar(t1, t2: typedesc): bool = + echo (t1 is t2) + (t2 is t1) + + proc bar[T](x: T, t2: typedesc): bool = + echo (T is t2) + (t2 is T) + + doAssert bar(int, Foo) == false + doAssert bar(4, Foo) == false + doAssert bar(any, int) + doAssert bar(int, any) == false + doAssert bar(Foo, Foo) + doAssert bar(any, Foo) + doAssert bar(Foo, any) == false diff --git a/tests/metatype/tautoproc.nim b/tests/metatype/tautoproc.nim deleted file mode 100644 index 2c8f6a3f71..0000000000 --- a/tests/metatype/tautoproc.nim +++ /dev/null @@ -1,22 +0,0 @@ -discard """ - output: "void" -""" - -# bug #898 - -import typetraits - -proc measureTime(e: auto) = - echo e.type.name - -proc generate(a: int): void = - discard - -proc runExample = - var builder: int = 0 - - measureTime: - builder.generate() - -measureTime: - discard diff --git a/tests/metatype/tautotypetrait.nim b/tests/metatype/tautotypetrait.nim deleted file mode 100644 index 84cd7b9f34..0000000000 --- a/tests/metatype/tautotypetrait.nim +++ /dev/null @@ -1,14 +0,0 @@ -discard """ - output: '''(Field0: "string", Field1: "string")''' -""" - -# 7528 -import macros -import typetraits - -macro bar*(n: untyped): typed = - result = newNimNode(nnkStmtList, n) - result.add(newCall("write", newIdentNode("stdout"), n)) - -proc foo0[T](): auto = return (T.name, T.name) -bar foo0[string]() diff --git a/tests/metatype/tcompilesregression.nim b/tests/metatype/tcompilesregression.nim deleted file mode 100644 index 489cd06d67..0000000000 --- a/tests/metatype/tcompilesregression.nim +++ /dev/null @@ -1,18 +0,0 @@ -discard """ - output: '''ok''' -""" - -# bug #5638 - -type X = object - a_impl: int - -proc a(x: X): int = - x.a_impl - -var x: X -assert(not compiles((block: - x.a = 1 -))) - -echo "ok" diff --git a/tests/metatype/tconstraints.nim b/tests/metatype/tconstraints.nim deleted file mode 100644 index 76e738a859..0000000000 --- a/tests/metatype/tconstraints.nim +++ /dev/null @@ -1,15 +0,0 @@ - - -proc myGenericProc[T: object|tuple|int|ptr|ref|distinct](x: T): string = - result = $x - -type - TMyObj = tuple[x, y: int] - -var - x: TMyObj - -assert myGenericProc(232) == "232" -assert myGenericProc(x) == "(x: 0, y: 0)" - - diff --git a/tests/metatype/tfieldaccessor.nim b/tests/metatype/tfieldaccessor.nim deleted file mode 100644 index 7054dd22b9..0000000000 --- a/tests/metatype/tfieldaccessor.nim +++ /dev/null @@ -1,17 +0,0 @@ -type - Test = object - x: int - case p: bool - of true: - a: int - else: - case q: bool - of true: - b: int - else: - discard - -proc f[T](t: typedesc[T]): int = - 1 - -assert Test.f == 1 diff --git a/tests/metatype/tissues.nim b/tests/metatype/tissues.nim new file mode 100644 index 0000000000..5c5380c9f4 --- /dev/null +++ b/tests/metatype/tissues.nim @@ -0,0 +1,150 @@ + + +import typetraits, macros + + +block t898: + proc measureTime(e: auto) = + echo e.type.name + + proc generate(a: int): void = + discard + + proc runExample = + var builder: int = 0 + + measureTime: + builder.generate() + + measureTime: + discard + + + +block t7528: + macro bar(n: untyped): typed = + result = newNimNode(nnkStmtList, n) + result.add(newCall("write", newIdentNode("stdout"), n)) + + proc foo0[T](): auto = return (T.name, T.name) + bar foo0[string]() + echo "" + + + +block t5638: + type X = object + a_impl: int + + proc a(x: X): int = + x.a_impl + + var x: X + assert(not compiles((block: + x.a = 1 + ))) + + + +block t3706: + type Modulo[M: static[int]] = distinct int + proc modulo(a: int, M: static[int]): Modulo[M] = Modulo[M](a %% M) + proc `+`[M: static[int]](a, b: Modulo[M]): Modulo[M] = (a.int + b.int).modulo(M) + proc `$`[M: static[int]](a: Modulo[M]): string = $(a.int) & " mod " & $(M) + + let + a = 3.modulo(7) + b = 5.modulo(7) + echo a + b + + + +block t3144: + type IntArray[N: static[int]] = array[N, int] + + proc `$`(a: IntArray): string = $(@(a)) + + proc `+=`[N: static[int]](a: var IntArray[N], b: IntArray[N]) = + for i in 0 ..< N: + a[i] += b[i] + + proc zeros(N: static[int]): IntArray[N] = + for i in 0 ..< N: + result[i] = 0 + + proc ones(N: static[int]): IntArray[N] = + for i in 0 ..< N: + result[i] = 1 + + proc sum[N: static[int]](vs: seq[IntArray[N]]): IntArray[N] = + result = zeros(N) + for v in vs: + result += v + + echo sum(@[ones(5), ones(5)]) + + + +block t6533: + type Value[T: static[int]] = typedesc + proc foo(order: Value[1]): auto = 0 + doAssert foo(Value[1]) == 0 + + + +block t2266: + proc impl(op: static[int]) = echo "impl 1 called" + proc impl(op: static[int], init: int) = echo "impl 2 called" + + macro wrapper2: untyped = newCall(bindSym"impl", newLit(0), newLit(0)) + + wrapper2() # Code generation for this fails. + + + +block t602: + type + TTest = object + TTest2 = object + TFoo = TTest | TTest2 + + proc f(src: ptr TFoo, dst: ptr TFoo) = + echo("asd") + + var x: TTest + f(addr x, addr x) + + + +block t3338: + type + Base[T] = Foo[T] | Bar[T] + + Foo[T] = ref object + x: T + + Bar[T] = ref object + x: T + + proc test[T](ks: Foo[T], x, y: T): T = + echo("Foo") + return x + y + ks.x + + proc test[T](ks: Bar[T], x, y: T): T = + echo("Bar") + return x + + proc add[T](ksa: Base[T]) = + var test = ksa.test(5, 10) + ksa.x = test + + var t1 = Foo[int32]() + t1.add() + doAssert t1.x == 15 + + var t2 = Bar[int32]() + t2.add() + doAssert t2.x == 5 + + + diff --git a/tests/metatype/tmodulo.nim b/tests/metatype/tmodulo.nim deleted file mode 100644 index 08bcc7935e..0000000000 --- a/tests/metatype/tmodulo.nim +++ /dev/null @@ -1,20 +0,0 @@ -discard """ - output: '''1 mod 7''' -""" - -# bug #3706 - -type Modulo[M: static[int]] = distinct int - -proc modulo(a: int, M: static[int]): Modulo[M] = Modulo[M](a %% M) - -proc `+`[M: static[int]](a, b: Modulo[M]): Modulo[M] = (a.int + b.int).modulo(M) - -proc `$`*[M: static[int]](a: Modulo[M]): string = $(a.int) & " mod " & $(M) - -when isMainModule: - let - a = 3.modulo(7) - b = 5.modulo(7) - echo a + b - diff --git a/tests/metatype/tprocbothmeta.nim b/tests/metatype/tprocbothmeta.nim deleted file mode 100644 index ba061dda2f..0000000000 --- a/tests/metatype/tprocbothmeta.nim +++ /dev/null @@ -1,10 +0,0 @@ - -proc myFun[A](x: A): auto = - result = float(x+10) - -proc myMap[T,S](sIn: seq[T], f: proc (q: T): S): seq[S] = - result = newSeq[S](sIn.len) - for i in 0.. prefer unit, thing! +test(b, c) +collide(a, b) +staticCollide(a, b) + + + +# tmultim6 +type + Thing = object {.inheritable.} + Unit[T] = object of Thing + x: T + Particle = object of Thing + a, b: int + +method collide(a, b: Thing) {.base, inline.} = + quit "to override!" + +method collide[T](a: Thing, b: Unit[T]) {.inline.} = + write stdout, "collide: thing, unit | " + +method collide[T](a: Unit[T], b: Thing) {.inline.} = + write stdout, "collide: unit, thing | " + +proc test(a, b: Thing) {.inline.} = + collide(a, b) + +var + aaa: Thing + bbb, ccc: Unit[string] +collide(bbb, Thing(ccc)) +test(bbb, ccc) +collide(aaa, bbb) +echo "" + + + +# tmethods1 +method somethin(obj: RootObj) {.base.} = + echo "do nothing" + +type + TNode* = object {.inheritable.} + PNode* = ref TNode + + PNodeFoo* = ref object of TNode + + TSomethingElse = object + PSomethingElse = ref TSomethingElse + +method foo(a: PNode, b: PSomethingElse) {.base.} = discard +method foo(a: PNodeFoo, b: PSomethingElse) = discard + +var o: RootObj +o.somethin() diff --git a/tests/method/tmultim1.nim b/tests/method/tmultim1.nim deleted file mode 100644 index 010468a5bf..0000000000 --- a/tests/method/tmultim1.nim +++ /dev/null @@ -1,29 +0,0 @@ -discard """ - file: "tmultim1.nim" - output: "7" -""" -# Test multi methods - -type - Expression = ref object {.inheritable.} - Literal = ref object of Expression - x: int - PlusExpr = ref object of Expression - a, b: Expression - -method eval(e: Expression): int {.base.} = quit "to override!" -method eval(e: Literal): int = return e.x -method eval(e: PlusExpr): int = return eval(e.a) + eval(e.b) - -proc newLit(x: int): Literal = - new(result) - result.x = x - -proc newPlus(a, b: Expression): PlusExpr = - new(result) - result.a = a - result.b = b - -echo eval(newPlus(newPlus(newLit(1), newLit(2)), newLit(4))) #OUT 7 - - diff --git a/tests/method/tmultim2.nim b/tests/method/tmultim2.nim deleted file mode 100644 index 98a08b1cbd..0000000000 --- a/tests/method/tmultim2.nim +++ /dev/null @@ -1,39 +0,0 @@ -discard """ - file: "tmultim2.nim" - output: '''collide: unit, thing -collide: unit, thing -collide: thing, unit -collide: thing, thing''' -""" -# Test multi methods - -type - TThing = object {.inheritable.} - TUnit = object of TThing - x: int - TParticle = object of TThing - a, b: int - -method collide(a, b: TThing) {.base, inline.} = - echo "collide: thing, thing" - -method collide(a: TThing, b: TUnit) {.inline.} = - echo "collide: thing, unit" - -method collide(a: TUnit, b: TThing) {.inline.} = - echo "collide: unit, thing" - -proc test(a, b: TThing) {.inline.} = - collide(a, b) - -proc staticCollide(a, b: TThing) {.inline.} = - procCall collide(a, b) - - -var - a: TThing - b, c: TUnit -collide(b, c) # ambiguous (unit, thing) or (thing, unit)? -> prefer unit, thing! -test(b, c) -collide(a, b) -staticCollide(a, b) diff --git a/tests/method/tmultim3.nim b/tests/method/tmultim3.nim deleted file mode 100644 index 373c84c0ec..0000000000 --- a/tests/method/tmultim3.nim +++ /dev/null @@ -1,20 +0,0 @@ -discard """ - file: "tmultim3.nim" - output: "Hi derived!" -""" -import mmultim3 - -type - TBObj* = object of TObj - - -method test123(a : ref TBObj) = - echo("Hi derived!") - -var a : ref TBObj -new(a) -myObj = a -testMyObj() - - - diff --git a/tests/method/tmultim4.nim b/tests/method/tmultim4.nim deleted file mode 100644 index a1d65d570a..0000000000 --- a/tests/method/tmultim4.nim +++ /dev/null @@ -1,47 +0,0 @@ -discard """ - file: "tmultim4.nim" - output: "hello" -""" -type - Test = object of RootObj - -method doMethod(a: ref RootObj) {.base, raises: [IoError].} = - quit "override" - -method doMethod(a: ref Test) = - echo "hello" - if a == nil: - raise newException(IoError, "arg") - -proc doProc(a: ref Test) = - echo "hello" - -proc newTest(): ref Test = - new(result) - -var s:ref Test = newTest() - - -#doesn't work -for z in 1..4: - s.doMethod() - break - -#works -#for z in 1..4: -# s.doProc() -# break - -#works -#while true: -# s.doMethod() -# break - -#works -#while true: -# s.doProc() -# break - - - - diff --git a/tests/method/tmultim6.nim b/tests/method/tmultim6.nim deleted file mode 100644 index 2c622b8327..0000000000 --- a/tests/method/tmultim6.nim +++ /dev/null @@ -1,30 +0,0 @@ -discard """ - output: "collide: unit, thing | collide: unit, thing | collide: thing, unit |" -""" -# Test multi methods - -type - Thing = object {.inheritable.} - Unit[T] = object of Thing - x: T - Particle = object of Thing - a, b: int - -method collide(a, b: Thing) {.base, inline.} = - quit "to override!" - -method collide[T](a: Thing, b: Unit[T]) {.inline.} = - write stdout, "collide: thing, unit | " - -method collide[T](a: Unit[T], b: Thing) {.inline.} = - write stdout, "collide: unit, thing | " - -proc test(a, b: Thing) {.inline.} = - collide(a, b) - -var - a: Thing - b, c: Unit[string] -collide(b, Thing(c)) -test(b, c) -collide(a, b) diff --git a/tests/method/tmultim7.nim b/tests/method/tmultim7.nim deleted file mode 100644 index 7a88596792..0000000000 --- a/tests/method/tmultim7.nim +++ /dev/null @@ -1,48 +0,0 @@ - -# bug #3431 - -type - Lexer = object - buf*: string - pos*: int - lastchar*: char - - ASTNode = object - -method init*(self: var Lexer; buf: string) {.base.} = - self.buf = buf - self.pos = 0 - self.lastchar = self.buf[0] - -method init*(self: var ASTNode; val: string) = - discard - - -# bug #3370 -type - RefTestA*[T] = ref object of RootObj - data*: T - -method tester*[S](self: S): bool = - true - -type - RefTestB* = RefTestA[(string, int)] - -method tester*(self: RefTestB): bool = - true - -type - RefTestC = RefTestA[string] - -method tester*(self: RefTestC): bool = - false - - -# bug #3468 - -type X = ref object of RootObj -type Y = ref object of RootObj - -method draw*(x: X) {.base.} = discard -method draw*(y: Y) {.base.} = discard diff --git a/tests/method/tmultim8.nim b/tests/method/tmultim8.nim deleted file mode 100644 index 0d067b668b..0000000000 --- a/tests/method/tmultim8.nim +++ /dev/null @@ -1,19 +0,0 @@ - -# bug #3550 - -type - BaseClass = ref object of RootObj - Class1 = ref object of BaseClass - Class2 = ref object of BaseClass - -method test(obj: Class1, obj2: BaseClass) = - discard - -method test(obj: Class2, obj2: BaseClass) = - discard - -var obj1 = Class1() -var obj2 = Class2() - -obj1.test(obj2) -obj2.test(obj1) diff --git a/tests/method/tmultimjs.nim b/tests/method/tmultimjs.nim new file mode 100644 index 0000000000..9dcfc0dcc8 --- /dev/null +++ b/tests/method/tmultimjs.nim @@ -0,0 +1,72 @@ +discard """ + output: ''' +7 +Hi derived! +hello +''' +""" + + +# tmultim1 +type + Expression = ref object {.inheritable.} + Literal = ref object of Expression + x: int + PlusExpr = ref object of Expression + a, b: Expression + +method eval(e: Expression): int {.base.} = quit "to override!" +method eval(e: Literal): int = return e.x +method eval(e: PlusExpr): int = return eval(e.a) + eval(e.b) + +proc newLit(x: int): Literal = + new(result) + result.x = x + +proc newPlus(a, b: Expression): PlusExpr = + new(result) + result.a = a + result.b = b + +echo eval(newPlus(newPlus(newLit(1), newLit(2)), newLit(4))) #OUT 7 + + + +# tmultim3 +import mmultim3 + +type TBObj* = object of TObj + +method test123(a : ref TBObj) = + echo("Hi derived!") + +var aa: ref TBObj +new(aa) +myObj = aa +testMyObj() + + + +# tmultim4 +type Test = object of RootObj + +method doMethod(a: ref RootObj) {.base, raises: [IoError].} = + quit "override" + +method doMethod(a: ref Test) = + echo "hello" + if a == nil: + raise newException(IoError, "arg") + +proc doProc(a: ref Test) = + echo "hello" + +proc newTest(): ref Test = + new(result) + +var s:ref Test = newTest() + +#doesn't work +for z in 1..4: + s.doMethod() + break \ No newline at end of file diff --git a/tests/method/trecmeth.nim b/tests/method/trecmeth.nim deleted file mode 100644 index ac0a1e977c..0000000000 --- a/tests/method/trecmeth.nim +++ /dev/null @@ -1,22 +0,0 @@ -# Note: We only compile this to verify that code generation -# for recursive methods works, no code is being executed - -type - Obj = ref object of RootObj - -# Mutual recursion - -method alpha(x: Obj) {.base.} -method beta(x: Obj) {.base.} - -method alpha(x: Obj) = - beta(x) - -method beta(x: Obj) = - alpha(x) - -# Simple recursion - -method gamma(x: Obj) {.base.} = - gamma(x) - diff --git a/tests/method/tsimmeth.nim b/tests/method/tsimmeth.nim deleted file mode 100644 index a057c35b7f..0000000000 --- a/tests/method/tsimmeth.nim +++ /dev/null @@ -1,14 +0,0 @@ -discard """ - file: "tsimmeth.nim" - output: "HELLO WORLD!" -""" -# Test method simulation - -import strutils - -var x = "hello world!".toLowerAscii.toUpperAscii -x.echo() -#OUT HELLO WORLD! - - - diff --git a/tests/method/tvarious.nim b/tests/method/tvarious.nim new file mode 100644 index 0000000000..fd022717bb --- /dev/null +++ b/tests/method/tvarious.nim @@ -0,0 +1,83 @@ +discard """ + output: ''' +do nothing +HELLO WORLD! +''' +""" + + +# tmethods1 +method somethin(obj: RootObj) {.base.} = + echo "do nothing" + +type + TNode* = object {.inheritable.} + PNode* = ref TNode + + PNodeFoo* = ref object of TNode + + TSomethingElse = object + PSomethingElse = ref TSomethingElse + +method foo(a: PNode, b: PSomethingElse) {.base.} = discard +method foo(a: PNodeFoo, b: PSomethingElse) = discard + +var o: RootObj +o.somethin() + + + +# tmproto +type + Obj1 = ref object {.inheritable.} + Obj2 = ref object of Obj1 + +method beta(x: Obj1): int {.base.} + +proc delta(x: Obj2): int = + beta(x) + +method beta(x: Obj2): int + +proc alpha(x: Obj1): int = + beta(x) + +method beta(x: Obj1): int = 1 +method beta(x: Obj2): int = 2 + +proc gamma(x: Obj1): int = + beta(x) + +doAssert alpha(Obj1()) == 1 +doAssert gamma(Obj1()) == 1 +doAssert alpha(Obj2()) == 2 +doAssert gamma(Obj2()) == 2 +doAssert delta(Obj2()) == 2 + + + +# tsimmeth +import strutils +var x = "hello world!".toLowerAscii.toUpperAscii +x.echo() + + + +# trecmeth +# Note: We only compile this to verify that code generation +# for recursive methods works, no code is being executed +type Obj = ref object of RootObj + +# Mutual recursion +method alpha(x: Obj) {.base.} +method beta(x: Obj) {.base.} + +method alpha(x: Obj) = + beta(x) + +method beta(x: Obj) = + alpha(x) + +# Simple recursion +method gamma(x: Obj) {.base.} = + gamma(x) diff --git a/tests/objects/tinherentedvalues.nim b/tests/objects/tinherentedvalues.nim deleted file mode 100644 index 7d4d7d23e6..0000000000 --- a/tests/objects/tinherentedvalues.nim +++ /dev/null @@ -1,53 +0,0 @@ -discard """ - output: '''tbObj of TC true -true -5''' -""" - -# bug #1053 -type - TA = object of RootObj - a: int - - TB = object of TA - b: int - - TC = object of TB - c: int - -proc test(p: TA) = - #echo "p of TB ", p of TB - if p of TB: - #var tbObj = TB(p) - - # tbObj is actually no longer compatible with TC: - echo "tbObj of TC ", p of TC - -var v = TC() -v.a = 1 -v.b = 2 -v.c = 3 -test(v) - - -# bug #924 -type - MyObject = object of RootObj - x: int - -var - asd: MyObject - -proc isMyObject(obj: RootObj) = - echo obj of MyObject - if obj of MyObject: - let a = MyObject(obj) - echo a.x - -asd.x = 5 - -#var asdCopy = RootObj(asd) -#echo asdCopy of MyObject - -isMyObject(asd) -#isMyObject(asdCopy) diff --git a/tests/objects/tinherit_from_generic.nim b/tests/objects/tinherit_from_generic.nim deleted file mode 100644 index 6e0e929ce0..0000000000 --- a/tests/objects/tinherit_from_generic.nim +++ /dev/null @@ -1,13 +0,0 @@ -discard """ - output: '''true''' -""" - -# bug #4673 -type - BaseObj[T] = ref object of RootObj - SomeObj = ref object of BaseObj[int] - -proc doSomething[T](o: BaseObj[T]) = - echo "true" -var o = new(SomeObj) -o.doSomething() # Error: cannot instantiate: 'T' diff --git a/tests/objects/tissues.nim b/tests/objects/tissues.nim new file mode 100644 index 0000000000..fddfff7d51 --- /dev/null +++ b/tests/objects/tissues.nim @@ -0,0 +1,117 @@ +discard """ + output: ''' +tbObj of TC true +true +5 +true +is Nil false +''' +""" + + +block t1053: + type + TA = object of RootObj + a: int + TB = object of TA + b: int + TC = object of TB + c: int + + proc test(p: TA) = + if p of TB: + echo "tbObj of TC ", p of TC + + var v = TC() + v.a = 1 + v.b = 2 + v.c = 3 + test(v) + + + +block t924: + type + MyObject = object of RootObj + x: int + var asd: MyObject + + proc isMyObject(obj: RootObj) = + echo obj of MyObject + if obj of MyObject: + let a = MyObject(obj) + echo a.x + + asd.x = 5 + isMyObject(asd) + + + +block t4673: + type + BaseObj[T] = ref object of RootObj + SomeObj = ref object of BaseObj[int] + + proc doSomething[T](o: BaseObj[T]) = + echo "true" + var o = new(SomeObj) + o.doSomething() # Error: cannot instantiate: 'T' + + + +block t1658: + type + Loop = ref object + onBeforeSelect: proc (L: Loop) + + var L: Loop + new L + L.onBeforeSelect = proc (bar: Loop) = + echo "is Nil ", bar.isNil + + L.onBeforeSelect(L) + + + +block t2508: + type + GenericNodeObj[T] = ref object + obj: T + Node = ref object + children: seq[Node] + parent: Node + nodeObj: GenericNodeObj[int] + + proc newNode(nodeObj: GenericNodeObj): Node = + result = Node(nodeObj: nodeObj) + newSeq(result.children, 10) + + var genericObj = GenericNodeObj[int]() + var myNode = newNode(genericObj) + + + +block t2540: + type + BaseSceneNode[T] = ref object of RootObj + children: seq[BaseSceneNode[T]] + parent: BaseSceneNode[T] + SceneNode[T] = ref object of BaseSceneNode[T] + SomeObj = ref object + + proc newSceneNode[T](): SceneNode[T] = + new result + result.children = @[] + + var aNode = newSceneNode[SomeObj]() + + +block t3038: + type + Data[T] = ref object of RootObj + data: T + Type = ref object of RootObj + SubType[T] = ref object of Type + data: Data[T] + SubSubType = ref object of SubType + SubSubSubType = ref object of SubSubType diff --git a/tests/objects/tobject2.nim b/tests/objects/tobject2.nim deleted file mode 100644 index a492968438..0000000000 --- a/tests/objects/tobject2.nim +++ /dev/null @@ -1,21 +0,0 @@ -# Tests the object implementation - -type - TPoint2d {.inheritable.} = object - x, y: int - - TPoint3d = object of TPoint2d - z: int # added a field - -proc getPoint( p: var TPoint2d) = - {.breakpoint.} - writeLine(stdout, p.x) - -var - p: TPoint3d - -TPoint2d(p).x = 34 -p.y = 98 -p.z = 343 - -getPoint(p) diff --git a/tests/objects/tobjloop.nim b/tests/objects/tobjloop.nim deleted file mode 100644 index 9fea1e2fb9..0000000000 --- a/tests/objects/tobjloop.nim +++ /dev/null @@ -1,15 +0,0 @@ -discard """ - output: "is Nil false" -""" -# bug #1658 - -type - Loop* = ref object - onBeforeSelect*: proc (L: Loop) - -var L: Loop -new L -L.onBeforeSelect = proc (bar: Loop) = - echo "is Nil ", bar.isNil - -L.onBeforeSelect(L) diff --git a/tests/objects/tofopr.nim b/tests/objects/tofopr.nim deleted file mode 100644 index ab28545711..0000000000 --- a/tests/objects/tofopr.nim +++ /dev/null @@ -1,26 +0,0 @@ -discard """ - file: "tofopr.nim" - output: "falsetrue" -""" -# Test is operator - -type - TMyType = object {.inheritable.} - len: int - data: string - - TOtherType = object of TMyType - -proc p(x: TMyType): bool = - return x of TOtherType - -var - m: TMyType - n: TOtherType - -write(stdout, p(m)) -write(stdout, p(n)) - -#OUT falsetrue - - diff --git a/tests/objects/toop.nim b/tests/objects/toop.nim deleted file mode 100644 index 4bd3998f3f..0000000000 --- a/tests/objects/toop.nim +++ /dev/null @@ -1,21 +0,0 @@ -discard """ - output: "b" -""" - -type - TA = object of RootObj - x, y: int - - TB = object of TA - z: int - - TC = object of TB - whatever: string - -proc p(a: var TA) = echo "a" -proc p(b: var TB) = echo "b" - -var c: TC - -p(c) - diff --git a/tests/objects/trefobjsyntax.nim b/tests/objects/trefobjsyntax.nim deleted file mode 100644 index 9b48de718a..0000000000 --- a/tests/objects/trefobjsyntax.nim +++ /dev/null @@ -1,27 +0,0 @@ -discard """ - output: '''wohoo -baz''' -""" - -# Test to ensure the popular 'ref T' syntax works everywhere - -type - Foo = object - a, b: int - s: string - - FooBar = object of RootObj - n, m: string - Baz = object of FooBar - -proc invoke(a: ref Baz) = - echo "baz" - -# check object construction: -let x = (ref Foo)(a: 0, b: 45, s: "wohoo") -echo x.s - -var y: ref FooBar = (ref Baz)(n: "n", m: "m") - -invoke((ref Baz)(y)) - diff --git a/tests/objects/trefobjsyntax2.nim b/tests/objects/trefobjsyntax2.nim deleted file mode 100644 index 8ee209cc75..0000000000 --- a/tests/objects/trefobjsyntax2.nim +++ /dev/null @@ -1,19 +0,0 @@ -# bug #2508 - -type - GenericNodeObj[T] = ref object - obj: T - - Node* = ref object - children*: seq[Node] - parent*: Node - - nodeObj*: GenericNodeObj[int] - -proc newNode*(nodeObj: GenericNodeObj): Node = - result = Node(nodeObj: nodeObj) - newSeq(result.children, 10) - -var genericObj = GenericNodeObj[int]() - -var myNode = newNode(genericObj) diff --git a/tests/objects/trefobjsyntax3.nim b/tests/objects/trefobjsyntax3.nim deleted file mode 100644 index 2d466eedae..0000000000 --- a/tests/objects/trefobjsyntax3.nim +++ /dev/null @@ -1,28 +0,0 @@ -# bug #2540 - -type - BaseSceneNode[T] = ref object of RootObj - children*: seq[BaseSceneNode[T]] - parent*: BaseSceneNode[T] - - SceneNode[T] = ref object of BaseSceneNode[T] - - SomeObj = ref object - -proc newSceneNode[T](): SceneNode[T] = - new result - result.children = @[] - -var aNode = newSceneNode[SomeObj]() - - -# bug #3038 - -type - Data[T] = ref object of RootObj - data: T - Type = ref object of RootObj - SubType[T] = ref object of Type - data: Data[T] - SubSubType = ref object of SubType - SubSubSubType = ref object of SubSubType diff --git a/tests/objects/tvarious.nim b/tests/objects/tvarious.nim new file mode 100644 index 0000000000..504681b99f --- /dev/null +++ b/tests/objects/tvarious.nim @@ -0,0 +1,87 @@ +discard """ + output: ''' +34 +b +wohoo +baz +''' +""" + + +block tobject2: + # Tests the object implementation + type + TPoint2d {.inheritable.} = object + x, y: int + TPoint3d = object of TPoint2d + z: int # added a field + + proc getPoint( p: var TPoint2d) = + {.breakpoint.} + writeLine(stdout, p.x) + + var p: TPoint3d + + TPoint2d(p).x = 34 + p.y = 98 + p.z = 343 + + getPoint(p) + + + +block tofopr: + type + TMyType = object {.inheritable.} + len: int + data: string + + TOtherType = object of TMyType + + proc p(x: TMyType): bool = + return x of TOtherType + + var + m: TMyType + n: TOtherType + + doAssert p(m) == false + doAssert p(n) + + + +block toop: + type + TA = object of RootObj + x, y: int + TB = object of TA + z: int + TC = object of TB + whatever: string + + proc p(a: var TA) = echo "a" + proc p(b: var TB) = echo "b" + + var c: TC + p(c) + + + +block tfefobjsyntax: + type + Foo = object + a, b: int + s: string + FooBar = object of RootObj + n, m: string + Baz = object of FooBar + + proc invoke(a: ref Baz) = + echo "baz" + + # check object construction: + let x = (ref Foo)(a: 0, b: 45, s: "wohoo") + echo x.s + + var y: ref FooBar = (ref Baz)(n: "n", m: "m") + invoke((ref Baz)(y)) diff --git a/tests/overload/timport.nim b/tests/overload/timport.nim deleted file mode 100644 index 8ea65e54d5..0000000000 --- a/tests/overload/timport.nim +++ /dev/null @@ -1,7 +0,0 @@ -# issue 4675 -import importA # comment this out to make it work -import importB - -var x: Foo[float] -var y: Foo[float] -let r = t1(x) + t2(y) diff --git a/tests/overload/tissue4475.nim b/tests/overload/tissue4475.nim deleted file mode 100644 index 34618cac57..0000000000 --- a/tests/overload/tissue4475.nim +++ /dev/null @@ -1,6 +0,0 @@ -# Bug: https://github.com/nim-lang/Nim/issues/4475 -# Fix: https://github.com/nim-lang/Nim/pull/4477 - -proc test(x: varargs[string], y: int) = discard - -test(y = 1) diff --git a/tests/overload/tissues.nim b/tests/overload/tissues.nim new file mode 100644 index 0000000000..7980f51a9c --- /dev/null +++ b/tests/overload/tissues.nim @@ -0,0 +1,185 @@ +discard """ + output: ''' +Version 2 was called. +This has the highest precedence. +This has the second-highest precedence. +This has the lowest precedence. +baseobj == +true +even better! == +true +done extraI=0 +test 0 complete, loops=0 +done extraI=1 +test 1.0 complete, loops=1 +done extraI=0 +done extraI passed 0 +test no extra complete, loops=2 +1 +''' +""" + + +# issue 4675 +import importA # comment this out to make it work +import importB + +var x: Foo[float] +var y: Foo[float] +let r = t1(x) + t2(y) + + + +# Bug: https://github.com/nim-lang/Nim/issues/4475 +# Fix: https://github.com/nim-lang/Nim/pull/4477 +proc test(x: varargs[string], y: int) = discard +test(y = 1) + + + +# bug #2220 +when true: + type A[T] = object + type B = A[int] + + proc q[X](x: X) = + echo "Version 1 was called." + + proc q(x: B) = + echo "Version 2 was called." + + q(B()) # This call reported as ambiguous. + + + +# bug #2219 +template testPred(a: untyped) = + block: + type A = object of RootObj + type B = object of A + type SomeA = A|A # A hack to make "A" a typeclass. + + when a >= 3: + proc p[X: A](x: X) = + echo "This has the highest precedence." + when a == 2: + proc p[X: SomeA](x: X) = + echo "This has the second-highest precedence." + when a >= 1: + proc p[X](x: X) = + echo "This has the lowest precedence." + + p(B()) + +testPred(3) +testPred(2) +testPred(1) + + + +# bug #6526 +type + BaseObj = ref object of RootObj + DerivedObj = ref object of BaseObj + OtherDerivate = ref object of BaseObj + +proc `==`*[T1, T2: BaseObj](a: T1, b: T2): bool = + echo "baseobj ==" + return true + +let a = DerivedObj() +let b = DerivedObj() +echo a == b + +proc `==`*[T1, T2: OtherDerivate](a: T1, b: T2): bool = + echo "even better! ==" + return true + +let a2 = OtherDerivate() +let b2 = OtherDerivate() +echo a2 == b2 + + + +# bug #2481 +import math + +template test(loopCount: int, extraI: int, testBody: untyped): typed = + block: + for i in 0..loopCount-1: + testBody + echo "done extraI=", extraI + +template test(loopCount: int, extraF: float, testBody: untyped): typed = + block: + test(loopCount, round(extraF).int, testBody) + +template test(loopCount: int, testBody: untyped): typed = + block: + test(loopCount, 0, testBody) + echo "done extraI passed 0" + +when isMainModule: + var + loops = 0 + + test 0, 0: + loops += 1 + echo "test 0 complete, loops=", loops + + test 1, 1.0: + loops += 1 + echo "test 1.0 complete, loops=", loops + + when true: + # when true we get the following compile time error: + # b.nim(35, 6) Error: expression 'loops += 1' has no type (or is ambiguous) + loops = 0 + test 2: + loops += 1 + echo "test no extra complete, loops=", loops + + + + +# bug #2229 +type + Type1 = object + id: int + Type2 = object + id: int + +proc init(self: var Type1, a: int, b: ref Type2) = + echo "1" + +proc init(self: var Type2, a: int) = + echo """ + Works when this proc commented out + Otherwise error: + test.nim(14, 4) Error: ambiguous call; both test.init(self: var Type1, a: int, b: ref Type2) and test.init(self: var Type1, a: int, b: ref Type2) match for: (Type1, int literal(1), ref Type2) + """ + +var aa: Type1 +init(aa, 1, ( + var bb = new(Type2); + bb +)) + + + +# bug #4545 +type + SomeObject = object + a: int + AbstractObject = object + objet: ptr SomeObject + +proc convert(this: var SomeObject): AbstractObject = + AbstractObject(objet: this.addr) + +proc varargProc(args: varargs[AbstractObject, convert]): int = + for arg in args: + result += arg.objet.a + +var obj = SomeObject(a: 17) +discard varargProc(obj) diff --git a/tests/overload/toverl2.nim b/tests/overload/toverl2.nim deleted file mode 100644 index 54714ac1b2..0000000000 --- a/tests/overload/toverl2.nim +++ /dev/null @@ -1,33 +0,0 @@ -discard """ - file: "toverl2.nim" - output: "true012innertrue" -""" -# Test new overloading resolution rules - -import strutils - -proc toverl2(x: int): string = return $x -proc toverl2(x: bool): string = return $x - -iterator toverl2(x: int): int = - var res = 0 - while res < x: - yield res - inc(res) - -var - pp: proc (x: bool): string {.nimcall.} = toverl2 - -stdout.write(pp(true)) - -for x in toverl2(3): - stdout.write(toverl2(x)) - -block: - proc toverl2(x: int): string = return "inner" - stdout.write(toverl2(5)) - stdout.write(true) - -stdout.write("\n") -#OUT true012innertrue - diff --git a/tests/overload/toverl3.nim b/tests/overload/toverl3.nim deleted file mode 100644 index 92cfc150d8..0000000000 --- a/tests/overload/toverl3.nim +++ /dev/null @@ -1,20 +0,0 @@ -discard """ - file: "toverl3.nim" - output: '''m1 -tup1''' -""" - -# Tests more specific generic match: - -proc m[T](x: T) = echo "m2" -proc m[T](x: var ref T) = echo "m1" - -proc tup[S, T](x: tuple[a: S, b: ref T]) = echo "tup1" -proc tup[S, T](x: tuple[a: S, b: T]) = echo "tup2" - -var - obj: ref int - tu: tuple[a: int, b: ref bool] - -m(obj) -tup(tu) diff --git a/tests/overload/toverprc.nim b/tests/overload/toverprc.nim deleted file mode 100644 index 9be2203f61..0000000000 --- a/tests/overload/toverprc.nim +++ /dev/null @@ -1,45 +0,0 @@ -discard """ - output: '''another number: 123 -yay''' -""" - -# Test overloading of procs when used as function pointers - -import strutils, sequtils - -proc parseInt(x: float): int {.noSideEffect.} = discard -proc parseInt(x: bool): int {.noSideEffect.} = discard -proc parseInt(x: float32): int {.noSideEffect.} = discard -proc parseInt(x: int8): int {.noSideEffect.} = discard -proc parseInt(x: File): int {.noSideEffect.} = discard -proc parseInt(x: char): int {.noSideEffect.} = discard -proc parseInt(x: int16): int {.noSideEffect.} = discard - -proc parseInt[T](x: T): int = echo x; 34 - -type - TParseInt = proc (x: string): int {.noSideEffect.} - -var - q = TParseInt(parseInt) - p: TParseInt = parseInt - -proc takeParseInt(x: proc (y: string): int {.noSideEffect.}): int = - result = x("123") - -if false: - echo "Give a list of numbers (separated by spaces): " - var x = stdin.readline.split.map(parseInt).max - echo x, " is the maximum!" -echo "another number: ", takeParseInt(parseInt) - - -type - TFoo[a,b] = object - lorem: a - ipsum: b - -proc bar[a,b](f: TFoo[a,b], x: a) = echo(x, " ", f.lorem, f.ipsum) -proc bar[a,b](f: TFoo[a,b], x: b) = echo(x, " ", f.lorem, f.ipsum) - -discard parseInt[string]("yay") diff --git a/tests/overload/toverwr.nim b/tests/overload/toverwr.nim deleted file mode 100644 index b5791072ef..0000000000 --- a/tests/overload/toverwr.nim +++ /dev/null @@ -1,13 +0,0 @@ -discard """ - file: "toverwr.nim" - output: "hello" -""" -# Test the overloading resolution in connection with a qualifier - -proc write(t: File, s: string) = - discard # a nop - -system.write(stdout, "hello") -#OUT hello - - diff --git a/tests/overload/tparams_after_varargs.nim b/tests/overload/tparams_after_varargs.nim deleted file mode 100644 index ad8f19ad3f..0000000000 --- a/tests/overload/tparams_after_varargs.nim +++ /dev/null @@ -1,19 +0,0 @@ -discard """ - output: '''a 1 b 2 x @[3, 4, 5] y 6 z 7 -yay -12 -''' -""" - -proc test(a, b: int, x: varargs[int]; y, z: int) = - echo "a ", a, " b ", b, " x ", @x, " y ", y, " z ", z - -test 1, 2, 3, 4, 5, 6, 7 - -# XXX maybe this should also work with ``varargs[untyped]`` -template takesBlockA(a, b: untyped; x: varargs[typed]; blck: untyped): untyped = - blck - echo a, b - -takesBlockA 1, 2, "some", 0.90, "random stuff": - echo "yay" diff --git a/tests/overload/tprefer_specialized_generic.nim b/tests/overload/tprefer_specialized_generic.nim deleted file mode 100644 index 2b41502d1e..0000000000 --- a/tests/overload/tprefer_specialized_generic.nim +++ /dev/null @@ -1,22 +0,0 @@ -discard """ - output: '''ref ref T ptr S''' -""" - -proc foo[T](x: T) = - echo "only T" - -proc foo[T](x: ref T) = - echo "ref T" - -proc foo[T, S](x: ref ref T; y: ptr S) = - echo "ref ref T ptr S" - -proc foo[T, S](x: ref T; y: ptr S) = - echo "ref T ptr S" - -proc foo[T](x: ref T; default = 0) = - echo "ref T; default" - -var x: ref ref int -var y: ptr ptr int -foo(x, y) diff --git a/tests/overload/tprefer_tygenericinst.nim b/tests/overload/tprefer_tygenericinst.nim deleted file mode 100644 index ab461a0f49..0000000000 --- a/tests/overload/tprefer_tygenericinst.nim +++ /dev/null @@ -1,68 +0,0 @@ -discard """ - output: '''Version 2 was called. -This has the highest precedence. -This has the second-highest precedence. -This has the lowest precedence. -baseobj == -true -even better! == -true''' -""" - -# bug #2220 -when true: - type A[T] = object - type B = A[int] - - proc q[X](x: X) = - echo "Version 1 was called." - - proc q(x: B) = - echo "Version 2 was called." - - q(B()) # This call reported as ambiguous. - -# bug #2219 -template testPred(a: untyped) = - block: - type A = object of RootObj - type B = object of A - type SomeA = A|A # A hack to make "A" a typeclass. - - when a >= 3: - proc p[X: A](x: X) = - echo "This has the highest precedence." - when a == 2: - proc p[X: SomeA](x: X) = - echo "This has the second-highest precedence." - when a >= 1: - proc p[X](x: X) = - echo "This has the lowest precedence." - - p(B()) - -testPred(3) -testPred(2) -testPred(1) - -# bug #6526 -type - BaseObj = ref object of RootObj - DerivedObj = ref object of BaseObj - OtherDerivate = ref object of BaseObj - -proc `==`*[T1, T2: BaseObj](a: T1, b: T2): bool = - echo "baseobj ==" - return true - -let a = DerivedObj() -let b = DerivedObj() -echo a == b - -proc `==`*[T1, T2: OtherDerivate](a: T1, b: T2): bool = - echo "even better! ==" - return true - -let a2 = OtherDerivate() -let b2 = OtherDerivate() -echo a2 == b2 diff --git a/tests/overload/tstaticoverload.nim b/tests/overload/tstaticoverload.nim deleted file mode 100644 index 33ca49e566..0000000000 --- a/tests/overload/tstaticoverload.nim +++ /dev/null @@ -1,30 +0,0 @@ -discard """ -output: ''' -dynamic: let -dynamic: var -static: const -static: literal -static: constant folding -static: static string -''' -""" - -proc foo(s: string) = - echo "dynamic: ", s - -proc foo(s: static[string]) = - echo "static: ", s - -let l = "let" -var v = "var" -const c = "const" - -type staticString = static[string] - -foo(l) -foo(v) -foo(c) -foo("literal") -foo("constant" & " " & "folding") -foo(staticString("static string")) - diff --git a/tests/overload/tstmtoverload.nim b/tests/overload/tstmtoverload.nim deleted file mode 100644 index 7c0194e603..0000000000 --- a/tests/overload/tstmtoverload.nim +++ /dev/null @@ -1,38 +0,0 @@ - -# bug #2481 -import math - -template test(loopCount: int, extraI: int, testBody: untyped): typed = - block: - for i in 0..loopCount-1: - testBody - echo "done extraI=", extraI - -template test(loopCount: int, extraF: float, testBody: untyped): typed = - block: - test(loopCount, round(extraF).int, testBody) - -template test(loopCount: int, testBody: untyped): typed = - block: - test(loopCount, 0, testBody) - echo "done extraI passed 0" - -when isMainModule: - var - loops = 0 - - test 0, 0: - loops += 1 - echo "test 0 complete, loops=", loops - - test 1, 1.0: - loops += 1 - echo "test 1.0 complete, loops=", loops - - when true: - # when true we get the following compile time error: - # b.nim(35, 6) Error: expression 'loops += 1' has no type (or is ambiguous) - loops = 0 - test 2: - loops += 1 - echo "test no extra complete, loops=", loops diff --git a/tests/overload/tsymtabchange_during_or.nim b/tests/overload/tsymtabchange_during_or.nim deleted file mode 100644 index b5551bcc76..0000000000 --- a/tests/overload/tsymtabchange_during_or.nim +++ /dev/null @@ -1,24 +0,0 @@ - -# bug #2229 - -type Type1 = object - id: int - -type Type2 = object - id: int - -proc init(self: var Type1, a: int, b: ref Type2) = - echo "1" - -proc init(self: var Type2, a: int) = - echo """ - Works when this proc commented out - Otherwise error: - test.nim(14, 4) Error: ambiguous call; both test.init(self: var Type1, a: int, b: ref Type2) and test.init(self: var Type1, a: int, b: ref Type2) match for: (Type1, int literal(1), ref Type2) - """ - -var a: Type1 -init(a, 1, ( - var b = new(Type2); - b -)) diff --git a/tests/overload/tvarious.nim b/tests/overload/tvarious.nim new file mode 100644 index 0000000000..4c17b6031d --- /dev/null +++ b/tests/overload/tvarious.nim @@ -0,0 +1,176 @@ +discard """ + output: ''' +true012innertrue +m1 +tup1 +another number: 123 +yay +helloa 1 b 2 x @[3, 4, 5] y 6 z 7 +yay +12 +ref ref T ptr S +dynamic: let +dynamic: var +static: const +static: literal +static: constant folding +static: static string +''' +""" + + +import strutils, sequtils + + +block overl2: + # Test new overloading resolution rules + proc toverl2(x: int): string = return $x + proc toverl2(x: bool): string = return $x + + iterator toverl2(x: int): int = + var res = 0 + while res < x: + yield res + inc(res) + + var + pp: proc (x: bool): string {.nimcall.} = toverl2 + + stdout.write(pp(true)) + + for x in toverl2(3): + stdout.write(toverl2(x)) + + block: + proc toverl2(x: int): string = return "inner" + stdout.write(toverl2(5)) + stdout.write(true) + + stdout.write("\n") + #OUT true012innertrue + + + +block overl3: + # Tests more specific generic match: + proc m[T](x: T) = echo "m2" + proc m[T](x: var ref T) = echo "m1" + proc tup[S, T](x: tuple[a: S, b: ref T]) = echo "tup1" + proc tup[S, T](x: tuple[a: S, b: T]) = echo "tup2" + + var + obj: ref int + tu: tuple[a: int, b: ref bool] + + m(obj) + tup(tu) + + + +block toverprc: + # Test overloading of procs when used as function pointers + proc parseInt(x: float): int {.noSideEffect.} = discard + proc parseInt(x: bool): int {.noSideEffect.} = discard + proc parseInt(x: float32): int {.noSideEffect.} = discard + proc parseInt(x: int8): int {.noSideEffect.} = discard + proc parseInt(x: File): int {.noSideEffect.} = discard + proc parseInt(x: char): int {.noSideEffect.} = discard + proc parseInt(x: int16): int {.noSideEffect.} = discard + + proc parseInt[T](x: T): int = echo x; 34 + + type + TParseInt = proc (x: string): int {.noSideEffect.} + + var + q = TParseInt(parseInt) + p: TParseInt = parseInt + + proc takeParseInt(x: proc (y: string): int {.noSideEffect.}): int = + result = x("123") + + if false: + echo "Give a list of numbers (separated by spaces): " + var x = stdin.readline.split.map(parseInt).max + echo x, " is the maximum!" + echo "another number: ", takeParseInt(parseInt) + + + type + TFoo[a,b] = object + lorem: a + ipsum: b + + proc bar[a,b](f: TFoo[a,b], x: a) = echo(x, " ", f.lorem, f.ipsum) + proc bar[a,b](f: TFoo[a,b], x: b) = echo(x, " ", f.lorem, f.ipsum) + + discard parseInt[string]("yay") + + + +block toverwr: + # Test the overloading resolution in connection with a qualifier + proc write(t: File, s: string) = + discard # a nop + system.write(stdout, "hello") + #OUT hello + + + +block tparams_after_varargs: + proc test(a, b: int, x: varargs[int]; y, z: int) = + echo "a ", a, " b ", b, " x ", @x, " y ", y, " z ", z + + test 1, 2, 3, 4, 5, 6, 7 + + # XXX maybe this should also work with ``varargs[untyped]`` + template takesBlockA(a, b: untyped; x: varargs[typed]; blck: untyped): untyped = + blck + echo a, b + + takesBlockA 1, 2, "some", 0.90, "random stuff": + echo "yay" + + + +block tprefer_specialized_generic: + proc foo[T](x: T) = + echo "only T" + + proc foo[T](x: ref T) = + echo "ref T" + + proc foo[T, S](x: ref ref T; y: ptr S) = + echo "ref ref T ptr S" + + proc foo[T, S](x: ref T; y: ptr S) = + echo "ref T ptr S" + + proc foo[T](x: ref T; default = 0) = + echo "ref T; default" + + var x: ref ref int + var y: ptr ptr int + foo(x, y) + + + +block tstaticoverload: + proc foo(s: string) = + echo "dynamic: ", s + + proc foo(s: static[string]) = + echo "static: ", s + + let l = "let" + var v = "var" + const c = "const" + + type staticString = static[string] + + foo(l) + foo(v) + foo(c) + foo("literal") + foo("constant" & " " & "folding") + foo(staticString("static string")) diff --git a/tests/overload/tvart_varargs.nim b/tests/overload/tvart_varargs.nim deleted file mode 100644 index c0c460c76a..0000000000 --- a/tests/overload/tvart_varargs.nim +++ /dev/null @@ -1,18 +0,0 @@ - -# bug #4545 -type SomeObject = object - a : int - -type AbstractObject = object - objet: ptr SomeObject - -proc convert(this: var SomeObject): AbstractObject = - AbstractObject(objet: this.addr) - -proc varargProc(args: varargs[AbstractObject, convert]): int = - for arg in args: - result += arg.objet.a - -var obj = SomeObject(a: 17) - -discard varargProc(obj) diff --git a/tests/proc/t8357.nim b/tests/proc/t8357.nim deleted file mode 100644 index 350ebe356d..0000000000 --- a/tests/proc/t8357.nim +++ /dev/null @@ -1,10 +0,0 @@ -discard """ - output: "Hello" -""" - -type - T = ref int - -let r = new(string) -r[] = "Hello" -echo r[] diff --git a/tests/proc/t8683.nim b/tests/proc/t8683.nim deleted file mode 100644 index 8c7e7af08e..0000000000 --- a/tests/proc/t8683.nim +++ /dev/null @@ -1,11 +0,0 @@ -discard """ - output: "1" -""" - -proc foo[T](bar: proc (x, y: T): int = system.cmp, baz: int) = - echo "1" - -proc foo[T](bar: proc (x, y: T): int = system.cmp) = - echo "2" - -foo[int](baz = 5) diff --git a/tests/proc/tnestprc.nim b/tests/proc/tnestprc.nim deleted file mode 100644 index 9b3c33d5e3..0000000000 --- a/tests/proc/tnestprc.nim +++ /dev/null @@ -1,16 +0,0 @@ -discard """ - file: "tnestprc.nim" - output: "10" -""" -# Test nested procs without closures - -proc Add3(x: int): int = - proc add(x, y: int): int {.noconv.} = - result = x + y - - result = add(x, 3) - -echo Add3(7) #OUT 10 - - - diff --git a/tests/proc/tproc.nim b/tests/proc/tproc.nim new file mode 100644 index 0000000000..d7f8619917 --- /dev/null +++ b/tests/proc/tproc.nim @@ -0,0 +1,31 @@ +discard """ + output: ''' +Hello +1 +''' +""" + + +block t8357: + type T = ref int + + let r = new(string) + r[] = "Hello" + echo r[] + + +block t8683: + proc foo[T](bar: proc (x, y: T): int = system.cmp, baz: int) = + echo "1" + proc foo[T](bar: proc (x, y: T): int = system.cmp) = + echo "2" + + foo[int](baz = 5) + + +block tnestprc: + proc Add3(x: int): int = + proc add(x, y: int): int {.noconv.} = + result = x + y + result = add(x, 3) + doAssert Add3(7) == 10 diff --git a/tests/procvar/tgenericprocvar.nim b/tests/procvar/tgenericprocvar.nim deleted file mode 100644 index e642e3577f..0000000000 --- a/tests/procvar/tgenericprocvar.nim +++ /dev/null @@ -1,5 +0,0 @@ -proc foo[T](thing: T) = - discard thing - -var a: proc (thing: int) {.nimcall.} = foo[int] - diff --git a/tests/procvar/tprocvar.nim b/tests/procvar/tprocvar.nim index f523aa391e..14f24efdc4 100644 --- a/tests/procvar/tprocvar.nim +++ b/tests/procvar/tprocvar.nim @@ -1,18 +1,39 @@ discard """ - errormsg: "type mismatch" - line: 17 - file: "tprocvar.nim" + output: ''' +papbpcpdpe7 +''' """ -type - TCallback = proc (a, b: int) +block genericprocvar: + proc foo[T](thing: T) = + discard thing + var a: proc (thing: int) {.nimcall.} = foo[int] -proc huh(x, y: var int) = - x = 0 - y = x+1 -proc so(c: TCallback) = - c(2, 4) +block tprocvar2: + proc pa() {.cdecl.} = write(stdout, "pa") + proc pb() {.cdecl.} = write(stdout, "pb") + proc pc() {.cdecl.} = write(stdout, "pc") + proc pd() {.cdecl.} = write(stdout, "pd") + proc pe() {.cdecl.} = write(stdout, "pe") -so(huh) + const algos = [pa, pb, pc, pd, pe] + var x: proc (a, b: int): int {.cdecl.} + + proc ha(c, d: int): int {.cdecl.} = + echo(c + d) + result = c + d + + for a in items(algos): + a() + + x = ha + discard x(3, 4) + + +block tprocvars: + proc doSomething(v: int, x: proc(v:int):int): int = return x(v) + proc doSomething(v: int, x: proc(v:int)) = x(v) + + doAssert doSomething(10, proc(v: int): int = return v div 2) == 5 diff --git a/tests/procvar/tprocvar2.nim b/tests/procvar/tprocvar2.nim deleted file mode 100644 index a590bc4bd7..0000000000 --- a/tests/procvar/tprocvar2.nim +++ /dev/null @@ -1,32 +0,0 @@ -discard """ - file: "tprocvar.nim" - output: "papbpcpdpe7" -""" -# test variables of type proc - -proc pa() {.cdecl.} = write(stdout, "pa") -proc pb() {.cdecl.} = write(stdout, "pb") -proc pc() {.cdecl.} = write(stdout, "pc") -proc pd() {.cdecl.} = write(stdout, "pd") -proc pe() {.cdecl.} = write(stdout, "pe") - -const - algos = [pa, pb, pc, pd, pe] - -var - x: proc (a, b: int): int {.cdecl.} - -proc ha(c, d: int): int {.cdecl.} = - echo(c + d) - result = c + d - -for a in items(algos): - a() - -x = ha -discard x(3, 4) - -#OUT papbpcpdpe7 - - - diff --git a/tests/procvar/tprocvarmismatch.nim b/tests/procvar/tprocvarmismatch.nim new file mode 100644 index 0000000000..4d6be9be61 --- /dev/null +++ b/tests/procvar/tprocvarmismatch.nim @@ -0,0 +1,18 @@ +discard """ + errormsg: "type mismatch" + line: 17 + file: "tprocvarmismatch.nim" +""" + +type + TCallback = proc (a, b: int) + +proc huh(x, y: var int) = + x = 0 + y = x+1 + +proc so(c: TCallback) = + c(2, 4) + +so(huh) + diff --git a/tests/procvar/tprocvars.nim b/tests/procvar/tprocvars.nim deleted file mode 100644 index 50d5d29f20..0000000000 --- a/tests/procvar/tprocvars.nim +++ /dev/null @@ -1,6 +0,0 @@ -proc doSomething(v: int, x: proc(v:int):int): int = return x(v) -proc doSomething(v: int, x: proc(v:int)) = x(v) - - -echo doSomething(10, proc(v: int): int = return v div 2) - diff --git a/tests/range/tbug499771.nim b/tests/range/tbug499771.nim deleted file mode 100644 index 1504a2ad70..0000000000 --- a/tests/range/tbug499771.nim +++ /dev/null @@ -1,14 +0,0 @@ -discard """ - file: "tbug499771.nim" - output: '''TSubRange: 5 from 1 to 10 -true true true''' -""" -type - TSubRange = range[1 .. 10] - TEnum = enum A, B, C -var sr: TSubRange = 5 -echo("TSubRange: " & $sr & " from " & $low(TSubRange) & " to " & - $high(TSubRange)) - -const cset = {A} + {B} -echo A in cset, " ", B in cset, " ", C notin cset diff --git a/tests/range/tcolors.nim b/tests/range/tcolors.nim deleted file mode 100644 index ab5b3e1993..0000000000 --- a/tests/range/tcolors.nim +++ /dev/null @@ -1,39 +0,0 @@ -import strutils - -type - TColor = distinct int32 - -proc rgb(r, g, b: range[0..255]): TColor = - result = TColor(r or g shl 8 or b shl 16) - -proc `$`(c: TColor): string = - result = "#" & toHex(int32(c), 6) - -echo rgb(34, 55, 255) - -when false: - type - TColor = distinct int32 - TColorComponent = distinct int8 - - proc red(a: TColor): TColorComponent = - result = TColorComponent(int32(a) and 0xff'i32) - - proc green(a: TColor): TColorComponent = - result = TColorComponent(int32(a) shr 8'i32 and 0xff'i32) - - proc blue(a: TColor): TColorComponent = - result = TColorComponent(int32(a) shr 16'i32 and 0xff'i32) - - proc rgb(r, g, b: range[0..255]): TColor = - result = TColor(r or g shl 8 or b shl 8) - - proc `+!` (a, b: TColorComponent): TColorComponent = - ## saturated arithmetic: - result = TColorComponent(min(ze(int8(a)) + ze(int8(b)), 255)) - - proc `+` (a, b: TColor): TColor = - ## saturated arithmetic for colors makes sense, I think: - return rgb(red(a) +! red(b), green(a) +! green(b), blue(a) +! blue(b)) - - rgb(34, 55, 255) diff --git a/tests/range/tmatrix3.nim b/tests/range/tmatrix3.nim deleted file mode 100644 index fe666b0d8c..0000000000 --- a/tests/range/tmatrix3.nim +++ /dev/null @@ -1,41 +0,0 @@ -discard """ - output: '''0.0 -0.0 -0 -0 -0 -''' -""" - -include compilehelpers - -type - Matrix*[M, N, T] = object - aij*: array[M, array[N, T]] - - Matrix2*[T] = Matrix[range[0..1], range[0..1], T] - - Matrix3*[T] = Matrix[range[0..2], range[0..2], T] - -proc mn(x: Matrix): Matrix.T = x.aij[0][0] - -proc m2(x: Matrix2): Matrix2.T = x.aij[0][0] - -proc m3(x: Matrix3): auto = x.aij[0][0] - -var - matn: Matrix[range[0..3], range[0..2], int] - mat2: Matrix2[int] - mat3: Matrix3[float] - -echo m3(mat3) -echo mn(mat3) -echo m2(mat2) -echo mn(mat2) -echo mn(matn) - -reject m3(mat2) -reject m3(matn) -reject m2(mat3) -reject m2(matn) - diff --git a/tests/range/tn8vsint16.nim b/tests/range/tn8vsint16.nim deleted file mode 100644 index bf4f78e3ba..0000000000 --- a/tests/range/tn8vsint16.nim +++ /dev/null @@ -1,18 +0,0 @@ -discard """ - output: '''-9''' -""" - -type - n32 = range[0..high(int)] - n8* = range[0'i8..high(int8)] - -proc `+`*(a: n32, b: n32{nkIntLit}): n32 = discard - -proc `-`*(a: n8, b: n8): n8 = n8(system.`-`(a, b)) - -var x, y: n8 -var z: int16 - -# ensure this doesn't call our '-' but system.`-` for int16: -echo z - n8(9) - diff --git a/tests/range/trange.nim b/tests/range/trange.nim new file mode 100644 index 0000000000..bc48e95662 --- /dev/null +++ b/tests/range/trange.nim @@ -0,0 +1,107 @@ +discard """ + output: ''' +TSubRange: 5 from 1 to 10 +#FF3722 +''' +""" + + +block tbug499771: + type + TSubRange = range[1 .. 10] + TEnum = enum A, B, C + var sr: TSubRange = 5 + echo("TSubRange: " & $sr & " from " & $low(TSubRange) & " to " & + $high(TSubRange)) + + const cset = {A} + {B} + doAssert A in cset + doAssert B in cset + doAssert C notin cset + + + +include compilehelpers +block tmatrix3: + type + Matrix[M, N, T] = object + aij: array[M, array[N, T]] + + Matrix2[T] = Matrix[range[0..1], range[0..1], T] + + Matrix3[T] = Matrix[range[0..2], range[0..2], T] + + proc mn(x: Matrix): Matrix.T = x.aij[0][0] + + proc m2(x: Matrix2): Matrix2.T = x.aij[0][0] + + proc m3(x: Matrix3): auto = x.aij[0][0] + + var + matn: Matrix[range[0..3], range[0..2], int] + mat2: Matrix2[int] + mat3: Matrix3[float] + + doAssert m3(mat3) == 0.0 + doAssert mn(mat3) == 0.0 + doAssert m2(mat2) == 0 + doAssert mn(mat2) == 0 + doAssert mn(matn) == 0 + + reject m3(mat2) + reject m3(matn) + reject m2(mat3) + reject m2(matn) + + + +block tn8vsint16: + type + n32 = range[0..high(int)] + n8 = range[0'i8..high(int8)] + + proc `+`(a: n32, b: n32{nkIntLit}): n32 = discard + + proc `-`(a: n8, b: n8): n8 = n8(system.`-`(a, b)) + + var x, y: n8 + var z: int16 + + # ensure this doesn't call our '-' but system.`-` for int16: + doAssert z - n8(9) == -9 + + + +import strutils +block tcolors: + type TColor = distinct int32 + + proc rgb(r, g, b: range[0..255]): TColor = + result = TColor(r or g shl 8 or b shl 16) + proc `$`(c: TColor): string = + result = "#" & toHex(int32(c), 6) + echo rgb(34, 55, 255) + + when false: + type + TColor = distinct int32 + TColorComponent = distinct int8 + + proc red(a: TColor): TColorComponent = + result = TColorComponent(int32(a) and 0xff'i32) + proc green(a: TColor): TColorComponent = + result = TColorComponent(int32(a) shr 8'i32 and 0xff'i32) + proc blue(a: TColor): TColorComponent = + result = TColorComponent(int32(a) shr 16'i32 and 0xff'i32) + proc rgb(r, g, b: range[0..255]): TColor = + result = TColor(r or g shl 8 or b shl 8) + + proc `+!` (a, b: TColorComponent): TColorComponent = + ## saturated arithmetic: + result = TColorComponent(min(ze(int8(a)) + ze(int8(b)), 255)) + + proc `+` (a, b: TColor): TColor = + ## saturated arithmetic for colors makes sense, I think: + return rgb(red(a) +! red(b), green(a) +! green(b), blue(a) +! blue(b)) + + rgb(34, 55, 255) diff --git a/tests/seq/tseq.nim b/tests/seq/tseq.nim new file mode 100644 index 0000000000..6528d518e8 --- /dev/null +++ b/tests/seq/tseq.nim @@ -0,0 +1,181 @@ +discard """ + output: ''' +Hithere, what's your name?Hathere, what's your name? +fA13msg1falsefB14msg2truefC15msg3false +Zip: [{"Field0": 1, "Field1": 2}, {"Field0": 3, "Field1": 4}, {"Field0": 5, "Field1": 6}] +Filter Iterator: 3 +Filter Iterator: 5 +Filter Iterator: 7 +Filter: [3, 5, 7] +FilterIt: [1, 3, 7] +Concat: [1, 3, 5, 7, 2, 4, 6] +Deduplicate: [1, 2, 3, 4, 5, 7] +@[()] +@[1, 42, 3] +@[1, 42, 3] +2345623456 +''' +""" + +block tseq2: + proc `*`(a, b: seq[int]): seq[int] = + # allocate a new sequence: + newSeq(result, len(a)) + # multiply two int sequences: + for i in 0..len(a)-1: result[i] = a[i] * b[i] + + assert(@[1, 2, 3] * @[1, 2, 3] == @[1, 4, 9]) + + + +block tseqcon: + const nestedFixed = true + + type + TRec {.final.} = object + x, y: int + s: string + seq: seq[string] + TRecSeq = seq[TRec] + + proc test() = + var s, b: seq[string] + s = @[] + add(s, "Hi") + add(s, "there, ") + add(s, "what's your name?") + + b = s # deep copying here! + b[0][1] = 'a' + + for i in 0 .. len(s)-1: + write(stdout, s[i]) + for i in 0 .. len(b)-1: + write(stdout, b[i]) + + when nestedFixed: + proc nested() = + var + s: seq[seq[string]] + for i in 0..10_000: # test if the garbage collector + # now works with sequences + s = @[ + @["A", "B", "C", "D"], + @["E", "F", "G", "H"], + @["I", "J", "K", "L"], + @["M", "N", "O", "P"]] + + test() + when nestedFixed: + nested() + echo "" + + + +import os +block tseqcon2: + proc rec_dir(dir: string): seq[string] = + result = @[] + for kind, path in walk_dir(dir): + if kind == pcDir: + add(result, rec_dir(path)) + else: + add(result, path) + + + +block tseqtuple: + type + TMsg = tuple[ + file: string, + line: int, + msg: string, + err: bool] + + var s: seq[TMsg] = @[] + + s.add(("fA", 13, "msg1", false)) + s.add(("fB", 14, "msg2", true)) + s.add(("fC", 15, "msg3", false)) + + for file, line, msg, err in items(s): + stdout.write(file) + stdout.write($line) + stdout.write(msg) + stdout.write($err) + echo "" + + +import sequtils, marshal +block tsequtils: + proc testFindWhere(item : int) : bool = + if item != 1: return true + + var seq1: seq[int] = @[] + + seq1.add(1) + seq1.add(3) + seq1.add(5) + seq1.add(7) + + var seq2: seq[int] = @[2, 4, 6] + var final = zip(seq1, seq2) + + echo "Zip: ", $$(final) + + #Test findWhere as a iterator + + for itms in filter(seq1, testFindWhere): + echo "Filter Iterator: ", $$(itms) + + + #Test findWhere as a proc + + var fullseq: seq[int] = filter(seq1, testFindWhere) + + echo "Filter: ", $$(fullseq) + + #Test findIt as a template + + var finditval: seq[int] = filterIt(seq1, it!=5) + + echo "FilterIt: ", $$(finditval) + + var concatseq = concat(seq1,seq2) + echo "Concat: ", $$(concatseq) + + var seq3 = @[1,2,3,4,5,5,5,7] + var dedupseq = deduplicate(seq3) + echo "Deduplicate: ", $$(dedupseq) + # bug #4973 + type + SomeObj = object + OtherObj = object + field: SomeObj + + let aSeq = @[OtherObj(field: SomeObj())] + let someObjSeq = aSeq.mapIt(it.field) + echo someObjSeq + + + +block tshallowseq: + proc xxx() = + var x: seq[int] = @[1, 2, 3] + var y: seq[int] + system.shallowCopy(y, x) + y[1] = 42 + echo y + echo x + xxx() + + + +import strutils +block ttoseq: + for x in toSeq(countup(2, 6)): + stdout.write(x) + for x in items(toSeq(countup(2, 6))): + stdout.write(x) + var y: type("a b c".split) + y = "xzy" diff --git a/tests/seq/tseq2.nim b/tests/seq/tseq2.nim deleted file mode 100644 index 5de9402ecb..0000000000 --- a/tests/seq/tseq2.nim +++ /dev/null @@ -1,11 +0,0 @@ -proc `*` *(a, b: seq[int]): seq[int] = - # allocate a new sequence: - newSeq(result, len(a)) - # multiply two int sequences: - for i in 0..len(a)-1: result[i] = a[i] * b[i] - -when isMainModule: - # test the new ``*`` operator for sequences: - assert(@[1, 2, 3] * @[1, 2, 3] == @[1, 4, 9]) - - diff --git a/tests/seq/tseqcon.nim b/tests/seq/tseqcon.nim deleted file mode 100644 index 902ac34853..0000000000 --- a/tests/seq/tseqcon.nim +++ /dev/null @@ -1,51 +0,0 @@ -discard """ - file: "tseqcon.nim" - output: "Hithere, what\'s your name?Hathere, what\'s your name?" -""" -# Test the add proc for sequences and strings - -const - nestedFixed = true - -type - TRec {.final.} = object - x, y: int - s: string - seq: seq[string] - TRecSeq = seq[TRec] - -proc test() = - var s, b: seq[string] - s = @[] - add(s, "Hi") - add(s, "there, ") - add(s, "what's your name?") - - b = s # deep copying here! - b[0][1] = 'a' - - for i in 0 .. len(s)-1: - write(stdout, s[i]) - for i in 0 .. len(b)-1: - write(stdout, b[i]) - - -when nestedFixed: - proc nested() = - var - s: seq[seq[string]] - for i in 0..10_000: # test if the garbage collector - # now works with sequences - s = @[ - @["A", "B", "C", "D"], - @["E", "F", "G", "H"], - @["I", "J", "K", "L"], - @["M", "N", "O", "P"]] - -test() -when nestedFixed: - nested() - -#OUT Hithere, what's your name?Hathere, what's your name? - - diff --git a/tests/seq/tseqcon2.nim b/tests/seq/tseqcon2.nim deleted file mode 100644 index 4f2763ffe1..0000000000 --- a/tests/seq/tseqcon2.nim +++ /dev/null @@ -1,9 +0,0 @@ -import os - -proc rec_dir(dir: string): seq[string] = - result = @[] - for kind, path in walk_dir(dir): - if kind == pcDir: - add(result, rec_dir(path)) - else: - add(result, path) diff --git a/tests/seq/tseqtuple.nim b/tests/seq/tseqtuple.nim deleted file mode 100644 index a0102c9efb..0000000000 --- a/tests/seq/tseqtuple.nim +++ /dev/null @@ -1,28 +0,0 @@ -discard """ - file: "tseqtuple.nim" - output: "fA13msg1falsefB14msg2truefC15msg3false" -""" - -type - TMsg = tuple[ - file: string, - line: int, - msg: string, - err: bool] - -var s: seq[TMsg] = @[] - -s.add(("fA", 13, "msg1", false)) -s.add(("fB", 14, "msg2", true)) -s.add(("fC", 15, "msg3", false)) - -for file, line, msg, err in items(s): - stdout.write(file) - stdout.write($line) - stdout.write(msg) - stdout.write($err) - -#OUT fA13msg1falsefB14msg2truefC15msg3false - - - diff --git a/tests/seq/tsequtils.nim b/tests/seq/tsequtils.nim deleted file mode 100644 index 06a981e922..0000000000 --- a/tests/seq/tsequtils.nim +++ /dev/null @@ -1,64 +0,0 @@ -discard """ -file: "tsequtils.nim" -output: '''Zip: [{"Field0": 1, "Field1": 2}, {"Field0": 3, "Field1": 4}, {"Field0": 5, "Field1": 6}] -Filter Iterator: 3 -Filter Iterator: 5 -Filter Iterator: 7 -Filter: [3, 5, 7] -FilterIt: [1, 3, 7] -Concat: [1, 3, 5, 7, 2, 4, 6] -Deduplicate: [1, 2, 3, 4, 5, 7] -@[()]''' - -""" - -import sequtils, marshal - -proc testFindWhere(item : int) : bool = - if item != 1: return true - -var seq1: seq[int] = @[] - -seq1.add(1) -seq1.add(3) -seq1.add(5) -seq1.add(7) - -var seq2: seq[int] = @[2, 4, 6] -var final = zip(seq1, seq2) - -echo "Zip: ", $$(final) - -#Test findWhere as a iterator - -for itms in filter(seq1, testFindWhere): - echo "Filter Iterator: ", $$(itms) - - -#Test findWhere as a proc - -var fullseq: seq[int] = filter(seq1, testFindWhere) - -echo "Filter: ", $$(fullseq) - -#Test findIt as a template - -var finditval: seq[int] = filterIt(seq1, it!=5) - -echo "FilterIt: ", $$(finditval) - -var concatseq = concat(seq1,seq2) -echo "Concat: ", $$(concatseq) - -var seq3 = @[1,2,3,4,5,5,5,7] -var dedupseq = deduplicate(seq3) -echo "Deduplicate: ", $$(dedupseq) -# bug #4973 -type - SomeObj = object - OtherObj = object - field: SomeObj - -let aSeq = @[OtherObj(field: SomeObj())] -let someObjSeq = aSeq.mapIt(it.field) -echo someObjSeq diff --git a/tests/seq/tshallowseq.nim b/tests/seq/tshallowseq.nim deleted file mode 100644 index 9a8bdb954f..0000000000 --- a/tests/seq/tshallowseq.nim +++ /dev/null @@ -1,17 +0,0 @@ -discard """ - output: '''@[1, 42, 3] -@[1, 42, 3] -''' -""" -proc xxx() = - var x: seq[int] = @[1, 2, 3] - var y: seq[int] - - system.shallowCopy(y, x) - - y[1] = 42 - - echo y - echo x - -xxx() diff --git a/tests/seq/ttoseq.nim b/tests/seq/ttoseq.nim deleted file mode 100644 index 33de59538d..0000000000 --- a/tests/seq/ttoseq.nim +++ /dev/null @@ -1,18 +0,0 @@ -discard """ - output: "2345623456" -""" - -import sequtils - -for x in toSeq(countup(2, 6)): - stdout.write(x) -for x in items(toSeq(countup(2, 6))): - stdout.write(x) - -import strutils - -var y: type("a b c".split) -y = "xzy" - - - diff --git a/tests/sets/tsetpop.nim b/tests/sets/tsetpop.nim deleted file mode 100644 index c37bda57d9..0000000000 --- a/tests/sets/tsetpop.nim +++ /dev/null @@ -1,22 +0,0 @@ -discard """ - targets: "c c++ js" - output: '''1000 -0 -set is empty -''' -""" - -import sets - -var a = initSet[int]() -for i in 1..1000: - a.incl(i) -echo len(a) -for i in 1..1000: - discard a.pop() -echo len(a) - -try: - echo a.pop() -except KeyError as e: - echo e.msg \ No newline at end of file diff --git a/tests/sets/tsets2.nim b/tests/sets/tsets2.nim deleted file mode 100644 index f288228403..0000000000 --- a/tests/sets/tsets2.nim +++ /dev/null @@ -1,71 +0,0 @@ -discard """ - output: '''true''' -""" - -import hashes, sets - -const - data = [ - "34", "12", - "90", "0", - "1", "2", - "3", "4", - "5", "6", - "7", "8", - "9", "---00", - "10", "11", "19", - "20", "30", "40", - "50", "60", "70", - "80"] - -block tableTest1: - var t = initSet[tuple[x, y: int]]() - t.incl((0,0)) - t.incl((1,0)) - assert(not t.containsOrIncl((0,1))) - t.incl((1,1)) - - for x in 0..1: - for y in 0..1: - assert((x,y) in t) - #assert($t == - # "{(x: 0, y: 0), (x: 0, y: 1), (x: 1, y: 0), (x: 1, y: 1)}") - -block setTest2: - var t = initSet[string]() - t.incl("test") - t.incl("111") - t.incl("123") - t.excl("111") - t.incl("012") - t.incl("123") # test duplicates - - assert "123" in t - assert "111" notin t # deleted - - assert t.missingOrExcl("000") == true - assert "000" notin t - assert t.missingOrExcl("012") == false - assert "012" notin t - - assert t.containsOrIncl("012") == false - assert t.containsOrIncl("012") == true - assert "012" in t # added back - - for key in items(data): t.incl(key) - for key in items(data): assert key in t - - for key in items(data): t.excl(key) - for key in items(data): assert key notin t - -block orderedSetTest1: - var t = data.toOrderedSet - for key in items(data): assert key in t - var i = 0 - # `items` needs to yield in insertion order: - for key in items(t): - assert key == data[i] - inc(i) - -echo "true" - diff --git a/tests/sets/tsets3.nim b/tests/sets/tsets3.nim deleted file mode 100644 index f599f8e7d6..0000000000 --- a/tests/sets/tsets3.nim +++ /dev/null @@ -1,100 +0,0 @@ -include sets - -let - s1: TSet[int] = toSet([1, 2, 4, 8, 16]) - s2: TSet[int] = toSet([1, 2, 3, 5, 8]) - s3: TSet[int] = toSet([3, 5, 7]) - -block union: - let - s1_s2 = union(s1, s2) - s1_s3 = s1 + s3 - s2_s3 = s2 + s3 - - assert s1_s2.len == 7 - assert s1_s3.len == 8 - assert s2_s3.len == 6 - - for i in s1: - assert i in s1_s2 - assert i in s1_s3 - for i in s2: - assert i in s1_s2 - assert i in s2_s3 - for i in s3: - assert i in s1_s3 - assert i in s2_s3 - - assert((s1 + s1) == s1) - assert((s2 + s1) == s1_s2) - -block intersection: - let - s1_s2 = intersection(s1, s2) - s1_s3 = intersection(s1, s3) - s2_s3 = s2 * s3 - - assert s1_s2.len == 3 - assert s1_s3.len == 0 - assert s2_s3.len == 2 - - for i in s1_s2: - assert i in s1 - assert i in s2 - for i in s1_s3: - assert i in s1 - assert i in s3 - for i in s2_s3: - assert i in s2 - assert i in s3 - - assert((s2 * s2) == s2) - assert((s3 * s2) == s2_s3) - -block symmetricDifference: - let - s1_s2 = symmetricDifference(s1, s2) - s1_s3 = s1 -+- s3 - s2_s3 = s2 -+- s3 - - assert s1_s2.len == 4 - assert s1_s3.len == 8 - assert s2_s3.len == 4 - - for i in s1: - assert i in s1_s2 xor i in s2 - assert i in s1_s3 xor i in s3 - for i in s2: - assert i in s1_s2 xor i in s1 - assert i in s2_s3 xor i in s3 - for i in s3: - assert i in s1_s3 xor i in s1 - assert i in s2_s3 xor i in s2 - - assert((s3 -+- s3) == initSet[int]()) - assert((s3 -+- s1) == s1_s3) - -block difference: - let - s1_s2 = difference(s1, s2) - s1_s3 = difference(s1, s3) - s2_s3 = s2 - s3 - - assert s1_s2.len == 2 - assert s1_s3.len == 5 - assert s2_s3.len == 3 - - for i in s1: - assert i in s1_s2 xor i in s2 - assert i in s1_s3 xor i in s3 - for i in s2: - assert i in s2_s3 xor i in s3 - - assert((s2 - s2) == initSet[int]()) - assert((s1 - s3 - s1) == s1 -+- s3) - -block disjoint: - assert(not disjoint(s1, s2)) - assert disjoint(s1, s3) - assert(not disjoint(s2, s3)) - assert(not disjoint(s2, s2)) diff --git a/tests/sets/tsets_lt.nim b/tests/sets/tsets_lt.nim deleted file mode 100644 index 6d0b3a60c3..0000000000 --- a/tests/sets/tsets_lt.nim +++ /dev/null @@ -1,12 +0,0 @@ -discard """ - output: '''true -true -true''' -""" - -var s, s1: set[char] -s = {'a'..'d'} -s1 = {'a'..'c'} -echo s1 < s -echo s1 * s == {'a'..'c'} -echo s1 <= s diff --git a/tests/sets/tvarious.nim b/tests/sets/tvarious.nim new file mode 100644 index 0000000000..7cb9a6eec4 --- /dev/null +++ b/tests/sets/tvarious.nim @@ -0,0 +1,200 @@ +discard """ + output: ''' +set is empty +''' +""" + + +import sets, hashes + + +block tsetpop: + var a = initSet[int]() + for i in 1..1000: + a.incl(i) + doAssert len(a) == 1000 + for i in 1..1000: + discard a.pop() + doAssert len(a) == 0 + + try: + echo a.pop() + except KeyError as e: + echo e.msg + + + +block tsets_lt: + var s, s1: set[char] + s = {'a'..'d'} + s1 = {'a'..'c'} + doAssert s1 < s + doAssert s1 * s == {'a'..'c'} + doAssert s1 <= s + + + +block tsets2: + const + data = [ + "34", "12", + "90", "0", + "1", "2", + "3", "4", + "5", "6", + "7", "8", + "9", "---00", + "10", "11", "19", + "20", "30", "40", + "50", "60", "70", + "80"] + + block tableTest1: + var t = initSet[tuple[x, y: int]]() + t.incl((0,0)) + t.incl((1,0)) + assert(not t.containsOrIncl((0,1))) + t.incl((1,1)) + + for x in 0..1: + for y in 0..1: + assert((x,y) in t) + #assert($t == + # "{(x: 0, y: 0), (x: 0, y: 1), (x: 1, y: 0), (x: 1, y: 1)}") + + block setTest2: + var t = initSet[string]() + t.incl("test") + t.incl("111") + t.incl("123") + t.excl("111") + t.incl("012") + t.incl("123") # test duplicates + + assert "123" in t + assert "111" notin t # deleted + + assert t.missingOrExcl("000") + assert "000" notin t + assert t.missingOrExcl("012") == false + assert "012" notin t + + assert t.containsOrIncl("012") == false + assert t.containsOrIncl("012") + assert "012" in t # added back + + for key in items(data): t.incl(key) + for key in items(data): assert key in t + + for key in items(data): t.excl(key) + for key in items(data): assert key notin t + + block orderedSetTest1: + var t = data.toOrderedSet + for key in items(data): assert key in t + var i = 0 + # `items` needs to yield in insertion order: + for key in items(t): + assert key == data[i] + inc(i) + + + +block tsets3: + let + s1: TSet[int] = toSet([1, 2, 4, 8, 16]) + s2: TSet[int] = toSet([1, 2, 3, 5, 8]) + s3: TSet[int] = toSet([3, 5, 7]) + + block union: + let + s1_s2 = union(s1, s2) + s1_s3 = s1 + s3 + s2_s3 = s2 + s3 + + assert s1_s2.len == 7 + assert s1_s3.len == 8 + assert s2_s3.len == 6 + + for i in s1: + assert i in s1_s2 + assert i in s1_s3 + for i in s2: + assert i in s1_s2 + assert i in s2_s3 + for i in s3: + assert i in s1_s3 + assert i in s2_s3 + + assert((s1 + s1) == s1) + assert((s2 + s1) == s1_s2) + + block intersection: + let + s1_s2 = intersection(s1, s2) + s1_s3 = intersection(s1, s3) + s2_s3 = s2 * s3 + + assert s1_s2.len == 3 + assert s1_s3.len == 0 + assert s2_s3.len == 2 + + for i in s1_s2: + assert i in s1 + assert i in s2 + for i in s1_s3: + assert i in s1 + assert i in s3 + for i in s2_s3: + assert i in s2 + assert i in s3 + + assert((s2 * s2) == s2) + assert((s3 * s2) == s2_s3) + + block symmetricDifference: + let + s1_s2 = symmetricDifference(s1, s2) + s1_s3 = s1 -+- s3 + s2_s3 = s2 -+- s3 + + assert s1_s2.len == 4 + assert s1_s3.len == 8 + assert s2_s3.len == 4 + + for i in s1: + assert i in s1_s2 xor i in s2 + assert i in s1_s3 xor i in s3 + for i in s2: + assert i in s1_s2 xor i in s1 + assert i in s2_s3 xor i in s3 + for i in s3: + assert i in s1_s3 xor i in s1 + assert i in s2_s3 xor i in s2 + + assert((s3 -+- s3) == initSet[int]()) + assert((s3 -+- s1) == s1_s3) + + block difference: + let + s1_s2 = difference(s1, s2) + s1_s3 = difference(s1, s3) + s2_s3 = s2 - s3 + + assert s1_s2.len == 2 + assert s1_s3.len == 5 + assert s2_s3.len == 3 + + for i in s1: + assert i in s1_s2 xor i in s2 + assert i in s1_s3 xor i in s3 + for i in s2: + assert i in s2_s3 xor i in s3 + + assert((s2 - s2) == initSet[int]()) + + block disjoint: + assert(not disjoint(s1, s2)) + assert disjoint(s1, s3) + assert(not disjoint(s2, s3)) + assert(not disjoint(s2, s2)) diff --git a/tests/typerel/t2plus.nim b/tests/typerel/t2plus.nim index 08378b8046..d099eeeb0e 100644 --- a/tests/typerel/t2plus.nim +++ b/tests/typerel/t2plus.nim @@ -4,7 +4,7 @@ discard """ {.warning[TypelessParam]: off.} -import future +import sugar # bug #3329 diff --git a/tests/types/tauto_canbe_void.nim b/tests/types/tauto_canbe_void.nim index fd42cb701b..b071c08e15 100644 --- a/tests/types/tauto_canbe_void.nim +++ b/tests/types/tauto_canbe_void.nim @@ -1,5 +1,5 @@ -import future +import sugar template tempo(s) = s("arg") diff --git a/tests/vm/tanonproc.nim b/tests/vm/tanonproc.nim index c5cb57d75f..a89b53e83d 100644 --- a/tests/vm/tanonproc.nim +++ b/tests/vm/tanonproc.nim @@ -4,7 +4,7 @@ discard """ # bug #3561 -import macros, future, strutils +import macros, sugar, strutils type Option[T] = ref object diff --git a/tests/vm/tvmmisc.nim b/tests/vm/tvmmisc.nim index 6a8084647f..350f3c08e3 100644 --- a/tests/vm/tvmmisc.nim +++ b/tests/vm/tvmmisc.nim @@ -31,7 +31,7 @@ static: assert str == "abc" # #6086 -import math, sequtils, future +import math, sequtils, sugar block: proc f: int =