mt2.nim 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. from ./m1 {.all.} as r1 import foo1
  2. from ./m1 {.all.} as r2 import foo7
  3. block: # different symbol kinds
  4. doAssert foo1 == 2
  5. doAssert r1.foo1 == 2
  6. doAssert r1.foo2 == 2
  7. doAssert compiles(foo1)
  8. doAssert compiles(r1.foo2)
  9. doAssert not compiles(foo2)
  10. doAssert not compiles(m3h2)
  11. doAssert r1.foo3 == 2
  12. block: # enum
  13. var a: r1.Foo4
  14. let a1 = r1.kg1
  15. doAssert a1 == r1.Foo4.kg1
  16. type A = r1.Foo4
  17. doAssert a1 == A.kg1
  18. doAssert not compiles(kg1)
  19. doAssert compiles(A.kg1)
  20. var witness = false
  21. for ai in r1.Foo4:
  22. doAssert ai == a
  23. doAssert ai == a1
  24. witness = true
  25. break
  26. doAssert witness
  27. block: # {.pure.} enum
  28. var a: r1.Foo4b
  29. doAssert not compiles(r1.foo4b1) # because pure
  30. doAssert not compiles(foo4b1)
  31. let a1 = r1.Foo4b.foo4b1
  32. doAssert a1 == a
  33. type A = r1.Foo4b
  34. doAssert a1 == A.foo4b1
  35. var witness = false
  36. for ai in A:
  37. doAssert ai == a
  38. doAssert ai == a1
  39. witness = true
  40. break
  41. doAssert witness
  42. block: # object
  43. doAssert compiles(r1.Foo5)
  44. var a: r1.Foo5
  45. doAssert compiles(a.z4)
  46. doAssert not compiles(a.z3)
  47. block: # remaining symbol kinds
  48. doAssert r1.foo6() == 2
  49. doAssert r1.foo6b() == 2
  50. doAssert foo7() == 2
  51. doAssert r2.foo6b() == 2
  52. r1.foo8()
  53. r1.foo9(1)
  54. doAssert r1.foo13() == 2
  55. for a in r1.foo14a(): discard
  56. for a in r1.foo14b(): discard
  57. for a in r1.foo14c(): discard
  58. for a in r1.foo14d(): discard
  59. doAssert r1.foo15() == 2
  60. doAssert r1.foo16() == 2
  61. doAssert r1.foo17() == 2
  62. doAssert compiles(r1.foo18)
  63. doAssert declared(r1.foo18)
  64. block: # declarations at block scope should not be visible
  65. doAssert declared(foo7)
  66. doAssert declared(r1.foo6)
  67. doAssert not declared(foo10)
  68. doAssert not declared(foo6)
  69. doAssert not declared(r1.Foo11)
  70. doAssert not declared(r1.kg1b)
  71. doAssert not declared(r1.foo12)
  72. doAssert not compiles(r1.foo12())
  73. ## field access
  74. import std/importutils
  75. privateAccess(r1.Foo5)
  76. var x = r1.Foo5(z1: "foo", z2: r1.kg1)
  77. doAssert x.z1 == "foo"
  78. var f0: r1.Foo5
  79. f0.z3 = 3
  80. doAssert f0.z3 == 3
  81. var f = r1.initFoo5(z3=3)
  82. doAssert f.z3 == 3
  83. doAssert r1.z3(f) == 30
  84. import ./m1 as r3
  85. doAssert not declared(foo2)
  86. doAssert not declared(r3.foo2)
  87. from ./m1 {.all.} as r4 import nil
  88. doAssert not declared(foo2)
  89. doAssert declared(r4.foo2)
  90. from ./m1 {.all.} import nil
  91. doAssert not declared(foo2)
  92. doAssert declared(m1.foo2)