/framework/starter_test.go

http://github.com/sut-go/gon · Go · 51 lines · 42 code · 9 blank · 0 comment · 0 complexity · 04ee78d810e4fd1cf26eb93336b27413 MD5 · raw file

  1. package starter
  2. import "github.com/bmizerany/assert"
  3. import "testing"
  4. import . "framework/mv"
  5. import "reflect"
  6. func TestSplitControllerAndAction(t *testing.T) {
  7. v1, v2 := splitControllerAndAction("hello/index")
  8. assert.Equal(t, v1, "hello")
  9. assert.Equal(t, v2, "index")
  10. }
  11. func TestSplitControllerAndActionWithDefault(t *testing.T) {
  12. v1, v2 := splitControllerAndAction("hello")
  13. assert.Equal(t, v1, "hello")
  14. assert.Equal(t, v2, "index")
  15. }
  16. func TestSplitControllerSlashAndActionWithDefault(t *testing.T) {
  17. v1, v2 := splitControllerAndAction("hello/")
  18. assert.Equal(t, v1, "hello")
  19. assert.Equal(t, v2, "index")
  20. }
  21. func TestToUpperFirstLetter(t *testing.T) {
  22. assert.Equal(t, toUpperFirstLetter("index"), "Index")
  23. assert.Equal(t, toUpperFirstLetter("indexAndIndex"), "IndexAndIndex")
  24. assert.Equal(t, toUpperFirstLetter(""), "")
  25. assert.Equal(t, toUpperFirstLetter("a"), "A")
  26. assert.Equal(t, toUpperFirstLetter("A"), "A")
  27. }
  28. type HelloController struct {
  29. Params
  30. }
  31. func (h *HelloController) Index() Model {
  32. return Model{"key":"value"}
  33. }
  34. func TestFindMethodAndInvoke(test *testing.T) {
  35. t := reflect.ValueOf(HelloController{}).Type()
  36. _, ok1 := findMethod("NotExist", t)
  37. assert.Equal(test, ok1, false)
  38. f, ok2 := findMethod("Index", t)
  39. assert.Equal(test, ok2, true)
  40. ret := f.Call([]reflect.Value{reflect.ValueOf(new(HelloController))})
  41. assert.Equal(test, ret[0].Interface().(Model), Model{"key":"value"})
  42. }