2018-11-18 22:23:31 +08:00
|
|
|
package vars
|
|
|
|
|
2021-03-24 12:15:27 +08:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"src.elv.sh/pkg/eval/errs"
|
2021-10-14 06:57:14 +08:00
|
|
|
"src.elv.sh/pkg/tt"
|
2021-03-24 12:15:27 +08:00
|
|
|
)
|
2018-11-18 22:23:31 +08:00
|
|
|
|
|
|
|
func TestNewReadOnly(t *testing.T) {
|
|
|
|
v := NewReadOnly("haha")
|
|
|
|
if v.Get() != "haha" {
|
|
|
|
t.Errorf("Get doesn't return initial value")
|
|
|
|
}
|
2021-03-24 12:15:27 +08:00
|
|
|
|
|
|
|
err := v.Set("lala")
|
|
|
|
if _, ok := err.(errs.SetReadOnlyVar); !ok {
|
|
|
|
t.Errorf("Set a readonly var doesn't error as expected: %#v", err)
|
2018-11-18 22:23:31 +08:00
|
|
|
}
|
|
|
|
}
|
2021-10-14 06:57:14 +08:00
|
|
|
|
|
|
|
func TestIsReadOnly(t *testing.T) {
|
2024-01-11 23:42:43 +08:00
|
|
|
tt.Test(t, IsReadOnly,
|
2021-10-14 06:57:14 +08:00
|
|
|
Args(NewReadOnly("foo")).Rets(true),
|
2022-03-20 23:50:25 +08:00
|
|
|
Args(FromGet(func() any { return "foo" })).Rets(true),
|
2021-10-14 06:57:14 +08:00
|
|
|
Args(FromInit("foo")).Rets(false),
|
2024-01-11 23:42:43 +08:00
|
|
|
)
|
2021-10-14 06:57:14 +08:00
|
|
|
}
|