MCPcopy
hub / github.com/davyxu/tabtoy / checkDataType

Function checkDataType

v3/checker/checker_data.go:10–55  ·  view source on GitHub ↗

检查数据与定义类型是否匹配

(globals *model.Globals)

Source from the content-addressed store, hash-verified

8
9// 检查数据与定义类型是否匹配
10func 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
57func checkSingleValue(header *model.HeaderField, value string) error {
58 switch model.LanguagePrimitive(header.TypeInfo.FieldType, "go") {

Callers 1

PostCheckFunction · 0.85

Calls 6

StringMethod · 0.95
ReportErrorFunction · 0.92
checkSingleValueFunction · 0.85
AllTablesMethod · 0.80
GetCellMethod · 0.80
IsArrayMethod · 0.45

Tested by

no test coverage detected