tenumutils.nim 883 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. discard """
  2. matrix: "--mm:refc; --mm:orc"
  3. targets: "c js"
  4. """
  5. import std/enumutils
  6. from std/sequtils import toSeq
  7. import std/assertions
  8. template main =
  9. block: # items
  10. type A = enum a0 = 2, a1 = 4, a2
  11. type B[T] = enum b0 = 2, b1 = 4
  12. doAssert A.toSeq == [a0, a1, a2]
  13. doAssert B[float].toSeq == [B[float].b0, B[float].b1]
  14. block: # symbolName
  15. block:
  16. type A2 = enum a20, a21, a22
  17. doAssert $a21 == "a21"
  18. doAssert a21.symbolName == "a21"
  19. proc `$`(a: A2): string = "foo"
  20. doAssert $a21 == "foo"
  21. doAssert a21.symbolName == "a21"
  22. var a = a22
  23. doAssert $a == "foo"
  24. doAssert a.symbolName == "a22"
  25. type B = enum
  26. b0 = (10, "kb0")
  27. b1 = "kb1"
  28. b2
  29. let b = B.low
  30. doAssert b.symbolName == "b0"
  31. doAssert $b == "kb0"
  32. static: doAssert B.high.symbolName == "b2"
  33. static: main()
  34. main()