2018-10-04 21:43:04 +02:00
|
|
|
package core_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2018-10-04 21:46:34 +02:00
|
|
|
"github.com/MontFerret/ferret/pkg/runtime/core"
|
2018-10-04 21:43:04 +02:00
|
|
|
"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())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-10-05 17:51:43 +02:00
|
|
|
func TestTypeError(t *testing.T) {
|
|
|
|
Convey("Should match", t, func() {
|
2018-10-05 18:07:31 +02:00
|
|
|
e := core.TypeError(core.BooleanType)
|
2018-10-05 17:51:43 +02:00
|
|
|
So(e, ShouldNotBeNil)
|
|
|
|
|
2018-10-05 18:07:31 +02:00
|
|
|
e = core.TypeError(core.BooleanType, core.BooleanType)
|
2018-10-05 17:51:43 +02:00
|
|
|
So(e, ShouldNotBeNil)
|
|
|
|
|
2018-10-05 18:07:31 +02:00
|
|
|
e = core.TypeError(core.BooleanType, core.BooleanType, core.IntType, core.FloatType)
|
2018-10-05 17:51:43 +02:00
|
|
|
So(e, ShouldNotBeNil)
|
|
|
|
|
|
|
|
cause := errors.New("invalid type: expected none or boolean or int or float, but got none")
|
2018-10-05 18:07:31 +02:00
|
|
|
e = core.TypeError(core.NoneType, core.NoneType, core.BooleanType, core.IntType, core.FloatType)
|
2018-10-05 17:51:43 +02:00
|
|
|
So(e.Error(), ShouldEqual, cause.Error())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-10-04 21:43:04 +02:00
|
|
|
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())
|
|
|
|
})
|
|
|
|
}
|