diff --git a/.travis/check-generate.sh b/.travis/check-generate.sh index bf791d29..9a95d019 100755 --- a/.travis/check-generate.sh +++ b/.travis/check-generate.sh @@ -1,6 +1,7 @@ #!/bin/bash -go generate gonum.org/v1/gonum/blas/native +go generate gonum.org/v1/gonum/blas/gonum +go generate gonum.org/v1/gonum/unit if [ -n "$(git diff)" ]; then exit 1 fi diff --git a/unit/autogen/autogen.go b/unit/autogen.go similarity index 87% rename from unit/autogen/autogen.go rename to unit/autogen.go index 881180fa..829c7318 100644 --- a/unit/autogen/autogen.go +++ b/unit/autogen.go @@ -1,3 +1,9 @@ +// Copyright ©2014 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build ignore + package main import ( @@ -197,7 +203,7 @@ func init() { log.Fatal("no gopath") } - unitPkgPath = filepath.Join(gopath, "src", "github.com", "gonum", "unit") + unitPkgPath = filepath.Join(gopath, "src", "gonum.org", "v1", "gonum", "unit") } // Generate generates a file for each of the units @@ -207,8 +213,7 @@ func main() { } } -const headerTemplate = `// This file is autogenerated by github.com/gonum/unit/autogen -// Changes should be made to the autogenerated template rather than this one +const headerTemplate = `// Code generated by "go generate gonum.org/v1/gonum/unit”; DO NOT EDIT. // Copyright ©2014 The gonum Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -243,7 +248,7 @@ var prefix = template.Must(template.New("prefix").Parse(constTemplate)) const methodTemplate = ` // Unit converts the {{.Name}} to a *Unit -func ({{.Receiver}} {{.Name}}) Unit() *Unit{ +func ({{.Receiver}} {{.Name}}) Unit() *Unit { return New(float64({{.Receiver}}), Dimensions{ {{range .Dimensions}} {{.Name}}: {{.Power}}, {{end}} @@ -257,7 +262,7 @@ func ({{.Receiver}} {{.Name}}) {{.Name}}() {{.Name}} { // From converts the unit into the receiver. From returns an // error if there is a mismatch in dimension -func ({{.Receiver}} *{{.Name}}) From(u Uniter) error{ +func ({{.Receiver}} *{{.Name}}) From(u Uniter) error { if !DimensionsMatch(u, {{.Singular}}){ *{{.Receiver}} = {{.Name}}(math.NaN()) return errors.New("Dimension mismatch") @@ -270,7 +275,7 @@ func ({{.Receiver}} *{{.Name}}) From(u Uniter) error{ var methods = template.Must(template.New("methods").Parse(methodTemplate)) const formatTemplate = ` -func ({{.Receiver}} {{.Name}}) Format(fs fmt.State, c rune){ +func ({{.Receiver}} {{.Name}}) Format(fs fmt.State, c rune) { switch c { case 'v': if fs.Flag('#') { @@ -280,19 +285,21 @@ func ({{.Receiver}} {{.Name}}) Format(fs fmt.State, c rune){ fallthrough case 'e', 'E', 'f', 'F', 'g', 'G': p, pOk := fs.Precision() - if !pOk { - p = -1 - } w, wOk := fs.Width() - if !wOk { - w = -1 + switch { + case pOk && wOk: + fmt.Fprintf(fs, "%*.*"+string(c), w, p, float64({{.Receiver}})) + case pOk: + fmt.Fprintf(fs, "%.*"+string(c), p, float64({{.Receiver}})) + case wOk: + fmt.Fprintf(fs, "%*"+string(c), w, float64({{.Receiver}})) + default: + fmt.Fprintf(fs, "%"+string(c), float64({{.Receiver}})) } - fmt.Fprintf(fs, "%*.*"+string(c), w, p, float64({{.Receiver}})) fmt.Fprint(fs, " {{.PrintString}}") default: fmt.Fprintf(fs, "%%!%c(%T=%g {{.PrintString}})", c, {{.Receiver}}, float64({{.Receiver}})) - return -} + } } ` diff --git a/unit/doc.go b/unit/doc.go index 5e4c6999..97ca4386 100644 --- a/unit/doc.go +++ b/unit/doc.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:generate go run autogen.go + // Package unit provides a set of types and constants that facilitate // the use of the International System of Units (SI). // diff --git a/unit/length.go b/unit/length.go index 671d4328..f7ffde23 100644 --- a/unit/length.go +++ b/unit/length.go @@ -1,5 +1,4 @@ -// This file is autogenerated by github.com/gonum/unit/autogen -// Changes should be made to the autogenerated template rather than this one +// Code generated by "go generate gonum.org/v1/gonum/unit”; DO NOT EDIT. // Copyright ©2014 The gonum Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -87,6 +86,5 @@ func (l Length) Format(fs fmt.State, c rune) { fmt.Fprint(fs, " m") default: fmt.Fprintf(fs, "%%!%c(%T=%g m)", c, l, float64(l)) - return } } diff --git a/unit/mass.go b/unit/mass.go index d3334551..2b127046 100644 --- a/unit/mass.go +++ b/unit/mass.go @@ -1,5 +1,4 @@ -// This file is autogenerated by github.com/gonum/unit/autogen -// Changes should be made to the autogenerated template rather than this one +// Code generated by "go generate gonum.org/v1/gonum/unit”; DO NOT EDIT. // Copyright ©2014 The gonum Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -87,6 +86,5 @@ func (m Mass) Format(fs fmt.State, c rune) { fmt.Fprint(fs, " kg") default: fmt.Fprintf(fs, "%%!%c(%T=%g kg)", c, m, float64(m)) - return } } diff --git a/unit/time.go b/unit/time.go index 8e841793..ef70fb8a 100644 --- a/unit/time.go +++ b/unit/time.go @@ -1,5 +1,4 @@ -// This file is autogenerated by github.com/gonum/unit/autogen -// Changes should be made to the autogenerated template rather than this one +// Code generated by "go generate gonum.org/v1/gonum/unit”; DO NOT EDIT. // Copyright ©2014 The gonum Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -90,6 +89,5 @@ func (t Time) Format(fs fmt.State, c rune) { fmt.Fprint(fs, " s") default: fmt.Fprintf(fs, "%%!%c(%T=%g s)", c, t, float64(t)) - return } }