Package xycond supports to assert or expect many conditions.
It makes source code to be shorter and more readable by using inline commands.
This package has the following features:
- Assert a condition, panic in case condition is false.
- Expect a condition to occur and perform actions on this expectation.
- Panic with an assertion error.
op | time per op |
---|---|
large-map | 293ns |
small-map | 209ns |
large-array | 196507ns |
small-array | 375ns |
large-string-string | 115002ns |
small-string-string | 455ns |
large-string-rune | 194ns |
small-string-rune | 192ns |
- Assert conditions
xycond.AssertFalse(1 == 2)
var x int
xycond.AssertZero(x)
xycond.ExpectFalse(true).Assert("this is a custom assertion message")
- Testing
// Test a condition with *testing.T or *testing.B.
func TestSomething(t *testing.T) {
xycond.ExpectEmpty("").Test(t)
}
- Perform actions on expectation
// Perform actions on an expectation.
xycond.ExpectEqual(1, 2).
True(func() {
fmt.Printf("1 == 2")
}).
False(func() {
fmt.Printf("1 != 2")
})
// Output:
// 1 != 2
- Panic with formatted string
func foo() {
xycond.Panicf("foo %s", "bar")
}
func bar() int {
return xycond.Panic("buzzz").(int)
}