func runTest(t *testing.T, fp interface{}, name string, content string, ev interface{}, errCount int) { var mainData2 *data.MainData mainData := &data.MainData{} mainData.ParseData = gparselib.NewParseData(name, content) callWithInterfaceFunc(fp, "SetOutPort", func(dat interface{}) { mainData2 = dat.(*data.MainData) }) callWithMainData(fp, "InPort", mainData) Convey("Parsing '"+name+"', ...", t, func() { Convey(`... should create a result.`, func() { So(mainData2.ParseData.Result, ShouldNotBeNil) }) valueTest(mainData2.ParseData.Result.Value, ev) Convey(`... should give the right number of errors.`, func() { errs := mainData2.ParseData.Result.Feedback.Errors if errCount <= 0 { So(errs, ShouldBeNil) } else { So(len(errs), ShouldEqual, errCount) } }) Convey(`... should give the right error text.`, func() { errs := mainData2.ParseData.Result.Feedback.Errors if errCount > 0 { if len(errs) != errCount { So(printErrors(errs), ShouldBeBlank) } else { So(errs[errCount-1].Error(), ShouldNotBeNil) } } }) }) }
func main() { var mainData2 *data.MainData mainData := &data.MainData{} mainData.ParseData = gparselib.NewParseData("testfile", "smallIdent") p := parser.NewParseSmallIdent() p.SetOutPort(func(dat interface{}) { mainData2 = dat.(*data.MainData) }) p.InPort(mainData) fmt.Printf("Result.Value: %#v\n", mainData2.ParseData.Result.Value) }