-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
679 additions
and
119 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package builder | ||
|
||
import "testing" | ||
|
||
func TestInfo_String(t *testing.T) { | ||
runtimeVersion = func() string { | ||
return "go.test" | ||
} | ||
tests := []struct { | ||
name string | ||
info buildInfo | ||
want string | ||
}{ | ||
{ | ||
name: "empty", | ||
info: buildInfo{}, | ||
want: " (: ) built at by go.test", | ||
}, | ||
{ | ||
name: "full", | ||
info: buildInfo{ | ||
Name: "app", | ||
Version: "v1.0.0", | ||
Branch: "main", | ||
Commit: "abcdefg", | ||
DateTime: "2021-01-01T00:00:00Z", | ||
}, | ||
want: "app v1.0.0(main: abcdefg) built at 2021-01-01T00:00:00Z by go.test", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := tt.info.String(); got != tt.want { | ||
t.Errorf("buildInfo.String() = %q, want %q", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestInfo(t *testing.T) { | ||
defaultAppName := appName() | ||
tests := []struct { | ||
name string | ||
want buildInfo | ||
}{ | ||
{ | ||
name: "empty", | ||
want: buildInfo{ | ||
Name: "", | ||
Version: "", | ||
Branch: "", | ||
Commit: "", | ||
DateTime: "", | ||
}, | ||
}, | ||
{ | ||
name: "full", | ||
want: buildInfo{ | ||
Name: "app", | ||
Version: "v1.0.0", | ||
Branch: "main", | ||
Commit: "abcdefg", | ||
DateTime: "2021-01-01T00:00:00Z", | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
name = tt.want.Name | ||
version = tt.want.Version | ||
branch = tt.want.Branch | ||
commit = tt.want.Commit | ||
datetime = tt.want.DateTime | ||
if name == "" { | ||
tt.want.Name = defaultAppName | ||
} | ||
if got := Info(); got != tt.want { | ||
t.Errorf("Info() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package constraints_test | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gopherd/core/constraints" | ||
) | ||
|
||
func sum[T constraints.Addable](values ...T) T { | ||
var result T | ||
for _, v := range values { | ||
result += v | ||
} | ||
return result | ||
} | ||
|
||
func ExampleAddable() { | ||
fmt.Println(sum(1, 2)) | ||
fmt.Println(sum("hello", " ", "world")) | ||
// Output: | ||
// 3 | ||
// hello world | ||
} |
Oops, something went wrong.