Skip to content

Commit

Permalink
Initial internal use of generics (#7)
Browse files Browse the repository at this point in the history
* Initial internal use of generics

* Lock version of govulncheck to fix Go 1.18 issue

* Update Go to 1.19

* Appease linters
  • Loading branch information
myshkin5 authored Jul 31, 2024
1 parent 79eabd1 commit 1ac4ccb
Show file tree
Hide file tree
Showing 9 changed files with 1,364 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ orbs:
executors:
go:
docker:
- image: cimg/go:1.18
- image: cimg/go:1.19

jobs:
build:
Expand All @@ -28,7 +28,7 @@ jobs:
PACKAGE_NAMES=$(go list ./... | circleci tests split --split-by=timings --timings-type=classname)
gotestsum --junitfile ${TEST_RESULTS}/gotestsum-report.xml -- \
-race -covermode=atomic -coverprofile=coverage.out $PACKAGE_NAMES
go install golang.org/x/vuln/cmd/govulncheck@latest
go install golang.org/x/vuln/cmd/govulncheck@v1.0.4
govulncheck ./...
- codecov/upload
Expand Down
19 changes: 13 additions & 6 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,23 @@ linters-settings:
- standard
- default
- prefix(moqueries.org/runtime)
depguard:
rules:
main:
list-mode: strict
allow:
- $gostd
- moqueries.org/deephash
- moqueries.org/runtime
revive:
rules:
- name: var-naming
arguments:
- ["ID"]
disabled: true
stylecheck:
checks:
- "all"
- "-ST1000"
- "-ST1003"
initialisms:
- "-ID"

Expand All @@ -58,10 +69,6 @@ issues:
- gocritic
- goerr113
- nestif
# No easy way to break up go:generate lines
- linters:
- lll
source: "^//go:generate "
- path: 'testpkg'
linters:
- deadcode
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module moqueries.org/runtime

go 1.15
go 1.19

require moqueries.org/deephash v0.26.0

require golang.org/x/text v0.16.0
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
moqueries.org/deephash v0.26.0 h1:KvMnNvb/N9lId0OOO1X6Yp2BifVuDuJJQH3epAeF178=
moqueries.org/deephash v0.26.0/go.mod h1:brwHe2Ks78ZEA1xIgUTEy0gtZfO7tJTqXT9haTdIRNE=
249 changes: 249 additions & 0 deletions impl/internal/fnprototype_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
package internal_test

import (
"fmt"

"moqueries.org/runtime/hash"
"moqueries.org/runtime/impl"
"moqueries.org/runtime/moq"
)

type UsualFn func(sParam string, bParam bool) (sResult string, err error)

// MoqUsualFn holds the state of a moq of the UsualFn type
type MoqUsualFn struct {
Moq *impl.Moq[
*MoqUsualFn_adaptor,
MoqUsualFn_params,
MoqUsualFn_paramsKey,
MoqUsualFn_results,
]

Runtime MoqUsualFn_runtime
}

// MoqUsualFn_runtime holds runtime configuration for the UsualFn type
type MoqUsualFn_runtime struct {
ParameterIndexing MoqUsualFn_paramIndexing
}

// MoqUsualFn_adaptor adapts MoqUsualFn a needed by the runtime
type MoqUsualFn_adaptor struct {
Moq *MoqUsualFn
}

// MoqUsualFn_params holds the params of the UsualFn type
type MoqUsualFn_params struct {
SParam string
BParam bool
}

// MoqUsualFn_paramsKey holds the map key params of the UsualFn type
type MoqUsualFn_paramsKey struct {
Params struct {
SParam string
BParam bool
}
Hashes struct {
SParam hash.Hash
BParam hash.Hash
}
}

// MoqUsualFn_results holds the results of the UsualFn type
type MoqUsualFn_results struct {
SResult string
Err error
}

// MoqUsualFn_paramIndexing hold the parameter indexing runtime configuration
// for the UsualFn type
type MoqUsualFn_paramIndexing struct {
SParam moq.ParamIndexing
BParam moq.ParamIndexing
}

// MoqUsualFn_doFn defines the type of function needed when calling AndDo for
// the UsualFn type
type MoqUsualFn_doFn func(sParam string, bParam bool)

// MoqUsualFn_doReturnFn defines the type of function needed when calling
// DoReturnResults for the UsualFn type
type MoqUsualFn_doReturnFn func(sParam string, bParam bool) (sResult string, err error)

// MoqUsualFn_recorder routes recorded function calls to the MoqUsualFn moq
type MoqUsualFn_recorder struct {
Recorder *impl.Recorder[
*MoqUsualFn_adaptor,
MoqUsualFn_params,
MoqUsualFn_paramsKey,
MoqUsualFn_results,
]
}

// MoqUsualFn_anyParams isolates the any params functions of the UsualFn type
type MoqUsualFn_anyParams struct {
Recorder *MoqUsualFn_recorder
}

// NewMoqUsualFn creates a new moq of the UsualFn type
func NewMoqUsualFn(scene *moq.Scene, config *moq.Config) *MoqUsualFn {
adaptor0 := &MoqUsualFn_adaptor{}
m := &MoqUsualFn{
Moq: impl.NewMoq[
*MoqUsualFn_adaptor,
MoqUsualFn_params,
MoqUsualFn_paramsKey,
MoqUsualFn_results,
](scene, adaptor0, config),

Runtime: MoqUsualFn_runtime{ParameterIndexing: MoqUsualFn_paramIndexing{
SParam: moq.ParamIndexByValue,
BParam: moq.ParamIndexByValue,
}},
}
adaptor0.Moq = m

scene.AddMoq(m)
return m
}

// Mock returns the moq implementation of the UsualFn type
func (m *MoqUsualFn) Mock() UsualFn {
return func(sParam string, bParam bool) (string, error) {
m.Moq.Scene.T.Helper()
params := MoqUsualFn_params{
SParam: sParam,
BParam: bParam,
}

var result0 string
var result1 error
if result := m.Moq.Function(params); result != nil {
result0 = result.SResult
result1 = result.Err
}
return result0, result1
}
}

func (m *MoqUsualFn) OnCall(sParam string, bParam bool) *MoqUsualFn_recorder {
return &MoqUsualFn_recorder{
Recorder: m.Moq.OnCall(MoqUsualFn_params{
SParam: sParam,
BParam: bParam,
}),
}
}

func (r *MoqUsualFn_recorder) Any() *MoqUsualFn_anyParams {
r.Recorder.Moq.Scene.T.Helper()
if !r.Recorder.IsAnyPermitted(true) {
return nil
}
return &MoqUsualFn_anyParams{Recorder: r}
}

func (a *MoqUsualFn_anyParams) SParam() *MoqUsualFn_recorder {
a.Recorder.Recorder.AnyParam(0)
return a.Recorder
}

func (a *MoqUsualFn_anyParams) BParam() *MoqUsualFn_recorder {
a.Recorder.Recorder.AnyParam(1)
return a.Recorder
}

func (r *MoqUsualFn_recorder) Seq() *MoqUsualFn_recorder {
r.Recorder.Moq.Scene.T.Helper()
if !r.Recorder.Seq(true, "Seq", true) {
return nil
}
return r
}

func (r *MoqUsualFn_recorder) NoSeq() *MoqUsualFn_recorder {
r.Recorder.Moq.Scene.T.Helper()
if !r.Recorder.Seq(false, "NoSeq", true) {
return nil
}
return r
}

func (r *MoqUsualFn_recorder) ReturnResults(sResult string, err error) *MoqUsualFn_recorder {
r.Recorder.Moq.Scene.T.Helper()
r.Recorder.ReturnResults(MoqUsualFn_results{
SResult: sResult,
Err: err,
})
return r
}

func (r *MoqUsualFn_recorder) AndDo(fn MoqUsualFn_doFn) *MoqUsualFn_recorder {
r.Recorder.Moq.Scene.T.Helper()
if !r.Recorder.AndDo(func(params MoqUsualFn_params) {
fn(params.SParam, params.BParam)
}, true) {
return nil
}
return r
}

func (r *MoqUsualFn_recorder) DoReturnResults(fn MoqUsualFn_doReturnFn) *MoqUsualFn_recorder {
r.Recorder.Moq.Scene.T.Helper()
r.Recorder.DoReturnResults(func(params MoqUsualFn_params) *MoqUsualFn_results {
sResult, err := fn(params.SParam, params.BParam)
return &MoqUsualFn_results{
SResult: sResult,
Err: err,
}
})
return r
}

func (r *MoqUsualFn_recorder) Repeat(repeaters ...moq.Repeater) *MoqUsualFn_recorder {
r.Recorder.Moq.Scene.T.Helper()
if !r.Recorder.Repeat(repeaters, true) {
return nil
}
return r
}

func (*MoqUsualFn_adaptor) PrettyParams(params MoqUsualFn_params) string {
return fmt.Sprintf("UsualFn(%#v, %#v)", params.SParam, params.BParam)
}

func (a *MoqUsualFn_adaptor) ParamsKey(params MoqUsualFn_params, anyParams uint64) MoqUsualFn_paramsKey {
a.Moq.Moq.Scene.T.Helper()
sParamUsed, sParamUsedHash := impl.ParamKey(
params.SParam, 0, a.Moq.Runtime.ParameterIndexing.SParam, anyParams)
bParamUsed, bParamUsedHash := impl.ParamKey(
params.BParam, 1, a.Moq.Runtime.ParameterIndexing.BParam, anyParams)
return MoqUsualFn_paramsKey{
Params: struct {
SParam string
BParam bool
}{
SParam: sParamUsed,
BParam: bParamUsed,
},
Hashes: struct {
SParam hash.Hash
BParam hash.Hash
}{
SParam: sParamUsedHash,
BParam: bParamUsedHash,
},
}
}

// Reset resets the state of the moq
func (m *MoqUsualFn) Reset() {
m.Moq.Reset()
}

// AssertExpectationsMet asserts that all expectations have been met
func (m *MoqUsualFn) AssertExpectationsMet() {
m.Moq.Scene.T.Helper()
m.Moq.AssertExpectationsMet()
}
Loading

0 comments on commit 1ac4ccb

Please sign in to comment.