forked from switchupcb/copygen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix non-alphabetical function-option mismatch
fixes switchupcb#29; non-alphabetical output
- Loading branch information
switchupcb
committed
Jun 22, 2022
1 parent
c7d0408
commit e50ba33
Showing
8 changed files
with
157 additions
and
46 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
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
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,26 @@ | ||
// Package copygen contains the setup information for copygen generated code. | ||
package copygen | ||
|
||
import ( | ||
"github.com/switchupcb/copygen/examples/map/domain" | ||
"github.com/switchupcb/copygen/examples/map/models" | ||
) | ||
|
||
// Copygen defines the functions that will be generated. | ||
type Copygen interface { | ||
A(*models.Account) | ||
B(*models.User) | ||
// custom comment | ||
C(*domain.Account) | ||
// type basic | ||
D(int) | ||
// type basic | ||
E(string) | ||
// type basic | ||
G(float64) | ||
// type alias | ||
F(byte) | ||
H(rune) | ||
// | ||
Z() | ||
} |
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,11 @@ | ||
# Define where the code will be generated. | ||
generated: | ||
setup: ./setup.go | ||
output: ../copygen.go | ||
|
||
# Define the optional custom templates used to generate the file (.go, .tmpl supported). | ||
template: ../template/generate.go | ||
|
||
# Define custom options (which are passed to generator options) for customization. | ||
custom: | ||
option: The possibilities are endless. |
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,89 @@ | ||
package tests | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/switchupcb/copygen/cli" | ||
"github.com/switchupcb/copygen/cli/config" | ||
"github.com/switchupcb/copygen/cli/parser" | ||
) | ||
|
||
// TestGeneratorOptions tests whether the Generator Options are parsed from the setup file correctly. | ||
func TestGeneratorOptions(t *testing.T) { | ||
checkwd(t) | ||
|
||
env := cli.Environment{ | ||
YMLPath: "_tests/option/setup/setup.yml", | ||
Output: false, | ||
Write: false, | ||
} | ||
|
||
gen, err := config.LoadYML(env.YMLPath) | ||
if err != nil { | ||
t.Fatalf("Options(%q) error: %v", "Generator", err) | ||
} | ||
|
||
want := "The possibilities are endless." | ||
if v, ok := gen.Options.Custom["option"]; ok { | ||
if vs, ok := v.(string); ok { | ||
if vs != want { | ||
t.Fatalf("Options(%q) got %q, want %q", "Generator", vs, want) | ||
} | ||
|
||
return | ||
} | ||
|
||
t.Fatalf("Options(%q) does not contain a custom option with a string value.", "Generator") | ||
} | ||
|
||
t.Fatalf("Options(%q) does not contain a custom option.", "Generator") | ||
} | ||
|
||
// TestCustomFunctionOptions tests whether custom Function Options are parsed from the setup file correctly. | ||
func TestCustomFunctionOptions(t *testing.T) { | ||
checkwd(t) | ||
|
||
env := cli.Environment{ | ||
YMLPath: "_tests/option/setup/setup.yml", | ||
Output: false, | ||
Write: false, | ||
} | ||
|
||
gen, err := config.LoadYML(env.YMLPath) | ||
if err != nil { | ||
t.Fatalf("Options(%q) error: %v", "Function", err) | ||
} | ||
|
||
if err = parser.Parse(gen); err != nil { | ||
t.Fatalf("Options(%q) error: %v", "Function", err) | ||
} | ||
|
||
wanted := []map[string][]string{ | ||
make(map[string][]string), // A | ||
make(map[string][]string), // B | ||
{ // C | ||
"custom": []string{"comment"}, | ||
}, | ||
{ // D | ||
"type": []string{"basic"}, | ||
}, | ||
{ // E | ||
"type": []string{"basic"}, | ||
}, | ||
{ // G | ||
"type": []string{"basic"}, | ||
}, | ||
{ // F | ||
"type": []string{"alias"}, | ||
}, | ||
make(map[string][]string), // H | ||
make(map[string][]string), // Z | ||
} | ||
|
||
for i, function := range gen.Functions { | ||
if !reflect.DeepEqual(function.Options.Custom, wanted[i]) { | ||
t.Fatalf("Options(%q) got %q, want %q", "Function", function.Options.Custom, wanted[i]) | ||
} | ||
} | ||
} |