Skip to content

Commit

Permalink
Merge pull request #85 from maxatome/json++
Browse files Browse the repository at this point in the history
Json++
  • Loading branch information
maxatome authored Nov 18, 2019
2 parents a156109 + 5eaad3b commit 7d84fc4
Show file tree
Hide file tree
Showing 36 changed files with 3,553 additions and 374 deletions.
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,16 @@ go-testdeep

## Latest news

- 2019/11/18:
- new [`SubJSONOf`] & [`SuperJSONOf`] operators (and their
friends [`CmpSubJSONOf`], [`CmpSuperJSONOf`], [`T.SubJSONOf`] &
[`T.SuperJSONOf`]),
- JSON data can now contain comments and some operator shortcuts;
- 2019/11/01: new [`Catch`] operator;
- 2019/10/31: new [`JSON`] operator (and its friends [`CmpJSON`]
& [`T.JSON`] along with new fully dedicated [`Tag`] operator;
- 2019/10/29: new web site
[go-testdeep.zetta.rocks](https://go-testdeep.zetta.rocks/)
- 2019/09/22: new
[`BeLax` feature](https://godoc.org/github.com/maxatome/go-testdeep#T.BeLax)
with its
[`Lax`](https://godoc.org/github.com/maxatome/go-testdeep#Lax)
operator counterpart (and its friends
[`CmpLax`](https://godoc.org/github.com/maxatome/go-testdeep#CmpLax)
&
[`T.CmpLax`](https://godoc.org/github.com/maxatome/go-testdeep#T.CmpLax));
- see [commits history](https://github.com/maxatome/go-testdeep/commits/master)
for other/older changes.

Expand Down Expand Up @@ -92,11 +89,12 @@ func TestMyApi(t *testing.T) {
Status: http.StatusCreated,
// Header can be tested too… See tdhttp doc.
Body: td.JSON(`
// Note that comments are allowed
{
"id": $id,
"id": $id, // set by the API/DB
"name": "Bob",
"age": 42,
"created_at": "$createdAt",
"created_at": "$createdAt", // set by the API/DB
}`,
td.Tag("id", td.Catch(&id, td.NotZero())), // catch $id and check ≠ 0
td.Tag("created_at", td.All( // ← All combines several operators like a AND
Expand Down Expand Up @@ -258,9 +256,11 @@ See [FAQ](https://go-testdeep.zetta.rocks/faq/).
[`String`]: https://go-testdeep.zetta.rocks/operators/string/
[`Struct`]: https://go-testdeep.zetta.rocks/operators/struct/
[`SubBagOf`]: https://go-testdeep.zetta.rocks/operators/subbagof/
[`SubJSONOf`]: https://go-testdeep.zetta.rocks/operators/subjsonof/
[`SubMapOf`]: https://go-testdeep.zetta.rocks/operators/submapof/
[`SubSetOf`]: https://go-testdeep.zetta.rocks/operators/subsetof/
[`SuperBagOf`]: https://go-testdeep.zetta.rocks/operators/superbagof/
[`SuperJSONOf`]: https://go-testdeep.zetta.rocks/operators/superjsonof/
[`SuperMapOf`]: https://go-testdeep.zetta.rocks/operators/supermapof/
[`SuperSetOf`]: https://go-testdeep.zetta.rocks/operators/supersetof/
[`Tag`]: https://go-testdeep.zetta.rocks/operators/tag/
Expand Down Expand Up @@ -313,9 +313,11 @@ See [FAQ](https://go-testdeep.zetta.rocks/faq/).
[`CmpString`]:https://go-testdeep.zetta.rocks/operators/string/#cmpstring-shortcut
[`CmpStruct`]:https://go-testdeep.zetta.rocks/operators/struct/#cmpstruct-shortcut
[`CmpSubBagOf`]:https://go-testdeep.zetta.rocks/operators/subbagof/#cmpsubbagof-shortcut
[`CmpSubJSONOf`]:https://go-testdeep.zetta.rocks/operators/subjsonof/#cmpsubjsonof-shortcut
[`CmpSubMapOf`]:https://go-testdeep.zetta.rocks/operators/submapof/#cmpsubmapof-shortcut
[`CmpSubSetOf`]:https://go-testdeep.zetta.rocks/operators/subsetof/#cmpsubsetof-shortcut
[`CmpSuperBagOf`]:https://go-testdeep.zetta.rocks/operators/superbagof/#cmpsuperbagof-shortcut
[`CmpSuperJSONOf`]:https://go-testdeep.zetta.rocks/operators/superjsonof/#cmpsuperjsonof-shortcut
[`CmpSuperMapOf`]:https://go-testdeep.zetta.rocks/operators/supermapof/#cmpsupermapof-shortcut
[`CmpSuperSetOf`]:https://go-testdeep.zetta.rocks/operators/supersetof/#cmpsupersetof-shortcut
[`CmpTruncTime`]:https://go-testdeep.zetta.rocks/operators/trunctime/#cmptrunctime-shortcut
Expand Down Expand Up @@ -367,9 +369,11 @@ See [FAQ](https://go-testdeep.zetta.rocks/faq/).
[`T.String`]: https://go-testdeep.zetta.rocks/operators/string/#t-string-shortcut
[`T.Struct`]: https://go-testdeep.zetta.rocks/operators/struct/#t-struct-shortcut
[`T.SubBagOf`]: https://go-testdeep.zetta.rocks/operators/subbagof/#t-subbagof-shortcut
[`T.SubJSONOf`]: https://go-testdeep.zetta.rocks/operators/subjsonof/#t-subjsonof-shortcut
[`T.SubMapOf`]: https://go-testdeep.zetta.rocks/operators/submapof/#t-submapof-shortcut
[`T.SubSetOf`]: https://go-testdeep.zetta.rocks/operators/subsetof/#t-subsetof-shortcut
[`T.SuperBagOf`]: https://go-testdeep.zetta.rocks/operators/superbagof/#t-superbagof-shortcut
[`T.SuperJSONOf`]: https://go-testdeep.zetta.rocks/operators/superjsonof/#t-superjsonof-shortcut
[`T.SuperMapOf`]: https://go-testdeep.zetta.rocks/operators/supermapof/#t-supermapof-shortcut
[`T.SuperSetOf`]: https://go-testdeep.zetta.rocks/operators/supersetof/#t-supersetof-shortcut
[`T.TruncTime`]: https://go-testdeep.zetta.rocks/operators/trunctime/#t-trunctime-shortcut
Expand Down
38 changes: 38 additions & 0 deletions cmp_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,25 @@ func CmpSubBagOf(t TestingT, got interface{}, expectedItems []interface{}, args
return Cmp(t, got, SubBagOf(expectedItems...), args...)
}

// CmpSubJSONOf is a shortcut for:
//
// Cmp(t, got, SubJSONOf(expectedJSON, params...), args...)
//
// See https://godoc.org/github.com/maxatome/go-testdeep#SubJSONOf for details.
//
// Returns true if the test is OK, false if it fails.
//
// "args..." are optional and allow to name the test. This name is
// used in case of failure to qualify the test. If len(args) > 1 and
// the first item of "args" is a string and contains a '%' rune then
// fmt.Fprintf is used to compose the name, else "args" are passed to
// fmt.Fprint. Do not forget it is the name of the test, not the
// reason of a potential failure.
func CmpSubJSONOf(t TestingT, got interface{}, expectedJSON interface{}, params []interface{}, args ...interface{}) bool {
t.Helper()
return Cmp(t, got, SubJSONOf(expectedJSON, params...), args...)
}

// CmpSubMapOf is a shortcut for:
//
// Cmp(t, got, SubMapOf(model, expectedEntries), args...)
Expand Down Expand Up @@ -936,6 +955,25 @@ func CmpSuperBagOf(t TestingT, got interface{}, expectedItems []interface{}, arg
return Cmp(t, got, SuperBagOf(expectedItems...), args...)
}

// CmpSuperJSONOf is a shortcut for:
//
// Cmp(t, got, SuperJSONOf(expectedJSON, params...), args...)
//
// See https://godoc.org/github.com/maxatome/go-testdeep#SuperJSONOf for details.
//
// Returns true if the test is OK, false if it fails.
//
// "args..." are optional and allow to name the test. This name is
// used in case of failure to qualify the test. If len(args) > 1 and
// the first item of "args" is a string and contains a '%' rune then
// fmt.Fprintf is used to compose the name, else "args" are passed to
// fmt.Fprint. Do not forget it is the name of the test, not the
// reason of a potential failure.
func CmpSuperJSONOf(t TestingT, got interface{}, expectedJSON interface{}, params []interface{}, args ...interface{}) bool {
t.Helper()
return Cmp(t, got, SuperJSONOf(expectedJSON, params...), args...)
}

// CmpSuperMapOf is a shortcut for:
//
// Cmp(t, got, SuperMapOf(model, expectedEntries), args...)
Expand Down
Loading

0 comments on commit 7d84fc4

Please sign in to comment.