Skip to content

Commit

Permalink
update some test for new methods
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jul 1, 2019
1 parent 7914299 commit f42895a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
28 changes: 17 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,59 +87,59 @@ some = change val
- Get integer

```go
age := config.Int("age")
age := ini.Int("age")
fmt.Print(age) // 100
```

- Get bool

```go
val := config.Bool("debug")
val := ini.Bool("debug")
fmt.Print(val) // true
```

- Get string

```go
name := config.String("name")
name := ini.String("name")
fmt.Print(name) // inhere
```

- Get section data(string map)

```go
val := config.StringMap("sec1")
val := ini.StringMap("sec1")
fmt.Println(val)
// map[string]string{"key":"val0", "some":"change val", "stuff":"things", "newK":"newVal"}
```

- Value is ENV var

```go
value := config.String("shell")
value := ini.String("shell")
fmt.Printf("%q", value) // "/bin/zsh"
```

- Get value by key path
- **Get value by key path**

```go
value := config.String("sec1.key")
value := ini.String("sec1.key")
fmt.Print(value) // val0
```

- Use var refer

```go
value := config.String("sec1.varRef")
value := ini.String("sec1.varRef")
fmt.Printf("%q", value) // "val in default section"
```

- Setting new value

```go
// set value
config.Set("name", "new name")
name = config.String("name")
ini.Set("name", "new name")
name = ini.String("name")
fmt.Printf("%q", value) // "new name"
```

Expand Down Expand Up @@ -189,7 +189,13 @@ type Options struct {
}
```

- setting options
- setting options for default instance

```go
ini.WithOptions(ini.ParseEnv,ini.ParseVar)
```

- setting options with new instance

```go
cfg := ini.New()
Expand Down
6 changes: 6 additions & 0 deletions ini.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ func IgnoreCase(opts *Options) {
opts.IgnoreCase = true
}

// GetOptions get options info.
// Notice: return is value. so, cannot change Ini instance
func GetOptions() Options {
return dc.Options()
}

// Options get options info.
// Notice: return is value. so, cannot change Ini instance
func (c *Ini) Options() Options {
Expand Down
8 changes: 8 additions & 0 deletions ini_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,14 @@ func TestOther(t *testing.T) {
err := ini.LoadStrings(iniStr)
st.Nil(err)

ns := ini.SectionKeys(false)
st.Contains(ns, "sec1")
st.NotContains(ns, ini.GetOptions().DefSection)

ns = ini.SectionKeys(true)
st.Contains(ns, "sec1")
st.Contains(ns, ini.GetOptions().DefSection)

conf := ini.Default()

// export as INI string
Expand Down

0 comments on commit f42895a

Please sign in to comment.