data_workshop/case_test.go

48 lines
1.1 KiB
Go
Raw Permalink Normal View History

2020-05-13 06:57:57 +00:00
package main
import (
2020-05-19 10:12:18 +00:00
"encoding/gob"
"os"
2020-05-13 06:57:57 +00:00
"testing"
)
2020-05-19 10:12:18 +00:00
// func TestCheckCountry2(t *testing.T) {
// gob.Register(Country{})
// ("./data/country.gob", reflect.TypeOf(Country{}), NewKeyKind("country-name-", "Name"), NewKeyKind("country-pic-%s", "Pic"))
2020-05-19 10:12:18 +00:00
// }
// func TestLastName(t *testing.T) {
// gob.Register(Country{})
// ln := &KeyList{}
// LoadGob("./data/lastname.gob", ln)
// t.Error(ln.GetLength(), string(ln.Keys[0].([]byte)))
// nln := KeyList{}
// for _, buf := range ln.Keys {
// lnn := LastName{}
// lnn.Name = buf.([]byte)
// nln.AppendKey(lnn)
// }
// SaveData("./data/lastname-test.gob", nln)
// }
func estS(t *testing.T) {
2020-05-19 10:12:18 +00:00
gob.Register(Country{})
ln := &KeyList{}
LoadGob("./data/lastname1.gob", ln)
t.Error(len(ln.Keys))
country := ln.Keys[0].(Country)
f, _ := os.OpenFile("./1.png", os.O_CREATE|os.O_TRUNC|os.O_RDWR, os.ModePerm)
f.Write(country.Pic)
2020-05-13 06:57:57 +00:00
}
func estReadData(t *testing.T) {
2020-05-19 10:12:18 +00:00
gob.Register(Country{})
ln := &KeyList{}
LoadGob("./data/country.gob", ln)
t.Error(len(ln.Keys))
country := ln.Keys[0].(Country)
f, _ := os.OpenFile("./1.png", os.O_CREATE|os.O_TRUNC|os.O_RDWR, os.ModePerm)
f.Write(country.Pic)
2020-05-13 06:57:57 +00:00
}