检查数据与定义类型是否匹配
(globals *model.Globals)
| 8 | |
| 9 | // 检查数据与定义类型是否匹配 |
| 10 | func checkDataType(globals *model.Globals) { |
| 11 | |
| 12 | var currHeader *model.HeaderField |
| 13 | var crrCell *model.Cell |
| 14 | |
| 15 | for _, tab := range globals.Datas.AllTables() { |
| 16 | |
| 17 | // 遍历输入数据的每一列 |
| 18 | for _, header := range tab.Headers { |
| 19 | |
| 20 | // 输入的列头,为空表示改列被注释 |
| 21 | if header.TypeInfo == nil { |
| 22 | continue |
| 23 | } |
| 24 | |
| 25 | for row := 1; row < len(tab.Rows); row++ { |
| 26 | |
| 27 | inputCell := tab.GetCell(row, header.Cell.Col) |
| 28 | |
| 29 | // 这行被注释,无效行 |
| 30 | if inputCell == nil { |
| 31 | continue |
| 32 | } |
| 33 | |
| 34 | crrCell = inputCell |
| 35 | currHeader = header |
| 36 | |
| 37 | if header.TypeInfo.IsArray() { |
| 38 | for _, value := range inputCell.ValueList { |
| 39 | |
| 40 | err := checkSingleValue(header, value) |
| 41 | if err != nil { |
| 42 | report.ReportError("DataMissMatchTypeDefine", currHeader.TypeInfo.FieldType, crrCell.String()) |
| 43 | } |
| 44 | } |
| 45 | } else if inputCell.Value != "" { |
| 46 | err := checkSingleValue(header, inputCell.Value) |
| 47 | if err != nil { |
| 48 | report.ReportError("DataMissMatchTypeDefine", currHeader.TypeInfo.FieldType, crrCell.String()) |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | func checkSingleValue(header *model.HeaderField, value string) error { |
| 58 | switch model.LanguagePrimitive(header.TypeInfo.FieldType, "go") { |
no test coverage detected