Skip to content

Commit

Permalink
up the code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
abice committed Mar 20, 2022
1 parent f542b76 commit eba8f4b
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 44 deletions.
2 changes: 1 addition & 1 deletion example/enum_32_bit.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate ../bin/go-enum -f=$GOFILE --ptr --marshal
//go:generate ../bin/go-enum -f=$GOFILE --names

package example

Expand Down
45 changes: 24 additions & 21 deletions example/enum_32_bit_enum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions example/enum_32_bit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package example

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestEnum32Bit(t *testing.T) {

tests := map[string]struct {
input string
output Enum32bit
}{
"E2P15": {
input: `E2P15`,
output: Enum32bitE2P15,
},
"E2P30": {
input: `E2P30`,
output: Enum32bitE2P30,
},
}

for name, tc := range tests {
t.Run(name, func(t *testing.T) {
output, err := ParseEnum32bit(tc.input)
assert.NoError(t, err)
assert.Equal(t, tc.output, output)

assert.Equal(t, tc.input, output.String())
})
}

t.Run("basics", func(t *testing.T) {
assert.Equal(t, "E2P23", Enum32bitE2P23.String())
assert.Equal(t, "Enum32bit(99)", Enum32bit(99).String())
_, err := ParseEnum32bit("-1")
assert.Error(t, err)

names := Enum32bitNames()
assert.Len(t, names, 12)
})

}
2 changes: 1 addition & 1 deletion example/enum_64_bit.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate ../bin/go-enum -f=$GOFILE --ptr --marshal
//go:generate ../bin/go-enum -f=$GOFILE --names

package example

Expand Down
49 changes: 28 additions & 21 deletions example/enum_64_bit_enum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions example/enum_64_bit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package example

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestEnum64Bit(t *testing.T) {

tests := map[string]struct {
input string
output Enum64bit
}{
"E2P15": {
input: `E2P15`,
output: Enum64bitE2P15,
},
"E2P63": {
input: `E2P63`,
output: Enum64bitE2P63,
},
}

for name, tc := range tests {
t.Run(name, func(t *testing.T) {
output, err := ParseEnum64bit(tc.input)
assert.NoError(t, err)
assert.Equal(t, tc.output, output)

assert.Equal(t, tc.input, output.String())
})
}

t.Run("basics", func(t *testing.T) {
assert.Equal(t, "E2P23", Enum64bitE2P23.String())
assert.Equal(t, "Enum64bit(99)", Enum64bit(99).String())
_, err := ParseEnum64bit("-1")
assert.Error(t, err)

names := Enum64bitNames()
assert.Len(t, names, 16)
})

}
7 changes: 7 additions & 0 deletions example/force_lower_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,11 @@ func TestForceLowerString(t *testing.T) {
assert.Equal(t, tc.input, output.String())
})
}

t.Run("failures", func(t *testing.T) {
assert.Equal(t, "ForceLowerType(99)", ForceLowerType(99).String())
_, err := ParseForceLowerType("-1")
assert.Error(t, err)

})
}
8 changes: 8 additions & 0 deletions example/user_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,12 @@ func TestUserTemplateColor(t *testing.T) {
assert.Equal(t, true, ParseOceanColorExample())
assert.Equal(t, true, ParseOceanColorGlobbedExample())
assert.Equal(t, true, ParseOceanColorGlobbedExample2())

val, err := ParseOceanColor("Cerulean")
assert.NoError(t, err)
assert.Equal(t, "Cerulean", val.String())

assert.Equal(t, "OceanColor(99)", OceanColor(99).String())
_, err = ParseOceanColor("-1")
assert.Error(t, err)
}

0 comments on commit eba8f4b

Please sign in to comment.