PageRenderTime 10ms CodeModel.GetById 2ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

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