-
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
yangyile
committed
Dec 3, 2024
1 parent
4597f46
commit 10a10cb
Showing
25 changed files
with
308 additions
and
93 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
5 changes: 3 additions & 2 deletions
5
...gen/example0/example0node/example0node.go → ...example_cls_stub_gen/example0/example0.go
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,6 +1,7 @@ | ||
package example0node | ||
package example0 | ||
|
||
var NODE = &A{} | ||
var STUB1 = &A{} | ||
var STUB2 = &A{} | ||
|
||
type A struct{} | ||
|
||
|
16 changes: 16 additions & 0 deletions
16
internal/examples/example_cls_stub_gen/example0/example0x1gen/gen.go
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,16 @@ | ||
package example0x1gen | ||
|
||
import "github.com/yyle88/sure/internal/examples/example_cls_stub_gen/example0" | ||
|
||
func Get() *example0.A { | ||
return example0.STUB1.Get() | ||
} | ||
func Set(arg string) { | ||
example0.STUB1.Set(arg) | ||
} | ||
func Add(x int, y int) int { | ||
return example0.STUB1.Add(x, y) | ||
} | ||
func Sub(x int, y int) (int, error) { | ||
return example0.STUB1.Sub(x, y) | ||
} |
10 changes: 5 additions & 5 deletions
10
...example_cls_stub_gen/example0/gen_test.go → ...ub_gen/example0/example0x1gen/gen_test.go
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,25 +1,25 @@ | ||
package example0 | ||
package example0x1gen | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/yyle88/runpath" | ||
"github.com/yyle88/runpath/runtestpath" | ||
"github.com/yyle88/sure/cls_stub_gen" | ||
"github.com/yyle88/sure/internal/examples/example_cls_stub_gen/example0/example0node" | ||
"github.com/yyle88/sure/internal/examples/example_cls_stub_gen/example0" | ||
"github.com/yyle88/syntaxgo" | ||
"github.com/yyle88/syntaxgo/syntaxgo_ast" | ||
) | ||
|
||
func TestGen(t *testing.T) { | ||
param := cls_stub_gen.NewStubParam(&example0node.A{}, "example0node.NODE") | ||
param := cls_stub_gen.NewStubParam(&example0.A{}, "example0.STUB1") | ||
|
||
cfg := &cls_stub_gen.StubGenConfig{ | ||
SourceRootPath: runpath.PARENT.Join("example0node"), | ||
SourceRootPath: runpath.PARENT.Join("../../example0"), | ||
TargetPackageName: syntaxgo.CurrentPackageName(), | ||
ImportOptions: syntaxgo_ast.NewPackageImportOptions(), | ||
OutputPath: runtestpath.SrcPath(t), | ||
AllowFileCreation: false, | ||
} | ||
cls_stub_gen.GenerateStubsFile(cfg, param) | ||
cls_stub_gen.GenerateStubs(cfg, param) | ||
} |
16 changes: 16 additions & 0 deletions
16
internal/examples/example_cls_stub_gen/example0/example0x2gen/gen.go
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,16 @@ | ||
package example0x2gen | ||
|
||
import "github.com/yyle88/sure/internal/examples/example_cls_stub_gen/example0" | ||
|
||
func Get() *example0.A { | ||
return example0.STUB2.Get() | ||
} | ||
func Set(arg string) { | ||
example0.STUB2.Set(arg) | ||
} | ||
func Add(x int, y int) int { | ||
return example0.STUB2.Add(x, y) | ||
} | ||
func Sub(x int, y int) (int, error) { | ||
return example0.STUB2.Sub(x, y) | ||
} |
25 changes: 25 additions & 0 deletions
25
internal/examples/example_cls_stub_gen/example0/example0x2gen/gen_test.go
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,25 @@ | ||
package example0x2gen | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/yyle88/runpath" | ||
"github.com/yyle88/runpath/runtestpath" | ||
"github.com/yyle88/sure/cls_stub_gen" | ||
"github.com/yyle88/sure/internal/examples/example_cls_stub_gen/example0" | ||
"github.com/yyle88/syntaxgo" | ||
"github.com/yyle88/syntaxgo/syntaxgo_ast" | ||
) | ||
|
||
func TestGen(t *testing.T) { | ||
param := cls_stub_gen.NewStubParam(&example0.A{}, "example0.STUB2") | ||
|
||
cfg := &cls_stub_gen.StubGenConfig{ | ||
SourceRootPath: runpath.PARENT.Join("../../example0"), | ||
TargetPackageName: syntaxgo.CurrentPackageName(), | ||
ImportOptions: syntaxgo_ast.NewPackageImportOptions(), | ||
OutputPath: runtestpath.SrcPath(t), | ||
AllowFileCreation: false, | ||
} | ||
cls_stub_gen.GenerateStubs(cfg, param) | ||
} |
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
internal/examples/example_cls_stub_gen/example6/example6.go
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,13 @@ | ||
package example6 | ||
|
||
type A struct { | ||
name string | ||
} | ||
|
||
func NewA(name string) *A { | ||
return &A{name: name} | ||
} | ||
|
||
func (a *A) Name() string { | ||
return a.name | ||
} |
5 changes: 5 additions & 0 deletions
5
internal/examples/example_cls_stub_gen/example6/example6x1gen/gen.go
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,5 @@ | ||
package example6x1gen | ||
|
||
func Name() string { | ||
return A100.Name() | ||
} |
25 changes: 25 additions & 0 deletions
25
internal/examples/example_cls_stub_gen/example6/example6x1gen/gen_test.go
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,25 @@ | ||
package example6x1gen | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/yyle88/runpath" | ||
"github.com/yyle88/runpath/runtestpath" | ||
"github.com/yyle88/sure/cls_stub_gen" | ||
"github.com/yyle88/sure/internal/examples/example_cls_stub_gen/example6" | ||
"github.com/yyle88/syntaxgo" | ||
"github.com/yyle88/syntaxgo/syntaxgo_ast" | ||
) | ||
|
||
func TestGen(t *testing.T) { | ||
param := cls_stub_gen.NewStubParam(&example6.A{}, "A100") | ||
|
||
cfg := &cls_stub_gen.StubGenConfig{ | ||
SourceRootPath: runpath.PARENT.Join("../../example6"), | ||
TargetPackageName: syntaxgo.CurrentPackageName(), | ||
ImportOptions: syntaxgo_ast.NewPackageImportOptions(), | ||
OutputPath: runtestpath.SrcPath(t), | ||
AllowFileCreation: false, | ||
} | ||
cls_stub_gen.GenerateStubs(cfg, param) | ||
} |
5 changes: 5 additions & 0 deletions
5
internal/examples/example_cls_stub_gen/example6/example6x1gen/singleton.go
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,5 @@ | ||
package example6x1gen | ||
|
||
import "github.com/yyle88/sure/internal/examples/example_cls_stub_gen/example6" | ||
|
||
var A100 = example6.NewA("100") |
5 changes: 5 additions & 0 deletions
5
internal/examples/example_cls_stub_gen/example6/example6x2gen/gen.go
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,5 @@ | ||
package example6x2gen | ||
|
||
func Name() string { | ||
return A200.Name() | ||
} |
25 changes: 25 additions & 0 deletions
25
internal/examples/example_cls_stub_gen/example6/example6x2gen/gen_test.go
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,25 @@ | ||
package example6x2gen | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/yyle88/runpath" | ||
"github.com/yyle88/runpath/runtestpath" | ||
"github.com/yyle88/sure/cls_stub_gen" | ||
"github.com/yyle88/sure/internal/examples/example_cls_stub_gen/example6" | ||
"github.com/yyle88/syntaxgo" | ||
"github.com/yyle88/syntaxgo/syntaxgo_ast" | ||
) | ||
|
||
func TestGen(t *testing.T) { | ||
param := cls_stub_gen.NewStubParam(&example6.A{}, "A200") | ||
|
||
cfg := &cls_stub_gen.StubGenConfig{ | ||
SourceRootPath: runpath.PARENT.Join("../../example6"), | ||
TargetPackageName: syntaxgo.CurrentPackageName(), | ||
ImportOptions: syntaxgo_ast.NewPackageImportOptions(), | ||
OutputPath: runtestpath.SrcPath(t), | ||
AllowFileCreation: false, | ||
} | ||
cls_stub_gen.GenerateStubs(cfg, param) | ||
} |
5 changes: 5 additions & 0 deletions
5
internal/examples/example_cls_stub_gen/example6/example6x2gen/singleton.go
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,5 @@ | ||
package example6x2gen | ||
|
||
import "github.com/yyle88/sure/internal/examples/example_cls_stub_gen/example6" | ||
|
||
var A200 = example6.NewA("200") |
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,26 @@ | ||
package example_cls_stub_gen | ||
|
||
import ( | ||
"math/rand/v2" | ||
|
||
"github.com/yyle88/sure/internal/examples/example_cls_stub_gen/example0/example0x1gen" | ||
"github.com/yyle88/sure/internal/examples/example_cls_stub_gen/example0/example0x2gen" | ||
"github.com/yyle88/sure/internal/examples/example_cls_stub_gen/example6/example6x1gen" | ||
"github.com/yyle88/sure/internal/examples/example_cls_stub_gen/example6/example6x2gen" | ||
) | ||
|
||
func Example0x1() int { | ||
return example0x1gen.Add(rand.IntN(100), rand.IntN(100)) | ||
} | ||
|
||
func Example0x2() int { | ||
return example0x2gen.Add(rand.IntN(100), rand.IntN(100)) | ||
} | ||
|
||
func Example6x1() string { | ||
return example6x1gen.Name() | ||
} | ||
|
||
func Example6x2() string { | ||
return example6x2gen.Name() | ||
} |
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 example_cls_stub_gen | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestExample0x1(t *testing.T) { | ||
t.Log(Example0x1()) | ||
} | ||
|
||
func TestExample0x2(t *testing.T) { | ||
t.Log(Example0x2()) | ||
} | ||
|
||
func TestExample6x1(t *testing.T) { | ||
require.Equal(t, "100", Example6x1()) | ||
} | ||
|
||
func TestExample6x2(t *testing.T) { | ||
require.Equal(t, "200", Example6x2()) | ||
} |
10 changes: 5 additions & 5 deletions
10
.../example5surenode/example5mustsoftnode.go → ...xample5sure_custom/example5sure_custom.go
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
25 changes: 25 additions & 0 deletions
25
...al/examples/example_sure_cls_gen/example5/example5sure_custom/example5sure_custom_test.go
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,25 @@ | ||
package example5sure_custom | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
func TestNode_Must(t *testing.T) { | ||
run := func() (string, error) { | ||
return "OK", nil | ||
} | ||
res, err := run() | ||
NODE.Must(err) | ||
t.Log(res) | ||
} | ||
|
||
func TestNode_Soft(t *testing.T) { | ||
run := func() (string, error) { | ||
return "", errors.New("wrong") | ||
} | ||
res, err := run() | ||
NODE.Soft(err) | ||
t.Log(res) | ||
} |
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
Oops, something went wrong.