forked from mirror/enumer
Fix some golint suggestions
This commit is contained in:
parent
58936429ea
commit
87dc173c7b
|
@ -22,41 +22,41 @@ type Golden struct {
|
|||
}
|
||||
|
||||
var golden = []Golden{
|
||||
{"day", day_in, day_out},
|
||||
{"offset", offset_in, offset_out},
|
||||
{"gap", gap_in, gap_out},
|
||||
{"num", num_in, num_out},
|
||||
{"unum", unum_in, unum_out},
|
||||
{"prime", prime_in, prime_out},
|
||||
{"day", dayIn, dayOut},
|
||||
{"offset", offsetIn, offsetOut},
|
||||
{"gap", gapIn, gapOut},
|
||||
{"num", numIn, numOut},
|
||||
{"unum", unumIn, unumOut},
|
||||
{"prime", primeIn, primeOut},
|
||||
}
|
||||
|
||||
var goldenJSON = []Golden{
|
||||
{"prime", prime_json_in, prime_json_out},
|
||||
{"prime", primeJsonIn, primeJsonOut},
|
||||
}
|
||||
var goldenText = []Golden{
|
||||
{"prime", prime_text_in, prime_text_out},
|
||||
{"prime", primeTextIn, primeTextOut},
|
||||
}
|
||||
|
||||
var goldenYAML = []Golden{
|
||||
{"prime", prime_yaml_in, prime_yaml_out},
|
||||
{"prime", primeYamlIn, primeYamlOut},
|
||||
}
|
||||
|
||||
var goldenSQL = []Golden{
|
||||
{"prime", prime_sql_in, prime_sql_out},
|
||||
{"prime", primeSqlIn, primeSqlOut},
|
||||
}
|
||||
|
||||
var goldenJSONAndSQL = []Golden{
|
||||
{"prime", prime_json_and_sql_in, prime_json_and_sql_out},
|
||||
{"prime", primeJsonAndSqlIn, primeJsonAndSqlOut},
|
||||
}
|
||||
|
||||
var goldenPrefix = []Golden{
|
||||
{"prefix", prefix_in, day_out},
|
||||
{"prefix", prefixIn, dayOut},
|
||||
}
|
||||
|
||||
// Each example starts with "type XXX [u]int", with a single space separating them.
|
||||
|
||||
// Simple test: enumeration of type int starting at 0.
|
||||
const day_in = `type Day int
|
||||
const dayIn = `type Day int
|
||||
const (
|
||||
Monday Day = iota
|
||||
Tuesday
|
||||
|
@ -68,7 +68,7 @@ const (
|
|||
)
|
||||
`
|
||||
|
||||
const day_out = `
|
||||
const dayOut = `
|
||||
const _DayName = "MondayTuesdayWednesdayThursdayFridaySaturdaySunday"
|
||||
|
||||
var _DayIndex = [...]uint8{0, 6, 13, 22, 30, 36, 44, 50}
|
||||
|
@ -119,7 +119,7 @@ func (i Day) IsADay() bool {
|
|||
|
||||
// Enumeration with an offset.
|
||||
// Also includes a duplicate.
|
||||
const offset_in = `type Number int
|
||||
const offsetIn = `type Number int
|
||||
const (
|
||||
_ Number = iota
|
||||
One
|
||||
|
@ -129,7 +129,7 @@ const (
|
|||
)
|
||||
`
|
||||
|
||||
const offset_out = `
|
||||
const offsetOut = `
|
||||
const _NumberName = "OneTwoThree"
|
||||
|
||||
var _NumberIndex = [...]uint8{0, 3, 6, 11}
|
||||
|
@ -176,7 +176,7 @@ func (i Number) IsANumber() bool {
|
|||
`
|
||||
|
||||
// Gaps and an offset.
|
||||
const gap_in = `type Gap int
|
||||
const gapIn = `type Gap int
|
||||
const (
|
||||
Two Gap = 2
|
||||
Three Gap = 3
|
||||
|
@ -189,7 +189,7 @@ const (
|
|||
)
|
||||
`
|
||||
|
||||
const gap_out = `
|
||||
const gapOut = `
|
||||
const (
|
||||
_GapName_0 = "TwoThree"
|
||||
_GapName_1 = "FiveSixSevenEightNine"
|
||||
|
@ -256,7 +256,7 @@ func (i Gap) IsAGap() bool {
|
|||
`
|
||||
|
||||
// Signed integers spanning zero.
|
||||
const num_in = `type Num int
|
||||
const numIn = `type Num int
|
||||
const (
|
||||
m_2 Num = -2 + iota
|
||||
m_1
|
||||
|
@ -266,7 +266,7 @@ const (
|
|||
)
|
||||
`
|
||||
|
||||
const num_out = `
|
||||
const numOut = `
|
||||
const _NumName = "m_2m_1m0m1m2"
|
||||
|
||||
var _NumIndex = [...]uint8{0, 3, 6, 8, 10, 12}
|
||||
|
@ -315,7 +315,7 @@ func (i Num) IsANum() bool {
|
|||
`
|
||||
|
||||
// Unsigned integers spanning zero.
|
||||
const unum_in = `type Unum uint
|
||||
const unumIn = `type Unum uint
|
||||
const (
|
||||
m_2 Unum = iota + 253
|
||||
m_1
|
||||
|
@ -328,7 +328,7 @@ const (
|
|||
)
|
||||
`
|
||||
|
||||
const unum_out = `
|
||||
const unumOut = `
|
||||
const (
|
||||
_UnumName_0 = "m0m1m2"
|
||||
_UnumName_1 = "m_2m_1"
|
||||
|
@ -388,7 +388,7 @@ func (i Unum) IsAUnum() bool {
|
|||
|
||||
// Enough gaps to trigger a map implementation of the method.
|
||||
// Also includes a duplicate to test that it doesn't cause problems
|
||||
const prime_in = `type Prime int
|
||||
const primeIn = `type Prime int
|
||||
const (
|
||||
p2 Prime = 2
|
||||
p3 Prime = 3
|
||||
|
@ -407,7 +407,7 @@ const (
|
|||
)
|
||||
`
|
||||
|
||||
const prime_out = `
|
||||
const primeOut = `
|
||||
const _PrimeName = "p2p3p5p7p11p13p17p19p23p29p37p41p43"
|
||||
|
||||
var _PrimeMap = map[Prime]string{
|
||||
|
@ -471,7 +471,7 @@ func (i Prime) IsAPrime() bool {
|
|||
return ok
|
||||
}
|
||||
`
|
||||
const prime_json_in = `type Prime int
|
||||
const primeJsonIn = `type Prime int
|
||||
const (
|
||||
p2 Prime = 2
|
||||
p3 Prime = 3
|
||||
|
@ -490,7 +490,7 @@ const (
|
|||
)
|
||||
`
|
||||
|
||||
const prime_json_out = `
|
||||
const primeJsonOut = `
|
||||
const _PrimeName = "p2p3p5p7p11p13p17p19p23p29p37p41p43"
|
||||
|
||||
var _PrimeMap = map[Prime]string{
|
||||
|
@ -572,7 +572,7 @@ func (i *Prime) UnmarshalJSON(data []byte) error {
|
|||
}
|
||||
`
|
||||
|
||||
const prime_text_in = `type Prime int
|
||||
const primeTextIn = `type Prime int
|
||||
const (
|
||||
p2 Prime = 2
|
||||
p3 Prime = 3
|
||||
|
@ -591,7 +591,7 @@ const (
|
|||
)
|
||||
`
|
||||
|
||||
const prime_text_out = `
|
||||
const primeTextOut = `
|
||||
const _PrimeName = "p2p3p5p7p11p13p17p19p23p29p37p41p43"
|
||||
|
||||
var _PrimeMap = map[Prime]string{
|
||||
|
@ -668,7 +668,7 @@ func (i *Prime) UnmarshalText(text []byte) error {
|
|||
}
|
||||
`
|
||||
|
||||
const prime_yaml_in = `type Prime int
|
||||
const primeYamlIn = `type Prime int
|
||||
const (
|
||||
p2 Prime = 2
|
||||
p3 Prime = 3
|
||||
|
@ -687,7 +687,7 @@ const (
|
|||
)
|
||||
`
|
||||
|
||||
const prime_yaml_out = `
|
||||
const primeYamlOut = `
|
||||
const _PrimeName = "p2p3p5p7p11p13p17p19p23p29p37p41p43"
|
||||
|
||||
var _PrimeMap = map[Prime]string{
|
||||
|
@ -769,7 +769,7 @@ func (i *Prime) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|||
}
|
||||
`
|
||||
|
||||
const prime_sql_in = `type Prime int
|
||||
const primeSqlIn = `type Prime int
|
||||
const (
|
||||
p2 Prime = 2
|
||||
p3 Prime = 3
|
||||
|
@ -788,7 +788,7 @@ const (
|
|||
)
|
||||
`
|
||||
|
||||
const prime_sql_out = `
|
||||
const primeSqlOut = `
|
||||
const _PrimeName = "p2p3p5p7p11p13p17p19p23p29p37p41p43"
|
||||
|
||||
var _PrimeMap = map[Prime]string{
|
||||
|
@ -881,7 +881,7 @@ func (i *Prime) Scan(value interface{}) error {
|
|||
}
|
||||
`
|
||||
|
||||
const prime_json_and_sql_in = `type Prime int
|
||||
const primeJsonAndSqlIn = `type Prime int
|
||||
const (
|
||||
p2 Prime = 2
|
||||
p3 Prime = 3
|
||||
|
@ -900,7 +900,7 @@ const (
|
|||
)
|
||||
`
|
||||
|
||||
const prime_json_and_sql_out = `
|
||||
const primeJsonAndSqlOut = `
|
||||
const _PrimeName = "p2p3p5p7p11p13p17p19p23p29p37p41p43"
|
||||
|
||||
var _PrimeMap = map[Prime]string{
|
||||
|
@ -1010,7 +1010,7 @@ func (i *Prime) Scan(value interface{}) error {
|
|||
}
|
||||
`
|
||||
|
||||
const prefix_in = `type Day int
|
||||
const prefixIn = `type Day int
|
||||
const (
|
||||
DayMonday Day = iota
|
||||
DayTuesday
|
||||
|
|
|
@ -191,6 +191,7 @@ type Generator struct {
|
|||
pkg *Package // Package we are scanning.
|
||||
}
|
||||
|
||||
// Printf prints the string to the output
|
||||
func (g *Generator) Printf(format string, args ...interface{}) {
|
||||
fmt.Fprintf(&g.buf, format, args...)
|
||||
}
|
||||
|
@ -204,6 +205,7 @@ type File struct {
|
|||
values []Value // Accumulator for constant values of that type.
|
||||
}
|
||||
|
||||
// Package holds information about a Go package
|
||||
type Package struct {
|
||||
dir string
|
||||
name string
|
||||
|
|
14
util_test.go
14
util_test.go
|
@ -22,11 +22,11 @@ type SplitTest struct {
|
|||
}
|
||||
|
||||
var (
|
||||
m2 = uint64(2)
|
||||
m1 = uint64(1)
|
||||
m0 = uint64(0)
|
||||
m_1 = ^uint64(0) // -1 when signed.
|
||||
m_2 = ^uint64(0) - 1 // -2 when signed.
|
||||
m2 = uint64(2)
|
||||
m1 = uint64(1)
|
||||
m0 = uint64(0)
|
||||
m1Spanning0 = ^uint64(0) // -1 when signed.
|
||||
m2Spanning0 = ^uint64(0) - 1 // -2 when signed.
|
||||
)
|
||||
|
||||
var splitTests = []SplitTest{
|
||||
|
@ -44,9 +44,9 @@ var splitTests = []SplitTest{
|
|||
// Gaps throughout
|
||||
{u{33, 44, 1, 32, 45, 31}, uu{u{1}, u{31, 32, 33}, u{44, 45}}, true},
|
||||
// Unsigned values spanning 0.
|
||||
{u{m1, m0, m_1, m2, m_2}, uu{u{m0, m1, m2}, u{m_2, m_1}}, false},
|
||||
{u{m1, m0, m1Spanning0, m2, m2Spanning0}, uu{u{m0, m1, m2}, u{m2Spanning0, m1Spanning0}}, false},
|
||||
// Signed values spanning 0
|
||||
{u{m1, m0, m_1, m2, m_2}, uu{u{m_2, m_1, m0, m1, m2}}, true},
|
||||
{u{m1, m0, m1Spanning0, m2, m2Spanning0}, uu{u{m2Spanning0, m1Spanning0, m0, m1, m2}}, true},
|
||||
}
|
||||
|
||||
func TestSplitIntoRuns(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue