-
Notifications
You must be signed in to change notification settings - Fork 2
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
8 changed files
with
549 additions
and
282 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,80 @@ | ||
package cmd | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/kelveny/mockcompose/pkg/gosyntax" | ||
"github.com/stretchr/testify/mock" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_generatorContext_findClassMethods_caching(t *testing.T) { | ||
assert := require.New(t) | ||
|
||
g := &gctx_findClassMethods{} | ||
|
||
g.mock_gctx_findClassMethods_findClassMethods_gosyntax.On( | ||
"FindClassMethods", | ||
mock.Anything, | ||
mock.Anything, | ||
mock.Anything, | ||
).Return( | ||
map[string]*gosyntax.ReceiverSpec{ | ||
"Foo": { | ||
Name: "f", | ||
TypeDecl: "*foo", | ||
}, | ||
}, | ||
) | ||
|
||
// call it once | ||
methods := g.findClassMethods("*foo", nil, nil) | ||
assert.EqualValues( | ||
map[string]*gosyntax.ReceiverSpec{ | ||
"Foo": { | ||
Name: "f", | ||
TypeDecl: "*foo", | ||
}, | ||
}, | ||
methods, | ||
) | ||
|
||
// call it the second time | ||
methods = g.findClassMethods("*foo", nil, nil) | ||
assert.EqualValues( | ||
map[string]*gosyntax.ReceiverSpec{ | ||
"Foo": { | ||
Name: "f", | ||
TypeDecl: "*foo", | ||
}, | ||
}, | ||
methods, | ||
) | ||
|
||
// assert on caching behave | ||
g.mock_gctx_findClassMethods_findClassMethods_gosyntax.AssertNumberOfCalls(t, "FindClassMethods", 1) | ||
} | ||
|
||
func Test_generatorContext_findClassMethods_nil_return(t *testing.T) { | ||
assert := require.New(t) | ||
|
||
g := &gctx_findClassMethods{} | ||
|
||
g.mock_gctx_findClassMethods_findClassMethods_gosyntax.On( | ||
"FindClassMethods", | ||
mock.Anything, | ||
mock.Anything, | ||
mock.Anything, | ||
).Return(nil) | ||
|
||
// call it once | ||
methods := g.findClassMethods("*foo", nil, nil) | ||
assert.Nil(methods) | ||
|
||
// call it the second time | ||
methods = g.findClassMethods("*foo", nil, nil) | ||
assert.Nil(methods) | ||
|
||
// assert on caching behave | ||
g.mock_gctx_findClassMethods_findClassMethods_gosyntax.AssertNumberOfCalls(t, "FindClassMethods", 1) | ||
} |
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,52 @@ | ||
// CODE GENERATED AUTOMATICALLY WITH github.com/kelveny/mockcompose | ||
// THIS FILE SHOULD NOT BE EDITED BY HAND | ||
package cmd | ||
|
||
import ( | ||
"go/ast" | ||
"go/token" | ||
|
||
"github.com/kelveny/mockcompose/pkg/gosyntax" | ||
gosyntaxtyp "github.com/kelveny/mockcompose/pkg/gosyntax" | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
type gctx_findClassMethods struct { | ||
generatorContext | ||
mock.Mock | ||
mock_gctx_findClassMethods_findClassMethods_gosyntax | ||
} | ||
|
||
type mock_gctx_findClassMethods_findClassMethods_gosyntax struct { | ||
mock.Mock | ||
} | ||
|
||
func (c *gctx_findClassMethods) findClassMethods(clzTypeDeclString string, fset *token.FileSet, f *ast.File) map[string]*gosyntaxtyp.ReceiverSpec { | ||
gosyntax := &c.mock_gctx_findClassMethods_findClassMethods_gosyntax | ||
|
||
if c.clzMethods == nil { | ||
c.clzMethods = make(map[string]map[string]*gosyntaxtyp.ReceiverSpec) | ||
} | ||
if _, ok := c.clzMethods[clzTypeDeclString]; !ok { | ||
c.clzMethods[clzTypeDeclString] = gosyntax.FindClassMethods(clzTypeDeclString, fset, f) | ||
} | ||
return c.clzMethods[clzTypeDeclString] | ||
} | ||
|
||
func (m *mock_gctx_findClassMethods_findClassMethods_gosyntax) FindClassMethods(clzTypeDeclString string, fset *token.FileSet, f *ast.File) map[string]*gosyntax.ReceiverSpec { | ||
|
||
_mc_ret := m.Called(clzTypeDeclString, fset, f) | ||
|
||
var _r0 map[string]*gosyntax.ReceiverSpec | ||
|
||
if _rfn, ok := _mc_ret.Get(0).(func(string, *token.FileSet, *ast.File) map[string]*gosyntax.ReceiverSpec); ok { | ||
_r0 = _rfn(clzTypeDeclString, fset, f) | ||
} else { | ||
if _mc_ret.Get(0) != nil { | ||
_r0 = _mc_ret.Get(0).(map[string]*gosyntax.ReceiverSpec) | ||
} | ||
} | ||
|
||
return _r0 | ||
|
||
} |
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,39 @@ | ||
package mix | ||
|
||
type mixReceiver struct { | ||
value string | ||
} | ||
|
||
func (v mixReceiver) getValue() string { | ||
return v.value | ||
} | ||
|
||
func (p *mixReceiver) setValue(val string) { | ||
p.value = val | ||
} | ||
|
||
// only callees with the same receiver type (either by-value or by-reference type) | ||
// will be considered as peer callee method | ||
// | ||
// in checkAndSet method, since receiver type of checkAndSet is by-reference, | ||
// only by-reference setValue will be considered as its peer callee method automatically. | ||
// | ||
// in checkAndSetOnTarget, since receiver type of checkAndSetOnTarget is by-value | ||
// only by-value getValue will be considered as its peer callee method automatically. | ||
|
||
//go:generate mockcompose -n mix_checkAndSet -c mixReceiver -real checkAndSet,this | ||
func (p *mixReceiver) checkAndSet(s string, val string) { | ||
if p.getValue() != s { | ||
p.setValue(val) | ||
} | ||
} | ||
|
||
//go:generate mockcompose -n mix_checkAndSetOnTarget -c mixReceiver -real checkAndSetOnTarget,this | ||
func (v mixReceiver) checkAndSetOnTarget(p *mixReceiver, s string, val string) { | ||
if v.getValue() != s { | ||
|
||
// use it for code generation validation, has no effect on v | ||
v.setValue(val) | ||
p.setValue(val) | ||
} | ||
} |
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,37 @@ | ||
// CODE GENERATED AUTOMATICALLY WITH github.com/kelveny/mockcompose | ||
// THIS FILE SHOULD NOT BE EDITED BY HAND | ||
package mix | ||
|
||
import ( | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
type mix_checkAndSetOnTarget struct { | ||
mixReceiver | ||
mock.Mock | ||
} | ||
|
||
func (v mix_checkAndSetOnTarget) checkAndSetOnTarget(p *mixReceiver, s string, val string) { | ||
if v.getValue() != s { | ||
v.setValue(val) | ||
p.setValue(val) | ||
} | ||
} | ||
|
||
func (m *mix_checkAndSetOnTarget) getValue() string { | ||
|
||
_mc_ret := m.Called() | ||
|
||
var _r0 string | ||
|
||
if _rfn, ok := _mc_ret.Get(0).(func() string); ok { | ||
_r0 = _rfn() | ||
} else { | ||
if _mc_ret.Get(0) != nil { | ||
_r0 = _mc_ret.Get(0).(string) | ||
} | ||
} | ||
|
||
return _r0 | ||
|
||
} |
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,24 @@ | ||
// CODE GENERATED AUTOMATICALLY WITH github.com/kelveny/mockcompose | ||
// THIS FILE SHOULD NOT BE EDITED BY HAND | ||
package mix | ||
|
||
import ( | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
type mix_checkAndSet struct { | ||
mixReceiver | ||
mock.Mock | ||
} | ||
|
||
func (p *mix_checkAndSet) checkAndSet(s string, val string) { | ||
if p.getValue() != s { | ||
p.setValue(val) | ||
} | ||
} | ||
|
||
func (m *mix_checkAndSet) setValue(val string) { | ||
|
||
m.Called(val) | ||
|
||
} |