tenumutils.nim 851 B

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