diff options
author | Ivan Bobev <bobeff@protonmail.ch> | 2020-11-09 11:02:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-09 10:02:01 +0100 |
commit | d03f24147a185091344c67a720a13ca0b3c98dc2 (patch) | |
tree | fdefb9206cb008c9067a64750608ab143dcce569 /tests | |
parent | 5db181f377e30f3a06e70b48e14337722d4dc114 (diff) | |
download | Nim-d03f24147a185091344c67a720a13ca0b3c98dc2.tar.gz |
Add a macro returning enum items count (#15824)
Add a macro `enumLen` which is used to determine the number of items in an enumeration type to the `typetraits.nim` module. Also, add unit tests for it in the `ttypetraits.nim` module. Related to nimlang/Nim#15824
Diffstat (limited to 'tests')
-rw-r--r-- | tests/metatype/ttypetraits.nim | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/metatype/ttypetraits.nim b/tests/metatype/ttypetraits.nim index 50c474fe9..326faac82 100644 --- a/tests/metatype/ttypetraits.nim +++ b/tests/metatype/ttypetraits.nim @@ -303,3 +303,43 @@ block: # elementType var a: seq[int] doAssert elementType(a) is int doAssert elementType(seq[char].default) is char + +block: # enum.len + type + Direction = enum + north, east, south, west + + Direction2 = Direction + Direction3 = Direction2 + + TokenType = enum + a = 2, b = 4, c = 89 + + MyEnum = enum + ##[This is test of enum with a doc comment. + + Which is also a multi line one.]## + valueA = (0, "my value A"), + ## The items are also commented. This has both integer and string + ## values. + valueB = "value B", + ## This item has only a string value, + valueC = 2, + ## and this one only an integer. + valueD = (3, "abc") + ## Both, integer and string values again. + + OtherEnum {.pure.} = enum + valueX, valueY, valueZ + + MyFlag {.size: sizeof(cint).} = enum + A, B, C, D + + static: + doAssert Direction.enumLen == 4 + doAssert Direction2.enumLen == 4 + doAssert Direction3.enumLen == 4 + doAssert TokenType.enumLen == 3 + doAssert MyEnum.enumLen == 4 + doAssert OtherEnum.enumLen == 3 + doAssert MyFlag.enumLen == 4 |