-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port
codec
package tests to quicktest
Implement `NodeContentEquals` quicktest checker that checks two given nodes have equal content by comparing their printout using `printer`. This simplifies the tests that use `datamode.DeepEqual` by performing an equivalent check while producing a human-readable error when nodes are not equal. The naming for this check is inspired by a similar equality check in quicktest, named `ContentEquals`. Port the tests in `codec` package to quicktest; use: - `qt.Assert` for `wish.Require` - `qt.Check` for `wish.Wish` - `qt.IsTrue` for ShouldEqual` over `true` - `qt.IsFalse` for `ShouldEqual` over `false` - `qt.IsNil` for `ShouldEqual` over `nil` - `NodeContentEquals` for `ShouldEqual` over nodes Address TODO in node tests by using `NodeContentEquals` to check node equality. Relates to: - #219
- Loading branch information
Showing
10 changed files
with
170 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package tests | ||
|
||
import ( | ||
"errors" | ||
|
||
qt "github.com/frankban/quicktest" | ||
|
||
"github.com/ipld/go-ipld-prime/datamodel" | ||
"github.com/ipld/go-ipld-prime/printer" | ||
) | ||
|
||
// NodeContentEquals prints the content of the actual and expected nodes using printer.Sprint, and | ||
// checks that the generated strings are identical. | ||
// | ||
// See: printer.Sprint. | ||
var NodeContentEquals = &nodeContentEqualsChecker{} | ||
|
||
type nodeContentEqualsChecker struct{} | ||
|
||
func (n *nodeContentEqualsChecker) Check(got interface{}, args []interface{}, note func(key string, value interface{})) error { | ||
want := args[0] | ||
if want == nil { | ||
return qt.IsNil.Check(got, args, note) | ||
} | ||
wantNode, ok := want.(datamodel.Node) | ||
if !ok { | ||
return errors.New("this checker only supports checking datamodel.Node values") | ||
} | ||
wantPrint := printer.Sprint(wantNode) | ||
|
||
gotNode, ok := got.(datamodel.Node) | ||
if !ok { | ||
return errors.New("this checker only supports checking datamodel.Node values") | ||
} | ||
gotPrint := printer.Sprint(gotNode) | ||
return qt.Equals.Check(gotPrint, []interface{}{wantPrint}, note) | ||
} | ||
|
||
func (n *nodeContentEqualsChecker) ArgNames() []string { | ||
return []string{"got", "want node"} | ||
} |
Oops, something went wrong.