예제 #1
0
파일: utils_test.go 프로젝트: axcoto/alpaca
func TestArgsFunctionMaker(t *testing.T) {
	terst.Terst(t)

	var nul interface{}

	f := ArgsFunctionMaker("$", ", ").(func(interface{}, ...bool) string)

	args := make([]interface{}, 2)
	params := make([]interface{}, 2)

	args[0] = "id"
	args[1] = "url"

	params[0] = make(map[string]interface{})
	params[1] = make(map[string]interface{})

	params[0].(map[string]interface{})["name"] = "id"
	params[0].(map[string]interface{})["required"] = true
	params[1].(map[string]interface{})["name"] = "url"

	terst.Is(f(args), "$id, $url, ")
	terst.Is(f(args, false), "$id, $url, ")
	terst.Is(f(args, true), "$id, $url")
	terst.Is(f(args, true, false), "$id, $url")
	terst.Is(f(args, true, true), ", $id, $url")
	terst.Is(f(args, false, true), ", $id, $url, ")

	terst.Is(f(params), "$id, ")
	terst.Is(f(params, true), "$id")
	terst.Is(f(params, false, true), ", $id, ")

	terst.Is(f(nul), "")
	terst.Is(f(nul, true), "")
	terst.Is(f(nul, false, true), "")
}
예제 #2
0
파일: utils_test.go 프로젝트: axcoto/alpaca
func TestArrayInterfaceToString(t *testing.T) {
	terst.Terst(t)

	var nul interface{}

	terst.Is(ArrayInterfaceToString(nul), []string{})
}
예제 #3
0
파일: utils_test.go 프로젝트: axcoto/alpaca
func TestPrntFunctionMaker(t *testing.T) {
	terst.Terst(t)

	var nul interface{}

	f := PrntFunctionMaker(true, "  ", "'", "'", "[", "]", "{", "}", ":", " => ").(func(interface{}, string, bool) string)

	args := make(map[string]interface{})
	vals := make(map[string]interface{})
	orgs := make([]interface{}, 3)
	hash := make(map[string]interface{})

	orgs[0] = false
	orgs[1] = "alpaca-api"
	orgs[2] = 00

	hash["html"] = "haml"
	hash["rest"] = false

	vals["msid"] = 3737
	vals["plan"] = 1.99
	vals["name"] = "pksunkara"
	vals["hire"] = true
	vals["orgs"] = orgs
	vals["hash"] = hash
	vals["dump"] = make(map[string]string)

	args["id"] = make(map[string]interface{})
	args["id"].(map[string]interface{})["value"] = vals

	terst.Is(f(args, ", ", true), "{\n  :msid => 3737,\n  :plan => 1.99,\n  :name => 'pksunkara',\n  :hire => True,\n  :orgs => [\n    False,\n    'alpaca-api',\n    0\n  ],\n  :hash => {\n    :html => 'haml',\n    :rest => False\n  },\n  :dump => \n}, ")
	terst.Is(f(args, ", ", false), "{\n  :msid => 3737,\n  :plan => 1.99,\n  :name => 'pksunkara',\n  :hire => True,\n  :orgs => [\n    False,\n    'alpaca-api',\n    0\n  ],\n  :hash => {\n    :html => 'haml',\n    :rest => False\n  },\n  :dump => \n}")
	terst.Is(f(nul, ", ", true), "")
}
예제 #4
0
func TestArgsFunctionMaker(t *testing.T) {
	terst.Terst(t)

	f := ArgsFunctionMaker("$", ", ").(func(interface{}, ...bool) string)

	args := []string{"id", "url"}
	params := make([]ApiParam, 2)

	nulArgs := []string{}
	nulParams := make([]ApiParam, 0)

	params[0] = ApiParam{"id", true, false}
	params[1] = ApiParam{"url", false, false}

	terst.Is(f(args), "$id, $url, ")
	terst.Is(f(args, false), "$id, $url, ")
	terst.Is(f(args, true), "$id, $url")
	terst.Is(f(args, true, false), "$id, $url")
	terst.Is(f(args, true, true), ", $id, $url")
	terst.Is(f(args, false, true), ", $id, $url, ")

	terst.Is(f(params), "$id, ")
	terst.Is(f(params, true), "$id")
	terst.Is(f(params, false, true), ", $id, ")

	terst.Is(f(nulArgs), "")
	terst.Is(f(nulArgs, true), "")
	terst.Is(f(nulArgs, false, true), "")

	terst.Is(f(nulParams), "")
	terst.Is(f(nulParams, true), "")
	terst.Is(f(nulParams, false, true), "")
}
예제 #5
0
파일: utils_test.go 프로젝트: Jacke/alpaca
func TestArrayInterfaceToString(t *testing.T) {
	terst.Terst(t)

	old := make([]interface{}, 2)

	old[0] = "hello"
	old[1] = "world"

	terst.Is(ArrayInterfaceToString(old), []string{"hello", "world"})
}
예제 #6
0
func TestPrntFunctionMaker(t *testing.T) {
	terst.Terst(t)

	f := PrntFunctionMaker(true, "  ", "'", "'", "[", "]", "{", "}", ":", " => ").(func(interface{}, map[string]DocParam, string, bool) string)

	apis := []string{"id"}
	apip := make([]ApiParam, 2)
	docs := make(map[string]DocParam)
	vals := make(map[string]interface{})
	orgs := make([]interface{}, 3)
	null := make(map[string]string)

	orgs[0] = false
	orgs[1] = "alpaca-api"
	orgs[2] = 00

	apip[0] = ApiParam{"id", true, false}
	apip[1] = ApiParam{"flag", false, false}

	docs["flag"] = DocParam{"", false}

	terst.Is(f([]string{}, make(map[string]DocParam), ", ", true), "")
	terst.Is(f([]ApiParam{}, make(map[string]DocParam), ", ", true), "")
	terst.Is(f([]int{}, make(map[string]DocParam), ", ", true), "")

	vals["key"] = 3737
	docs["id"] = DocParam{"", vals}
	terst.Is(f(apis, docs, ", ", true), "{\n  :key => 3737\n}, ")
	terst.Is(f(apip, docs, ", ", true), "{\n  :key => 3737\n}, ")

	vals["key"] = 1.99
	docs["id"] = DocParam{"", vals}
	terst.Is(f(apis, docs, ", ", false), "{\n  :key => 1.99\n}")
	terst.Is(f(apip, docs, ", ", false), "{\n  :key => 1.99\n}")

	vals["key"] = "pksunkara"
	docs["id"] = DocParam{"", vals}
	terst.Is(f(apis, docs, ", ", false), "{\n  :key => 'pksunkara'\n}")
	terst.Is(f(apip, docs, ", ", false), "{\n  :key => 'pksunkara'\n}")

	vals["key"] = true
	docs["id"] = DocParam{"", vals}
	terst.Is(f(apis, docs, ", ", false), "{\n  :key => True\n}")
	terst.Is(f(apip, docs, ", ", false), "{\n  :key => True\n}")

	vals["key"] = orgs
	docs["id"] = DocParam{"", vals}
	terst.Is(f(apis, docs, ", ", false), "{\n  :key => [\n    False,\n    'alpaca-api',\n    0\n  ]\n}")
	terst.Is(f(apip, docs, ", ", false), "{\n  :key => [\n    False,\n    'alpaca-api',\n    0\n  ]\n}")

	vals["key"] = null
	docs["id"] = DocParam{"", vals}
	terst.Is(f(apis, docs, ", ", false), "{\n  :key => \n}")
	terst.Is(f(apip, docs, ", ", false), "{\n  :key => \n}")
}
예제 #7
0
파일: utils_test.go 프로젝트: Jacke/alpaca
func TestPathFunctionMaker(t *testing.T) {
	terst.Terst(t)

	f := PathFunctionMaker("\"+@", "+\"").(func(string, interface{}) string)
	args := make([]interface{}, 2)

	args[0] = "id"
	args[1] = "url"

	terst.Is(f("/user/:id/:not/:url/wow", args), "/user/\"+@id+\"/:not/\"+@url+\"/wow")
}
예제 #8
0
파일: utils_test.go 프로젝트: Jacke/alpaca
func TestMapKeysToStringArray(t *testing.T) {
	terst.Terst(t)

	old := make(map[string]interface{})

	old["a"] = "aaa"
	old["b"] = "bbb"
	old["c"] = "ccc"

	terst.Is(MapKeysToStringArray(old, []string{"b"}), []string{"a", "c"})
}
예제 #9
0
func TestPathFunctionMaker(t *testing.T) {
	terst.Terst(t)

	f := PathFunctionMaker("\"+", "@", "+\"").(func(string, []string, []ApiParam) string)

	cargs := []string{"id", "url"}
	margs := make([]ApiParam, 1)

	margs[0] = ApiParam{"one", false, false}

	terst.Is(f("/user/:id/:not/:url/wow:one", cargs, margs), "/user/\"+@id+\"/:not/\"+@url+\"/wow\"+one+\"")
}
예제 #10
0
파일: utils_test.go 프로젝트: axcoto/alpaca
func TestActiveClassInfo(t *testing.T) {
	terst.Terst(t)

	old := make(map[string]interface{})

	old["args"] = []string{"id", "url"}
	old["create"] = make(map[string]interface{})
	old["update"] = make(map[string]interface{})

	v := ActiveClassInfo("test", old)

	terst.Is(v["name"], "test")
	terst.Is(v["args"].([]string), []string{"id", "url"})
	terst.Is(v["methods"].([]string), []string{"create", "update"})
}
예제 #11
0
파일: utils_test.go 프로젝트: axcoto/alpaca
func TestPathFunctionMaker(t *testing.T) {
	terst.Terst(t)

	f := PathFunctionMaker("\"+", "@", "+\"").(func(string, interface{}, interface{}) string)

	cargs := make([]interface{}, 2)
	margs := make([]interface{}, 1)

	cargs[0] = "id"
	cargs[1] = "url"

	margs[0] = make(map[string]interface{})
	margs[0].(map[string]interface{})["name"] = "one"

	terst.Is(f("/user/:id/:not/:url/wow:one", cargs, margs), "/user/\"+@id+\"/:not/\"+@url+\"/wow\"+one+\"")
}
예제 #12
0
파일: utils_test.go 프로젝트: Jacke/alpaca
func TestArgsFunctionMaker(t *testing.T) {
	terst.Terst(t)

	f := ArgsFunctionMaker("$", ", ").(func(interface{}, ...bool) string)
	args, noargs := make([]interface{}, 2), make([]interface{}, 0)

	args[0] = "id"
	args[1] = "url"

	terst.Is(f(args), "$id, $url, ")
	terst.Is(f(args, false), "$id, $url, ")
	terst.Is(f(args, true), "$id, $url")
	terst.Is(f(args, true, false), "$id, $url")
	terst.Is(f(args, true, true), ", $id, $url")
	terst.Is(f(args, false, true), ", $id, $url, ")

	terst.Is(f(noargs), "")
	terst.Is(f(noargs, true), "")
	terst.Is(f(noargs, false, true), "")
}