|
|
|
package starainrt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test_CfgParse(t *testing.T) {
|
|
|
|
data := `#lalala
|
|
|
|
ok =true\# #ok
|
|
|
|
[happy] #ok
|
|
|
|
#kkk
|
|
|
|
me = \=tru
|
|
|
|
sa = p\\k
|
|
|
|
migrate = ok #oooo
|
|
|
|
[siki]
|
|
|
|
sakurs = ssss #[ossk]`
|
|
|
|
//data, _ := ioutil.ReadFile(`c:\Users\Starainrt\Desktop\postgresql.conf`)
|
|
|
|
ini := new(StarCfg)
|
|
|
|
ini.Parse([]byte(data))
|
|
|
|
ini.Seg("happy").SetInt64("sakura", 986787, "")
|
|
|
|
fmt.Println(string(ini.Build()))
|
|
|
|
}
|
|
|
|
|
|
|
|
type Ntest struct {
|
|
|
|
N string `seg:"happy" key:"me"`
|
|
|
|
}
|
|
|
|
type Testsss struct {
|
|
|
|
Okk string `seg:"unnamed" key:"ok"`
|
|
|
|
Migrate string `seg:"happy" key:"migrate" comment:"whnb"`
|
|
|
|
Ntest
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_CfgParseStruct(t *testing.T) {
|
|
|
|
data := `#lalala
|
|
|
|
ok =true\# #ok
|
|
|
|
[happy] #ok
|
|
|
|
#kkk
|
|
|
|
me = \=tru
|
|
|
|
sa = p\\k
|
|
|
|
migrate = ok #oooo
|
|
|
|
[siki]
|
|
|
|
sakurs = ssss #[ossk]`
|
|
|
|
//data, _ := ioutil.ReadFile(`c:\Users\Starainrt\Desktop\postgresql.conf`)
|
|
|
|
okk := Testsss{}
|
|
|
|
ini := new(StarCfg)
|
|
|
|
ini.Parse([]byte(data))
|
|
|
|
//fmt.Println(ini.Seg("happy").Get("migrate"))
|
|
|
|
fmt.Println(ini.Unmarshal(&okk))
|
|
|
|
fmt.Println(okk)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_DeleteAdd(t *testing.T) {
|
|
|
|
data := `[A]
|
|
|
|
a=1
|
|
|
|
b=2
|
|
|
|
c=3
|
|
|
|
[B]
|
|
|
|
a=1
|
|
|
|
b=2
|
|
|
|
c=3
|
|
|
|
[C]
|
|
|
|
a=1
|
|
|
|
b=2
|
|
|
|
c=3
|
|
|
|
`
|
|
|
|
ini := new(StarCfg)
|
|
|
|
ini.Parse([]byte(data))
|
|
|
|
fmt.Println(ini.Seg("A").Int("a"))
|
|
|
|
fmt.Println(ini.Seg("A").Int("b"))
|
|
|
|
fmt.Println(ini.Seg("B").Int("c"))
|
|
|
|
fmt.Println("-----------------------")
|
|
|
|
ini.Seg("A").Set("d", "4", "")
|
|
|
|
ini.DeleteSeg("B")
|
|
|
|
ini.AddSeg("D")
|
|
|
|
ini.AddSeg("E").SetInt("a", 1, "")
|
|
|
|
ini.Seg("C").Delete("a")
|
|
|
|
fmt.Println(string(ini.Build()))
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_Marshal(t *testing.T) {
|
|
|
|
var a Testsss
|
|
|
|
a.Migrate = "1"
|
|
|
|
a.N = "2"
|
|
|
|
a.Okk = "okkkkk"
|
|
|
|
ini := StarCfg{}
|
|
|
|
data, err := ini.Marshal(a)
|
|
|
|
fmt.Println(string(data), err)
|
|
|
|
}
|