elvish/pkg/eval/vars/read_only_test.go
Qi Xiao 6e36058d0a pkg/tt: Improve API.
- Use reflection to derive function name.

- Take test cases as variadic arguments, instead of requiring them to be wrapped
  in a Table.

- Support naming test cases.

- Run test cases as subtests with t.Run.
2024-01-11 15:42:43 +00:00

29 lines
566 B
Go

package vars
import (
"testing"
"src.elv.sh/pkg/eval/errs"
"src.elv.sh/pkg/tt"
)
func TestNewReadOnly(t *testing.T) {
v := NewReadOnly("haha")
if v.Get() != "haha" {
t.Errorf("Get doesn't return initial value")
}
err := v.Set("lala")
if _, ok := err.(errs.SetReadOnlyVar); !ok {
t.Errorf("Set a readonly var doesn't error as expected: %#v", err)
}
}
func TestIsReadOnly(t *testing.T) {
tt.Test(t, IsReadOnly,
Args(NewReadOnly("foo")).Rets(true),
Args(FromGet(func() any { return "foo" })).Rets(true),
Args(FromInit("foo")).Rets(false),
)
}