Other: Safer user types

This commit is contained in:
James Houlahan
2022-10-12 00:20:04 +02:00
parent 4dc32dc7f2
commit fd63611b41
35 changed files with 1253 additions and 771 deletions

View 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")
}
}