diff --git a/parser/fixtures/file1.go b/parser/fixtures/file1.go new file mode 100644 index 0000000..419679f --- /dev/null +++ b/parser/fixtures/file1.go @@ -0,0 +1,11 @@ +package file1 + +// TODO: 1 + +// FIXME: 2 + +// OPTIMIZE: 3 + +// BUG: 4 + +// BAD SMELL: 5 diff --git a/parser/parser_suite_test.go b/parser/parser_suite_test.go new file mode 100644 index 0000000..3a7da0d --- /dev/null +++ b/parser/parser_suite_test.go @@ -0,0 +1,13 @@ +package parser_test + +import ( + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + + "testing" +) + +func TestParser(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Parser Suite") +} diff --git a/parser/parser_test.go b/parser/parser_test.go new file mode 100644 index 0000000..a60d89f --- /dev/null +++ b/parser/parser_test.go @@ -0,0 +1,81 @@ +package parser_test + +import ( + . "github.com/cthulhu/go-notes/parser" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +var _ = Describe("Parser", func() { + Context("All annotations", func() { + It("returns information about annotations", func() { + parser := New(false, false, false, "") + Expect(parser.Parse("fixtures/file1.go")).NotTo(HaveOccurred()) + aggregated := parser.Aggregate() + Expect(aggregated).To(ContainSubstring("TODO: 1")) + Expect(aggregated).To(ContainSubstring("FIXME: 2")) + Expect(aggregated).To(ContainSubstring("OPTIMIZE: 3")) + Expect(aggregated).NotTo(ContainSubstring("BUG: 4")) + Expect(aggregated).NotTo(ContainSubstring("BAD SMELL: 5")) + }) + }) + Context("only todos", func() { + It("returns information about annotations", func() { + parser := New(false, true, false, "") + Expect(parser.Parse("fixtures/file1.go")).NotTo(HaveOccurred()) + aggregated := parser.Aggregate() + Expect(aggregated).To(ContainSubstring("TODO: 1")) + Expect(aggregated).NotTo(ContainSubstring("FIXME: 2")) + Expect(aggregated).NotTo(ContainSubstring("OPTIMIZE: 3")) + Expect(aggregated).NotTo(ContainSubstring("BUG: 4")) + Expect(aggregated).NotTo(ContainSubstring("BAD SMELL: 5")) + }) + }) + Context("only fixme's", func() { + It("returns information about annotations", func() { + parser := New(true, false, false, "") + Expect(parser.Parse("fixtures/file1.go")).NotTo(HaveOccurred()) + aggregated := parser.Aggregate() + Expect(aggregated).NotTo(ContainSubstring("TODO: 1")) + Expect(aggregated).To(ContainSubstring("FIXME: 2")) + Expect(aggregated).NotTo(ContainSubstring("OPTIMIZE: 3")) + Expect(aggregated).NotTo(ContainSubstring("BUG: 4")) + Expect(aggregated).NotTo(ContainSubstring("BAD SMELL: 5")) + }) + }) + Context("only optimizes", func() { + It("returns information about annotations", func() { + parser := New(false, false, true, "") + Expect(parser.Parse("fixtures/file1.go")).NotTo(HaveOccurred()) + aggregated := parser.Aggregate() + Expect(aggregated).NotTo(ContainSubstring("TODO: 1")) + Expect(aggregated).NotTo(ContainSubstring("FIXME: 2")) + Expect(aggregated).To(ContainSubstring("OPTIMIZE: 3")) + Expect(aggregated).NotTo(ContainSubstring("BUG: 4")) + Expect(aggregated).NotTo(ContainSubstring("BAD SMELL: 5")) + }) + }) + Context("custom annotation", func() { + It("returns information about BUG", func() { + parser := New(false, false, false, "BUG") + Expect(parser.Parse("fixtures/file1.go")).NotTo(HaveOccurred()) + aggregated := parser.Aggregate() + Expect(aggregated).NotTo(ContainSubstring("TODO: 1")) + Expect(aggregated).NotTo(ContainSubstring("FIXME: 2")) + Expect(aggregated).NotTo(ContainSubstring("OPTIMIZE: 3")) + Expect(aggregated).To(ContainSubstring("BUG: 4")) + Expect(aggregated).NotTo(ContainSubstring("BAD SMELL: 5")) + }) + It("returns information about BAD SMELL", func() { + parser := New(false, false, false, "BUG") + Expect(parser.Parse("fixtures/file1.go")).NotTo(HaveOccurred()) + aggregated := parser.Aggregate() + Expect(aggregated).NotTo(ContainSubstring("TODO: 1")) + Expect(aggregated).NotTo(ContainSubstring("FIXME: 2")) + Expect(aggregated).NotTo(ContainSubstring("OPTIMIZE: 3")) + Expect(aggregated).To(ContainSubstring("BUG: 4")) + Expect(aggregated).NotTo(ContainSubstring("BAD SMELL: 5")) + }) + }) +})