Skip to content

Commit

Permalink
🐛 fix space sep.
Browse files Browse the repository at this point in the history
  • Loading branch information
perillaroc committed Feb 5, 2019
1 parent cd69912 commit 38a3ba3
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
7 changes: 6 additions & 1 deletion slurm/category.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ type QueryCategoryList struct {

func (ql *QueryCategoryList) UpdateTokenIndex(titleLine string, sep string) {
titleLine = strings.TrimSpace(titleLine)
tokens := strings.Split(titleLine, sep)
var tokens []string
if sep == "" || sep == " " {
tokens = strings.Fields(titleLine)
} else {
tokens = strings.Split(titleLine, sep)
}
for index, label := range tokens {
category := ql.CategoryFromLabel(label)
if category != nil {
Expand Down
60 changes: 60 additions & 0 deletions slurm/category_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,63 @@ func TestQueryCategoryList_UpdateTokenIndex(t *testing.T) {
}
}
}

func TestBuildModel2(t *testing.T) {
categoryList := &slurm.QueryCategoryList{
QueryCategoryList: hpcmodel.QueryCategoryList{
CategoryList: []*hpcmodel.QueryCategory{
{
ID: "sinfo.partition",
DisplayName: "Partition",
Label: "PARTITION",
PropertyClass: "StringProperty",
PropertyCreateArguments: []string{},
},
{
ID: "squeue.avail",
DisplayName: "Avail",
Label: "AVAIL",
PropertyClass: "StringProperty",
PropertyCreateArguments: []string{},
},
},
},
}

tests := []struct {
label string
index int
sep string
}{
{
"PARTITION",
0,
"",
},
{
"AVAIL",
1,
"",
},
}

titleLine := "PARTITION AVAIL NODES(A/I/O/T) CPUS(A/I/O/T)"

categoryList.UpdateTokenIndex(titleLine, "")
for _, test := range tests {
category := categoryList.CategoryFromLabel(test.label)
if category == nil {
t.Errorf("can't find category with label %s", test.label)
}
args := category.RecordParserArguments
if len(args) != 2 {
t.Errorf("RecordParserArguments length is not 2")
}
if args[0] != strconv.Itoa(test.index) {
t.Errorf("index is %s, should %d", args[0], test.index)
}
if args[1] != test.sep {
t.Errorf("sep is %s, should %s", args[0], test.sep)
}
}
}

0 comments on commit 38a3ba3

Please sign in to comment.