Пример #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
}
Пример #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")
}
Пример #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)
}
Пример #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")
}
Пример #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)
}