increased test coverage (83.9%)
This commit is contained in:
+11
-13
@@ -42,12 +42,16 @@ func ImportInContextByGlobPattern(ctx kern.ExprContext, pattern string) (count i
|
||||
return
|
||||
}
|
||||
|
||||
func fixCtrlVar(name string) string {
|
||||
if !strings.HasPrefix(name, "_") {
|
||||
name = "_" + name
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
func GlobalCtrlSet(ctx kern.ExprContext, name string, newValue any) (currentValue any) {
|
||||
if globalCtx := ctx.GetGlobal(); globalCtx != nil {
|
||||
if !strings.HasPrefix(name, "_") {
|
||||
name = "_" + name
|
||||
}
|
||||
|
||||
name = fixCtrlVar(name)
|
||||
currentValue, _ = globalCtx.GetVar(name)
|
||||
globalCtx.SetVar(name, newValue)
|
||||
}
|
||||
@@ -56,18 +60,14 @@ func GlobalCtrlSet(ctx kern.ExprContext, name string, newValue any) (currentValu
|
||||
|
||||
func GlobalCtrlGet(ctx kern.ExprContext, name string) (currentValue any) {
|
||||
if globalCtx := ctx.GetGlobal(); globalCtx != nil {
|
||||
if !strings.HasPrefix(name, "_") {
|
||||
name = "_" + name
|
||||
}
|
||||
name = fixCtrlVar(name)
|
||||
currentValue, _ = globalCtx.GetVar(name)
|
||||
}
|
||||
return currentValue
|
||||
}
|
||||
|
||||
func CtrlEnable(ctx kern.ExprContext, name string) (currentStatus bool) {
|
||||
if !strings.HasPrefix(name, "_") {
|
||||
name = "_" + name
|
||||
}
|
||||
name = fixCtrlVar(name)
|
||||
if v, exists := ctx.GetVar(name); exists && kern.IsBool(v) {
|
||||
currentStatus, _ = v.(bool)
|
||||
}
|
||||
@@ -77,9 +77,7 @@ func CtrlEnable(ctx kern.ExprContext, name string) (currentStatus bool) {
|
||||
}
|
||||
|
||||
func CtrlDisable(ctx kern.ExprContext, name string) (currentStatus bool) {
|
||||
if !strings.HasPrefix(name, "_") {
|
||||
name = "_" + name
|
||||
}
|
||||
name = fixCtrlVar(name)
|
||||
if v, exists := ctx.GetVar(name); exists && kern.IsBool(v) {
|
||||
currentStatus, _ = v.(bool)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user