예제 #1
0
파일: input_test.go 프로젝트: caixw/apidoc
func testParse(a *assert.Assertion, lang string) {
	o := &Options{
		Lang:      lang,
		Dir:       "./testdata/" + lang,
		Recursive: true,
	}
	a.NotError(o.Init()) // 初始化扩展名信息

	docs := doc.New()
	err := Parse(docs, o)
	a.NotError(err).
		Equal(len(docs.Apis), 2)

		// doc.xx
	a.Equal(docs.Title, "title of api").
		Equal(docs.Version, "2.9").
		Equal(docs.BaseURL, "https://api.caixw.io").
		Equal(docs.LicenseName, "MIT").
		Equal(docs.LicenseURL, "https://opensources.org/licenses/MIT").
		Equal(docs.Content, "\n line1\n line2\n")

	// test1.xx
	api0 := docs.Apis[0]
	api1 := docs.Apis[1]
	a.Equal(api0.URL, "/users/login").
		Equal(api1.URL, "/users/login").
		Equal(api0.Group, "users").
		Equal(api1.Group, "users")
}
예제 #2
0
파일: input_test.go 프로젝트: caixw/apidoc
func testParseFile(a *assert.Assertion, lang, path string) {
	docs := doc.New()
	a.NotNil(docs)

	b, found := langs[lang]
	if !found {
		a.T().Error("不支持该语言")
	}

	parseFile(docs, path, b, nil)
	a.Equal(2, len(docs.Apis))

	api0 := docs.Apis[0]
	api1 := docs.Apis[1]

	a.T().Log(api0.Success.Examples[0])
	a.T().Log(api1.Success.Examples[0])

	a.Equal(api0.URL, "/users/login").
		Equal(api1.URL, "/users/login").
		Equal(api0.Group, "users").
		Equal(api1.Group, "users")

	if api0.Method == "POST" {
		a.Equal(api1.Method, "DELETE").
			Equal(1, len(api1.Request.Headers))
	} else {
		a.Equal(api0.Method, "DELETE").
			Equal(api1.Method, "POST").
			Equal(1, len(api0.Request.Headers))
	}
}