diff options
Diffstat (limited to 'tests/array')
-rw-r--r-- | tests/array/t15117.nim | 27 | ||||
-rw-r--r-- | tests/array/t20248.nim | 14 | ||||
-rw-r--r-- | tests/array/tarray.nim | 20 | ||||
-rw-r--r-- | tests/array/tinvalidarrayaccess.nim | 21 | ||||
-rw-r--r-- | tests/array/tinvalidarrayaccess2.nim | 10 | ||||
-rw-r--r-- | tests/array/tlargeindex.nim | 18 |
6 files changed, 109 insertions, 1 deletions
diff --git a/tests/array/t15117.nim b/tests/array/t15117.nim new file mode 100644 index 000000000..157b04bee --- /dev/null +++ b/tests/array/t15117.nim @@ -0,0 +1,27 @@ +discard """ + matrix: "--cc:vcc" + disabled: "linux" + disabled: "bsd" + disabled: "osx" + disabled: "unix" + disabled: "posix" +""" +{.experimental: "views".} + +let a: array[0, byte] = [] +discard a + +type B = object + a:int +let b: array[0, B] = [] +let c: array[0, ptr B] = [] +let d: array[0, ref B] = [] +discard b +discard c +discard d + +discard default(array[0, B]) + +type + View1 = openArray[byte] +discard default(View1) diff --git a/tests/array/t20248.nim b/tests/array/t20248.nim new file mode 100644 index 000000000..66142548b --- /dev/null +++ b/tests/array/t20248.nim @@ -0,0 +1,14 @@ +discard """ +cmd: "nim check --hints:off $file" +errormsg: "ordinal type expected; given: Error Type" +nimout: ''' +t20248.nim(10, 36) Error: ordinal type expected; given: Error Type +t20248.nim(14, 20) Error: ordinal type expected; given: Error Type +''' +""" + +type Vec[N: static[int]] = array[0 ..< N, float] + +var v: Vec[32] + +var stuff: array[0 ..< 16, int] diff --git a/tests/array/tarray.nim b/tests/array/tarray.nim index 81a43f203..e9f330e3b 100644 --- a/tests/array/tarray.nim +++ b/tests/array/tarray.nim @@ -44,7 +44,7 @@ block tarray: arr: TMyarray - proc sum(a: openarray[int]): int = + proc sum(a: openArray[int]): int = result = 0 var i = 0 while i < len(a): @@ -587,3 +587,21 @@ block t12466: a[0'u16 + i] = i for i in 0'u16 ..< 8'u16: a[0'u16 + i] = i + +block t17705: + # https://github.com/nim-lang/Nim/pull/17705 + var a = array[0, int].low + a = int(a) + var b = array[0, int].high + b = int(b) + +block t18643: + # https://github.com/nim-lang/Nim/issues/18643 + let a: array[0, int] = [] + var caught = false + let b = 9999999 + try: + echo a[b] + except IndexDefect: + caught = true + doAssert caught, "IndexDefect not caught!" diff --git a/tests/array/tinvalidarrayaccess.nim b/tests/array/tinvalidarrayaccess.nim new file mode 100644 index 000000000..f8bce45ef --- /dev/null +++ b/tests/array/tinvalidarrayaccess.nim @@ -0,0 +1,21 @@ +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/array/tinvalidarrayaccess2.nim b/tests/array/tinvalidarrayaccess2.nim new file mode 100644 index 000000000..0a0703834 --- /dev/null +++ b/tests/array/tinvalidarrayaccess2.nim @@ -0,0 +1,10 @@ +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/array/tlargeindex.nim b/tests/array/tlargeindex.nim new file mode 100644 index 000000000..61bcbd61d --- /dev/null +++ b/tests/array/tlargeindex.nim @@ -0,0 +1,18 @@ +discard """ + cmd: "nim check --hints:off $file" +""" + +# issue #17163 +var e: array[int32, byte] #[tt.Error + ^ index type 'int32' for array is too large]# +var f: array[uint32, byte] #[tt.Error + ^ index type 'uint32' for array is too large]# +var g: array[int64, byte] #[tt.Error + ^ index type 'int64' for array is too large]# +var h: array[uint64, byte] #[tt.Error + ^ index type 'uint64' for array is too large]# + +# crash in issue #23204 +proc y[N](): array[N, int] = default(array[N, int]) #[tt.Error + ^ index type 'int' for array is too large]# +discard y[int]() |