Skip to content

Commit

Permalink
test: add tests for boolean settings, pattern errors and invalid map
Browse files Browse the repository at this point in the history
  • Loading branch information
jmattheis committed Oct 22, 2023
1 parent ba843a6 commit 3e2054b
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 0 deletions.
18 changes: 18 additions & 0 deletions scenario/bool_setting_invalid_value.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
input:
input.go: |
package structs
// goverter:converter
// goverter:useZeroValueOnPointerInconsistency abc
type Converter interface {
Convert(Input) Output
}
type Input struct { Name string }
type Output struct { Name string }
error: |-
error parsing 'goverter:useZeroValueOnPointerInconsistency' at
/ABSOLUTE/execution/input.go:5:1
github.com/jmattheis/goverter/execution.Converter
invalid boolean value: 'abc' must be one of 'yes', 'no'
18 changes: 18 additions & 0 deletions scenario/bool_setting_too_many_values.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
input:
input.go: |
package structs
// goverter:converter
// goverter:useZeroValueOnPointerInconsistency 1 2
type Converter interface {
Convert(Input) Output
}
type Input struct { Name string }
type Output struct { Name string }
error: |-
error parsing 'goverter:useZeroValueOnPointerInconsistency' at
/ABSOLUTE/execution/input.go:5:1
github.com/jmattheis/goverter/execution.Converter
expected at most one value but got 2: []string{"1", "2"}
23 changes: 23 additions & 0 deletions scenario/map_invalid.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
input:
input.go: |
package structs
// goverter:converter
type Converter interface {
// goverter:map | Malformed
ConvertPerson(source Person) APIPerson
}
type Person struct {
Name string
}
type APIPerson struct {
Name string
}
error: |-
error parsing 'goverter:map' at
/ABSOLUTE/execution/input.go:6:5
func (github.com/jmattheis/goverter/execution.Converter).ConvertPerson(source github.com/jmattheis/goverter/execution.Person) github.com/jmattheis/goverter/execution.APIPerson
missing target field
19 changes: 19 additions & 0 deletions scenario/pattern_error.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
input:
pkg1/input.go: |
package pkg1
// goverter:converter
// goverter:output @cwd/generated/output.go
type Converter interface {
Convert(source Input) Output
}
type Input struct {
ID int
}
type Output struct {
ID int
}
patterns:
- hello=test
error: invalid query type "hello" in query pattern "hello=test"
94 changes: 94 additions & 0 deletions scenario/skipcopy_identity_setting_inheritance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
input:
input.go: |
package skip
// goverter:converter
type UsesGlobal interface {
Enabled(*string) *string
}
// goverter:converter
// goverter:skipCopySameType yes
type KeepsGlobalValue interface {
Enabled(*string) *string
}
// goverter:converter
// goverter:skipCopySameType no
type DisablesGlobal interface {
Disabled(*int) *int
}
// goverter:converter
// goverter:skipCopySameType no
type EnableInSubMethod interface {
Disable(*string) *string
// goverter:skipCopySameType
Enabled(*int) *int
}
// goverter:converter
type DisableInSubMethod interface {
Enabled(*string) *string
// goverter:skipCopySameType no
Disable(*int) *int
}
global:
- skipCopySameType yes
success:
- generated/generated.go: |
// Code generated by github.com/jmattheis/goverter, DO NOT EDIT.
package generated
type DisableInSubMethodImpl struct{}
func (c *DisableInSubMethodImpl) Disable(source *int) *int {
var pInt *int
if source != nil {
xint := *source
pInt = &xint
}
return pInt
}
func (c *DisableInSubMethodImpl) Enabled(source *string) *string {
return source
}
type DisablesGlobalImpl struct{}
func (c *DisablesGlobalImpl) Disabled(source *int) *int {
var pInt *int
if source != nil {
xint := *source
pInt = &xint
}
return pInt
}
type EnableInSubMethodImpl struct{}
func (c *EnableInSubMethodImpl) Disable(source *string) *string {
var pString *string
if source != nil {
xstring := *source
pString = &xstring
}
return pString
}
func (c *EnableInSubMethodImpl) Enabled(source *int) *int {
return source
}
type KeepsGlobalValueImpl struct{}
func (c *KeepsGlobalValueImpl) Enabled(source *string) *string {
return source
}
type UsesGlobalImpl struct{}
func (c *UsesGlobalImpl) Enabled(source *string) *string {
return source
}

0 comments on commit 3e2054b

Please sign in to comment.