mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2024-11-14 02:37:25 +01:00
parent
71d85bbaad
commit
74a8709edd
@ -92,6 +92,7 @@ func (nle NLExprIntRange) consume(input string) (next string, ok bool) {
|
|||||||
func ParseNodeList(raw string) (NodeList, error) {
|
func ParseNodeList(raw string) (NodeList, error) {
|
||||||
isLetter := func(r byte) bool { return ('a' <= r && r <= 'z') || ('A' <= r && r <= 'Z') }
|
isLetter := func(r byte) bool { return ('a' <= r && r <= 'z') || ('A' <= r && r <= 'Z') }
|
||||||
isDigit := func(r byte) bool { return '0' <= r && r <= '9' }
|
isDigit := func(r byte) bool { return '0' <= r && r <= '9' }
|
||||||
|
isDash := func(r byte) bool { return r == '-' }
|
||||||
|
|
||||||
rawterms := []string{}
|
rawterms := []string{}
|
||||||
prevterm := 0
|
prevterm := 0
|
||||||
@ -121,7 +122,7 @@ func ParseNodeList(raw string) (NodeList, error) {
|
|||||||
c := rawterm[i]
|
c := rawterm[i]
|
||||||
if isLetter(c) || isDigit(c) {
|
if isLetter(c) || isDigit(c) {
|
||||||
j := i
|
j := i
|
||||||
for j < len(rawterm) && (isLetter(rawterm[j]) || isDigit(rawterm[j])) {
|
for j < len(rawterm) && (isLetter(rawterm[j]) || isDigit(rawterm[j]) || isDash(rawterm[j])) {
|
||||||
j++
|
j++
|
||||||
}
|
}
|
||||||
exprs = append(exprs, NLExprString(rawterm[i:j]))
|
exprs = append(exprs, NLExprString(rawterm[i:j]))
|
||||||
|
@ -57,3 +57,19 @@ func TestNodeListCommasInBrackets(t *testing.T) {
|
|||||||
t.Fatal("4")
|
t.Fatal("4")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNodeListCommasOutsideBrackets(t *testing.T) {
|
||||||
|
nl, err := ParseNodeList("cn-0010,cn0011,cn-00[13-18,22-24]")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if !nl.Contains("cn-0010") || !nl.Contains("cn0011") {
|
||||||
|
t.Fatal("1")
|
||||||
|
}
|
||||||
|
if !nl.Contains("cn-0013") ||
|
||||||
|
!nl.Contains("cn-0015") ||
|
||||||
|
!nl.Contains("cn-0022") ||
|
||||||
|
!nl.Contains("cn-0018") {
|
||||||
|
t.Fatal("2")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user