-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mathutil] Add min/max for integer type #123
- Loading branch information
Showing
10 changed files
with
187 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,22 @@ | ||
package generator_test | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
"text/template" | ||
|
||
"github.com/dyweb/gommon/generator" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestUcFirst(t *testing.T) { | ||
tmpl, err := template.New("test_ucfirst").Funcs(template.FuncMap{"UcFirst": generator.UcFirst}).Parse(`{{ .foo | UcFirst }}`) | ||
require.Nil(t, err) | ||
var buf bytes.Buffer | ||
err = tmpl.Execute(&buf, map[string]string{ | ||
"foo": "int64", | ||
}) | ||
assert.Nil(t, err) | ||
assert.Equal(t, "Int64", buf.String()) | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
gotmpls: | ||
- src: max_generated.go.tmpl | ||
dst: max_generated.go | ||
go: true | ||
data: | ||
- int | ||
- uint | ||
- int32 | ||
- uint32 | ||
- int64 | ||
- uint64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package mathutil | ||
|
||
func MaxInt(a, b int) int { | ||
if a > b { | ||
return a | ||
} | ||
return b | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package mathutil | ||
|
||
{{ range .}} | ||
func Max{{. | UcFirst }} (a, b {{.}}) {{.}} { | ||
if a > b { | ||
return a | ||
} | ||
return b | ||
} | ||
|
||
func Min{{. | UcFirst }} (a, b {{.}}) {{.}} { | ||
if a < b { | ||
return a | ||
} | ||
return b | ||
} | ||
{{ end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Package mathutil provides supplement functions for math package, e.g. MaxInt, MaxInt64 | ||
package mathutil |