summary refs log tree commit diff stats
path: root/tests/accept/run/tslices.nim
blob: 1061b42458090da3ea4528cc159d4b2af1680fa5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
discard """
  file: "tslices.nim"
  output: '''456456
456456
456456
Zugr5nd
'''
"""

# Test the new slices.

import strutils

var mystr = "Abgrund"
mystr[..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]

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