Register types with encoding/gob. Rewrite test/basic.

This commit is contained in:
Greg 2018-08-03 15:14:10 -04:00
parent b880a5671d
commit 8f78a6c6d2
3 changed files with 28 additions and 15 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
test/basic/basic
test/basic/pgen.go
test/basic/db

View File

@ -2,6 +2,7 @@ package main
const template string = `package main const template string = `package main
import ( import (
"encoding/gob"
"time" "time"
"unsafe" "unsafe"
"gitlab.wow.st/gmp/persist" "gitlab.wow.st/gmp/persist"
@ -11,6 +12,7 @@ type Var_N persist.Var
func New(name string, xs ..._T) *Var_N { func New(name string, xs ..._T) *Var_N {
var x _T var x _T
gob.Register(x)
if len(xs) > 0 { if len(xs) > 0 {
x = xs[0] x = xs[0]
} }

View File

@ -9,29 +9,36 @@ import (
func main() { func main() {
persist.Init() persist.Init()
x := persistInt("x",5) x := persistInt("x",5)
var y1 mine1 = 6
y2 := mine2{}
y1p := persistM1("y",y1)
y2p := persistM2("y",y2)
y3 := token.FileSet{}
y3p := persistM3("y",y3)
y4 := make(map[*token.FileSet]*token.File)
y4p := persistM4("y",y4)
y5 := make(map[*token.FileSet]*persist.Var)
y5p := persistM5("y",y5)
y6 := make(map[persist.Var]token.FileSet)
y6p := persistM6("y",y6)
_,_,_,_,_,_ = y1p, y2p, y3p, y4p, y5p, y6p
fmt.Println(x) fmt.Println(x)
fmt.Println(x.Get()) fmt.Println(x.Get())
x.Set(3) x.Set(3)
fmt.Println(x) fmt.Println(x)
var y1 mine1 = 6
y2 := mine2{}
y1p := persistM1("y1",y1)
y1 = y1p.Get()
y2p := persistM2("y2",y2)
y2 = y2p.Get()
y3 := token.FileSet{}
y3p := persistM3("y3",y3)
y3 = y3p.Get()
y4 := make(map[*token.FileSet]*token.File)
y4p := persistM4("y4",y4)
y4 = y4p.Get()
y5 := make(map[*token.FileSet]*persist.Var)
y5p := persistM5("y5",y5)
y5 = y5p.Get()
y6 := make(map[persist.Var]token.FileSet)
y6p := persistM6("y6",y6)
y6 = y6p.Get()
z := func(interface{}) { z := func(interface{}) {
_ = persistFloat("y",1.0) _ = persistFloat("y7",1.0)
} }
z(persistString("name","ok")) z(persistString("z","ok"))
s := persistString("s","ok bye") s := persistString("s","ok bye")
fmt.Println(s) fmt.Println(s)
@ -41,5 +48,6 @@ func main() {
ts = s.Get() // this works ts = s.Get() // this works
_ = ts _ = ts
persist.Commit() persist.Commit()
persist.Shutdown()
} }