1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-16 11:37:36 +02:00
ferret/pkg/runtime/core/errors_test.go
Tim Voronov 1af8b37a0f
New type system (#232)
* New type system

* Fixed dot notation for HTML elements
2019-02-13 12:31:18 -05:00

50 lines
1.1 KiB
Go

package core_test
import (
"testing"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/pkg/errors"
. "github.com/smartystreets/goconvey/convey"
)
func TestSourceError(t *testing.T) {
Convey("Should match", t, func() {
sm := core.NewSourceMap("test", 1, 1)
msg := "test at 1:1"
cause := errors.New("cause")
e := errors.Errorf("%s: %s", cause.Error(), msg)
cse := core.SourceError(sm, cause)
So(cse, ShouldNotBeNil)
So(cse.Error(), ShouldEqual, e.Error())
})
}
func TestTypeError(t *testing.T) {
Convey("Should match", t, func() {
e := core.TypeError(TypeA{})
So(e, ShouldNotBeNil)
e = core.TypeError(TypeA{}, TypeB{})
So(e, ShouldNotBeNil)
cause := errors.New("invalid type: expected type_b or type_c, but got type_a")
e = core.TypeError(TypeA{}, TypeB{}, TypeC{})
So(e.Error(), ShouldEqual, cause.Error())
})
}
func TestError(t *testing.T) {
Convey("Should match", t, func() {
msg := "test message"
cause := errors.New("cause")
e := errors.Errorf("%s: %s", cause.Error(), msg)
ce := core.Error(cause, msg)
So(ce, ShouldNotBeNil)
So(ce.Error(), ShouldEqual, e.Error())
})
}