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.
staros/sysconf/sysconf_test.go

68 lines
1.2 KiB
Go

5 years ago
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`)
9 months ago
//fmt.Println(cfg.Data[0].comment)
5 years ago
fmt.Println(string(cfg.Build()))
}
4 years ago
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) {
9 months ago
var info string = `
4 years ago
[love]
a=abc
b=123
[star]
a=456
b=789
`
var tmp testme
9 months ago
ini := NewIni()
4 years ago
ini.Parse([]byte(info))
ini.Unmarshal(&tmp)
9 months ago
fmt.Printf("%+v\n", tmp)
b, _ := ini.Marshal(tmp)
4 years ago
fmt.Println(string(b))
9 months ago
}