Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #4 from JustinHines/bool

Add bool
  • Loading branch information...
commit c70d7b62dc1d58bd067ca6f6680cefce87ddac22 2 parents 721c96c + 11f5cb2
@mreiferson authored
Showing with 14 additions and 2 deletions.
  1. +9 −1 simplejson.go
  2. +5 −1 simplejson_test.go
View
10 simplejson.go
@@ -8,7 +8,7 @@ import (
// returns the current implementation version
func Version() string {
- return "0.2"
+ return "0.3"
}
type Json struct {
@@ -79,6 +79,14 @@ func (j *Json) Array() ([]interface{}, error) {
return nil, errors.New("type assertion to []interface{} failed")
}
+// Bool type asserts to `bool`
+func (j *Json) Bool() (bool, error) {
+ if s, ok := (j.data).(bool); ok {
+ return s, nil
+ }
+ return false, errors.New("type assertion to bool failed")
+}
+
// String type asserts to `string`
func (j *Json) String() (string, error) {
if s, ok := (j.data).(string); ok {
View
6 simplejson_test.go
@@ -20,7 +20,8 @@ func TestSimplejson(t *testing.T) {
"int": 10,
"float": 5.150,
"bignum": 9223372036854775807,
- "string": "simplejson"
+ "string": "simplejson",
+ "bool": true
}
}`))
@@ -55,6 +56,9 @@ func TestSimplejson(t *testing.T) {
s, _ := js.Get("test").Get("string").String()
assert.Equal(t, "simplejson", s)
+ b, _ := js.Get("test").Get("bool").Bool()
+ assert.Equal(t, true, b)
+
mi := js.Get("test").Get("int").MustInt()
assert.Equal(t, 10, mi)
Please sign in to comment.
Something went wrong with that request. Please try again.