Esempio n. 1
0
func JsonObject(r *P.Reader) (result interface{}, rd *P.Reader, err error) {
	key := P.Between(quote, quote, P.String("key"))
	value := P.Between(quote, quote, P.String("value"))
	p := P.And(lBrace, key, colon, value, rBrace)

	result, rd, err = p(r)
	if err != nil {
		return
	}

	res := result.([]interface{})
	return map[string]interface{}{res[1].(string): res[3]}, rd, nil
}
Esempio n. 2
0
func (s *S) TestStringSuccess(c *C) {
	v := "null"
	value, err := P.Parse(P.String(v), srd(v))
	c.Assert(err, IsNil)
	c.Assert(value, FitsTypeOf, v)
	c.Assert(value, Equals, "null")
}
Esempio n. 3
0
func (s *S) TestStringFailure(c *C) {
	value, err := P.Parse(P.String("null"), srd("facebook"))
	c.Assert(err, NotNil)
	c.Assert(value, Equals, nil)
}
Esempio n. 4
0
func (s *S) TestOrSuccessRest(c *C) {
	p := P.Or(P.String("batman"), P.String("robin"))
	value, err := P.Parse(p, srd("robin"))
	c.Assert(err, IsNil)
	c.Assert(value, Equals, "robin")
}
Esempio n. 5
0
func (s *S) TestOrFailure(c *C) {
	p := P.Or(P.String("batman"), P.String("robin"))
	value, err := P.Parse(p, srd("joker"))
	c.Assert(err, NotNil)
	c.Assert(value, Equals, nil)
}