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