expr/t_context_test.go

61 lines
1.6 KiB
Go

// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
// All rights reserved.
// t_context_test.go
package expr
import (
"testing"
)
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)
}
}