Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(test): remove 'MatchDocumentFragmentGroups' matcher #1091

Merged
merged 1 commit into from
Oct 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions pkg/parser/attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var _ = Describe("attributes", func() {
},
},
}
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragmentGroups(expected))
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragments(expected))
})

It("block image with empty alt and extra whitespace", func() {
Expand All @@ -54,7 +54,7 @@ var _ = Describe("attributes", func() {
},
},
}
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragmentGroups(expected))
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragments(expected))
})

It("block image with empty positional parameters", func() {
Expand All @@ -74,7 +74,7 @@ var _ = Describe("attributes", func() {
},
},
}
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragmentGroups(expected))
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragments(expected))
})

It("block image with empty first parameter, non-empty width", func() {
Expand All @@ -97,7 +97,7 @@ var _ = Describe("attributes", func() {
},
},
}
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragmentGroups(expected))
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragments(expected))
})

It("block image with double quoted alt", func() {
Expand All @@ -120,7 +120,7 @@ var _ = Describe("attributes", func() {
},
},
}
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragmentGroups(expected))
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragments(expected))
})

It("block image with double quoted alt and escaped double quotes", func() {
Expand All @@ -143,7 +143,7 @@ var _ = Describe("attributes", func() {
},
},
}
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragmentGroups(expected))
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragments(expected))
})

It("block image with single quoted alt and escaped single quotes", func() {
Expand All @@ -166,7 +166,7 @@ var _ = Describe("attributes", func() {
},
},
}
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragmentGroups(expected))
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragments(expected))
})

It("block image with double quoted alt and standalone backslash", func() {
Expand All @@ -189,7 +189,7 @@ var _ = Describe("attributes", func() {
},
},
}
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragmentGroups(expected))
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragments(expected))
})

It("block image with single quoted alt and standalone backslash", func() {
Expand All @@ -212,7 +212,7 @@ var _ = Describe("attributes", func() {
},
},
}
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragmentGroups(expected))
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragments(expected))
})

It("block image alt and named pair", func() {
Expand All @@ -238,7 +238,7 @@ var _ = Describe("attributes", func() {
}
result, err := ParseDocumentFragments(source)
Expect(err).NotTo(HaveOccurred())
Expect(result).To(MatchDocumentFragmentGroups(expected))
Expect(result).To(MatchDocumentFragments(expected))
})

It("block image alt, width, height, and named pair", func() {
Expand All @@ -263,7 +263,7 @@ var _ = Describe("attributes", func() {
},
},
}
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragmentGroups(expected))
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragments(expected))
})

It("block image alt, width, height, and named pair (spacing)", func() {
Expand All @@ -290,7 +290,7 @@ var _ = Describe("attributes", func() {
},
},
}
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragmentGroups(expected))
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragments(expected))
})

It("block image alt, width, height, and named pair embedded quote", func() {
Expand All @@ -317,7 +317,7 @@ var _ = Describe("attributes", func() {
},
},
}
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragmentGroups(expected))
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragments(expected))
})
})

Expand Down Expand Up @@ -350,7 +350,7 @@ var _ = Describe("attributes", func() {
},
},
}
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragmentGroups(expected))
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragments(expected))
})

It("section with attributes detached", func() {
Expand Down Expand Up @@ -382,7 +382,7 @@ var _ = Describe("attributes", func() {
},
},
}
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragmentGroups(expected))
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragments(expected))
})
})

Expand Down Expand Up @@ -410,7 +410,7 @@ var _ = Describe("attributes", func() {
},
},
}
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragmentGroups(expected))
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragments(expected))
})
})
})
Expand Down
6 changes: 3 additions & 3 deletions pkg/parser/blank_line_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ second paragraph`
},
},
}
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragmentGroups(expected))
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragments(expected))
})

It("blank line with spaces and tabs between 2 paragraphs and after second paragraph", func() {
Expand Down Expand Up @@ -126,7 +126,7 @@ second paragraph
},
},
}
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragmentGroups(expected))
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragments(expected))
})

It("blank line with attributes", func() {
Expand All @@ -136,7 +136,7 @@ second paragraph
expected := []types.DocumentFragment{
// standalone attribute is ignored
}
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragmentGroups(expected))
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragments(expected))
})
})

Expand Down
2 changes: 1 addition & 1 deletion pkg/parser/delimited_block_passthrough_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ another paragraph`
},
},
}
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragmentGroups(expected))
Expect(ParseDocumentFragments(source)).To(MatchDocumentFragments(expected))
})
})

