summary refs log tree commit diff stats
path: root/tests/assign
Commit message (Expand)AuthorAgeFilesLines
* fix rtti sizeof for varargs in global scope (#13125) [backport]Jasper Jenkins2020-01-131-0/+9
* make tests green againAraq2019-05-271-4/+2
* require errormsg to be specified before file.Arne Döring2018-12-112-4/+1
* make tests green againAndreas Rumpf2018-10-131-4/+6
* Merge tests into a larger file (part 1 of ∞) (#9318)Miran2018-10-126-212/+204
* make tests green againAndreas Rumpf2018-07-051-2/+2
* make tests green againAndreas Rumpf2018-04-242-0/+2
* tests: Trim .nim files trailing whitespaceAdam Strzelecki2015-09-044-34/+34
* renamed writeln to writeLine in testspatrick dw2015-06-192-7/+7
* overloading of '=' worksAraq2015-04-063-0/+107
* Improves tobjasgn test.Dominik Picheta2014-04-181-6/+6
* Fixes #1005Dominik Picheta2014-04-151-5/+10
* new tester; all tests categorizedAraq2014-01-136-0/+165
'author Andreas Rumpf <rumpf_a@web.de> 2020-07-25 20:26:30 +0200 committer Andreas Rumpf <rumpf_a@web.de> 2020-07-26 01:16:06 +0200 fixes #15052' href='/ahoang/Nim/commit/tests/arc/tarcmisc.nim?h=devel&id=624762cfb7ab17606616f75ca280b83c55c3ec3b'>624762cfb ^
aae998fef ^
c70b3952f ^
2b0e336c9 ^

c70b3952f ^
034dad8e3 ^


b6fb609e0 ^












034dad8e3 ^




2b0e336c9 ^
034dad8e3 ^



2b0e336c9 ^
034dad8e3 ^










c70b3952f ^
2b0e336c9 ^





















c70b3952f ^















d9e907c0e ^
c70b3952f ^
f10689d3d ^















d9e907c0e ^










0d8507cd3 ^








3105909f8 ^
0d8507cd3 ^

3105909f8 ^
0d8507cd3 ^

5fa7d374c ^













5fb40af57 ^





3105909f8 ^
5fb40af57 ^
3105909f8 ^
5fb40af57 ^





3105909f8 ^



























1854d2978 ^
af27e6bde ^




1854d2978 ^
af27e6bde ^

1854d2978 ^
af27e6bde ^

1854d2978 ^
af27e6bde ^

1854d2978 ^
af27e6bde ^

1854d2978 ^
af27e6bde ^
1854d2978 ^
af27e6bde ^



1854d2978 ^
af27e6bde ^

1854d2978 ^
af27e6bde ^


1854d2978 ^
af27e6bde ^

2b0e336c9 ^




282128ab6 ^











f25454d5c ^
c90c53e8b ^
















f25454d5c ^





624762cfb ^









aae998fef ^
























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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321

             
         

                




                      
 










         
 

                        
         
     
     
      

                       
   


                             












                                          




                                                 
                                         



                                        
                                          










                                    
 





















                                                       















                                                                               
 
                                           















                                                                               










                                                                          








                                                                               
                                           

          
                                            

                        













                                                                               





                                                                               
    
                     
 





                              



























                         
 




                     
 

                                    
 

                                                  
 

                                  
 

                          
 
            
 



                              
 

                                                         
 


                                                        
 

                     




                           











                                  
 
















                             





                               









                         
























                                                      
discard """
  output: '''
123xyzabc
destroyed: false
destroyed: false
destroyed2: false
destroyed2: false
destroying variable: 2
destroying variable: 1
whiley ends :(
1
(x: "0")
(x: "1")
(x: "2")
(x: "3")
(x: "4")
(x: "5")
(x: "6")
(x: "7")
(x: "8")
(x: "9")
(x: "10")
0
new line before - @['a']
new line after - @['a']
finalizer
aaaaa
hello
closed
destroying variable: 20
destroying variable: 10
'''
  cmd: "nim c --gc:arc $file"
"""

proc takeSink(x: sink string): bool = true

proc b(x: sink string): string =
  if takeSink(x):
    return x & "abc"

proc bbb(inp: string) =
  let y = inp & "xyz"
  echo b(y)

bbb("123")


# bug #13691
type Variable = ref object
  value: int

proc `=destroy`(self: var typeof(Variable()[])) =
  echo "destroying variable: ",self.value

proc newVariable(value: int): Variable =
  result = Variable()
  result.value = value
  #echo "creating variable: ",result.value

proc test(count: int) =
  var v {.global.} = newVariable(10)

  var count = count - 1
  if count == 0: return

  test(count)
  echo "destroyed: ", v.isNil

test(3)

proc test2(count: int) =
  #block: #XXX: Fails with block currently
    var v {.global.} = newVariable(20)

    var count = count - 1
    if count == 0: return

    test2(count)
    echo "destroyed2: ", v.isNil

test2(3)

proc whiley =
  var a = newVariable(1)
  while true:
    var b = newVariable(2)
    if true: raise newException(CatchableError, "test")

try:
  whiley()
except CatchableError:
  echo "whiley ends :("

#------------------------------------------------------------------------------
# issue #13810

import streams

type
  A = ref AObj
  AObj = object of RootObj
    io: Stream
  B = ref object of A
    x: int

proc `=destroy`(x: var AObj) =
  close(x.io)
  echo "closed"

var x = B(io: newStringStream("thestream"))


#------------------------------------------------------------------------------
# issue #14003

proc cryptCTR*(nonce: var openArray[char]) =
  nonce[1] = 'A'

proc main() =
  var nonce1 = "0123456701234567"
  cryptCTR(nonce1)
  doAssert(nonce1 == "0A23456701234567")
  var nonce2 = "01234567"
  cryptCTR(nonce2.toOpenArray(0, nonce2.len-1))
  doAssert(nonce2 == "0A234567")

main()

# bug #14079
import std/algorithm

let
  n = @["c", "b"]
  q = @[("c", "2"), ("b", "1")]

assert n.sortedByIt(it) == @["b", "c"], "fine"
assert q.sortedByIt(it[0]) == @[("b", "1"), ("c", "2")], "fails under arc"


#------------------------------------------------------------------------------
# issue #14236

type
  MyType = object
    a: seq[int]

proc re(x: static[string]): static MyType =
  MyType()

proc match(inp: string, rg: static MyType) =
  doAssert rg.a.len == 0

match("ac", re"a(b|c)")

#------------------------------------------------------------------------------
# issue #14243

type
  Game* = ref object

proc free*(game: Game) =
  let a = 5

proc newGame*(): Game =
  new(result, free)

var game*: Game


#------------------------------------------------------------------------------
# issue #14333

type
  SimpleLoop = object

  Lsg = object
    loops: seq[ref SimpleLoop]
    root: ref SimpleLoop

var lsg: Lsg
lsg.loops.add lsg.root
echo lsg.loops.len

# bug #14495
type
  Gah = ref object
    x: string

proc bug14495 =
  var owners: seq[Gah]
  for i in 0..10:
    owners.add Gah(x: $i)

  var x: seq[Gah]
  for i in 0..10:
    x.add owners[i]

  for i in 0..100:
    setLen(x, 0)
    setLen(x, 10)

  for i in 0..x.len-1:
    if x[i] != nil:
      echo x[i][]

  for o in owners:
    echo o[]

bug14495()

# bug #14396
type
  Spinny = ref object
    t: ref int
    text: string

proc newSpinny*(): Spinny =
  Spinny(t: new(int), text: "hello")

proc spinnyLoop(x: ref int, spinny: sink Spinny) =
  echo x[]

proc start*(spinny: sink Spinny) =
  spinnyLoop(spinny.t, spinny)

var spinner1 = newSpinny()
spinner1.start()

# bug #14345

type
  SimpleLoopB = ref object
    children: seq[SimpleLoopB]
    parent: SimpleLoopB

proc addChildLoop(self: SimpleLoopB, loop: SimpleLoopB) =
  self.children.add loop

proc setParent(self: SimpleLoopB, parent: SimpleLoopB) =
  self.parent = parent
  self.parent.addChildLoop(self)

var l = SimpleLoopB()
l.setParent(l)


# bug #14968
import times
let currentTime = now().utc


# bug #14994
import sequtils
var newLine = @['a']
let indent = newSeq[char]()

echo "new line before - ", newline

newline.insert(indent, 0)

echo "new line after - ", newline

# bug #15044

type
  Test = ref object

proc test: Test =
  # broken
  new(result, proc(x: Test) =
    echo "finalizer"
  )

proc tdirectFinalizer =
  discard test()

tdirectFinalizer()


# bug #14480
proc hello(): int =
  result = 42

var leaves {.global.} = hello()
doAssert leaves == 42

# bug #15052

proc mutstrings =
  var data = "hello"
  for c in data.mitems():
    c = 'a'
  echo data

mutstrings()

# bug #15038

type
  Machine = ref object
    hello: string

var machineTypes: seq[tuple[factory: proc(): Machine]]

proc registerMachine(factory: proc(): Machine) =
  var mCreator = proc(): Machine =
    result = factory()

  machineTypes.add((factory: mCreator))

proc facproc(): Machine =
  result = Machine(hello: "hello")

registerMachine(facproc)

proc createMachine =
  for machine in machineTypes:
    echo machine.factory().hello

createMachine()