Skip to content

Commit

Permalink
Add IsArray and IsDict for checking config type
Browse files Browse the repository at this point in the history
  • Loading branch information
urso committed Jul 26, 2016
1 parent c2070c5 commit 1afef8d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]

### Added
- Add `(*Config).IsArray` and `(*Config).IsDict`. #44

### Changed

Expand Down
5 changes: 5 additions & 0 deletions getset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ func TestSetGetPrimitives(t *testing.T) {
c.SetFloat("float", -1, 2.3)
c.SetString("str", -1, "abc")

assert.True(t, c.IsDict())
assert.False(t, c.IsArray())

assert.True(t, c.HasField("bool"))
assert.True(t, c.HasField("int"))
assert.True(t, c.HasField("uint"))
Expand Down Expand Up @@ -127,6 +130,8 @@ func TestSetGetArray(t *testing.T) {

a, err := c.Child("a", -1)
assert.NoError(t, err)
assert.True(t, a.IsArray())
assert.False(t, a.IsDict())

l, err = a.CountField("")
assert.NoError(t, err)
Expand Down
8 changes: 8 additions & 0 deletions ucfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ func NewFrom(from interface{}, opts ...Option) (*Config, error) {
return c, nil
}

func (c *Config) IsDict() bool {
return c.fields.arr == nil
}

func (c *Config) IsArray() bool {
return c.fields.arr != nil
}

func (c *Config) GetFields() []string {
var names []string
for k := range c.fields.fields {
Expand Down

0 comments on commit 1afef8d

Please sign in to comment.