Example #1
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")
}
Example #2
0
func (s *S) TestBasicJson(c *C) {
	value, err := P.Parse(JsonObject, srd(`{"key":"value"}`))
	c.Assert(err, IsNil)
	c.Assert(value, DeepEquals, map[string]interface{}{"key": "value"})
}
Example #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)
}
Example #4
0
func (s *S) TestByteSuccess(c *C) {
	value, err := P.Parse(P.Byte(':'), srd(":symbol"))
	c.Assert(err, IsNil)
	c.Assert(value, Equals, byte(':'))
}
Example #5
0
func (s *S) TestByteFailure(c *C) {
	value, err := P.Parse(P.Byte(':'), srd("batman"))
	c.Assert(err, NotNil)
	c.Assert(value, Equals, nil)
}
Example #6
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")
}
Example #7
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)
}