-
Notifications
You must be signed in to change notification settings - Fork 3
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
3 changed files
with
60 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea | ||
.vscode | ||
genericfunc* |
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,22 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/dengsgo/go-decorator/decor" | ||
"log" | ||
) | ||
|
||
func logging(ctx *decor.Context) { | ||
log.Println("logging print target in", ctx.TargetIn) | ||
ctx.TargetDo() | ||
log.Println("logging print target out", ctx.TargetOut) | ||
} | ||
|
||
//go:decor logging | ||
func plus[T int8 | int16 | int | int32 | int64 | float32 | float64](a, b T) T { | ||
return a + b | ||
} | ||
|
||
func main() { | ||
log.SetFlags(0) | ||
log.Println("plus(1, 10) = ", plus(1, 10)) | ||
} |
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,35 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
const out = `logging print target in [1 10] | ||
logging print target out [11] | ||
plus(1, 10) = 11 | ||
` | ||
|
||
func TestPlus(t *testing.T) { | ||
args := []string{ | ||
"go", "run", "-toolexec", "decorator", "./main.go", | ||
} | ||
cmd := exec.Command(args[0], args[1:]...) | ||
cmd.Env = os.Environ() | ||
log.Println("args", args) | ||
bf := bytes.NewBuffer([]byte{}) | ||
cmd.Stdout = bf | ||
cmd.Stderr = bf | ||
err := cmd.Run() | ||
if err != nil { | ||
t.Fatalf("Run plus fail %s", err) | ||
} | ||
if strings.ReplaceAll(bf.String(), "\r\n", "\n") != | ||
strings.ReplaceAll(out, "\r\n", "\n") { | ||
t.Fatalf("plus out fail, out %s", bf.String()) | ||
} | ||
} |