Permalink
Browse files

Git accident.. revert last commit

  • Loading branch information...
1 parent cba1a40 commit 015ff447cb41a6aa6d2e76fbb1a4fdef452275ba @robfig committed Jan 13, 2013
Showing with 31 additions and 10 deletions.
  1. +6 −1 controller.go
  2. +3 −0 harness/reflect.go
  3. +22 −9 harness/reflect_test.go
View
@@ -91,7 +91,12 @@ func (c *Controller) Invoke(appControllerPtr reflect.Value, method reflect.Value
if c.Result == nil {
// Invoke the action.
- resultValue := method.Call(methodArgs)[0]
+ var resultValue reflect.Value
+ if method.Type().IsVariadic() {
+ resultValue = method.CallSlice(methodArgs)[0]
+ } else {
+ resultValue = method.Call(methodArgs)[0]
+ }
if resultValue.Kind() == reflect.Interface && !resultValue.IsNil() {
c.Result = resultValue.Interface().(Result)
}
View
@@ -672,6 +672,9 @@ func NewTypeExpr(pkgName string, expr ast.Expr) TypeExpr {
case *ast.ArrayType:
e := NewTypeExpr(pkgName, t.Elt)
return TypeExpr{"[]" + e.Expr, e.PkgName, e.pkgIndex + 2}
+ case *ast.Ellipsis:
+ e := NewTypeExpr(pkgName, t.Elt)
+ return TypeExpr{"[]" + e.Expr, e.PkgName, e.pkgIndex + 2}
default:
log.Println("Failed to generate name for field.")
ast.Print(nil, expr)
@@ -86,23 +86,33 @@ func TestGetValidationKeys(t *testing.T) {
}
var TypeExprs = map[string]TypeExpr{
- "int": TypeExpr{"int", "", 0},
- "*int": TypeExpr{"*int", "", 1},
- "[]int": TypeExpr{"[]int", "", 2},
- "[]*int": TypeExpr{"[]*int", "", 3},
- "MyType": TypeExpr{"MyType", "pkg", 0},
- "*MyType": TypeExpr{"*MyType", "pkg", 1},
- "[]MyType": TypeExpr{"[]MyType", "pkg", 2},
- "[]*MyType": TypeExpr{"[]*MyType", "pkg", 3},
+ "int": TypeExpr{"int", "", 0},
+ "*int": TypeExpr{"*int", "", 1},
+ "[]int": TypeExpr{"[]int", "", 2},
+ "...int": TypeExpr{"[]int", "", 2},
+ "[]*int": TypeExpr{"[]*int", "", 3},
+ "...*int": TypeExpr{"[]*int", "", 3},
+ "MyType": TypeExpr{"MyType", "pkg", 0},
+ "*MyType": TypeExpr{"*MyType", "pkg", 1},
+ "[]MyType": TypeExpr{"[]MyType", "pkg", 2},
+ "...MyType": TypeExpr{"[]MyType", "pkg", 2},
+ "[]*MyType": TypeExpr{"[]*MyType", "pkg", 3},
+ "...*MyType": TypeExpr{"[]*MyType", "pkg", 3},
}
func TestTypeExpr(t *testing.T) {
for typeStr, expected := range TypeExprs {
- // Handle arrays myself, since ParseExpr() does not.
+ // Handle arrays and ... myself, since ParseExpr() does not.
array := strings.HasPrefix(typeStr, "[]")
if array {
typeStr = typeStr[2:]
}
+
+ ellipsis := strings.HasPrefix(typeStr, "...")
+ if ellipsis {
+ typeStr = typeStr[3:]
+ }
+
expr, err := parser.ParseExpr(typeStr)
if err != nil {
t.Error("Failed to parse test expr:", typeStr)
@@ -112,6 +122,9 @@ func TestTypeExpr(t *testing.T) {
if array {
expr = &ast.ArrayType{expr.Pos(), nil, expr}
}
+ if ellipsis {
+ expr = &ast.Ellipsis{expr.Pos(), expr}
+ }
actual := NewTypeExpr("pkg", expr)
if !reflect.DeepEqual(expected, actual) {

0 comments on commit 015ff44

Please sign in to comment.