crontabex/condition_test.go

108 lines
1.5 KiB
Go
Raw Normal View History

2018-12-25 11:46:02 +00:00
package crontab
import (
"strings"
"testing"
)
//xx={xx()},n>f|n > x |{w=5},5<f<8{w=5s;},
// Condition 条件表达式的结构实例
type Condition struct {
}
type Cond struct {
expr string
op string
}
func (cond *Cond) Execute() bool {
i := 0
for ; i < len(cond.expr); i++ {
switch cond.expr[i] {
case '(':
case '<':
case '>':
case '=':
case ' ':
i++
}
}
return false
}
// func indexOperator(s string, start int) (start int, end int) {
// return 0, 1
// }
func parseCond(cond string) {
var CondList []Cond
s := 0
i := 0
for ; i < len(cond); i++ {
switch cond[i] {
// case '{':
// // take execute proccess
case '|':
CondList = append(CondList, Cond{expr: cond[s:i], op: "|"})
s = i + 1
case '&':
CondList = append(CondList, Cond{expr: cond[s:i], op: "&"})
s = i + 1
case ' ':
i++
}
}
}
func parseMethod(expr string) {
}
func parseDefine(v, method string) {
}
func TestBaseCond(t *testing.T) {
condExpr := "n>f|n > x |{w=5},{w=5s;}"
for _, expr := range strings.Split(condExpr, ",") {
// condexpr
for i := 0; i <= len(expr); i++ {
if expr[i] == '{' {
s := i - 1
for s > 0 {
switch expr[s] {
case ' ':
s--
case '=':
// 判断 = 定义表达
parseDefine(expr[0:s], expr[s+1:])
default:
// 判断 = 条件表达
parseCond(expr[0:i])
parseMethod(expr[i:])
}
}
// 判断 = 执行表达
parseMethod(expr)
}
}
// 找不到{ 判断 = 执行表达
parseMethod(expr)
}
}