-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenum_test.go
More file actions
54 lines (40 loc) · 971 Bytes
/
Copy pathenum_test.go
File metadata and controls
54 lines (40 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package enum
import (
"github.com/stretchr/testify/assert"
"testing"
)
type eTestInt struct {
EnumImpl[TestInt, eTestInt]
}
var ETestInt eTestInt
type TestInt int
func (t TestInt) String() string {
return ETestInt.String(t)
}
func (eTestInt) Foo() TestInt {
return 1
}
func (eTestInt) Bar() TestInt {
return 2
}
func (eTestInt) Baz() TestInt {
return 3
}
func TestEnumInt(t *testing.T) {
a := assert.New(t)
a.Equal(ETestInt.Foo().String(), "Foo")
a.Equal(ETestInt.Bar().String(), "Bar")
a.Equal(ETestInt.Baz().String(), "Baz")
res, err := ETestInt.Parse("string", true)
a.Error(err, "string should not parse")
a.Equal(res, TestInt(0))
res, err = ETestInt.Parse("foo", true)
a.NoError(err, "foo should parse")
a.Equal(res, TestInt(1))
res, err = ETestInt.Parse("Bar", true)
a.NoError(err, "Bar should parse")
a.Equal(res, TestInt(2))
res, err = ETestInt.Parse("baZ", true)
a.NoError(err, "baZ should parse")
a.Equal(res, TestInt(3))
}