summary refs log tree commit diff stats
path: root/tests/array
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2017-11-02 10:46:30 +0100
committerAndreas Rumpf <rumpf_a@web.de>2017-11-02 10:46:30 +0100
commit1eaeccc15d15d15d2f62ea1648f7dd64722dbd37 (patch)
treeb922cdabc780fa3a8837a6804d2df31793d9e2ca /tests/array
parente9243a16167b24899d4fcf051f3252b3a5804811 (diff)
parentbd19b5f4d36bb40b4af93d7e15fdfa582e9fe3b7 (diff)
downloadNim-1eaeccc15d15d15d2f62ea1648f7dd64722dbd37.tar.gz
Merge branch 'devel' into araq
Diffstat (limited to 'tests/array')
-rw-r--r--tests/array/troof1.nim39
-rw-r--r--tests/array/troof2.nim10
-rw-r--r--tests/array/troof3.nim5
-rw-r--r--tests/array/troof4.nim37
4 files changed, 22 insertions, 69 deletions
diff --git a/tests/array/troof1.nim b/tests/array/troof1.nim
index 96669a121..1ee63826e 100644
--- a/tests/array/troof1.nim
+++ b/tests/array/troof1.nim
@@ -1,7 +1,10 @@
 discard """
   output: '''@[2, 3, 4]321
 9.0 4.0
-(a: 1.0, b: 2.0, c: 8.0)2.0'''
+3
+@[(Field0: 1, Field1: 2), (Field0: 3, Field1: 5)]
+2
+@[a, new one, c]'''
 """
 
 proc foo[T](x, y: T): T = x
@@ -11,26 +14,24 @@ var b: array[3, array[2, float]] = [[1.0,2], [3.0,4], [8.0,9]]
 echo a[1.. ^1], a[^2], a[^3], a[^4]
 echo b[^1][^1], " ", (b[^2]).foo(b[^1])[^1]
 
-type
-  MyArray = object
-    a, b, c: float
+b[^1] = [8.8, 8.9]
 
-var
-  ma = MyArray(a: 1.0, b: 2.0, c: 3.0)
+var c: seq[(int, int)] = @[(1,2), (3,4)]
 
-proc len(x: MyArray): int = 3
+proc takeA(x: ptr int) = echo x[]
 
-proc `[]=`(x: var MyArray; idx: range[0..2]; val: float) =
-  case idx
-  of 0: x.a = val
-  of 1: x.b = val
-  of 2: x.c = val
+takeA(addr c[^1][0])
+c[^1][1] = 5
+echo c
 
-proc `[]`(x: var MyArray; idx: range[0..2]): float =
-  case idx
-  of 0: result = x.a
-  of 1: result = x.b
-  of 2: result = x.c
+proc useOpenarray(x: openArray[int]) =
+  echo x[^2]
 
-ma[^1] = 8.0
-echo ma, ma[^2]
+proc mutOpenarray(x: var openArray[string]) =
+  x[^2] = "new one"
+
+useOpenarray([1, 2, 3])
+
+var z = @["a", "b", "c"]
+mutOpenarray(z)
+echo z
diff --git a/tests/array/troof2.nim b/tests/array/troof2.nim
deleted file mode 100644
index e4b4f4b3c..000000000
--- a/tests/array/troof2.nim
+++ /dev/null
@@ -1,10 +0,0 @@
-discard """
-  errormsg: "invalid context for '^' as 'foo()' has side effects"
-  line: "9"
-"""
-# XXX This needs to be fixed properly!
-proc foo(): seq[int] {.sideEffect.} =
-  echo "ha"
-
-let f = foo()[^1]
-
diff --git a/tests/array/troof3.nim b/tests/array/troof3.nim
index 4b6e22223..efe0eafb8 100644
--- a/tests/array/troof3.nim
+++ b/tests/array/troof3.nim
@@ -1,8 +1,7 @@
 discard """
-  errormsg: "invalid context for '^' as len!=high+1 for 'a'"
-  line: "8"
+  output: '''c'''
 """
 
-var a: array[1..3, string]
+var a: array['a'..'c', string] = ["a", "b", "c"]
 
 echo a[^1]
diff --git a/tests/array/troof4.nim b/tests/array/troof4.nim
deleted file mode 100644
index 7a262d9de..000000000
--- a/tests/array/troof4.nim
+++ /dev/null
@@ -1,37 +0,0 @@
-discard """
-  errormsg: "no surrounding array access context for '^'"
-  line: "37"
-"""
-
-proc foo[T](x, y: T): T = x
-
-var a = @[1, 2, 3, 4]
-var b: array[3, array[2, float]] = [[1.0,2], [3.0,4], [8.0,9]]
-echo a[1.. ^1], a[^2], a[^3], a[^4]
-echo b[^1][^1], " ", (b[^2]).foo(b[^1])[^1]
-
-type
-  MyArray = object
-    a, b, c: float
-
-var
-  ma = MyArray(a: 1.0, b: 2.0, c: 3.0)
-
-proc len(x: MyArray): int = 3
-
-proc `[]=`(x: var MyArray; idx: range[0..2]; val: float) =
-  case idx
-  of 0: x.a = val
-  of 1: x.b = val
-  of 2: x.c = val
-
-proc `[]`(x: var MyArray; idx: range[0..2]): float =
-  case idx
-  of 0: result = x.a
-  of 1: result = x.b
-  of 2: result = x.c
-
-ma[^1] = 8.0
-echo ma, ma[^2]
-
-echo(^1)