123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- package assertions
- import (
- "fmt"
- "runtime"
- )
- var serializer Serializer = new(noopSerializer)
- func GoConveyMode(yes bool) {
- if yes {
- serializer = newSerializer()
- } else {
- serializer = new(noopSerializer)
- }
- }
- type testingT interface {
- Error(args ...interface{})
- }
- type Assertion struct {
- t testingT
- failed bool
- }
- func New(t testingT) *Assertion {
- return &Assertion{t: t}
- }
- func (this *Assertion) Failed() bool {
- return this.failed
- }
- func (this *Assertion) So(actual interface{}, assert assertion, expected ...interface{}) bool {
- ok, result := So(actual, assert, expected...)
- if !ok {
- this.failed = true
- _, file, line, _ := runtime.Caller(1)
- this.t.Error(fmt.Sprintf("\n%s:%d\n%s", file, line, result))
- }
- return ok
- }
- func So(actual interface{}, assert assertion, expected ...interface{}) (bool, string) {
- if result := so(actual, assert, expected...); len(result) == 0 {
- return true, result
- } else {
- return false, result
- }
- }
- func so(actual interface{}, assert func(interface{}, ...interface{}) string, expected ...interface{}) string {
- return assert(actual, expected...)
- }
- type assertion func(actual interface{}, expected ...interface{}) string
- ////////////////////////////////////////////////////////////////////////////
|