From 91a68607c389a3a9107d1fd3266299c7f9e92734 Mon Sep 17 00:00:00 2001 From: Ned Palacios Date: Sat, 3 Feb 2024 21:39:02 +0800 Subject: [PATCH] refactor: introduce new fn for creating explaingen with error, update tests --- translation.go | 6 ++++++ translation_test.go | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/translation.go b/translation.go index de88096..145d718 100644 --- a/translation.go +++ b/translation.go @@ -39,6 +39,12 @@ func (gen *ExplainGenerator) CreateSection(name string) *ExplainGenerator { return gen.Sections[name] } +func NewExplainGeneratorForError(name string) *ExplainGenerator { + return &ExplainGenerator{ + ErrorName: name, + } +} + type BugFixSuggestion struct { Title string Steps []*BugFixStep diff --git a/translation_test.go b/translation_test.go index d3fd28f..5449857 100644 --- a/translation_test.go +++ b/translation_test.go @@ -10,7 +10,7 @@ import ( func TestExplainGenerator(t *testing.T) { t.Run("errorName", func(t *testing.T) { - gen := &lib.ExplainGenerator{ErrorName: "TestError"} + gen := lib.NewExplainGeneratorForError("TestError") if gen.ErrorName != "TestError" { t.Errorf("Expected 'TestError', got %s", gen.ErrorName) @@ -65,7 +65,7 @@ func TestExplainGenerator(t *testing.T) { }) t.Run("Append with newline", func(t *testing.T) { - gen := &lib.ExplainGenerator{ErrorName: "TestError"} + gen := lib.NewExplainGeneratorForError("TestError") gen.Add("This is a simple error explanation.\n") gen.Add("This is another error message.")