privateAccess now works with ref | ptr (#17760)
This commit is contained in:
parent
d6c8efa5d4
commit
0a10af5a2c
8 changed files with 149 additions and 15 deletions
17
tests/stdlib/mimportutils.nim
Normal file
17
tests/stdlib/mimportutils.nim
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
type
|
||||
A* = object
|
||||
a0*: int
|
||||
ha1: float
|
||||
B = object
|
||||
b0*: int
|
||||
hb1: float
|
||||
C* = ref object
|
||||
c0: int
|
||||
hc1: float
|
||||
D* = ptr object
|
||||
d0: int
|
||||
hd1: float
|
||||
PA* = ref A
|
||||
PtA* = ptr A
|
||||
|
||||
proc initB*(): B = B()
|
||||
82
tests/stdlib/timportutils.nim
Normal file
82
tests/stdlib/timportutils.nim
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
import std/importutils
|
||||
import stdtest/testutils
|
||||
import mimportutils
|
||||
|
||||
template main =
|
||||
block: # privateAccess
|
||||
assertAll:
|
||||
var a: A
|
||||
var b = initB() # B is private
|
||||
compiles(a.a0)
|
||||
compiles(b.b0)
|
||||
not compiles(a.ha1)
|
||||
not compiles(b.hb1)
|
||||
|
||||
block:
|
||||
assertAll:
|
||||
privateAccess A
|
||||
compiles(a.ha1)
|
||||
a.ha1 == 0.0
|
||||
not compiles(a.hb1)
|
||||
privateAccess b.typeof
|
||||
b.hb1 = 3
|
||||
type B2 = b.typeof
|
||||
let b2 = B2(b0: 4, hb1: 5)
|
||||
b.hb1 == 3
|
||||
b2 == B2(b0: 4, hb1: 5)
|
||||
|
||||
assertAll:
|
||||
not compiles(a.ha1)
|
||||
not compiles(b.hb1)
|
||||
|
||||
block:
|
||||
assertAll:
|
||||
not compiles(C(c0: 1, hc1: 2))
|
||||
privateAccess C
|
||||
let c = C(c0: 1, hc1: 2)
|
||||
c.hc1 == 2
|
||||
|
||||
block:
|
||||
assertAll:
|
||||
privateAccess PA
|
||||
var pa = PA(a0: 1, ha1: 2)
|
||||
pa.ha1 == 2
|
||||
pa.ha1 = 3
|
||||
pa.ha1 == 3
|
||||
|
||||
block:
|
||||
assertAll:
|
||||
var a = A(a0: 1)
|
||||
var a2 = a.addr
|
||||
not compiles(a2.ha1)
|
||||
privateAccess PtA
|
||||
a2.type is PtA
|
||||
a2.ha1 = 2
|
||||
a2.ha1 == 2
|
||||
a.ha1 = 3
|
||||
a2.ha1 == 3
|
||||
|
||||
block:
|
||||
disableVm:
|
||||
assertAll:
|
||||
var a = A.create()
|
||||
defer: dealloc(a)
|
||||
a is PtA
|
||||
a.typeof is PtA
|
||||
not compiles(a.ha1)
|
||||
privateAccess a.typeof
|
||||
a.ha1 = 2
|
||||
a.ha1 == 2
|
||||
a[].ha1 = 3
|
||||
a.ha1 == 3
|
||||
|
||||
block:
|
||||
disableVm:
|
||||
assertAll:
|
||||
var a = A.create()
|
||||
defer: dealloc(a)
|
||||
privateAccess PtA
|
||||
a.ha1 == 0
|
||||
|
||||
static: main()
|
||||
main()
|
||||
|
|
@ -1,11 +1,24 @@
|
|||
import stdtest/testutils
|
||||
|
||||
block: # greedyOrderedSubsetLines
|
||||
doAssert greedyOrderedSubsetLines("a1\na3", "a0\na1\na2\na3\na4")
|
||||
doAssert not greedyOrderedSubsetLines("a3\na1", "a0\na1\na2\na3\na4") # out of order
|
||||
doAssert not greedyOrderedSubsetLines("a1\na5", "a0\na1\na2\na3\na4") # a5 not in lhs
|
||||
block: # assertAll
|
||||
assertAll:
|
||||
1+1 == 2
|
||||
var a = 3
|
||||
a == 3
|
||||
|
||||
doAssert not greedyOrderedSubsetLines("a1\na5", "a0\na1\na2\na3\na4\nprefix:a5")
|
||||
doAssert not greedyOrderedSubsetLines("a1\na5", "a0\na1\na2\na3\na4\na5:suffix")
|
||||
doAssert not greedyOrderedSubsetLines("a5", "a0\na1\na2\na3\na4\nprefix:a5")
|
||||
doAssert not greedyOrderedSubsetLines("a5", "a0\na1\na2\na3\na4\na5:suffix")
|
||||
doAssertRaises(AssertionDefect):
|
||||
assertAll:
|
||||
1+1 == 2
|
||||
var a = 3
|
||||
a == 4
|
||||
|
||||
block: # greedyOrderedSubsetLines
|
||||
assertAll:
|
||||
greedyOrderedSubsetLines("a1\na3", "a0\na1\na2\na3\na4")
|
||||
not greedyOrderedSubsetLines("a3\na1", "a0\na1\na2\na3\na4") # out of order
|
||||
not greedyOrderedSubsetLines("a1\na5", "a0\na1\na2\na3\na4") # a5 not in lhs
|
||||
|
||||
not greedyOrderedSubsetLines("a1\na5", "a0\na1\na2\na3\na4\nprefix:a5")
|
||||
not greedyOrderedSubsetLines("a1\na5", "a0\na1\na2\na3\na4\na5:suffix")
|
||||
not greedyOrderedSubsetLines("a5", "a0\na1\na2\na3\na4\nprefix:a5")
|
||||
not greedyOrderedSubsetLines("a5", "a0\na1\na2\na3\na4\na5:suffix")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue