Skip to content

Commit

Permalink
backfill tests for broken references
Browse files Browse the repository at this point in the history
  • Loading branch information
vito committed Sep 30, 2017
1 parent 1d8ef3a commit 41ad8a3
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.
5 changes: 5 additions & 0 deletions errors.go
@@ -0,0 +1,5 @@
package booklit

import "errors"

var ErrBrokenReference = errors.New("broken reference")
7 changes: 2 additions & 5 deletions stages/resolve.go
@@ -1,7 +1,6 @@
package stages

import (
"errors"
"fmt"

"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -51,8 +50,6 @@ func (resolve *Resolve) VisitPreformatted(con booklit.Preformatted) error {
return nil
}

var ErrBrokenReference = errors.New("broken reference")

func (resolve *Resolve) VisitReference(con *booklit.Reference) error {
tags := resolve.Section.FindTag(con.TagName)

Expand All @@ -63,7 +60,7 @@ func (resolve *Resolve) VisitReference(con *booklit.Reference) error {
"section": resolve.Section.Path,
}).Warnf("broken reference: %s", con.TagName)

err = ErrBrokenReference
err = booklit.ErrBrokenReference
case 1:
con.Tag = &tags[0]
default:
Expand All @@ -77,7 +74,7 @@ func (resolve *Resolve) VisitReference(con *booklit.Reference) error {
"defined-in": paths,
}).Warnf("ambiguous reference: %s", con.TagName)

err = ErrBrokenReference
err = booklit.ErrBrokenReference
}

if err == nil {
Expand Down
6 changes: 6 additions & 0 deletions tests/example.go
Expand Up @@ -17,6 +17,7 @@ type Example struct {
Input string
Inputs Files
Outputs Files
Err error
}

type Files map[string]string
Expand All @@ -38,6 +39,11 @@ func (example Example) Run() {

fakePath := filepath.Join(dir, ginkgo.CurrentGinkgoTestDescription().TestText+".lit")
section, err := processor.LoadSource(fakePath, []byte(example.Input))
if example.Err != nil {
Expect(err).To(MatchError(err))
return
}

Expect(err).ToNot(HaveOccurred())

engine := render.NewHTMLRenderingEngine()
Expand Down
31 changes: 31 additions & 0 deletions tests/references_test.go
Expand Up @@ -2,6 +2,7 @@ package tests

import (
. "github.com/onsi/ginkgo/extensions/table"
"github.com/vito/booklit"
)

var _ = DescribeTable("Booklit", (Example).Run,
Expand Down Expand Up @@ -245,4 +246,34 @@ See also \reference{section-c}{the last section}.
`,
},
}),

Entry("ambiguous references", Example{
Input: `\title{Hello, world!}
See also \reference{dupe-tag}{this tag}.
\section{
\title{First Tag}
\target{dupe-tag}{I'm the first tag.}
}
\section{
\title{Second Tag}
\target{dupe-tag}{I'm the second tag.}
}
`,

Err: booklit.ErrBrokenReference,
}),

Entry("missing references", Example{
Input: `\title{Hello, world!}
See also \reference{missing-tag}{this tag}.
`,

Err: booklit.ErrBrokenReference,
}),
)
5 changes: 5 additions & 0 deletions tests/suite_test.go
Expand Up @@ -3,6 +3,7 @@ package tests
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/sirupsen/logrus"

"testing"
)
Expand All @@ -11,3 +12,7 @@ func TestBooklit(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Booklit Suite")
}

var _ = BeforeSuite(func() {
logrus.SetLevel(logrus.FatalLevel)
})

0 comments on commit 41ad8a3

Please sign in to comment.