github.com/markusbkk/elvish@v0.0.0-20231204143114-91dc52438621/pkg/eval/vars/read_only_test.go (about)

     1  package vars
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/markusbkk/elvish/pkg/eval/errs"
     7  	"github.com/markusbkk/elvish/pkg/tt"
     8  )
     9  
    10  var Args = tt.Args
    11  
    12  func TestNewReadOnly(t *testing.T) {
    13  	v := NewReadOnly("haha")
    14  	if v.Get() != "haha" {
    15  		t.Errorf("Get doesn't return initial value")
    16  	}
    17  
    18  	err := v.Set("lala")
    19  	if _, ok := err.(errs.SetReadOnlyVar); !ok {
    20  		t.Errorf("Set a readonly var doesn't error as expected: %#v", err)
    21  	}
    22  }
    23  
    24  func TestIsReadOnly(t *testing.T) {
    25  	tt.Test(t, tt.Fn("IsReadOnly", IsReadOnly), tt.Table{
    26  		Args(NewReadOnly("foo")).Rets(true),
    27  		Args(FromGet(func() interface{} { return "foo" })).Rets(true),
    28  		Args(FromInit("foo")).Rets(false),
    29  	})
    30  }