diff --git a/src/gen-project.go b/src/gen-project.go index 090bb307ac6880c5d5c84e63202192d10092887e..f8ad550343aa00878d919e3fbdeaf46da876382d 100644 --- a/src/gen-project.go +++ b/src/gen-project.go @@ -3,49 +3,20 @@ package main import ( "encoding/json" "fmt" - "io/ioutil" + "model" "os" "strconv" "strings" + "utils" ) -type Response struct { - Code int - Cases []TestCase -} - -type TestCase struct { - Id int - Title string - Steps []TestStep -} - -type TestStep struct { - Id int - Title string - Steps []TestStep - - Expect string - IsGroup bool - IsCheckPoint bool -} - -func ReadAll(filePth string) []byte { - buf, err := ioutil.ReadFile(filePth) - if err != nil { - return nil - } - - return buf -} - -func DealwithTestCase(tc TestCase, langType string) { +func DealwithTestCase(tc model.TestCase, langType string) { caseId := tc.Id caseTitle := tc.Title - steps := []string{} - expects := []string{} - srcCode := []string{} + steps := make([]string, 0) + expects := make([]string, 0) + srcCode := make([]string, 0) level := 1 @@ -53,21 +24,21 @@ func DealwithTestCase(tc TestCase, langType string) { DealwithTestStep(ts, langType, level, &steps, &expects, &srcCode) } - template := ReadAll("xdoc/script-template.txt") + template := utils.ReadFile("xdoc/script-template.txt") content := string(fmt.Sprintf(string(template), langType, caseTitle, caseId, strings.Join(steps, "\n"), strings.Join(expects, "\n"), strings.Join(srcCode, "\n"))) fmt.Println(content) } -func DealwithTestStep(ts TestStep, langType string, level int, +func DealwithTestStep(ts model.TestStep, langType string, level int, steps *[]string, expects *[]string, srcCode *[]string) { isGroup := ts.IsGroup isCheckPoint := ts.IsCheckPoint stepId := ts.Id stepTitle := ts.Title - stepExpect := ts.Expect + // stepExpect := ts.Expect // 处理steps stepLine := "" @@ -94,12 +65,11 @@ func DealwithTestStep(ts TestStep, langType string, level int, *steps = append(*steps, stepLine) // 处理expects - if isCheckPoint { expectsLine := "" - expectsLine = "# " + stepLineSimple + " " + stepExpect + "\n" - expectsLine += "<期望值字符串, 可以有多行>\n" + expectsLine = "# \n" // + stepLineSimple + " " + stepExpect + "\n" + expectsLine += "<" + stepType + strconv.Itoa(stepId) + " 期望结果, 可以有多行>\n" *expects = append(*expects, expectsLine) } @@ -128,9 +98,9 @@ func main() { } caseFile, langType := os.Args[1], os.Args[2] - buf := ReadAll(caseFile) + buf := utils.ReadFile(caseFile) - var resp Response + var resp model.Response json.Unmarshal(buf, &resp) if resp.Code != 1 { diff --git a/src/model/test-model.go b/src/model/test-model.go new file mode 100644 index 0000000000000000000000000000000000000000..0ecd347d97ee26243d1e0f7875401c84cc5e7da0 --- /dev/null +++ b/src/model/test-model.go @@ -0,0 +1,20 @@ +package model + +type Response struct { + Code int + Cases []TestCase +} + +type TestCase struct { + Id int + Title string + Steps []TestStep +} + +type TestStep struct { + TestCase + + Expect string + IsGroup bool + IsCheckPoint bool +} diff --git a/src/utils/utils.go b/src/utils/utils.go new file mode 100644 index 0000000000000000000000000000000000000000..6d313ad99724e4510c9a6b59f92fdc3cef25a12c --- /dev/null +++ b/src/utils/utils.go @@ -0,0 +1,12 @@ +package utils + +import "io/ioutil" + +func ReadFile(filePth string) []byte { + buf, err := ioutil.ReadFile(filePth) + if err != nil { + return nil + } + + return buf +}