Skip to content

Commit

Permalink
[ToyC] ssrl#11 Added test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
noppanit committed Jul 6, 2011
1 parent 026309e commit f732eeb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
35 changes: 27 additions & 8 deletions framework/starter.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package starter

import "fmt"
import "web"
import "reflect"
import "mustache"
Expand Down Expand Up @@ -50,20 +49,42 @@ func internalGet(context gon.WebContext, val string) {
return
}

func getViewAndControllerFromURL(value string) (string, string) {
func getViewAndControllerFromURL(url string) (string, string) {
pointerOfMappings := reflect.ValueOf(mapping.URL)
valueOfMappings := reflect.Indirect(pointerOfMappings)
fmt.Println("Test",valueOfMappings.String())
// numField := valueOfMappings.NumField()
// fmt.Println(numField)
return "", ""
numField := valueOfMappings.NumField()
var realMappings map[string]string
for i := 0; i < numField; i++ {
maps := valueOfMappings.Field(i).Interface()
realMaps := maps.(map[string]string)
if realMaps["url"] == url {
realMappings = realMaps
} else {
realMappings = nil
}
}
controllerName := ""
viewName := ""

if realMappings != nil {
controllerName = realMappings["controller"]
viewName = realMappings["view"]
}
return controllerName, viewName
}

func splitControllerAndAction(value string) (string,string) {

controllerAndActionName := strings.Split(value,"/",2)
controllerName := ""
actionName := ""

controllerName, actionName = getViewAndControllerFromURL("/"+value)
if controllerName != "" && actionName != ""{
return controllerName, actionName
}


if len(controllerAndActionName) == 2 {
controllerName,actionName = controllerAndActionName[0],controllerAndActionName[1]
if actionName == "" {
Expand All @@ -74,8 +95,6 @@ func splitControllerAndAction(value string) (string,string) {
actionName = "index"
}



return controllerName, actionName
}

Expand Down
2 changes: 1 addition & 1 deletion framework/starter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestFindMethodAndInvoke(test *testing.T) {
}

func TestGetViewAndControllerFromURL(test *testing.T){
controllerName, viewName := getViewAndControllerFromURL("test");
controllerName, viewName := getViewAndControllerFromURL("/test");
assert.Equal(test, controllerName, "hello")
assert.Equal(test, viewName, "index")
}

0 comments on commit f732eeb

Please sign in to comment.