mirror of
https://github.com/status-im/nim-stew.git
synced 2025-01-10 04:05:44 +00:00
7b4c9407f2
For serialization and parsing, distinguishing enums with numeric values from enums with associated strings for each value is useful. This adds foundational helpers to allow such distinction.
38 lines
894 B
Nim
38 lines
894 B
Nim
# stew
|
|
# Copyright 2023 Status Research & Development GmbH
|
|
# Licensed under either of
|
|
#
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
|
#
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
{.used.}
|
|
|
|
import
|
|
unittest2,
|
|
../stew/enums
|
|
|
|
suite "enumStyle":
|
|
test "OrdinalEnum":
|
|
type EnumTest = enum
|
|
x0,
|
|
x1,
|
|
x2
|
|
check EnumTest.enumStyle == EnumStyle.Numeric
|
|
|
|
test "HoleyEnum":
|
|
type EnumTest = enum
|
|
y1 = 1,
|
|
y3 = 3,
|
|
y4,
|
|
y6 = 6
|
|
check EnumTest.enumStyle == EnumStyle.Numeric
|
|
|
|
test "StringEnum":
|
|
type EnumTest = enum
|
|
z1 = "aaa",
|
|
z2 = "bbb",
|
|
z3 = "ccc"
|
|
check EnumTest.enumStyle == EnumStyle.AssociatedStrings
|