Pass lint, add travis stuff to run golint

This commit is contained in:
Victor Quinn 2017-02-15 18:55:38 -05:00
parent 868a37b979
commit 2aa9963045
3 changed files with 29 additions and 25 deletions

View file

@ -6,8 +6,12 @@ go:
- 1.4 - 1.4
- tip - tip
before_install:
- go get github.com/golang/lint/golint
install: install:
- go build . - go build .
script: script:
- go test -v - go test -v
- golint

View file

@ -43,8 +43,8 @@ import (
// //
var DivisionPrecision = 16 var DivisionPrecision = 16
// Set this to true if you want the decimal to be JSON marshaled as a number, // MarshalJSONWithoutQuotes should be set to true if you want the decimal to
// instead of as a string. // be JSON marshaled as a number, instead of as a string.
// WARNING: this is dangerous for decimals with many digits, since many JSON // WARNING: this is dangerous for decimals with many digits, since many JSON
// unmarshallers (ex: Javascript's) will unmarshal JSON numbers to IEEE 754 // unmarshallers (ex: Javascript's) will unmarshal JSON numbers to IEEE 754
// double-precision floating point numbers, which means you can potentially // double-precision floating point numbers, which means you can potentially
@ -351,13 +351,13 @@ func (d Decimal) DivRound(d2 Decimal, precision int32) Decimal {
if c < 0 { if c < 0 {
return q return q
} else { }
if d.value.Sign()*d2.value.Sign() < 0 { if d.value.Sign()*d2.value.Sign() < 0 {
return q.Sub(New(1, -precision)) return q.Sub(New(1, -precision))
} else { }
return q.Add(New(1, -precision)) return q.Add(New(1, -precision))
}
}
} }
// Mod returns d % d2. // Mod returns d % d2.
@ -436,11 +436,11 @@ func (d Decimal) Rat() *big.Rat {
// NOTE(vadim): must negate after casting to prevent int32 overflow // NOTE(vadim): must negate after casting to prevent int32 overflow
denom := new(big.Int).Exp(tenInt, big.NewInt(-int64(d.exp)), nil) denom := new(big.Int).Exp(tenInt, big.NewInt(-int64(d.exp)), nil)
return new(big.Rat).SetFrac(d.value, denom) return new(big.Rat).SetFrac(d.value, denom)
} else { }
mul := new(big.Int).Exp(tenInt, big.NewInt(int64(d.exp)), nil) mul := new(big.Int).Exp(tenInt, big.NewInt(int64(d.exp)), nil)
num := new(big.Int).Mul(d.value, mul) num := new(big.Int).Mul(d.value, mul)
return new(big.Rat).SetFrac(num, oneInt) return new(big.Rat).SetFrac(num, oneInt)
}
} }
// Float64 returns the nearest float64 value for d and a bool indicating // Float64 returns the nearest float64 value for d and a bool indicating
@ -505,7 +505,7 @@ func (d Decimal) Round(places int32) Decimal {
// floor for positive numbers, ceil for negative numbers // floor for positive numbers, ceil for negative numbers
_, m := ret.value.DivMod(ret.value, tenInt, new(big.Int)) _, m := ret.value.DivMod(ret.value, tenInt, new(big.Int))
ret.exp += 1 ret.exp++
if ret.value.Sign() < 0 && m.Cmp(zeroInt) != 0 { if ret.value.Sign() < 0 && m.Cmp(zeroInt) != 0 {
ret.value.Add(ret.value, oneInt) ret.value.Add(ret.value, oneInt)
} }
@ -636,8 +636,8 @@ func (d Decimal) MarshalText() (text []byte, err error) {
return []byte(d.String()), nil return []byte(d.String()), nil
} }
// NOTE: buggy, unintuitive, and DEPRECATED! Use StringFixed instead.
// StringScaled first scales the decimal then calls .String() on it. // StringScaled first scales the decimal then calls .String() on it.
// NOTE: buggy, unintuitive, and DEPRECATED! Use StringFixed instead.
func (d Decimal) StringScaled(exp int32) string { func (d Decimal) StringScaled(exp int32) string {
return d.rescale(exp).String() return d.rescale(exp).String()
} }
@ -693,7 +693,7 @@ func (d *Decimal) ensureInitialized() {
} }
} }
// Returns the smallest Decimal that was passed in the arguments. // Min returns the smallest Decimal that was passed in the arguments.
// //
// To call this function with an array, you must do: // To call this function with an array, you must do:
// //
@ -710,7 +710,7 @@ func Min(first Decimal, rest ...Decimal) Decimal {
return ans return ans
} }
// Returns the largest Decimal that was passed in the arguments. // Max returns the largest Decimal that was passed in the arguments.
// //
// To call this function with an array, you must do: // To call this function with an array, you must do:
// //

View file

@ -1174,10 +1174,10 @@ func TestDecimal_Scan(t *testing.T) {
// at least SQLite returns an int64 when 0 is stored in the db // at least SQLite returns an int64 when 0 is stored in the db
// and you specified a numeric format on the schema // and you specified a numeric format on the schema
dbvalue_int := int64(0) dbvalueInt := int64(0)
expected = New(dbvalue_int, 0) expected = New(dbvalueInt, 0)
err = a.Scan(dbvalue_int) err = a.Scan(dbvalueInt)
if err != nil { if err != nil {
// Scan failed... no need to test result value // Scan failed... no need to test result value
t.Errorf("a.Scan(0) failed with message: %s", err) t.Errorf("a.Scan(0) failed with message: %s", err)
@ -1191,14 +1191,14 @@ func TestDecimal_Scan(t *testing.T) {
// in case you specified a varchar in your SQL schema, // in case you specified a varchar in your SQL schema,
// the database driver will return byte slice []byte // the database driver will return byte slice []byte
value_str := "535.666" valueStr := "535.666"
dbvalue_str := []byte(value_str) dbvalueStr := []byte(valueStr)
expected, err = NewFromString(value_str) expected, err = NewFromString(valueStr)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
err = a.Scan(dbvalue_str) err = a.Scan(dbvalueStr)
if err != nil { if err != nil {
// Scan failed... no need to test result value // Scan failed... no need to test result value
t.Errorf("a.Scan('535.666') failed with message: %s", err) t.Errorf("a.Scan('535.666') failed with message: %s", err)
@ -1211,12 +1211,12 @@ func TestDecimal_Scan(t *testing.T) {
} }
// lib/pq can also return strings // lib/pq can also return strings
expected, err = NewFromString(value_str) expected, err = NewFromString(valueStr)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
err = a.Scan(value_str) err = a.Scan(valueStr)
if err != nil { if err != nil {
// Scan failed... no need to test result value // Scan failed... no need to test result value
t.Errorf("a.Scan('535.666') failed with message: %s", err) t.Errorf("a.Scan('535.666') failed with message: %s", err)