* close #16123 std/sets with closures in cpp * fixup
This commit is contained in:
parent
6d485f545a
commit
0dc534832e
1 changed files with 13 additions and 5 deletions
|
|
@ -1,15 +1,12 @@
|
||||||
discard """
|
discard """
|
||||||
targets: "c cpp js"
|
targets: "c cpp js"
|
||||||
output: '''
|
|
||||||
set is empty
|
|
||||||
'''
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
import std/[sets, hashes]
|
import std/[sets, hashes]
|
||||||
|
|
||||||
from std/sequtils import toSeq
|
from std/sequtils import toSeq
|
||||||
from std/algorithm import sorted
|
from std/algorithm import sorted
|
||||||
|
from stdtest/testutils import whenVMorJs
|
||||||
|
|
||||||
proc sortedPairs[T](t: T): auto = toSeq(t.pairs).sorted
|
proc sortedPairs[T](t: T): auto = toSeq(t.pairs).sorted
|
||||||
template sortedItems(t: untyped): untyped = sorted(toSeq(t))
|
template sortedItems(t: untyped): untyped = sorted(toSeq(t))
|
||||||
|
|
@ -23,10 +20,12 @@ block tsetpop:
|
||||||
discard a.pop()
|
discard a.pop()
|
||||||
doAssert len(a) == 0
|
doAssert len(a) == 0
|
||||||
|
|
||||||
|
var msg = ""
|
||||||
try:
|
try:
|
||||||
echo a.pop()
|
echo a.pop()
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
echo e.msg
|
msg = e.msg
|
||||||
|
doAssert msg == "set is empty"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -258,6 +257,7 @@ block: # test correctness after a number of inserts/deletes
|
||||||
|
|
||||||
|
|
||||||
template main() =
|
template main() =
|
||||||
|
# xxx move all tests inside this
|
||||||
block:
|
block:
|
||||||
let a = {true, false}
|
let a = {true, false}
|
||||||
doAssert $a == "{false, true}"
|
doAssert $a == "{false, true}"
|
||||||
|
|
@ -273,6 +273,14 @@ template main() =
|
||||||
doAssert $a == "{false}"
|
doAssert $a == "{false}"
|
||||||
doAssert a.len == 1
|
doAssert a.len == 1
|
||||||
|
|
||||||
|
block: # bug #16123
|
||||||
|
whenVMorJs: discard
|
||||||
|
do:
|
||||||
|
type CallType = proc() {.closure.}
|
||||||
|
var setA = initHashSet[CallType]()
|
||||||
|
let foo = proc() = discard
|
||||||
|
setA.incl(foo)
|
||||||
|
doAssert setA.contains(foo)
|
||||||
|
|
||||||
static: main()
|
static: main()
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue