Skip to content

Commit

Permalink
refactor: introduce new function for creating bugfix, update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nedpals committed Feb 3, 2024
1 parent fefc077 commit b2384a2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 33 deletions.
6 changes: 6 additions & 0 deletions translation.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,9 @@ func (gen *BugFixGenerator) Add(title string, makerFn func(s *BugFixSuggestion))
gen.Suggestions = append(gen.Suggestions, suggestion)
return nil
}

func NewBugFixGenerator(doc *Document) *BugFixGenerator {
return &BugFixGenerator{
Document: doc,
}
}
44 changes: 11 additions & 33 deletions translation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@ func TestBugFixGenerator(t *testing.T) {

t.Run("Add", func(t *testing.T) {
t.Run("Simple", func(t *testing.T) {
gen := &lib.BugFixGenerator{
Document: doc,
}
gen := lib.NewBugFixGenerator(doc)

gen.Add("A descriptive suggestion sentence or phrase", func(s *lib.BugFixSuggestion) {
if s.Title != "A descriptive suggestion sentence or phrase" {
Expand All @@ -186,9 +184,7 @@ func TestBugFixGenerator(t *testing.T) {
})

t.Run("Empty title", func(t *testing.T) {
gen := &lib.BugFixGenerator{
Document: doc,
}
gen := lib.NewBugFixGenerator(doc)

err := gen.Add("", func(s *lib.BugFixSuggestion) {})
if err == nil {
Expand All @@ -201,9 +197,7 @@ func TestBugFixGenerator(t *testing.T) {
})

t.Run("Empty function", func(t *testing.T) {
gen := &lib.BugFixGenerator{
Document: doc,
}
gen := lib.NewBugFixGenerator(doc)

err := gen.Add("A descriptive suggestion sentence or phrase", nil)
if err == nil {
Expand All @@ -216,9 +210,7 @@ func TestBugFixGenerator(t *testing.T) {
})

t.Run("Multiple", func(t *testing.T) {
gen := &lib.BugFixGenerator{
Document: doc,
}
gen := lib.NewBugFixGenerator(doc)

gen.Add("A descriptive suggestion sentence or phrase", func(s *lib.BugFixSuggestion) {})
gen.Add("This is another error message.", func(s *lib.BugFixSuggestion) {})
Expand All @@ -231,9 +223,7 @@ func TestBugFixGenerator(t *testing.T) {

t.Run("Suggestion/AddStep", func(t *testing.T) {
t.Run("Simple", func(t *testing.T) {
gen := &lib.BugFixGenerator{
Document: doc,
}
gen := lib.NewBugFixGenerator(doc)

gen.Add("A descriptive suggestion sentence or phrase", func(s *lib.BugFixSuggestion) {
s.AddStep("This is a step.", func(step *lib.BugFixStep) {
Expand All @@ -249,9 +239,7 @@ func TestBugFixGenerator(t *testing.T) {
})

t.Run("Without period", func(t *testing.T) {
gen := &lib.BugFixGenerator{
Document: doc,
}
gen := lib.NewBugFixGenerator(doc)

gen.Add("A descriptive suggestion sentence or phrase", func(s *lib.BugFixSuggestion) {
s.AddStep("This is a step", func(step *lib.BugFixStep) {
Expand All @@ -263,9 +251,7 @@ func TestBugFixGenerator(t *testing.T) {
})

t.Run("With punctuation", func(t *testing.T) {
gen := &lib.BugFixGenerator{
Document: doc,
}
gen := lib.NewBugFixGenerator(doc)

gen.Add("A descriptive suggestion sentence or phrase", func(s *lib.BugFixSuggestion) {
s.AddStep("Oh wow!", func(step *lib.BugFixStep) {
Expand All @@ -277,9 +263,7 @@ func TestBugFixGenerator(t *testing.T) {
})

t.Run("With string data", func(t *testing.T) {
gen := &lib.BugFixGenerator{
Document: doc,
}
gen := lib.NewBugFixGenerator(doc)

gen.Add("A descriptive suggestion sentence or phrase", func(s *lib.BugFixSuggestion) {
s.AddStep("This is a step with data: %s", "Hello", func(step *lib.BugFixStep) {
Expand All @@ -291,9 +275,7 @@ func TestBugFixGenerator(t *testing.T) {
})

t.Run("With int data", func(t *testing.T) {
gen := &lib.BugFixGenerator{
Document: doc,
}
gen := lib.NewBugFixGenerator(doc)

gen.Add("A descriptive suggestion sentence or phrase", func(s *lib.BugFixSuggestion) {
s.AddStep("This is a step with data: %d", 10, func(step *lib.BugFixStep) {
Expand All @@ -305,9 +287,7 @@ func TestBugFixGenerator(t *testing.T) {
})

t.Run("With mixed data", func(t *testing.T) {
gen := &lib.BugFixGenerator{
Document: doc,
}
gen := lib.NewBugFixGenerator(doc)

gen.Add("A descriptive suggestion sentence or phrase", func(s *lib.BugFixSuggestion) {
s.AddStep("This is a step with data: %s and %d", "Hello", 10, func(step *lib.BugFixStep) {
Expand All @@ -319,9 +299,7 @@ func TestBugFixGenerator(t *testing.T) {
})

t.Run("Empty content", func(t *testing.T) {
gen := &lib.BugFixGenerator{
Document: doc,
}
gen := lib.NewBugFixGenerator(doc)

gen.Add("A descriptive suggestion sentence or phrase", func(s *lib.BugFixSuggestion) {
// recover
Expand Down

0 comments on commit b2384a2

Please sign in to comment.