mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-13 09:57:51 +08:00
47 lines
923 B
Go
47 lines
923 B
Go
|
package vars
|
||
|
|
||
|
import "testing"
|
||
|
|
||
|
func TestFromSetGet(t *testing.T) {
|
||
|
getCalled := false
|
||
|
get := func() interface{} {
|
||
|
getCalled = true
|
||
|
return "cb"
|
||
|
}
|
||
|
var setCalledWith interface{}
|
||
|
set := func(v interface{}) error {
|
||
|
setCalledWith = v
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
v := FromSetGet(set, get)
|
||
|
if v.Get() != "cb" {
|
||
|
t.Errorf("cbVariable doesn't return value from callback")
|
||
|
}
|
||
|
if !getCalled {
|
||
|
t.Errorf("cbVariable doesn't call callback")
|
||
|
}
|
||
|
v.Set("setting")
|
||
|
if setCalledWith != "setting" {
|
||
|
t.Errorf("cbVariable.Set doesn't call setter with value")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestFromGet(t *testing.T) {
|
||
|
getCalled := false
|
||
|
get := func() interface{} {
|
||
|
getCalled = true
|
||
|
return "cb"
|
||
|
}
|
||
|
v := FromGet(get)
|
||
|
if v.Get() != "cb" {
|
||
|
t.Errorf("roCbVariable doesn't return value from callback")
|
||
|
}
|
||
|
if !getCalled {
|
||
|
t.Errorf("roCbVariable doesn't call callback")
|
||
|
}
|
||
|
if v.Set("lala") == nil {
|
||
|
t.Errorf("roCbVariable.Set doesn't error")
|
||
|
}
|
||
|
}
|