summary refs log tree commit diff stats
path: root/tests/stdlib/tsharedlist.nim
blob: 0bb3ad827f6480c562a57ef71e443485974a268f (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
44
45
46
47
48
49
discard """
  matrix: "--threads:on"
"""

import std/sharedlist
import std/assertions

block:
  var
    list: SharedList[int]
    count: int

  init(list)

  for i in 1 .. 250:
    list.add i

  for i in list:
    inc count

  doAssert count == 250

  deinitSharedList(list)


block: # bug #17696
  var keysList = SharedList[string]()
  init(keysList)

  keysList.add("a")
  keysList.add("b")
  keysList.add("c")
  keysList.add("d")
  keysList.add("e")
  keysList.add("f")


  # Remove element "b" and "d" from the list. 
  keysList.iterAndMutate(proc (key: string): bool =
    if key == "b" or key == "d": # remove only "b" and "d"
      return true
    return false
  )

  var results: seq[string]
  for key in keysList.items:
    results.add key

  doAssert results == @["a", "f", "c", "e"]