]> 127.0.0.1 Git - part/.git/commitdiff
add v0.28.0+202308126b725b0
authorqydysky <qydysky@foxmail.com>
Sat, 12 Aug 2023 17:53:43 +0000 (01:53 +0800)
committerqydysky <qydysky@foxmail.com>
Sat, 12 Aug 2023 17:53:43 +0000 (01:53 +0800)
component/Component.go
component/Component_test.go

index a315c5f5a823f46161c5d1fdfd1c7a9c417d4f6e..f61c9d2344066337af8b569cbc61914280738ff7 100644 (file)
@@ -4,6 +4,7 @@ import (
        "context"
        "errors"
        "maps"
+       "reflect"
        "sync/atomic"
 
        psync "github.com/qydysky/part/sync"
@@ -81,4 +82,13 @@ func Link(link map[string][]string) error {
        return Comp.Link(link)
 }
 
+func PKG(sign ...string) (pkg string) {
+       type empty struct{}
+       pkg = reflect.TypeOf(empty{}).PkgPath()
+       for i := 0; i < len(sign); i++ {
+               pkg += "." + sign[i]
+       }
+       return
+}
+
 var Comp *components = NewComp()
index 25925581a490446347189fa5c2280d12bf228495..036d827b9e4939dd34940956422d4df0ddd9f56d 100644 (file)
@@ -9,6 +9,7 @@ import (
 )
 
 func Test1(t *testing.T) {
+       Comp = NewComp()
        Put(`1`, func(ctx context.Context, ptr *int) error {
                if *ptr > 1 {
                        return nil
@@ -60,6 +61,7 @@ func Test1(t *testing.T) {
 }
 
 func TestDot(t *testing.T) {
+       Comp = NewComp()
        Put[int](`1`, func(ctx context.Context, ptr *int) error {
                if *ptr == 1 {
                        return nil
@@ -83,6 +85,7 @@ func TestDot(t *testing.T) {
 }
 
 func Test3(t *testing.T) {
+       Comp = NewComp()
        sumup := func(ctx context.Context, ptr *int) error {
                return nil
        }
@@ -100,6 +103,12 @@ func Test3(t *testing.T) {
        }
 }
 
+func Test4(t *testing.T) {
+       if pkg := PKG(`1`, `2`); pkg != `github.com/qydysky/part/component.1.2` {
+               t.Fatal(pkg)
+       }
+}
+
 func Benchmark2(b *testing.B) {
        for i := 0; i < b.N; i++ {
                Put[int](strconv.Itoa(i), func(ctx context.Context, ptr *int) error {