github.com/xyproto/u-root@v6.0.1-0.20200302025726-5528e0c77a3c+incompatible/cmds/core/elvish/eval/vars/ptr_test.go (about) 1 package vars 2 3 import "testing" 4 5 func TestPtrVariable(t *testing.T) { 6 i := 10 7 variable := FromPtr(&i) 8 if g := variable.Get(); g != "10" { 9 t.Errorf(`Getting ptrVariable returns %v, want "10"`, g) 10 } 11 err := variable.Set("20") 12 if err != nil { 13 t.Errorf(`Setting ptrVariable with "20" returns error %v`, err) 14 } 15 if i != 20 { 16 t.Errorf(`Setting ptrVariable didn't change underlying value`) 17 } 18 err = variable.Set("x") 19 if err == nil { 20 t.Errorf("Setting ptrVariable with incompatible value returns no error") 21 } 22 }