-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The "arguments" allow services to act as factories without intermediate code. Services that have "arguments" will be turned into a func and only compatible with the prototype scope. Containers must now be created with NewContainer() (instead of &Container{}). Fixes #5
- Loading branch information
1 parent
cfd803f
commit 711d751
Showing
18 changed files
with
1,144 additions
and
240 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,28 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"sort" | ||
) | ||
|
||
type Arguments map[string]Type | ||
|
||
// Names returns all of the argument names sorted. | ||
func (args Arguments) Names() (names []string) { | ||
for arg := range args { | ||
names = append(names, arg) | ||
} | ||
|
||
sort.Strings(names) | ||
|
||
return | ||
} | ||
|
||
func (args Arguments) GoArguments() (ss []string) { | ||
for _, argName := range args.Names() { | ||
ss = append(ss, fmt.Sprintf("%s %s", argName, | ||
args[argName].LocalEntityType())) | ||
} | ||
|
||
return | ||
} |
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,54 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/elliotchance/testify-stats/assert" | ||
"testing" | ||
) | ||
|
||
var argumentTests = map[string]struct { | ||
Arguments Arguments | ||
Names []string | ||
GoArguments []string | ||
}{ | ||
"Nil": { | ||
Arguments: nil, | ||
Names: nil, | ||
GoArguments: nil, | ||
}, | ||
"Empty": { | ||
Arguments: map[string]Type{}, | ||
Names: nil, | ||
GoArguments: nil, | ||
}, | ||
"One": { | ||
Arguments: map[string]Type{"foo": "int"}, | ||
Names: []string{"foo"}, | ||
GoArguments: []string{"foo int"}, | ||
}, | ||
"ArgumentsAlwaysSortedByName": { | ||
Arguments: map[string]Type{"foo": "int", "bar": "*float64"}, | ||
Names: []string{"bar", "foo"}, | ||
GoArguments: []string{"bar *float64", "foo int"}, | ||
}, | ||
"RemovePackageName": { | ||
Arguments: map[string]Type{"req": "*net/http.Request"}, | ||
Names: []string{"req"}, | ||
GoArguments: []string{"req *http.Request"}, | ||
}, | ||
} | ||
|
||
func TestArguments_Names(t *testing.T) { | ||
for testName, test := range argumentTests { | ||
t.Run(testName, func(t *testing.T) { | ||
assert.Equal(t, test.Names, test.Arguments.Names()) | ||
}) | ||
} | ||
} | ||
|
||
func TestArguments_GoArguments(t *testing.T) { | ||
for testName, test := range argumentTests { | ||
t.Run(testName, func(t *testing.T) { | ||
assert.Equal(t, test.GoArguments, test.Arguments.GoArguments()) | ||
}) | ||
} | ||
} |
Oops, something went wrong.