tenumutils.nim 829 B

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