You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.2 KiB
Go
68 lines
1.2 KiB
Go
package sysconf
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func Test_SliceIn(t *testing.T) {
|
|
slice := []string{"ok", "11", "22"}
|
|
fmt.Println(SliceIn(slice, "ok"))
|
|
fmt.Println(SliceIn(slice, []rune("22")))
|
|
fmt.Println(SliceIn(slice, "342423r"))
|
|
fmt.Println(SliceIn(slice, 444))
|
|
}
|
|
|
|
func Test_Parse(t *testing.T) {
|
|
data := `
|
|
1.2.3.4 'ok.com'
|
|
#2.3.4.5 ppp.eor
|
|
2.3.4.5 'pp.com'
|
|
5.6.7.8 'ok.com'
|
|
`
|
|
cfg := new(SysConf)
|
|
cfg.SegStart = "["
|
|
cfg.SegEnd = "]"
|
|
cfg.ValueFlag = "'"
|
|
cfg.EqualFlag = " "
|
|
//cfg.CommentCR = true
|
|
cfg.CommentFlag = []string{"#"}
|
|
cfg.EscapeFlag = "\\"
|
|
cfg.HaveSegMent = false
|
|
cfg.segmap = make(map[string]int64)
|
|
fmt.Println(cfg.Parse([]byte(data)))
|
|
cfg.Reverse()
|
|
cfg.Data[0].Delete(`pp.com`)
|
|
//fmt.Println(cfg.Data[0].comment)
|
|
fmt.Println(string(cfg.Build()))
|
|
}
|
|
|
|
type slicetest struct {
|
|
A string `seg:"s" key:"a"`
|
|
B string `seg:"a" key:"b"`
|
|
}
|
|
|
|
type testme struct {
|
|
Love slicetest `seg:"love"`
|
|
Star slicetest `seg:"star"`
|
|
}
|
|
|
|
func Test_Marshal(t *testing.T) {
|
|
|
|
var info string = `
|
|
[love]
|
|
a=abc
|
|
b=123
|
|
[star]
|
|
a=456
|
|
b=789
|
|
`
|
|
var tmp testme
|
|
ini := NewIni()
|
|
ini.Parse([]byte(info))
|
|
ini.Unmarshal(&tmp)
|
|
fmt.Printf("%+v\n", tmp)
|
|
b, _ := ini.Marshal(tmp)
|
|
fmt.Println(string(b))
|
|
}
|