94 lines
2.5 KiB
Go
94 lines
2.5 KiB
Go
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
|
// All rights reserved.
|
|
|
|
// t_context_test.go
|
|
package expr
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.portale-stac.it/go-pkg/expr/kern"
|
|
)
|
|
|
|
func TestCtrlSet(t *testing.T) {
|
|
section := "Context"
|
|
varName := "_test_var"
|
|
varValue := "test-value"
|
|
prevValue := "test-prev"
|
|
|
|
ctx := NewSimpleStore()
|
|
GlobalCtrlSet(ctx, varName, prevValue)
|
|
if v := GlobalCtrlSet(ctx, varName, varValue); v != nil {
|
|
if s, ok := v.(string); ok {
|
|
if s != prevValue {
|
|
t.Errorf(`%s -- CtrlSet(%q, %q) should have returned %q, got %q`, section, varName, varValue, varValue, s)
|
|
}
|
|
} else {
|
|
t.Errorf(`%s -- CtrlSet(%q, %q) should have returned a string, got %v [%T]`, section, varName, varValue, v, v)
|
|
}
|
|
} else {
|
|
t.Errorf(`%s -- CtrlSet(%q, %q) should have returned a value, got nil`, section, varName, varValue)
|
|
}
|
|
}
|
|
|
|
func TestCtrlGet(t *testing.T) {
|
|
section := "Context"
|
|
varName := "_test_var"
|
|
varValue := "test-value"
|
|
|
|
ctx := NewSimpleStore()
|
|
GlobalCtrlSet(ctx, varName, varValue)
|
|
if v := GlobalCtrlGet(ctx, varName); v != nil {
|
|
if s, ok := v.(string); ok {
|
|
if s != "test-value" {
|
|
t.Errorf(`%s -- CtrlGet(%q) should have returned %q, got %q`, section, varName, varValue, s)
|
|
}
|
|
} else {
|
|
t.Errorf(`%s -- CtrlGet(%q) should have returned a string, got %v [%T]`, section, varName, v, v)
|
|
}
|
|
} else {
|
|
t.Errorf(`%s -- CtrlGet(%q) should have returned a value, got nil`, section, varName)
|
|
}
|
|
}
|
|
|
|
func TestCtrlGetNotDefined(t *testing.T) {
|
|
section := "Context"
|
|
varName := "_test_var"
|
|
|
|
ctx := NewSimpleStore()
|
|
if v := GlobalCtrlGet(ctx, varName); v != nil {
|
|
t.Errorf(`%s -- CtrlGet(%q) should have returned nil, got %v`, section, varName, v)
|
|
}
|
|
}
|
|
|
|
func TestCtrlEnable(t *testing.T) {
|
|
section := "Context"
|
|
varName := "test_var"
|
|
varValue := true
|
|
|
|
ctx := NewSimpleStore()
|
|
GlobalCtrlSet(ctx, varName, varValue)
|
|
if !CtrlEnable(ctx, varName) {
|
|
t.Errorf(`%s -- CtrlEnable(ctx, %q) should have returned 'true', got 'false'`, section, varName)
|
|
}
|
|
|
|
if !CtrlDisable(ctx, varName) {
|
|
t.Errorf(`%s -- CtrlEnable(ctx, %q) should have returned 'true', got 'false'`, section, varName)
|
|
}
|
|
|
|
}
|
|
|
|
func TestList(t *testing.T) {
|
|
section := "Context"
|
|
|
|
inputs := []inputType{
|
|
/* 1 */ {`$$(5)`, kern.NewLinkedListA(5), nil},
|
|
/* 2 */ {`$$($(2))`, kern.NewLinkedListA(0, 1), nil},
|
|
/* 3 */ {`string(($$global).funcs.bool)`, `bool(value):boolean{}`, nil},
|
|
}
|
|
|
|
// runTestSuiteSpec(t, section, inputs, 3)
|
|
runTestSuite(t, section, inputs)
|
|
|
|
}
|