Skip to content

Commit

Permalink
fix: update translation_test.go texts
Browse files Browse the repository at this point in the history
  • Loading branch information
nedpals committed Feb 3, 2024
1 parent c7570f5 commit 28083a7
Showing 1 changed file with 62 additions and 63 deletions.
125 changes: 62 additions & 63 deletions translation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,87 +20,87 @@ func TestExplainGenerator(t *testing.T) {
t.Run("Add", func(t *testing.T) {
t.Run("Simple", func(t *testing.T) {
gen := &lib.ExplainGenerator{}
gen.Add("This is a simple error message.")
gen.Add("This is a simple error explanation.")

if gen.Builder.String() != "This is a simple error message." {
t.Errorf("Expected 'This is a simple error message.', got %s", gen.Builder.String())
if gen.Builder.String() != "This is a simple error explanation." {
t.Errorf("Expected 'This is a simple error explanation.', got %s", gen.Builder.String())
}
})

t.Run("Simple with string data", func(t *testing.T) {
gen := &lib.ExplainGenerator{}
gen.Add("This is a simple error message with data: %s", "Hello")
gen.Add("This is a simple error explanation with data: %s", "Hello")

if gen.Builder.String() != "This is a simple error message with data: Hello" {
t.Errorf("Expected 'This is a simple error message with data: Hello', got %s", gen.Builder.String())
if gen.Builder.String() != "This is a simple error explanation with data: Hello" {
t.Errorf("Expected 'This is a simple error explanation with data: Hello', got %s", gen.Builder.String())
}
})

t.Run("Simple with int data", func(t *testing.T) {
gen := &lib.ExplainGenerator{}
gen.Add("This is a simple error message with data: %d", 10)
gen.Add("This is a simple error explanation with data: %d", 10)

if gen.Builder.String() != "This is a simple error message with data: 10" {
t.Errorf("Expected 'This is a simple error message with data: 10', got %s", gen.Builder.String())
if gen.Builder.String() != "This is a simple error explanation with data: 10" {
t.Errorf("Expected 'This is a simple error explanation with data: 10', got %s", gen.Builder.String())
}
})

t.Run("Simple with mixed data", func(t *testing.T) {
gen := &lib.ExplainGenerator{}
gen.Add("This is a simple error message with data: %s and %d", "Hello", 10)
gen.Add("This is a simple error explanation with data: %s and %d", "Hello", 10)

if gen.Builder.String() != "This is a simple error message with data: Hello and 10" {
t.Errorf("Expected 'This is a simple error message with data: Hello and 10', got %s", gen.Builder.String())
if gen.Builder.String() != "This is a simple error explanation with data: Hello and 10" {
t.Errorf("Expected 'This is a simple error explanation with data: Hello and 10', got %s", gen.Builder.String())
}
})

t.Run("Append", func(t *testing.T) {
gen := &lib.ExplainGenerator{}
gen.Add("This is a simple error message.")
gen.Add("This is a simple error explanation.")
gen.Add("This is another error message.")

if gen.Builder.String() != "This is a simple error message.This is another error message." {
t.Errorf("Expected 'This is a simple error message.This is another error message.', got %s", gen.Builder.String())
if gen.Builder.String() != "This is a simple error explanation.This is another error message." {
t.Errorf("Expected 'This is a simple error explanation.This is another error message.', got %s", gen.Builder.String())
}
})

t.Run("Append with newline", func(t *testing.T) {
gen := &lib.ExplainGenerator{ErrorName: "TestError"}
gen.Add("This is a simple error message.\n")
gen.Add("This is a simple error explanation.\n")
gen.Add("This is another error message.")

if gen.Builder.String() != "This is a simple error message.\nThis is another error message." {
t.Errorf("Expected 'This is a simple error message.\nThis is another error message.', got %s", gen.Builder.String())
if gen.Builder.String() != "This is a simple error explanation.\nThis is another error message." {
t.Errorf("Expected 'This is a simple error explanation.\nThis is another error message.', got %s", gen.Builder.String())
}
})

t.Run("Append with string data", func(t *testing.T) {
gen := &lib.ExplainGenerator{}
gen.Add("This is a simple error message with data: %s", "Hello")
gen.Add("This is a simple error explanation with data: %s", "Hello")
gen.Add("This is another error message with data: %s", "World")

if gen.Builder.String() != "This is a simple error message with data: HelloThis is another error message with data: World" {
t.Errorf("Expected 'This is a simple error message with data: HelloThis is another error message with data: World', got %s", gen.Builder.String())
if gen.Builder.String() != "This is a simple error explanation with data: HelloThis is another error message with data: World" {
t.Errorf("Expected 'This is a simple error explanation with data: HelloThis is another error message with data: World', got %s", gen.Builder.String())
}
})

t.Run("Append with int data", func(t *testing.T) {
gen := &lib.ExplainGenerator{}
gen.Add("This is a simple error message with data: %d", 10)
gen.Add("This is a simple error explanation with data: %d", 10)
gen.Add("This is another error message with data: %d", 20)

if gen.Builder.String() != "This is a simple error message with data: 10This is another error message with data: 20" {
t.Errorf("Expected 'This is a simple error message with data: 10This is another error message with data: 20', got %s", gen.Builder.String())
if gen.Builder.String() != "This is a simple error explanation with data: 10This is another error message with data: 20" {
t.Errorf("Expected 'This is a simple error explanation with data: 10This is another error message with data: 20', got %s", gen.Builder.String())
}
})

t.Run("Append with mixed data", func(t *testing.T) {
gen := &lib.ExplainGenerator{}
gen.Add("This is a simple error message with data: %s", "Hello")
gen.Add("This is a simple error explanation with data: %s", "Hello")
gen.Add("This is another error message with data: %d", 20)

if gen.Builder.String() != "This is a simple error message with data: HelloThis is another error message with data: 20" {
t.Errorf("Expected 'This is a simple error message with data: HelloThis is another error message with data: 20', got %s", gen.Builder.String())
if gen.Builder.String() != "This is a simple error explanation with data: HelloThis is another error message with data: 20" {
t.Errorf("Expected 'This is a simple error explanation with data: HelloThis is another error message with data: 20', got %s", gen.Builder.String())
}
})

Expand Down Expand Up @@ -174,9 +174,9 @@ func TestBugFixGenerator(t *testing.T) {
Document: doc,
}

gen.Add("This is a simple error message.", func(s *lib.BugFixSuggestion) {
if s.Title != "This is a simple error message." {
t.Errorf("Expected 'This is a simple error message.', got %s", s.Title)
gen.Add("A descriptive suggestion sentence or phrase", func(s *lib.BugFixSuggestion) {
if s.Title != "A descriptive suggestion sentence or phrase" {
t.Errorf("Expected 'A descriptive suggestion sentence or phrase', got %s", s.Title)
}

if s.Doc == nil {
Expand Down Expand Up @@ -205,7 +205,7 @@ func TestBugFixGenerator(t *testing.T) {
Document: doc,
}

err := gen.Add("This is a simple error message.", nil)
err := gen.Add("A descriptive suggestion sentence or phrase", nil)
if err == nil {
t.Errorf("Expected error, got nil")
}
Expand All @@ -220,7 +220,7 @@ func TestBugFixGenerator(t *testing.T) {
Document: doc,
}

gen.Add("This is a simple error message.", func(s *lib.BugFixSuggestion) {})
gen.Add("A descriptive suggestion sentence or phrase", func(s *lib.BugFixSuggestion) {})
gen.Add("This is another error message.", func(s *lib.BugFixSuggestion) {})

if len(gen.Suggestions) != 2 {
Expand All @@ -235,10 +235,10 @@ func TestBugFixGenerator(t *testing.T) {
Document: doc,
}

gen.Add("This is a simple error message.", func(s *lib.BugFixSuggestion) {
s.AddStep("This is a simple step.", func(step *lib.BugFixStep) {
if step.Content != "This is a simple step." {
t.Errorf("Expected 'This is a simple step.', got %s", step.Content)
gen.Add("A descriptive suggestion sentence or phrase", func(s *lib.BugFixSuggestion) {
s.AddStep("This is a step.", func(step *lib.BugFixStep) {
if step.Content != "This is a step." {
t.Errorf("Expected 'This is a step.', got %s", step.Content)
}

if step.Doc == nil {
Expand All @@ -253,10 +253,10 @@ func TestBugFixGenerator(t *testing.T) {
Document: doc,
}

gen.Add("This is a simple error message.", func(s *lib.BugFixSuggestion) {
s.AddStep("This is a simple step", func(step *lib.BugFixStep) {
if step.Content != "This is a simple step." {
t.Errorf("Expected 'This is a simple step.', got %s", step.Content)
gen.Add("A descriptive suggestion sentence or phrase", func(s *lib.BugFixSuggestion) {
s.AddStep("This is a step", func(step *lib.BugFixStep) {
if step.Content != "This is a step." {
t.Errorf("Expected 'This is a step.', got %s", step.Content)
}
})
})
Expand All @@ -267,7 +267,7 @@ func TestBugFixGenerator(t *testing.T) {
Document: doc,
}

gen.Add("This is a simple error message.", func(s *lib.BugFixSuggestion) {
gen.Add("A descriptive suggestion sentence or phrase", func(s *lib.BugFixSuggestion) {
s.AddStep("Oh wow!", func(step *lib.BugFixStep) {
if step.Content != "Oh wow!" {
t.Errorf("Expected 'Oh wow!', got %s", step.Content)
Expand All @@ -281,10 +281,10 @@ func TestBugFixGenerator(t *testing.T) {
Document: doc,
}

gen.Add("This is a simple error message.", func(s *lib.BugFixSuggestion) {
s.AddStep("This is a simple step with data: %s", "Hello", func(step *lib.BugFixStep) {
if step.Content != "This is a simple step with data: Hello." {
t.Errorf("Expected 'This is a simple step with data: Hello.', got %s", step.Content)
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) {
if step.Content != "This is a step with data: Hello." {
t.Errorf("Expected 'This is a step with data: Hello.', got %s", step.Content)
}
})
})
Expand All @@ -295,10 +295,10 @@ func TestBugFixGenerator(t *testing.T) {
Document: doc,
}

gen.Add("This is a simple error message.", func(s *lib.BugFixSuggestion) {
s.AddStep("This is a simple step with data: %d", 10, func(step *lib.BugFixStep) {
if step.Content != "This is a simple step with data: 10." {
t.Errorf("Expected 'This is a simple step with data: 10.', got %s", step.Content)
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) {
if step.Content != "This is a step with data: 10." {
t.Errorf("Expected 'This is a step with data: 10.', got %s", step.Content)
}
})
})
Expand All @@ -309,10 +309,10 @@ func TestBugFixGenerator(t *testing.T) {
Document: doc,
}

gen.Add("This is a simple error message.", func(s *lib.BugFixSuggestion) {
s.AddStep("This is a simple step with data: %s and %d", "Hello", 10, func(step *lib.BugFixStep) {
if step.Content != "This is a simple step with data: Hello and 10." {
t.Errorf("Expected 'This is a simple step with data: Hello and 10.', got %s", step.Content)
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) {
if step.Content != "This is a step with data: Hello and 10." {
t.Errorf("Expected 'This is a step with data: Hello and 10.', got %s", step.Content)
}
})
})
Expand All @@ -323,7 +323,7 @@ func TestBugFixGenerator(t *testing.T) {
Document: doc,
}

gen.Add("This is a simple error message.", func(s *lib.BugFixSuggestion) {
gen.Add("A descriptive suggestion sentence or phrase", func(s *lib.BugFixSuggestion) {
// recover
defer func() {
if r := recover(); r != nil {
Expand All @@ -344,9 +344,9 @@ func TestBugFixGenerator(t *testing.T) {
Document: doc,
}

gen.Add("This is a simple error message.", func(s *lib.BugFixSuggestion) {
gen.Add("A descriptive suggestion sentence or phrase", func(s *lib.BugFixSuggestion) {
// add a = 1 fix
step := s.AddStep("This is a simple step.").
step := s.AddStep("This is a step.").
AddFix(lib.FixSuggestion{
NewText: "\na = 1",
StartPosition: lib.Position{
Expand All @@ -367,16 +367,15 @@ func TestBugFixGenerator(t *testing.T) {
t.Errorf("Expected 1 fix, got %d", len(s.Steps[0].Fixes))
}
})

})

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

gen.Add("This is a simple error message.", func(s *lib.BugFixSuggestion) {
step := s.AddStep("This is a simple step.").
gen.Add("A descriptive suggestion sentence or phrase", func(s *lib.BugFixSuggestion) {
step := s.AddStep("This is a step.").
AddFix(lib.FixSuggestion{
NewText: "Welcome to the world",
StartPosition: lib.Position{
Expand Down Expand Up @@ -417,9 +416,9 @@ func TestBugFixGenerator(t *testing.T) {
Document: doc,
}

gen.Add("This is a simple error message.", func(s *lib.BugFixSuggestion) {
gen.Add("A descriptive suggestion sentence or phrase", func(s *lib.BugFixSuggestion) {
// removes the content inside the print function
step := s.AddStep("This is a simple step.").
step := s.AddStep("This is a step.").
AddFix(lib.FixSuggestion{
NewText: "",
StartPosition: lib.Position{
Expand All @@ -443,9 +442,9 @@ func TestBugFixGenerator(t *testing.T) {
Document: doc,
}

gen.Add("This is a simple error message.", func(s *lib.BugFixSuggestion) {
gen.Add("A descriptive suggestion sentence or phrase", func(s *lib.BugFixSuggestion) {
// removes the content inside the print function
step := s.AddStep("This is a simple step.").
step := s.AddStep("This is a step.").
AddFix(lib.FixSuggestion{
NewText: "",
StartPosition: lib.Position{
Expand Down

0 comments on commit 28083a7

Please sign in to comment.