Expand Down
2 changes: 1 addition & 1 deletion pkg/parser/document_processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func ParseDocument(r io.Reader, config *configuration.Configuration, opts ...Opt
CollectFootnotes(footnotes, done,
ApplySubstitutions(NewParseContext(config, opts...), done, // needs to be before 'ArrangeLists'
RefineFragments(NewParseContext(config, opts...), r, done,
ParseFragments(NewParseContext(config, opts...), r, done),
ParseDocumentFragments(NewParseContext(config, opts...), r, done),
),
),
),
Expand Down
2 changes: 1 addition & 1 deletion pkg/parser/document_processing_parse_fragments.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
log "github.com/sirupsen/logrus"
)

func ParseFragments(ctx *ParseContext, source io.Reader, done <-chan interface{}) <-chan types.DocumentFragment {
func ParseDocumentFragments(ctx *ParseContext, source io.Reader, done <-chan interface{}) <-chan types.DocumentFragment {
resultStream := make(chan types.DocumentFragment, bufferSize)
go func() {
defer close(resultStream)
Expand Down
49 changes: 0 additions & 49 deletions testsupport/document_fragment_groups_matcher.go

This file was deleted.

77 changes: 0 additions & 77 deletions testsupport/document_fragment_groups_matcher_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion testsupport/document_fragment_matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type documentFragmentMatcher struct {

func (m *documentFragmentMatcher) Match(actual interface{}) (success bool, err error) {
if _, ok := actual.(types.DocumentFragment); !ok {
return false, errors.Errorf("MatchDocumentFragment matcher expects a types.DocumentFragment (actual: %T)", actual)
return false, errors.Errorf("MatchDocumentFragment matcher expects a 'types.DocumentFragment' (actual: %T)", actual)
}
if diff := cmp.Diff(m.expected, actual, opts...); diff != "" {
if log.IsLevelEnabled(log.DebugLevel) {
Expand Down
2 changes: 1 addition & 1 deletion testsupport/document_fragment_matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var _ = Describe("document fragments matcher", func() {
result, err := matcher.Match(1)
// then
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("MatchDocumentFragment matcher expects a types.DocumentFragment (actual: int)"))
Expect(err.Error()).To(Equal("MatchDocumentFragment matcher expects a 'types.DocumentFragment' (actual: int)"))
Expect(result).To(BeFalse())
})

Expand Down
8 changes: 4 additions & 4 deletions testsupport/document_fragments_matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ type documentFragmentsMatcher struct {

func (m *documentFragmentsMatcher) Match(actual interface{}) (success bool, err error) {
if _, ok := actual.([]types.DocumentFragment); !ok {
return false, errors.Errorf("MatchDocumentFragments matcher expects an array of types.DocumentFragment (actual: %T)", actual)
return false, errors.Errorf("MatchDocumentFragments matcher expects a '[]types.DocumentFragment' (actual: %T)", actual)
}
if diff := cmp.Diff(m.expected, actual, opts...); diff != "" {
if log.IsLevelEnabled(log.DebugLevel) {
log.Debugf("actual raw document:\n%s", spew.Sdump(actual))
log.Debugf("expected raw document:\n%s", spew.Sdump(m.expected))
log.Debugf("actual document fragments:\n%s", spew.Sdump(actual))
log.Debugf("expected document fragments:\n%s", spew.Sdump(m.expected))
}
m.diffs = cmp.Diff(spew.Sdump(m.expected), spew.Sdump(actual))
m.diffs = diff
return false, nil
}
return true, nil
Expand Down
7 changes: 3 additions & 4 deletions testsupport/document_fragments_matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import (
"github.com/bytesparadise/libasciidoc/testsupport"
"github.com/google/go-cmp/cmp"

"github.com/davecgh/go-spew/spew"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("document fragments matcher", func() {
var _ = Describe("document fragment matcher", func() {

// given
expected := []types.DocumentFragment{
Expand Down Expand Up @@ -60,7 +59,7 @@ var _ = Describe("document fragments matcher", func() {
// then
Expect(err).ToNot(HaveOccurred())
Expect(result).To(BeFalse())
diffs := cmp.Diff(spew.Sdump(expected), spew.Sdump(actual))
diffs := cmp.Diff(expected, actual)
Expect(matcher.FailureMessage(actual)).To(Equal(fmt.Sprintf("expected document fragments to match:\n%s", diffs)))
Expect(matcher.NegatedFailureMessage(actual)).To(Equal(fmt.Sprintf("expected document fragments not to match:\n%s", diffs)))
})
Expand All @@ -70,7 +69,7 @@ var _ = Describe("document fragments matcher", func() {
result, err := matcher.Match(1)
// then
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("MatchDocumentFragments matcher expects an array of types.DocumentFragment (actual: int)"))
Expect(err.Error()).To(Equal("MatchDocumentFragments matcher expects a '[]types.DocumentFragment' (actual: int)"))
Expect(result).To(BeFalse())
})

Expand Down
Loading