tobjhash.nim 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # https://github.com/nim-lang/RFCs/issues/380
  2. from mobjhash import Obj, RefObj, GenericObj1, GenericObj2, GenericObj3, GenericObj4, GenericRefObj
  3. import tables
  4. block:
  5. var t: Table[Obj, int]
  6. t[Obj(x: 3, y: 4, z: "debug")] = 34
  7. doAssert t[Obj(x: 3, y: 4, z: "ignored")] == 34
  8. doAssert Obj(x: 4, y: 3, z: "debug") notin t
  9. block:
  10. var t: Table[RefObj, int]
  11. t[RefObj(x: 3, y: 4, z: "debug")] = 34
  12. doAssert t[RefObj(x: 3, y: 4, z: "ignored")] == 34
  13. doAssert RefObj(x: 4, y: 3, z: "debug") notin t
  14. block:
  15. var t: Table[GenericObj1[float], int]
  16. t[GenericObj1[float](x: 3, y: 4, z: "debug")] = 34
  17. doAssert t[GenericObj1[float](x: 3, y: 4, z: "ignored")] == 34
  18. doAssert GenericObj1[float](x: 4, y: 3, z: "debug") notin t
  19. block:
  20. var t: Table[GenericObj1[int], int]
  21. t[GenericObj1[int](x: 3, y: 4, z: "debug")] = 34
  22. doAssert t[GenericObj1[int](x: 3, y: 4, z: "ignored")] == 34
  23. doAssert GenericObj1[int](x: 4, y: 3, z: "debug") notin t
  24. block:
  25. var t: Table[GenericObj2[float], int]
  26. t[GenericObj2[float](x: 3, y: 4, z: "debug")] = 34
  27. doAssert t[GenericObj2[float](x: 3, y: 4, z: "ignored")] == 34
  28. doAssert GenericObj2[float](x: 4, y: 3, z: "debug") notin t
  29. block:
  30. var t: Table[GenericObj3[float], int]
  31. t[GenericObj3[float](x: 3, y: 4, z: "debug")] = 34
  32. doAssert t[GenericObj3[float](x: 3, y: 4, z: "ignored")] == 34
  33. doAssert GenericObj3[float](x: 4, y: 3, z: "debug") notin t
  34. block:
  35. var t: Table[GenericObj4[float], int]
  36. t[GenericObj4[float](x: 3, y: 4, z: "debug")] = 34
  37. doAssert t[GenericObj4[float](x: 3, y: 4, z: "ignored")] == 34
  38. doAssert GenericObj4[float](x: 4, y: 3, z: "debug") notin t
  39. block:
  40. var t: Table[GenericRefObj[float], int]
  41. t[GenericRefObj[float](x: 3, y: 4, z: "debug")] = 34
  42. doAssert t[GenericRefObj[float](x: 3, y: 4, z: "ignored")] == 34
  43. doAssert GenericRefObj[float](x: 4, y: 3, z: "debug") notin t
  44. block:
  45. type LocalAlias[T] = GenericObj4[T]
  46. var t: Table[LocalAlias[float], int]
  47. t[LocalAlias[float](x: 3, y: 4, z: "debug")] = 34
  48. doAssert t[LocalAlias[float](x: 3, y: 4, z: "ignored")] == 34
  49. doAssert LocalAlias[float](x: 4, y: 3, z: "debug") notin t