diff options
Diffstat (limited to 'tests/misc')
65 files changed, 303 insertions, 1497 deletions
diff --git a/tests/misc/mjsondoc.nim b/tests/misc/mjsondoc.nim index e4642f0b4..016c8522d 100644 --- a/tests/misc/mjsondoc.nim +++ b/tests/misc/mjsondoc.nim @@ -9,3 +9,6 @@ const type MyEnum* = enum foo, bar + +proc foo2*[T: int, M: string, U](x: T, y: U, z: M) = + echo 1 diff --git a/tests/misc/mspellsuggest.nim b/tests/misc/mspellsuggest.nim deleted file mode 100644 index ad449554f..000000000 --- a/tests/misc/mspellsuggest.nim +++ /dev/null @@ -1,7 +0,0 @@ -proc fooBar4*(a: int) = discard -var fooBar9* = 0 - -var fooCar* = 0 -type FooBar* = int -type FooCar* = int -type GooBa* = int diff --git a/tests/misc/t11634.nim b/tests/misc/t11634.nim new file mode 100644 index 000000000..390af40f4 --- /dev/null +++ b/tests/misc/t11634.nim @@ -0,0 +1,17 @@ +discard """ + action: reject +""" + +type Foo = ref object + val: int + +proc divmod(a, b: Foo): (Foo, Foo) = + ( + Foo(val: a.val div b.val), + Foo(val: a.val mod b.val) + ) + +block: + let a {.compileTime.} = Foo(val: 2) + let b {.compileTime.} = Foo(val: 3) + let (c11634 {.compileTime.}, d11634 {.compileTime.}) = divmod(a, b) diff --git a/tests/misc/t12869.nim b/tests/misc/t12869.nim new file mode 100644 index 000000000..054e28a03 --- /dev/null +++ b/tests/misc/t12869.nim @@ -0,0 +1,14 @@ +discard """ + errormsg: "type mismatch: got <openArray[int], proc (x: GenericParam, y: GenericParam): auto, SortOrder>" + line: 12 +""" + +import sugar +from algorithm import sorted, SortOrder + +let a = 5 + +proc sorted*[T](a: openArray[T], key: proc(v: T): int, order = SortOrder.Ascending): seq[T] = + sorted(a, (x, y) => key(x) < key(y), order) + +echo sorted(@[9, 1, 8, 2, 6, 4, 5, 0], (x) => (a - x).abs) diff --git a/tests/misc/t14667.nim b/tests/misc/t14667.nim new file mode 100644 index 000000000..3034e2841 --- /dev/null +++ b/tests/misc/t14667.nim @@ -0,0 +1,12 @@ +discard """ + matrix: "--cc:vcc" + disabled: "linux" + disabled: "bsd" + disabled: "osx" + disabled: "unix" + disabled: "posix" +""" + +type A = tuple +discard () +discard default(A) diff --git a/tests/misc/t15351.nim b/tests/misc/t15351.nim new file mode 100644 index 000000000..c31e604a2 --- /dev/null +++ b/tests/misc/t15351.nim @@ -0,0 +1,5 @@ +discard """ + action: "compile" +""" +var + ## TODO: broken diff --git a/tests/misc/t16244.nim b/tests/misc/t16244.nim new file mode 100644 index 000000000..5e8128736 --- /dev/null +++ b/tests/misc/t16244.nim @@ -0,0 +1,9 @@ +discard """ + errormsg: "type mismatch: got <int, float64>" + line: 9 +""" + +proc g(): auto = 1 +proc h(): auto = 1.0 + +var a = g() + h() diff --git a/tests/misc/t16541.nim b/tests/misc/t16541.nim new file mode 100644 index 000000000..452327e8f --- /dev/null +++ b/tests/misc/t16541.nim @@ -0,0 +1,12 @@ +discard """ + action: "reject" + +""" + +import strutils, sugar, nre + +proc my_replace*(s: string, r: Regex, by: string | (proc (match: string): string)): string = + nre.replace(s, r, by) + +discard my_replace("abcde", re"[bcd]", match => match.to_upper) == "aBCDe" +discard my_replace("abcde", re"[bcd]", (match: string) => match.to_upper) == "aBCDe" diff --git a/tests/misc/t18079.nim b/tests/misc/t18079.nim index 352348daf..ae64bbff9 100644 --- a/tests/misc/t18079.nim +++ b/tests/misc/t18079.nim @@ -1,3 +1,7 @@ +discard """ + matrix: "--mm:orc" +""" + type Foo = object y: int diff --git a/tests/misc/t20253.nim b/tests/misc/t20253.nim new file mode 100644 index 000000000..d47c36c55 --- /dev/null +++ b/tests/misc/t20253.nim @@ -0,0 +1,10 @@ +discard """ + errormsg: "'result' requires explicit initialization" + line: 10 +""" + +type Meow {.requiresInit.} = object + init: bool + +proc initMeow(): Meow = + discard diff --git a/tests/misc/t20289.nim b/tests/misc/t20289.nim new file mode 100644 index 000000000..5a0a269f0 --- /dev/null +++ b/tests/misc/t20289.nim @@ -0,0 +1,15 @@ +discard """ + action: reject +""" + +type E[T] = object + v: T + +template j[T](R: type E[T], x: untyped): R = R(v: x) +template d[T](O: type E, v: T): E[T] = E[T].j(v) + +proc w[T](): E[T] = + template r(k: int): auto = default(T) + E.d r + +discard w[int]() diff --git a/tests/misc/t20883.nim b/tests/misc/t20883.nim new file mode 100644 index 000000000..92e7929f4 --- /dev/null +++ b/tests/misc/t20883.nim @@ -0,0 +1,13 @@ +discard """ + action: reject +nimout: ''' +t20883.nim(13, 4) template/generic instantiation of `foo` from here +t20883.nim(9, 11) Error: cannot instantiate: 'U' +''' +""" + +proc foo*[U](x: U = U(1e-6)) = + echo x + +foo[float]() +foo() diff --git a/tests/misc/t21109.nim b/tests/misc/t21109.nim new file mode 100644 index 000000000..0f7980896 --- /dev/null +++ b/tests/misc/t21109.nim @@ -0,0 +1,13 @@ +discard """ + action: reject + errormsg: "type expected" + file: "iterators.nim" +""" + + +template b(j: untyped) = j +template m() = discard + +b: + for t, f in @[]: + m() diff --git a/tests/misc/t21443.nim b/tests/misc/t21443.nim new file mode 100644 index 000000000..70413c5b3 --- /dev/null +++ b/tests/misc/t21443.nim @@ -0,0 +1,6 @@ +import std/envvars + +# bug #19292 +putEnv("NimPutEnvTest", "test") +# bug #21122 +doAssert getEnv("NimPutEnvTest") == "test" diff --git a/tests/misc/t23240.nim b/tests/misc/t23240.nim new file mode 100644 index 000000000..d5edcefe8 --- /dev/null +++ b/tests/misc/t23240.nim @@ -0,0 +1,6 @@ +discard """ + cmd: "nim c foo/bar.nim" + action: "reject" + errormsg: "cannot open 'foo/'" + file: "" +""" diff --git a/tests/misc/t3907.nim b/tests/misc/t3907.nim new file mode 100644 index 000000000..45fc75e81 --- /dev/null +++ b/tests/misc/t3907.nim @@ -0,0 +1,10 @@ +import std/assertions + +let a = 0 +let b = if false: -1 else: a +doAssert b == 0 + +let c: range[0..high(int)] = 0 +let d = if false: -1 else: c + +doAssert d == 0 diff --git a/tests/misc/t8545.nim b/tests/misc/t8545.nim index 89957e1d3..48b886cb8 100644 --- a/tests/misc/t8545.nim +++ b/tests/misc/t8545.nim @@ -1,5 +1,6 @@ discard """ - targets: "c cpp js" + # just tests that this doesn't crash the compiler + errormsg: "cannot instantiate: 'a:type'" """ # bug #8545 diff --git a/tests/misc/taddr.nim b/tests/misc/taddr.nim index 48d4928ac..64f95c7e3 100644 --- a/tests/misc/taddr.nim +++ b/tests/misc/taddr.nim @@ -273,6 +273,16 @@ proc test15939() = # bug #15939 (v2) else: # can't take address of cstring element in js when not defined(js): cstringTest() +block: # bug #23499 + template volatileStore[T](dest: ptr T, val: T) = + dest[] = val + + proc foo = + var ctr = 0 + volatileStore(addr ctr, 0) + + foo() + template main = # xxx wrap all other tests here like that so they're also tested in VM test14420() diff --git a/tests/misc/tcast.nim b/tests/misc/tcast.nim index 6d67b1c52..73196e76c 100644 --- a/tests/misc/tcast.nim +++ b/tests/misc/tcast.nim @@ -1,6 +1,7 @@ discard """ output: ''' Hello World +Hello World Hello World''' joinable: false """ @@ -8,7 +9,7 @@ type MyProc = proc() {.cdecl.} type MyProc2 = proc() {.nimcall.} type MyProc3 = proc() #{.closure.} is implicit -proc testProc() = echo "Hello World" +proc testProc() {.exportc:"foo".} = echo "Hello World" template reject(x) = doAssert(not compiles(x)) @@ -23,6 +24,10 @@ proc callPointer(p: pointer) = ffunc0() ffunc1() + # bug #5901 + proc foo() {.importc.} + (cast[proc(a: int) {.cdecl.}](foo))(5) + callPointer(cast[pointer](testProc)) reject: discard cast[enum](0) diff --git a/tests/misc/tcolonisproc.nim b/tests/misc/tcolonisproc.nim deleted file mode 100644 index c10dabcf1..000000000 --- a/tests/misc/tcolonisproc.nim +++ /dev/null @@ -1,19 +0,0 @@ -discard """ -output: ''' -1 -2 -''' -""" - -proc p(a, b: int, c: proc ()) = - c() - -when false: - # language spec changed: - p(1, 3): - echo 1 - echo 3 - -p(1, 1, proc() = - echo 1 - echo 2) diff --git a/tests/misc/tconv.nim b/tests/misc/tconv.nim index 5e8eac729..90fae868b 100644 --- a/tests/misc/tconv.nim +++ b/tests/misc/tconv.nim @@ -2,6 +2,9 @@ discard """ matrix: "--warningAsError:EnumConv --warningAsError:CStringConv" """ +from std/enumutils import items # missing from the example code +from std/sequtils import toSeq + template reject(x) = static: doAssert(not compiles(x)) template accept(x) = @@ -85,6 +88,13 @@ block: # https://github.com/nim-lang/RFCs/issues/294 reject: Goo(k2) reject: k2.Goo + type KooRange = range[k2..k2] + accept: KooRange(k2) + accept: k2.KooRange + let k2ranged: KooRange = k2 + accept: Koo(k2ranged) + accept: k2ranged.Koo + reject: # bug #18550 proc f(c: char): cstring = @@ -117,4 +127,17 @@ reject: var va = 2 var vb = va.Hole +block: # bug #22844 + type + A = enum + a0 = 2 + a1 = 4 + a2 + B[T] = enum + b0 = 2 + b1 = 4 + + doAssert A.toSeq == [a0, a1, a2] + doAssert B[float].toSeq == [B[float].b0, B[float].b1] + {.pop.} diff --git a/tests/misc/tcsharpusingstatement.nim b/tests/misc/tcsharpusingstatement.nim index dd4cf589d..1ce553895 100644 --- a/tests/misc/tcsharpusingstatement.nim +++ b/tests/misc/tcsharpusingstatement.nim @@ -49,25 +49,13 @@ macro autoClose(args: varargs[untyped]): untyped = var finallyBlock = newNimNode(nnkStmtList) finallyBlock.add(closingCalls) - # XXX: Use a template here once getAst is working properly - var targetAst = parseStmt"""block: - var - x = foo() - y = bar() - - try: - body() - - finally: - close x - close y - """ - - targetAst[0][1][0] = varSection - targetAst[0][1][1][0] = body - targetAst[0][1][1][1][0] = finallyBlock - - result = targetAst + result = quote do: + block: + `varSection` + try: + `body` + finally: + `finallyBlock` type TResource* = object diff --git a/tests/misc/tdefine.nim b/tests/misc/tdefine.nim index c4d11c941..f3fa4711f 100644 --- a/tests/misc/tdefine.nim +++ b/tests/misc/tdefine.nim @@ -1,12 +1,23 @@ discard """ joinable: false -cmd: "nim c -d:booldef -d:booldef2=false -d:intdef=2 -d:strdef=foobar -d:namespaced.define=false -d:double.namespaced.define -r $file" +cmd: "nim c $options -d:booldef -d:booldef2=false -d:intdef=2 -d:strdef=foobar -d:namespaced.define=false -d:double.namespaced.define -r $file" +matrix: "; -d:useGenericDefine" """ -const booldef {.booldefine.} = false -const booldef2 {.booldefine.} = true -const intdef {.intdefine.} = 0 -const strdef {.strdefine.} = "" +when defined(useGenericDefine): + {.pragma: booldefine2, define.} + {.pragma: intdefine2, define.} + {.pragma: strdefine2, define.} +else: + + {.pragma: booldefine2, booldefine.} + {.pragma: intdefine2, intdefine.} + {.pragma: strdefine2, strdefine.} + +const booldef {.booldefine2.} = false +const booldef2 {.booldefine2.} = true +const intdef {.intdefine2.} = 0 +const strdef {.strdefine2.} = "" doAssert defined(booldef) doAssert defined(booldef2) @@ -17,17 +28,28 @@ doAssert not booldef2 doAssert intdef == 2 doAssert strdef == "foobar" +when defined(useGenericDefine): + block: + const uintdef {.define: "intdef".}: uint = 17 + doAssert intdef == int(uintdef) + const cstrdef {.define: "strdef".}: cstring = "not strdef" + doAssert $cstrdef == strdef + type FooBar = enum foo, bar, foobar + const enumdef {.define: "strdef".} = foo + doAssert $enumdef == strdef + doAssert enumdef == foobar + # Intentionally not defined from command line -const booldef3 {.booldefine.} = true -const intdef2 {.intdefine.} = 1 -const strdef2 {.strdefine.} = "abc" +const booldef3 {.booldefine2.} = true +const intdef2 {.intdefine2.} = 1 +const strdef2 {.strdefine2.} = "abc" type T = object - when booldef3: - field1: int - when intdef2 == 1: - field2: int - when strdef2 == "abc": - field3: int + when booldef3: + field1: int + when intdef2 == 1: + field2: int + when strdef2 == "abc": + field3: int doAssert not defined(booldef3) doAssert not defined(intdef2) @@ -35,11 +57,21 @@ doAssert not defined(strdef2) discard T(field1: 1, field2: 2, field3: 3) doAssert defined(namespaced.define) -const `namespaced.define` {.booldefine.} = true +const `namespaced.define` {.booldefine2.} = true doAssert not `namespaced.define` +when defined(useGenericDefine): + const aliasToNamespacedDefine {.define: "namespaced.define".} = not `namespaced.define` +else: + const aliasToNamespacedDefine {.booldefine: "namespaced.define".} = not `namespaced.define` +doAssert aliasToNamespacedDefine == `namespaced.define` doAssert defined(double.namespaced.define) -const `double.namespaced.define` {.booldefine.} = false +const `double.namespaced.define` {.booldefine2.} = false doAssert `double.namespaced.define` +when defined(useGenericDefine): + const aliasToDoubleNamespacedDefine {.define: "double.namespaced.define".} = not `double.namespaced.define` +else: + const aliasToDoubleNamespacedDefine {.booldefine: "double.namespaced.define".} = not `double.namespaced.define` +doAssert aliasToDoubleNamespacedDefine == `double.namespaced.define` doAssert not defined(namespaced.butnotdefined) diff --git a/tests/misc/temit.nim b/tests/misc/temit.nim deleted file mode 100644 index ee7455d4c..000000000 --- a/tests/misc/temit.nim +++ /dev/null @@ -1,15 +0,0 @@ -discard """ - output: "509" -""" -# Test the new ``emit`` pragma: - -{.emit: """ -static int cvariable = 420; - -""".} - -proc embedsC() = - var nimVar = 89 - {.emit: """printf("%d\n", cvariable + (int)`nimVar`);""".} - -embedsC() diff --git a/tests/misc/temptyecho.nim b/tests/misc/temptyecho.nim deleted file mode 100644 index a3c407897..000000000 --- a/tests/misc/temptyecho.nim +++ /dev/null @@ -1,6 +0,0 @@ -discard """ -output: "\n" -""" - -echo() - diff --git a/tests/misc/tgcregions.nim b/tests/misc/tgcregions.nim deleted file mode 100644 index e14865be3..000000000 --- a/tests/misc/tgcregions.nim +++ /dev/null @@ -1,6 +0,0 @@ -discard """ -cmd: "nim c --gc:regions $file" -""" - -# issue #12597 -# it just tests that --gc:regions compiles. Nothing else. :'( diff --git a/tests/misc/tgenconstraints.nim b/tests/misc/tgenconstraints.nim deleted file mode 100644 index 829da5173..000000000 --- a/tests/misc/tgenconstraints.nim +++ /dev/null @@ -1,31 +0,0 @@ -discard """ - errormsg: "cannot instantiate T2" - file: "tgenconstraints.nim" - line: 25 - disabled: true -""" - -type - T1[T: int|string] = object - x: T - - T2[T: Ordinal] = object - x: T - -var x1: T1[int] -var x2: T1[string] -var x3: T2[int] - -proc foo[T](x: T): T2[T] {.discardable.} = - var o: T1[T] - -foo(10) - -# XXX: allow type intersections in situation like this -proc bar(x: int|TNumber): T1[type(x)] {.discardable.} = - when type(x) is TNumber: - var o: T2[type(x)] - -bar "test" -bar 100 -bar 1.1 diff --git a/tests/misc/thints_off.nim b/tests/misc/thints_off.nim deleted file mode 100644 index 5a4cadad6..000000000 --- a/tests/misc/thints_off.nim +++ /dev/null @@ -1,4 +0,0 @@ -discard """ - matrix: "--hints:off" -""" -doAssert true diff --git a/tests/misc/tidentconcatenations.nim b/tests/misc/tidentconcatenations.nim deleted file mode 100644 index ddd2e49cc..000000000 --- a/tests/misc/tidentconcatenations.nim +++ /dev/null @@ -1,31 +0,0 @@ -type - Hash*[bits: static[int]] = object - data*: array[bits div 8, uint8] - -{.emit: """ - -void sha_256(void* input, int input_len, void* output, int output_len) {} -void sha_512(void* input, int input_len, void* output, int output_len) {} - -void keccak_256(void* input, int input_len, void* output, int output_len) {} -void keccak_512(void* input, int input_len, void* output, int output_len) {} - -""".} - -template defineKeccak(bits: untyped) = - proc `extKeccak bits`(output: pointer, outSize: csize_t, input: pointer, inputSize: csize_t) {.nodecl, importc: "keccak_" & astToStr(bits).} - -template defineSha(bits: static[int]) = - proc `extSha bits`(output: pointer, outSize: csize_t, input: pointer, inputSize: csize_t) {.nodecl, importc: "sha_" & astToStr(bits).} - -template defineHashProcs(bits) = - defineSha(bits) - defineKeccak(bits) - -defineHashProcs(256) -defineHashProcs(512) - -extSha256(nil, 0, nil, 0) -extSha512(nil, 0, nil, 0) -extKeccak256(nil, 0, nil, 0) -extKeccak512(nil, 0, nil, 0) diff --git a/tests/misc/tinc.nim b/tests/misc/tinc.nim deleted file mode 100644 index 91f6223e2..000000000 --- a/tests/misc/tinc.nim +++ /dev/null @@ -1,8 +0,0 @@ -discard """ - errormsg: "type mismatch: got <int>" - file: "tinc.nim" - line: 8 -""" -var x = 0 - -inc(x+1) diff --git a/tests/misc/tints.nim b/tests/misc/tints.nim deleted file mode 100644 index d24cbd4ac..000000000 --- a/tests/misc/tints.nim +++ /dev/null @@ -1,85 +0,0 @@ -discard """ - output: ''' -0 0 -0 0 -Success''' -""" -# Test the different integer operations - -var testNumber = 0 - -template test(opr, a, b, c: untyped): untyped = - # test the expression at compile and runtime - block: - const constExpr = opr(a, b) - when constExpr != c: - {.error: "Test failed " & $constExpr & " " & $c.} - inc(testNumber) - #Echo("Test: " & $testNumber) - var aa = a - var bb = b - var varExpr = opr(aa, bb) - assert(varExpr == c) - -test(`+`, 12'i8, -13'i16, -1'i16) -test(`shl`, 0b11, 0b100, 0b110000) -when not defined(js): - test(`shl`, 0b11'i32, 0b100'i64, 0b110000'i64) -test(`shl`, 0b11'i32, 0b100'i32, 0b110000'i32) - -test(`or`, 0xf0f0'i16, 0x0d0d'i16, 0xfdfd'i16) -test(`and`, 0xf0f0'i16, 0xfdfd'i16, 0xf0f0'i16) - -when not defined(js): - test(`shr`, 0xffffffffffffffff'i64, 0x4'i64, 0xffffffffffffffff'i64) -test(`shr`, 0xffff'i16, 0x4'i16, 0xffff'i16) -test(`shr`, 0xff'i8, 0x4'i8, 0xff'i8) - -when not defined(js): - test(`shr`, 0xffffffff'i64, 0x4'i64, 0x0fffffff'i64) -test(`shr`, 0xffffffff'i32, 0x4'i32, 0xffffffff'i32) - -when not defined(js): - test(`shl`, 0xffffffffffffffff'i64, 0x4'i64, 0xfffffffffffffff0'i64) -test(`shl`, 0xffff'i16, 0x4'i16, 0xfff0'i16) -test(`shl`, 0xff'i8, 0x4'i8, 0xf0'i8) - -when not defined(js): - test(`shl`, 0xffffffff'i64, 0x4'i64, 0xffffffff0'i64) -test(`shl`, 0xffffffff'i32, 0x4'i32, 0xfffffff0'i32) - -# bug #916 -proc unc(a: float): float = - return a - -echo int(unc(0.5)), " ", int(unc(-0.5)) -echo int(0.5), " ", int(-0.5) - -block: # Casts to uint - template testCast(fromValue: typed, toType: typed, expectedResult: typed) = - let src = fromValue - let dst = cast[toType](src) - if dst != expectedResult: - echo "Casting ", astToStr(fromValue), " to ", astToStr(toType), " = ", dst.int, " instead of ", astToStr(expectedResult) - doAssert(dst == expectedResult) - - testCast(-1'i16, uint16, 0xffff'u16) - testCast(0xffff'u16, int16, -1'i16) - - testCast(0xff'u16, uint8, 0xff'u8) - testCast(0xffff'u16, uint8, 0xff'u8) - - testCast(-1'i16, uint32, 0xffffffff'u32) - testCast(0xffffffff'u32, int32, -1) - - testCast(0xfffffffe'u32, int32, -2'i32) - testCast(0xffffff'u32, int16, -1'i32) - - testCast(-5'i32, uint8, 251'u8) - -# issue #7174 -let c = 1'u -let val = c > 0 -doAssert val - -echo("Success") #OUT Success diff --git a/tests/misc/tinvalidarrayaccess.nim b/tests/misc/tinvalidarrayaccess.nim deleted file mode 100644 index f8bce45ef..000000000 --- a/tests/misc/tinvalidarrayaccess.nim +++ /dev/null @@ -1,21 +0,0 @@ -discard """ - errormsg: "index 2 not in 0 .. 1" - line: 18 -""" -block: - try: - let a = @[1,2] - echo a[3] - except Exception as e: - doAssert e.msg == "index 3 not in 0 .. 1" - # note: this is not being tested, because the CT error happens before - -block: - type TTestArr = array[0..1, int16] - var f: TTestArr - f[0] = 30 - f[1] = 40 - f[2] = 50 - f[3] = 60 - - echo(repr(f)) diff --git a/tests/misc/tinvalidarrayaccess2.nim b/tests/misc/tinvalidarrayaccess2.nim deleted file mode 100644 index 0a0703834..000000000 --- a/tests/misc/tinvalidarrayaccess2.nim +++ /dev/null @@ -1,10 +0,0 @@ -discard """ - errormsg: "index 3 not in 0 .. 1" - line: 9 -""" - -# Note: merge in tinvalidarrayaccess.nim pending https://github.com/nim-lang/Nim/issues/9906 - -let a = [1,2] -echo a[3] - diff --git a/tests/misc/tlambdadonotation.nim b/tests/misc/tlambdadonotation.nim deleted file mode 100644 index 3160c0972..000000000 --- a/tests/misc/tlambdadonotation.nim +++ /dev/null @@ -1,78 +0,0 @@ -discard """ -output: ''' -issue #11812 -issue #10899 -123 -issue #11367 -event consumed! -''' -""" - -echo "issue #11812" - -proc run(a: proc()) = a() - -proc main() = - var test: int - run(proc() = test = 0) - run do: - test = 0 - -main() - - -echo "issue #10899" - -proc foo(x: proc {.closure.}) = - x() - -proc bar = - var x = 123 - # foo proc = echo x #[ ok ]# - foo: echo x #[ SIGSEGV: Illegal storage access. (Attempt to read from nil?) ]# - -bar() - -echo "issue #11367" - -type - - EventCB = proc() - - Emitter = object - cb: EventCB - - Subscriber = object - discard - -proc newEmitter(): Emitter = - result - -proc on_event(self: var Emitter, cb: EventCB) = - self.cb = cb - -proc emit(self: Emitter) = - self.cb() - -proc newSubscriber(): Subscriber = - result - -proc consume(self: Subscriber) = - echo "event consumed!" - -proc main2() = - var emitter = newEmitter() - var subscriber = newSubscriber() - - proc foo() = - subscriber.consume() - - emitter.on_event() do (): - subscriber.consume() - - # this works - # emitter.on_event(foo) - - emitter.emit() - -main2() diff --git a/tests/misc/tlocals.nim b/tests/misc/tlocals.nim deleted file mode 100644 index e59976102..000000000 --- a/tests/misc/tlocals.nim +++ /dev/null @@ -1,76 +0,0 @@ -discard """ - matrix: "--mm:refc; --mm:orc" - output: '''(x: "string here", a: 1) -b is 5 -x is 12''' -""" - -proc simple[T](a: T) = - var - x = "string here" - echo locals() - -simple(1) - -type Foo2[T]=object - a2: T - -proc numFields*(T: typedesc[tuple|object]): int= - var t:T - for _ in t.fields: inc result - -proc test(baz: int, qux: var int): int = - var foo: Foo2[int] - let bar = "abc" - let c1 = locals() - doAssert numFields(c1.foo.type) == 1 - doAssert c1.bar == "abc" - doAssert c1.baz == 123 - doAssert c1.result == 0 - doAssert c1.qux == 456 - -var x1 = 456 -discard test(123, x1) - -# bug #11958 -proc foo() = - var a = 5 - proc bar() {.nimcall.} = - var b = 5 - for k, v in fieldpairs(locals()): - echo k, " is ", v - - bar() -foo() - - -proc foo2() = - var a = 5 - proc bar2() {.nimcall.} = - for k, v in fieldpairs(locals()): - echo k, " is ", v - - bar2() -foo2() - - -proc foo3[T](y: T) = - var a = 5 - proc bar2[T](x: T) {.nimcall.} = - for k, v in fieldpairs(locals()): - echo k, " is ", v - - bar2(y) - -foo3(12) - -block: # bug #12682 - template foo(): untyped = - var c1 = locals() - 1 - - proc testAll()= - doAssert foo() == 1 - let c2=locals() - - testAll() diff --git a/tests/misc/tlowhigh.nim b/tests/misc/tlowhigh.nim deleted file mode 100644 index 6ae871255..000000000 --- a/tests/misc/tlowhigh.nim +++ /dev/null @@ -1,32 +0,0 @@ -discard """ - action: run - output: ''' -18446744073709551615 -9223372036854775807 -4294967295 -0 -0 -''' -""" - -var x: range[-1'f32..1'f32] -doAssert x.low == -1'f32 -doAssert x.high == 1'f32 -doAssert x.type.low == -1'f32 -doAssert x.type.high == 1'f32 -var y: range[-1'f64..1'f64] -doAssert y.low == -1'f64 -doAssert y.high == 1'f64 -doAssert y.type.low == -1'f64 -doAssert y.type.high == 1'f64 - -# bug #11972 -var num: uint8 -doAssert num.high.float == 255.0 - -echo high(uint64) -echo high(int64) -echo high(uint32) - -echo low(uint64) -echo low(uint32) diff --git a/tests/misc/tnew.nim b/tests/misc/tnew.nim deleted file mode 100644 index 41ef3fa19..000000000 --- a/tests/misc/tnew.nim +++ /dev/null @@ -1,59 +0,0 @@ -discard """ -matrix: "--mm:refc" -outputsub: ''' -Simple tree node allocation worked! -Simple cycle allocation worked! -''' -joinable: false -""" - -# Test the implementation of the new operator -# and the code generation for gc walkers -# (and the garbage collector): - -## todo fixme it doesn't work for ORC -type - PNode = ref TNode - TNode = object - data: int - str: string - le, ri: PNode - - TStressTest = ref array[0..45, array[1..45, TNode]] - -proc finalizer(n: PNode) = - write(stdout, n.data) - write(stdout, " is now freed\n") - -proc newNode(data: int, le, ri: PNode): PNode = - new(result, finalizer) - result.le = le - result.ri = ri - result.data = data - -# now loop and build a tree -proc main() = - var - i = 0 - p: TStressTest - while i < 1000: - var n: PNode - - n = newNode(i, nil, newNode(i + 10000, nil, nil)) - inc(i) - new(p) - - write(stdout, "Simple tree node allocation worked!\n") - i = 0 - while i < 1000: - var m = newNode(i + 20000, nil, nil) - var k = newNode(i + 30000, nil, nil) - m.le = m - m.ri = k - k.le = m - k.ri = k - inc(i) - - write(stdout, "Simple cycle allocation worked!\n") - -main() diff --git a/tests/misc/tnewderef.nim b/tests/misc/tnewderef.nim deleted file mode 100644 index 3394dbddf..000000000 --- a/tests/misc/tnewderef.nim +++ /dev/null @@ -1,11 +0,0 @@ -discard """ - output: 3 - -""" - -var x: ref int -new(x) -x[] = 3 - -echo x[] - diff --git a/tests/misc/tnewsets.nim b/tests/misc/tnewsets.nim deleted file mode 100644 index f239d4aa2..000000000 --- a/tests/misc/tnewsets.nim +++ /dev/null @@ -1,6 +0,0 @@ -# new test for sets: - -const elem = ' ' - -var s: set[char] = {elem} -assert(elem in s and 'a' not_in s and 'c' not_in s ) diff --git a/tests/misc/tnoinst.nim b/tests/misc/tnoinst.nim deleted file mode 100644 index 85db1e8e7..000000000 --- a/tests/misc/tnoinst.nim +++ /dev/null @@ -1,16 +0,0 @@ -discard """ - errormsg: "instantiate 'notConcrete' explicitly" - line: 12 - disabled: "true" -""" - -proc wrap[T]() = - proc notConcrete[T](x, y: int): int = - var dummy: T - result = x - y - - var x: proc (x, y: T): int - x = notConcrete - - -wrap[int]() diff --git a/tests/misc/tnoop.nim b/tests/misc/tnoop.nim deleted file mode 100644 index f55f2441a..000000000 --- a/tests/misc/tnoop.nim +++ /dev/null @@ -1,12 +0,0 @@ -discard """ - nimout: ''' - found 'a' [var declared in tnoop.nim(10, 3)] - ''' - file: "tnoop.nim" - errormsg: "attempting to call routine: 'a'" -""" - -var - a: int - -a() diff --git a/tests/misc/tnot.nim b/tests/misc/tnot.nim deleted file mode 100644 index a3669705b..000000000 --- a/tests/misc/tnot.nim +++ /dev/null @@ -1,19 +0,0 @@ -discard """ - errormsg: "type mismatch" - file: "tnot.nim" - line: 14 -""" -# BUG: following compiles, but should not: - -proc nodeOfDegree(x: int): bool = - result = false - -proc main = - for j in 0..2: - for i in 0..10: - if not nodeOfDegree(1) >= 0: #ERROR_MSG type mismatch - echo "Yes" - else: - echo "No" - -main() diff --git a/tests/misc/tparamsindefault.nim b/tests/misc/tparamsindefault.nim deleted file mode 100644 index 3fe917f2b..000000000 --- a/tests/misc/tparamsindefault.nim +++ /dev/null @@ -1,120 +0,0 @@ -discard """ -output: ''' -@[1, 2, 3]@[1, 2, 3] -a -a -1 -3 is an int -2 is an int -miau is a string -f1 1 1 1 -f1 2 3 3 -f1 10 20 30 -f2 100 100 100 -f2 200 300 300 -f2 300 400 400 -f3 10 10 20 -f3 10 15 25 -true true -false true -world -typedescDefault -''' -""" - -template reject(x) = - assert(not compiles(x)) - -block: - # https://github.com/nim-lang/Nim/issues/7756 - proc foo[T](x: seq[T], y: seq[T] = x) = - echo x, y - - let a = @[1, 2, 3] - foo(a) - -block: - # https://github.com/nim-lang/Nim/issues/1201 - proc issue1201(x: char|int = 'a') = echo x - - issue1201() - issue1201('a') - issue1201(1) - - # https://github.com/nim-lang/Nim/issues/7000 - proc test(a: int|string = 2) = - when a is int: - echo a, " is an int" - elif a is string: - echo a, " is a string" - - test(3) # works - test() # works - test("miau") - -block: - # https://github.com/nim-lang/Nim/issues/3002 and similar - proc f1(a: int, b = a, c = b) = - echo "f1 ", a, " ", b, " ", c - - proc f2(a: int, b = a, c: int = b) = - echo "f2 ", a, " ", b, " ", c - - proc f3(a: int, b = a, c = a + b) = - echo "f3 ", a, " ", b, " ", c - - f1 1 - f1(2, 3) - f1 10, 20, 30 - 100.f2 - 200.f2 300 - 300.f2(400) - - 10.f3() - 10.f3(15) - - reject: - # This is a type mismatch error: - proc f4(a: int, b = a, c: float = b) = discard - - reject: - # undeclared identifier - proc f5(a: int, b = c, c = 10) = discard - - reject: - # undeclared identifier - proc f6(a: int, b = b) = discard - - reject: - # undeclared identifier - proc f7(a = a) = discard - -block: - proc f(a: var int, b: ptr int, c = addr(a)) = - echo addr(a) == b, " ", b == c - - var x = 10 - f(x, addr(x)) - f(x, nil, nil) - -block: - # https://github.com/nim-lang/Nim/issues/1046 - proc pySubstr(s: string, start: int, endd = s.len()): string = - var - revStart = start - revEnd = endd - - if start < 0: - revStart = s.len() + start - if endd < 0: - revEnd = s.len() + endd - - return s[revStart .. revEnd-1] - - echo pySubstr("Hello world", -5) - - -# bug #11660 - -func typedescDefault(T: typedesc; arg: T = 0) = debugEcho "typedescDefault" -typedescDefault(int) diff --git a/tests/misc/tproveinit.nim b/tests/misc/tproveinit.nim deleted file mode 100644 index c9f688309..000000000 --- a/tests/misc/tproveinit.nim +++ /dev/null @@ -1,18 +0,0 @@ -discard """ - joinable: false -""" - -{.warningAsError[ProveInit]:on.} -template main() = - proc fn(): var int = - discard - discard fn() -doAssert not compiles(main()) - -# bug #9901 -import std/[sequtils, times] -proc parseMyDates(line: string): DateTime = - result = parse(line, "yyyy-MM-dd") -var dateStrings = @["2018-12-01", "2018-12-02", "2018-12-03"] -var parsed = dateStrings.map(parseMyDates) -discard parsed diff --git a/tests/misc/trangechecks.nim b/tests/misc/trangechecks.nim deleted file mode 100644 index e48b1272b..000000000 --- a/tests/misc/trangechecks.nim +++ /dev/null @@ -1,48 +0,0 @@ -discard """ - output: '''10 -10 -1 -1 -true''' -""" - -# bug #1344 - -var expected: int -var x: range[1..10] = 10 - -try: - x += 1 - echo x -except OverflowDefect, RangeDefect: - expected += 1 - echo x - -try: - inc x - echo x -except OverflowDefect, RangeDefect: - expected += 1 - echo x - -x = 1 -try: - x -= 1 - echo x -except OverflowDefect, RangeDefect: - expected += 1 - echo x - -try: - dec x - echo x -except OverflowDefect, RangeDefect: - expected += 1 - echo x - -echo expected == 4 - -# bug #13698 -var - x45 = "hello".cstring - p = x45.len.int32 diff --git a/tests/misc/trawstr.nim b/tests/misc/trawstr.nim deleted file mode 100644 index aa41071d5..000000000 --- a/tests/misc/trawstr.nim +++ /dev/null @@ -1,10 +0,0 @@ -discard """ - errormsg: "closing \" expected" - file: "trawstr.nim" - line: 10 -""" -# Test the new raw strings: - -const - xxx = r"This is a raw string!" - yyy = "This not\" #ERROR diff --git a/tests/misc/treadln.nim b/tests/misc/treadln.nim deleted file mode 100644 index b716c4711..000000000 --- a/tests/misc/treadln.nim +++ /dev/null @@ -1,21 +0,0 @@ - -discard """ -output: ''' -test the improved readline handling that does not care whether its -Macintosh, Unix or Windows text format. -''' -""" - -# test the improved readline handling that does not care whether its -# Macintosh, Unix or Windows text format. - -var - inp: File - line: string - -if open(inp, "tests/misc/treadln.nim"): - while not endOfFile(inp): - line = readLine(inp) - if line.len >= 2 and line[0] == '#' and line[1] == ' ': - echo line[2..^1] - close(inp) diff --git a/tests/misc/treservedcidentsasfields.nim b/tests/misc/treservedcidentsasfields.nim deleted file mode 100644 index a9a954651..000000000 --- a/tests/misc/treservedcidentsasfields.nim +++ /dev/null @@ -1,39 +0,0 @@ -discard """ - targets: "c cpp" -""" - -import macros - -macro make_test_type(idents: varargs[untyped]): untyped = - result = nnkStmtList.newTree() - - var ident_defs: seq[NimNode] = @[] - for i in idents: - ident_defs.add newIdentDefs(i, ident("int")) - - result.add newTree(nnkTypeSection, - newTree(nnkTypeDef, - ident("TestType"), - newEmptyNode(), - newTree(nnkObjectTy, - newEmptyNode(), - newEmptyNode(), - newTree(nnkRecList, - ident_defs - ) - ) - ) - ) - -make_test_type( - auto, bool, catch, char, class, compl, const_cast, default, delete, double, - dynamic_cast, explicit, extern, false, float, friend, goto, int, long, - mutable, namespace, new, operator, private, protected, public, register, - reinterpret_cast, restrict, short, signed, sizeof, static_cast, struct, switch, - this, throw, true, typedef, typeid, typeof, typename, union, packed, unsigned, - virtual, void, volatile, wchar_t, alignas, alignof, constexpr, decltype, nullptr, - noexcept, thread_local, static_assert, char16_t, char32_t -) - -# Make sure the type makes it to codegen. -var test_instance: TestType diff --git a/tests/misc/trfc405.nim b/tests/misc/trfc405.nim index 8c967eb77..0828879ee 100644 --- a/tests/misc/trfc405.nim +++ b/tests/misc/trfc405.nim @@ -79,6 +79,34 @@ template main = foobar3 foobar4 doAssert a2 == (1, 20, "\nfoobar1\nfoobar2", "\nfoobar3\nfoobar4") + + block: # issue #19015 + template hi(a: untyped, b: varargs[untyped]): untyped = + a + + var worked = false + hi: + worked = true + doAssert worked + worked = false + hi(doAssert(not worked)): + doesntCompile + hi(doAssert(not worked), doesntCompile, againDoesntCompile): + definitelyDoesntCompile + + template hi2(a: bool, b: untyped, c: varargs[untyped]): untyped = + b + doAssert a + + hi2 worked: + worked = true + doAssert worked + hi2 worked, doAssert(worked): + doesntCompile + hi2 worked, doAssert(worked), doesntCompile, againDoesntCompile: + definitelyDoesntCompile + hi2 worked, doAssert(worked), againDoesntCompile: + definitelyDoesntCompile static: main() main() diff --git a/tests/misc/trfc_341.nim b/tests/misc/trfc_341.nim deleted file mode 100644 index 37cf675c6..000000000 --- a/tests/misc/trfc_341.nim +++ /dev/null @@ -1,27 +0,0 @@ -# test for https://github.com/nim-lang/RFCs/issues/341 -import std/json -import std/jsonutils -import std/macros - -macro fn1(a: untyped): string = newLit a.lispRepr - -doAssert fn1(a.?b.c) == """(DotExpr (Infix (Ident ".?") (Ident "a") (Ident "b")) (Ident "c"))""" - -template `.?`(a: JsonNode, b: untyped{ident}): JsonNode = - a[astToStr(b)] - -proc identity[T](a: T): T = a -proc timesTwo[T](a: T): T = a * 2 - -template main = - let a = (a1: 1, a2: "abc", a3: (a4: 2.5)) - let j = a.toJson - doAssert j.?a1.getInt == 1 - doAssert j.?a3.?a4.getFloat == 2.5 - doAssert j.?a3.?a4.getFloat.timesTwo == 5.0 - doAssert j.?a3.identity.?a4.getFloat.timesTwo == 5.0 - doAssert j.identity.?a3.identity.?a4.identity.getFloat.timesTwo == 5.0 - doAssert j.identity.?a3.?a4.identity.getFloat.timesTwo == 5.0 - -static: main() -main() diff --git a/tests/misc/trunner.nim b/tests/misc/trunner.nim index 7fb437ce3..6e5487d1b 100644 --- a/tests/misc/trunner.nim +++ b/tests/misc/trunner.nim @@ -224,13 +224,15 @@ sub/mmain.idx""", context doAssert exitCode == 0, msg let data = parseJson(readFile(output))["entries"] - doAssert data.len == 4 + doAssert data.len == 5 let doSomething = data[0] doAssert doSomething["name"].getStr == "doSomething" doAssert doSomething["type"].getStr == "skProc" doAssert doSomething["line"].getInt == 1 doAssert doSomething["col"].getInt == 0 doAssert doSomething["code"].getStr == "proc doSomething(x, y: int): int {.raises: [], tags: [], forbids: [].}" + let foo2 = data[4] + doAssert $foo2["signature"] == """{"arguments":[{"name":"x","type":"T"},{"name":"y","type":"U"},{"name":"z","type":"M"}],"genericParams":[{"name":"T","types":"int"},{"name":"M","types":"string"},{"name":"U"}]}""" block: # nim jsondoc # bug #11953 let file = testsDir / "misc/mjsondoc.nim" @@ -241,7 +243,7 @@ sub/mmain.idx""", context doAssert exitCode == 0, msg let data = parseJson(readFile(destDir / "mjsondoc.json"))["entries"] - doAssert data.len == 4 + doAssert data.len == 5 let doSomething = data[0] doAssert doSomething["name"].getStr == "doSomething" doAssert doSomething["type"].getStr == "skProc" @@ -271,10 +273,13 @@ sub/mmain.idx""", context check execCmdEx(cmd) == ("12\n", 0) block: # bug #15316 - let file = testsDir / "misc/m15316.nim" - let cmd = fmt"{nim} check --hints:off --nimcache:{nimcache} {file}" - check execCmdEx(cmd) == ("m15316.nim(1, 15) Error: expression expected, but found \')\'\nm15316.nim(2, 1) Error: expected: \':\', but got: \'[EOF]\'\nm15316.nim(2, 1) Error: expression expected, but found \'[EOF]\'\nm15316.nim(2, 1) " & - "Error: expected: \')\', but got: \'[EOF]\'\nError: illformed AST: \n", 1) + when not defined(windows): + # This never worked reliably on Windows. Needs further investigation but it is hard to reproduce. + # Looks like a mild stack corruption when bailing out of nested exception handling. + let file = testsDir / "misc/m15316.nim" + let cmd = fmt"{nim} check --hints:off --nimcache:{nimcache} {file}" + check execCmdEx(cmd) == ("m15316.nim(1, 15) Error: expression expected, but found \')\'\nm15316.nim(2, 1) Error: expected: \':\', but got: \'[EOF]\'\nm15316.nim(2, 1) Error: expression expected, but found \'[EOF]\'\nm15316.nim(2, 1) " & + "Error: expected: \')\', but got: \'[EOF]\'\nError: illformed AST: \n", 1) block: # config.nims, nim.cfg, hintConf, bug #16557 @@ -342,8 +347,8 @@ tests/newconfig/bar/mfoo.nims""".splitLines when not defined(windows): check3 lines.len == 5 check3 lines[0].isDots - check3 lines[1].dup(removePrefix(">>> ")) == "3" # prompt depends on `nimUseLinenoise` - check3 lines[2].isDots + # check3 lines[1].isDots # todo nim secret might use parsing pipeline + check3 lines[2].dup(removePrefix(">>> ")) == "3" # prompt depends on `nimUseLinenoise` check3 lines[3] == "ab" check3 lines[4] == "" else: @@ -404,7 +409,7 @@ running: v2 block: # UnusedImport proc fn(opt: string, expected: string) = - let output = runNimCmdChk("pragmas/mused3.nim", fmt"--warning:all:off --warning:UnusedImport --hint:DuplicateModuleImport {opt}") + let output = runNimCmdChk("msgs/mused3.nim", fmt"--warning:all:off --warning:UnusedImport --hint:DuplicateModuleImport {opt}") doAssert output == expected, opt & "\noutput:\n" & output & "expected:\n" & expected fn("-d:case1"): """ mused3.nim(13, 8) Warning: imported and not used: 'mused3b' [UnusedImport] @@ -434,7 +439,6 @@ mused3.nim(75, 10) Hint: duplicate import of 'mused3a'; previous import here: mu fn("-d:case2 --gc:refc"): """mfield_defect.nim(25, 15) field 'f2' is not accessible for type 'Foo' [discriminant declared in mfield_defect.nim(14, 8)] using 'kind = k3'""" fn("-d:case1 -b:js"): """mfield_defect.nim(25, 15) Error: field 'f2' is not accessible for type 'Foo' [discriminant declared in mfield_defect.nim(14, 8)] using 'kind = k3'""" fn("-d:case2 -b:js"): """field 'f2' is not accessible for type 'Foo' [discriminant declared in mfield_defect.nim(14, 8)] using 'kind = k3'""" - # 3 instead of k3, because of lack of RTTI - fn("-d:case2 --gc:arc"): """mfield_defect.nim(25, 15) field 'f2' is not accessible for type 'Foo' [discriminant declared in mfield_defect.nim(14, 8)] using 'kind = 3'""" + fn("-d:case2 --gc:arc"): """mfield_defect.nim(25, 15) field 'f2' is not accessible for type 'Foo' [discriminant declared in mfield_defect.nim(14, 8)] using 'kind = k3'""" else: discard # only during debugging, tests added here will run with `-d:nimTestsTrunnerDebugging` enabled diff --git a/tests/misc/trunner_special.nim b/tests/misc/trunner_special.nim index 50a2e4d5a..e08b419b0 100644 --- a/tests/misc/trunner_special.nim +++ b/tests/misc/trunner_special.nim @@ -1,6 +1,7 @@ discard """ targets: "c cpp" joinable: false + disabled: osx """ #[ @@ -13,6 +14,10 @@ xxx test all tests/untestable/* here, possibly with adjustments to make running import std/[strformat,os,unittest,compilesettings] import stdtest/specialpaths + +from stdtest/testutils import disableSSLTesting + + const nim = getCurrentCompilerExe() mode = querySetting(backend) @@ -28,4 +33,5 @@ proc main = block: # SSL certificate check integration tests runCmd fmt"{nim} r {options} -d:ssl --threads:on --mm:refc {testsDir}/untestable/thttpclient_ssl_remotenetwork.nim" -main() +when not disableSSLTesting(): + main() diff --git a/tests/misc/tsimtych.nim b/tests/misc/tsimtych.nim deleted file mode 100644 index 74a6ad4c0..000000000 --- a/tests/misc/tsimtych.nim +++ /dev/null @@ -1,10 +0,0 @@ -discard """ - errormsg: "type mismatch: got <bool> but expected \'string\'" - file: "tsimtych.nim" - line: 10 -""" -# Test 2 -# Simple type checking - -var a: string -a = false #ERROR diff --git a/tests/misc/tsizeof.nim b/tests/misc/tsizeof.nim index 0d96a5e04..ce5334664 100644 --- a/tests/misc/tsizeof.nim +++ b/tests/misc/tsizeof.nim @@ -732,3 +732,11 @@ type doAssert sizeof(PackedUnion) == 11 doAssert alignof(PackedUnion) == 1 + +# bug #22553 +type + ChunkObj = object + data: UncheckedArray[byte] + +doAssert sizeof(ChunkObj) == 1 +doAssert offsetOf(ChunkObj, data) == 1 diff --git a/tests/misc/tslices.nim b/tests/misc/tslices.nim deleted file mode 100644 index 987b50de1..000000000 --- a/tests/misc/tslices.nim +++ /dev/null @@ -1,59 +0,0 @@ -discard """ -output: ''' -456456 -456456 -456456 -Zugr5nd -egerichtetd -verichtetd -''' -""" - -# Test the new slices. - -var mystr = "Abgrund" -# mystr[..1] = "Zu" # deprecated -mystr[0..1] = "Zu" - -mystr[4..4] = "5" - -type - TEnum = enum e1, e2, e3, e4, e5, e6 - -var myarr: array[TEnum, int] = [1, 2, 3, 4, 5, 6] -myarr[e1..e3] = myarr[e4..e6] -# myarr[..e3] = myarr[e4..e6] # deprecated -myarr[0..e3] = myarr[e4..e6] - -for x in items(myarr): stdout.write(x) -echo() - -var myarr2: array[0..5, int] = [1, 2, 3, 4, 5, 6] -myarr2[0..2] = myarr2[3..5] - -for x in items(myarr2): stdout.write(x) -echo() - - -var myseq = @[1, 2, 3, 4, 5, 6] -myseq[0..2] = myseq[^3 .. ^1] - -for x in items(myseq): stdout.write(x) -echo() - -echo mystr - -mystr[4..4] = "u" - -# test full replacement -# mystr[.. ^2] = "egerichtet" # deprecated -mystr[0 .. ^2] = "egerichtet" - -echo mystr - -mystr[0..2] = "ve" -echo mystr - -var s = "abcdef" -s[1 .. ^2] = "xyz" -assert s == "axyzf" diff --git a/tests/misc/tspellsuggest.nim b/tests/misc/tspellsuggest.nim deleted file mode 100644 index 033ed0afc..000000000 --- a/tests/misc/tspellsuggest.nim +++ /dev/null @@ -1,45 +0,0 @@ -discard """ - # pending bug #16521 (bug 12) use `matrix` - cmd: "nim c --spellsuggest:15 --hints:off $file" - action: "reject" - nimout: ''' -tspellsuggest.nim(45, 13) Error: undeclared identifier: 'fooBar' -candidates (edit distance, scope distance); see '--spellSuggest': - (1, 0): 'fooBar8' [var declared in tspellsuggest.nim(43, 9)] - (1, 1): 'fooBar7' [var declared in tspellsuggest.nim(41, 7)] - (1, 3): 'fooBar1' [var declared in tspellsuggest.nim(33, 5)] - (1, 3): 'fooBar2' [let declared in tspellsuggest.nim(34, 5)] - (1, 3): 'fooBar3' [const declared in tspellsuggest.nim(35, 7)] - (1, 3): 'fooBar4' [proc declared in tspellsuggest.nim(36, 6)] - (1, 3): 'fooBar5' [template declared in tspellsuggest.nim(37, 10)] - (1, 3): 'fooBar6' [macro declared in tspellsuggest.nim(38, 7)] - (1, 5): 'FooBar' [type declared in mspellsuggest.nim(5, 6)] - (1, 5): 'fooBar4' [proc declared in mspellsuggest.nim(1, 6)] - (1, 5): 'fooBar9' [var declared in mspellsuggest.nim(2, 5)] - (1, 5): 'fooCar' [var declared in mspellsuggest.nim(4, 5)] - (2, 5): 'FooCar' [type declared in mspellsuggest.nim(6, 6)] - (2, 5): 'GooBa' [type declared in mspellsuggest.nim(7, 6)] - (3, 0): 'fooBarBaz' [const declared in tspellsuggest.nim(44, 11)] -''' -""" - -# tests `--spellsuggest:num` - - - -# line 30 -import ./mspellsuggest - -var fooBar1 = 0 -let fooBar2 = 0 -const fooBar3 = 0 -proc fooBar4() = discard -template fooBar5() = discard -macro fooBar6() = discard - -proc main = - var fooBar7 = 0 - block: - var fooBar8 = 0 - const fooBarBaz = 0 - let x = fooBar diff --git a/tests/misc/tspellsuggest2.nim b/tests/misc/tspellsuggest2.nim deleted file mode 100644 index 78504c513..000000000 --- a/tests/misc/tspellsuggest2.nim +++ /dev/null @@ -1,45 +0,0 @@ -discard """ - # pending bug #16521 (bug 12) use `matrix` - cmd: "nim c --spellsuggest --hints:off $file" - action: "reject" - nimout: ''' -tspellsuggest2.nim(45, 13) Error: undeclared identifier: 'fooBar' -candidates (edit distance, scope distance); see '--spellSuggest': - (1, 0): 'fooBar8' [var declared in tspellsuggest2.nim(43, 9)] - (1, 1): 'fooBar7' [var declared in tspellsuggest2.nim(41, 7)] - (1, 3): 'fooBar1' [var declared in tspellsuggest2.nim(33, 5)] - (1, 3): 'fooBar2' [let declared in tspellsuggest2.nim(34, 5)] - (1, 3): 'fooBar3' [const declared in tspellsuggest2.nim(35, 7)] - (1, 3): 'fooBar4' [proc declared in tspellsuggest2.nim(36, 6)] - (1, 3): 'fooBar5' [template declared in tspellsuggest2.nim(37, 10)] - (1, 3): 'fooBar6' [macro declared in tspellsuggest2.nim(38, 7)] - (1, 5): 'FooBar' [type declared in mspellsuggest.nim(5, 6)] - (1, 5): 'fooBar4' [proc declared in mspellsuggest.nim(1, 6)] - (1, 5): 'fooBar9' [var declared in mspellsuggest.nim(2, 5)] - (1, 5): 'fooCar' [var declared in mspellsuggest.nim(4, 5)] -''' -""" - -# tests `--spellsuggest` - - - - - - -# line 30 -import ./mspellsuggest - -var fooBar1 = 0 -let fooBar2 = 0 -const fooBar3 = 0 -proc fooBar4() = discard -template fooBar5() = discard -macro fooBar6() = discard - -proc main = - var fooBar7 = 0 - block: - var fooBar8 = 0 - const fooBarBaz = 0 - let x = fooBar diff --git a/tests/misc/tstrtabs.nim b/tests/misc/tstrtabs.nim deleted file mode 100644 index 2f7eda9f7..000000000 --- a/tests/misc/tstrtabs.nim +++ /dev/null @@ -1,20 +0,0 @@ -discard """ - targets: "c cpp js" -""" - -import std/strtabs - -proc fun()= - let ret = newStringTable(modeCaseSensitive) - ret["foo"] = "bar" - - doAssert $ret == "{foo: bar}" - - let b = ret["foo"] - doAssert b == "bar" - -proc main()= - static: fun() - fun() - -main() diff --git a/tests/misc/tunsigned64mod.nim b/tests/misc/tunsigned64mod.nim deleted file mode 100644 index ca3286df3..000000000 --- a/tests/misc/tunsigned64mod.nim +++ /dev/null @@ -1,24 +0,0 @@ - -# bug #1638 - -let v1 = 7 -let v2 = 7'u64 - -let t1 = v1 mod 2 # works -let t2 = 7'u64 mod 2'u64 # works -let t3 = v2 mod 2'u64 # Error: invalid type: 'range 0..1(uint64) -let t4 = (v2 mod 2'u64).uint64 # works - -# bug #2550 - -var x: uint # doesn't work -doAssert x mod 2 == 0 - -var y: uint64 # doesn't work -doAssert y mod 2 == 0 - -var z: uint32 # works -doAssert z mod 2 == 0 - -var a: int # works -doAssert a mod 2 == 0 diff --git a/tests/misc/tunsignedcmp.nim b/tests/misc/tunsignedcmp.nim deleted file mode 100644 index 11b67ac5f..000000000 --- a/tests/misc/tunsignedcmp.nim +++ /dev/null @@ -1,43 +0,0 @@ -discard """ - output: '''true -true -true -5 -4 -3 -2 -1 -0 -it should stop now -18446744073709551615 -4294967295 -''' -""" - -# bug 1420 -var x = 40'u32 -var y = 30'u32 -echo x > y # works - -echo((40'i32) > (30'i32)) -echo((40'u32) > (30'u32)) # Error: ordinal type expected - -# bug #4220 - -const count: uint = 5 -var stop_me = false - -for i in countdown(count, 0): - echo i - if stop_me: break - if i == 0: - echo "it should stop now" - stop_me = true - -# bug #3985 -const - HIGHEST_64BIT_UINT = 0xFFFFFFFFFFFFFFFF'u - HIGHEST_32BIT_UINT = 0xFFFFFFFF'u - -echo($HIGHEST_64BIT_UINT) -echo($HIGHEST_32BIT_UINT) diff --git a/tests/misc/tunsignedcomp.nim b/tests/misc/tunsignedcomp.nim deleted file mode 100644 index 970c4ae9d..000000000 --- a/tests/misc/tunsignedcomp.nim +++ /dev/null @@ -1,136 +0,0 @@ -discard """ - output: '''''' - disabled: "true" -""" - -# All operations involving uint64 are commented out -# as they're not yet supported. -# All other operations are handled by implicit conversions from uints to ints -# uint64 could be supported but would need special implementation of the operators - -# unsigned < signed - -doAssert 10'u8 < 20'i8 -doAssert 10'u8 < 20'i16 -doAssert 10'u8 < 20'i32 -doAssert 10'u8 < 20'i64 - -doAssert 10'u16 < 20'i8 -doAssert 10'u16 < 20'i16 -doAssert 10'u16 < 20'i32 -doAssert 10'u16 < 20'i64 - -doAssert 10'u32 < 20'i8 -doAssert 10'u32 < 20'i16 -doAssert 10'u32 < 20'i32 -doAssert 10'u32 < 20'i64 - -# doAssert 10'u64 < 20'i8 -# doAssert 10'u64 < 20'i16 -# doAssert 10'u64 < 20'i32 -# doAssert 10'u64 < 20'i64 - -# signed < unsigned -doAssert 10'i8 < 20'u8 -doAssert 10'i8 < 20'u16 -doAssert 10'i8 < 20'u32 -# doAssert 10'i8 < 20'u64 - -doAssert 10'i16 < 20'u8 -doAssert 10'i16 < 20'u16 -doAssert 10'i16 < 20'u32 -# doAssert 10'i16 < 20'u64 - -doAssert 10'i32 < 20'u8 -doAssert 10'i32 < 20'u16 -doAssert 10'i32 < 20'u32 -# doAssert 10'i32 < 20'u64 - -doAssert 10'i64 < 20'u8 -doAssert 10'i64 < 20'u16 -doAssert 10'i64 < 20'u32 -# doAssert 10'i64 < 20'u64 - -# unsigned <= signed -doAssert 10'u8 <= 20'i8 -doAssert 10'u8 <= 20'i16 -doAssert 10'u8 <= 20'i32 -doAssert 10'u8 <= 20'i64 - -doAssert 10'u16 <= 20'i8 -doAssert 10'u16 <= 20'i16 -doAssert 10'u16 <= 20'i32 -doAssert 10'u16 <= 20'i64 - -doAssert 10'u32 <= 20'i8 -doAssert 10'u32 <= 20'i16 -doAssert 10'u32 <= 20'i32 -doAssert 10'u32 <= 20'i64 - -# doAssert 10'u64 <= 20'i8 -# doAssert 10'u64 <= 20'i16 -# doAssert 10'u64 <= 20'i32 -# doAssert 10'u64 <= 20'i64 - -# signed <= unsigned -doAssert 10'i8 <= 20'u8 -doAssert 10'i8 <= 20'u16 -doAssert 10'i8 <= 20'u32 -# doAssert 10'i8 <= 20'u64 - -doAssert 10'i16 <= 20'u8 -doAssert 10'i16 <= 20'u16 -doAssert 10'i16 <= 20'u32 -# doAssert 10'i16 <= 20'u64 - -doAssert 10'i32 <= 20'u8 -doAssert 10'i32 <= 20'u16 -doAssert 10'i32 <= 20'u32 -# doAssert 10'i32 <= 20'u64 - -doAssert 10'i64 <= 20'u8 -doAssert 10'i64 <= 20'u16 -doAssert 10'i64 <= 20'u32 -# doAssert 10'i64 <= 20'u64 - -# signed == unsigned -doAssert 10'i8 == 10'u8 -doAssert 10'i8 == 10'u16 -doAssert 10'i8 == 10'u32 -# doAssert 10'i8 == 10'u64 - -doAssert 10'i16 == 10'u8 -doAssert 10'i16 == 10'u16 -doAssert 10'i16 == 10'u32 -# doAssert 10'i16 == 10'u64 - -doAssert 10'i32 == 10'u8 -doAssert 10'i32 == 10'u16 -doAssert 10'i32 == 10'u32 -# doAssert 10'i32 == 10'u64 - -doAssert 10'i64 == 10'u8 -doAssert 10'i64 == 10'u16 -doAssert 10'i64 == 10'u32 -# doAssert 10'i64 == 10'u64 - -# unsigned == signed -doAssert 10'u8 == 10'i8 -doAssert 10'u8 == 10'i16 -doAssert 10'u8 == 10'i32 -# doAssert 10'u8 == 10'i64 - -doAssert 10'u16 == 10'i8 -doAssert 10'u16 == 10'i16 -doAssert 10'u16 == 10'i32 -# doAssert 10'u16 == 10'i64 - -doAssert 10'u32 == 10'i8 -doAssert 10'u32 == 10'i16 -doAssert 10'u32 == 10'i32 -# doAssert 10'u32 == 10'i64 - -# doAssert 10'u64 == 10'i8 -# doAssert 10'u64 == 10'i16 -# doAssert 10'u64 == 10'i32 -# doAssert 10'u64 == 10'i64 diff --git a/tests/misc/tunsignedconv.nim b/tests/misc/tunsignedconv.nim deleted file mode 100644 index 989f39277..000000000 --- a/tests/misc/tunsignedconv.nim +++ /dev/null @@ -1,96 +0,0 @@ -# Tests unsigned literals and implicit conversion between uints and ints - -var h8:uint8 = 128 -var h16:uint16 = 32768 -var h32:uint32 = 2147483648'u32 -var h64:uint64 = 9223372036854775808'u64 -var foobar:uint64 = 9223372036854775813'u64 # Issue 728 - -var v8:uint8 = 10 -var v16:uint16 = 10 -var v32:uint32 = 10 -var v64:uint64 = 10 - -# u8 + literal produces u8: -var a8: uint8 = v8 + 10 -var a16: uint16 = v16 + 10 - -when false: - var d8 = v8 + 10'i8 - var d16 = v8 + 10'i16 - var d32 = v8 + 10'i32 - -when false: - # these don't work yet because unsigned.nim is stupid. XXX We need to fix this. - var f8 = v16 + 10'u8 - var f16 = v16 + 10'u16 - var f32 = v16 + 10'u32 - - var g8 = v32 + 10'u8 - var g16 = v32 + 10'u16 - var g32 = v32 + 10'u32 - -var ar: array[0..20, int] -var n8 = ar[v8] -var n16 = ar[v16] -var n32 = ar[v32] -var n64 = ar[v64] - - -block t4176: - var yyy: uint8 = 0 - yyy = yyy - 127 - doAssert type(yyy) is uint8 - -# bug #13661 - -proc fun(): uint = cast[uint](-1) -const x0 = fun() - -doAssert typeof(x0) is uint - -discard $x0 - -# bug #13671 - -const x1 = cast[uint](-1) -discard $(x1,) - -# bug #13698 -let n2: csize_t = 1 -doAssert $n2.int32 == "1" - -# bug #14616 - -let limit = 1'u64 - -let rangeVar = 0'u64 ..< limit - -doAssert repr(rangeVar) == """0 .. 0""", repr(rangeVar) - -# bug #15210 - -let a3 = not 0'u64 -var success = false -try: - discard a3.int64 -except RangeDefect: - success = true - -doAssert success, "conversion should fail at runtime" - -template main() = - # xxx move all tests under here so it gets tested in CT and RT - block: # bug #17572 - type T = distinct uint64 - func f(x: uint64): auto = - let a = T(x) - (x, a.uint64) - const x = 1'u64 shl 63 or 7 - const b = T(x) - doAssert b.uint64 == 9223372036854775815'u64 - doAssert $b.uint64 == "9223372036854775815" - doAssert f(x) == (9223372036854775815'u64, 9223372036854775815'u64) - -static: main() -main() diff --git a/tests/misc/tunsignedinc.nim b/tests/misc/tunsignedinc.nim deleted file mode 100644 index 9d1a4bbb4..000000000 --- a/tests/misc/tunsignedinc.nim +++ /dev/null @@ -1,34 +0,0 @@ - -block: # bug #2427 - var x = 0'u8 - dec x # OverflowDefect - x -= 1 # OverflowDefect - x = x - 1 # No error - - doAssert(x == 253'u8) - -block: - var x = 130'u8 - x += 130'u8 - doAssert(x == 4'u8) - -block: - var x = 40000'u16 - x = x + 40000'u16 - doAssert(x == 14464'u16) - -block: - var x = 4000000000'u32 - x = x + 4000000000'u32 - doAssert(x == 3705032704'u32) - -block: - var x = 123'u16 - x -= 125 - doAssert(x == 65534'u16) - -block t4175: - let i = 0u - 1u - const j = 0u - 1u - doAssert i == j - doAssert j + 1u == 0u diff --git a/tests/misc/tunsignedmisc.nim b/tests/misc/tunsignedmisc.nim deleted file mode 100644 index b2a3849cf..000000000 --- a/tests/misc/tunsignedmisc.nim +++ /dev/null @@ -1,66 +0,0 @@ -discard """ - errormsg: "number out of range: '0x123'u8'" -""" - -# Bug #1179 - -# Unsigneds - -# 8 bit -let ref1 = 128'u8 shr 7 -let hex1 = 0x80'u8 shr 7 -let oct1 = 0o200'u8 shr 7 -let dig1 = 0b10000000'u8 shr 7 - -doAssert(ref1 == 1) -doAssert(ref1 == hex1) -doAssert(ref1 == oct1) -doAssert(ref1 == dig1) - -# 16 bit -let ref2 = 32768'u16 shr 15 -let hex2 = 0x8000'u16 shr 15 -let oct2 = 0o100000'u16 shr 15 -let dig2 = 0b1000000000000000'u16 shr 15 - -doAssert(ref2 == 1) -doAssert(ref2 == hex2) -doAssert(ref2 == oct2) -doAssert(ref2 == dig2) - -# 32 bit -let ref3 = 2147483648'u32 shr 31 -let hex3 = 0x80000000'u32 shr 31 -let oct3 = 0o20000000000'u32 shr 31 -let dig3 = 0b10000000000000000000000000000000'u32 shr 31 - -doAssert(ref3 == 1) -doAssert(ref3 == hex3) -doAssert(ref3 == oct3) -doAssert(ref3 == dig3) - -# Below doesn't work for lexer stage errors... -# doAssert(compiles(0xFF'u8) == true) -# doAssert(compiles(0xFFF'u16) == true) -# doAssert(compiles(0x7FFF'i16) == true) - -# doAssert(compiles(0x123'u8) == false) -# doAssert(compiles(0x123'i8) == false) -# doAssert(compiles(0x123123'u16) == false) -# doAssert(compiles(0x123123'i16) == false) - -# Should compile # -let boundOkHex1 = 0xFF'u8 -let boundOkHex2 = 0xFFFF'u16 -let boundOkHex3 = 0x7FFF'i16 - -let boundOkHex4 = 0x80'i8 -let boundOkHex5 = 0xFF'i8 -let boundOkHex6 = 0xFFFF'i16 -let boundOkHex7 = 0x7FFF'i16 - -# Should _not_ compile # -let boundBreakingHex1 = 0x123'u8 -let boundBreakingHex2 = 0x123'i8 -let boundBreakingHex3 = 0x123123'u16 -let boundBreakingHex4 = 0x123123'i16 diff --git a/tests/misc/twarningaserror.nim b/tests/misc/twarningaserror.nim deleted file mode 100644 index 6f7b76095..000000000 --- a/tests/misc/twarningaserror.nim +++ /dev/null @@ -1,35 +0,0 @@ -discard """ - joinable: false -""" - -#[ -tests: hintAsError, warningAsError -]# - -template fn1 = - {.hintAsError[ConvFromXtoItselfNotNeeded]:on.} - proc fn(a: string) = discard a.string - {.hintAsError[ConvFromXtoItselfNotNeeded]:off.} - -template fn2 = - {.hintAsError[ConvFromXtoItselfNotNeeded]:on.} - proc fn(a: string) = discard a - {.hintAsError[ConvFromXtoItselfNotNeeded]:off.} - -template gn1 = - {.warningAsError[ProveInit]:on.} - proc fn(): var int = discard - discard fn() - {.warningAsError[ProveInit]:off.} - -template gn2 = - {.warningAsError[ProveInit]:on.} - proc fn(): int = discard - discard fn() - {.warningAsError[ProveInit]:off.} - -doAssert not compiles(fn1()) -doAssert compiles(fn2()) - -doAssert not compiles(gn1()) -doAssert compiles(gn2()) |