func (runner *APIRunner) ParseAPIItems() error {
	headers := VmMap2HttpHeaders(DefaultHeaders)
	inited := false
	index := 0
	asserting := false
	for index < len(runner.Block) {
		line := runner.Block[index]
		switch line := line.(type) {
		case *funny.Comment:
			text := strings.Trim(line.Value, " ")
			texts := strings.Split(text, " ")
			if len(texts) < 2 {
				break
			}
			methods := []string{"GET", "POST", "DELETE", "PUT", "PATCH"}
			flag := false
			for _, item := range methods {
				if strings.ToUpper(item) == strings.ToUpper(texts[0]) {
					flag = true
				}
			}
			if flag {
				inited = true
				asserting = false
				req := ApiRequest{
					Method:  texts[0],
					Url:     texts[1],
					Headers: headers,
				}
				if len(texts) > 2 {
					req.Name = texts[2]
				}
				if len(texts) > 3 {
					req.Description = texts[3]
				}
				apiItem := &ApiItem{
					Request:  &req,
					Response: &ApiResponse{},
				}
				runner.APIItems = append(runner.APIItems, apiItem)
			}
		case *funny.FunctionCall:
			if line.Name == "assert" {
				asserting = true
			}
			if asserting {
				item := runner.APIItems[len(runner.APIItems)-1]
				item.Response.lines = append(item.Response.lines, line)
				break
			}
		default:
			if inited {
				if asserting {
					item := runner.APIItems[len(runner.APIItems)-1]
					item.Response.lines = append(item.Response.lines, line)
				} else {
					item := runner.APIItems[len(runner.APIItems)-1]
					item.Request.lines = append(item.Request.lines, line)
				}
			} else {
				runner.InitLines = append(runner.InitLines, line)
			}
		}
		index++
	}
	return nil
}
// ParseAPIItems parse ap items from pica code
ParseAPIItems parse ap items from pica code
// ParseAPIItems parse ap items from pica code
func (runner *APIRunner) ParseAPIItems() error {
	headers := VmMap2HttpHeaders(DefaultHeaders)
	inited := false
	index := 0
	asserting := false
	for index < len(runner.Block) {
		line := runner.Block[index]
		switch line := line.(type) {
		case *funny.Comment:
			text := strings.Trim(line.Value, " ")
			texts := strings.Split(text, " ")
			if len(texts) < 2 {
				break
			}
			methods := []string{"GET", "POST", "DELETE", "PUT", "PATCH"}
			flag := false
			for _, item := range methods {
				if strings.ToUpper(item) == strings.ToUpper(texts[0]) {
					flag = true
				}
			}
			if flag {
				inited = true
				asserting = false
				req := ApiRequest{
					Method:  texts[0],
					Url:     texts[1],
					Headers: headers,
				}
				if len(texts) > 2 {
					req.Name = texts[2]
				}
				if len(texts) > 3 {
					req.Description = texts[3]
				}
				apiItem := &ApiItem{
					Request:  &req,
					Response: &ApiResponse{},
				}
				runner.APIItems = append(runner.APIItems, apiItem)
			}
		case *funny.FunctionCall:
			if line.Name == "assert" {
				asserting = true
			}
			if asserting {
				item := runner.APIItems[len(runner.APIItems)-1]
				item.Response.lines = append(item.Response.lines, line)
				break
			}
		default:
			if inited {
				if asserting {
					item := runner.APIItems[len(runner.APIItems)-1]
					item.Response.lines = append(item.Response.lines, line)
				} else {
					item := runner.APIItems[len(runner.APIItems)-1]
					item.Request.lines = append(item.Request.lines, line)
				}
			} else {
				runner.InitLines = append(runner.InitLines, line)
			}
		}
		index++
	}
	return nil
}
func ( runner * APIRunner ) ParseAPIItems ( ) error { headers := VmMap2HttpHeaders ( DefaultHeaders ) inited := false index := 0 asserting := false for index < len ( runner . Block ) { line := runner . Block [ index ] switch line := line . ( type ) { case * funny . Comment : text := strings . Trim ( line . Value , " " ) texts := strings . Split ( text , " " ) if len ( texts ) < 2 { break } methods := [ ] string { " " , " " , " " , " " , " " } flag := false for _ , item := range methods { if strings . ToUpper ( item ) == strings . ToUpper ( texts [ 0 ] ) { flag = true } } if flag { inited = true asserting = false req := ApiRequest { Method : texts [ 0 ] , Url : texts [ 1 ] , Headers : headers , } if len ( texts ) > 2 { req . Name = texts [ 2 ] } if len ( texts ) > 3 { req . Description = texts [ 3 ] } apiItem := & ApiItem { Request : & req , Response : & ApiResponse { } , } runner . APIItems = append ( runner . APIItems , apiItem ) } case * funny . FunctionCall : if line . Name == " " { asserting = true } if asserting { item := runner . APIItems [ len ( runner . APIItems ) - 1 ] item . Response . lines = append ( item . Response . lines , line ) break } default : if inited { if asserting { item := runner . APIItems [ len ( runner . APIItems ) - 1 ] item . Response . lines = append ( item . Response . lines , line ) } else { item := runner . APIItems [ len ( runner . APIItems ) - 1 ] item . Request . lines = append ( item . Request . lines , line ) } } else { runner . InitLines = append ( runner . InitLines , line ) } } index ++ } return nil }
ParseAPIItems parse ap items from pica code
ParseAPIItems parse ap items from pica code