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
- tip
before_install:
- go get github.com/golang/lint/golint
install:
- go build .
script:
- go test -v
- golint

View file

@ -43,8 +43,8 @@ import (
//
var DivisionPrecision = 16
// Set this to true if you want the decimal to be JSON marshaled as a number,
// instead of as a string.
// MarshalJSONWithoutQuotes should be set to true if you want the decimal to
// be JSON marshaled as a number, instead of as a string.
// WARNING: this is dangerous for decimals with many digits, since many JSON
// unmarshallers (ex: Javascript's) will unmarshal JSON numbers to IEEE 754
// 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 {
return q
} else {
if d.value.Sign()*d2.value.Sign() < 0 {
return q.Sub(New(1, -precision))
} else {
return q.Add(New(1, -precision))
}
}
if d.value.Sign()*d2.value.Sign() < 0 {
return q.Sub(New(1, -precision))
}
return q.Add(New(1, -precision))
}
// Mod returns d % d2.
@ -436,11 +436,11 @@ func (d Decimal) Rat() *big.Rat {
// NOTE(vadim): must negate after casting to prevent int32 overflow
denom := new(big.Int).Exp(tenInt, big.NewInt(-int64(d.exp)), nil)
return new(big.Rat).SetFrac(d.value, denom)
} else {
mul := new(big.Int).Exp(tenInt, big.NewInt(int64(d.exp)), nil)
num := new(big.Int).Mul(d.value, mul)
return new(big.Rat).SetFrac(num, oneInt)
}
mul := new(big.Int).Exp(tenInt, big.NewInt(int64(d.exp)), nil)
num := new(big.Int).Mul(d.value, mul)
return new(big.Rat).SetFrac(num, oneInt)
}
// 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
_, m := ret.value.DivMod(ret.value, tenInt, new(big.Int))
ret.exp += 1
ret.exp++
if ret.value.Sign() < 0 && m.Cmp(zeroInt) != 0 {
ret.value.Add(ret.value, oneInt)
}
@ -636,8 +636,8 @@ func (d Decimal) MarshalText() (text []byte, err error) {
return []byte(d.String()), nil
}
// NOTE: buggy, unintuitive, and DEPRECATED! Use StringFixed instead.
// 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 {
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:
//
@ -710,7 +710,7 @@ func Min(first Decimal, rest ...Decimal) Decimal {
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:
//

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
// and you specified a numeric format on the schema
dbvalue_int := int64(0)
expected = New(dbvalue_int, 0)
dbvalueInt := int64(0)
expected = New(dbvalueInt, 0)
err = a.Scan(dbvalue_int)
err = a.Scan(dbvalueInt)
if err != nil {
// Scan failed... no need to test result value
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,
// the database driver will return byte slice []byte
value_str := "535.666"
dbvalue_str := []byte(value_str)
expected, err = NewFromString(value_str)
valueStr := "535.666"
dbvalueStr := []byte(valueStr)
expected, err = NewFromString(valueStr)
if err != nil {
t.Fatal(err)
}
err = a.Scan(dbvalue_str)
err = a.Scan(dbvalueStr)
if err != nil {
// Scan failed... no need to test result value
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
expected, err = NewFromString(value_str)
expected, err = NewFromString(valueStr)
if err != nil {
t.Fatal(err)
}
err = a.Scan(value_str)
err = a.Scan(valueStr)
if err != nil {
// Scan failed... no need to test result value
t.Errorf("a.Scan('535.666') failed with message: %s", err)