mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-15 14:56:42 +00:00
Other: Safer user types
This commit is contained in:
37
internal/safe/value_test.go
Normal file
37
internal/safe/value_test.go
Normal file
@ -0,0 +1,37 @@
|
||||
package safe
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestValue(t *testing.T) {
|
||||
v := NewValue("foo")
|
||||
|
||||
v.Load(func(data string) {
|
||||
if data != "foo" {
|
||||
t.Error("expected foo")
|
||||
}
|
||||
})
|
||||
|
||||
v.Save("bar")
|
||||
|
||||
v.Load(func(data string) {
|
||||
if data != "bar" {
|
||||
t.Error("expected bar")
|
||||
}
|
||||
})
|
||||
|
||||
v.Mod(func(data *string) {
|
||||
*data = "baz"
|
||||
})
|
||||
|
||||
v.Load(func(data string) {
|
||||
if data != "baz" {
|
||||
t.Error("expected baz")
|
||||
}
|
||||
})
|
||||
|
||||
if LoadRet(v, func(data string) string {
|
||||
return data
|
||||
}) != "baz" {
|
||||
t.Error("expected baz")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user