From a03f1707380bf9b811fd7490aeb521d0ecbac4be Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Tue, 12 Mar 2024 12:14:46 +0100 Subject: [PATCH] Add TestSpell function in spelling_test.go Added a new unit test, TestSpell, to the spelling_test.go file. This new test safely triggers several different spell checking scenarios, from empty strings to non-alphabetical characters. As a result, the function's reliability and robustness is significantly improved. --- spelling_test.go | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/spelling_test.go b/spelling_test.go index bfc3d6c..82fe73f 100644 --- a/spelling_test.go +++ b/spelling_test.go @@ -51,3 +51,62 @@ func TestConvertByteToWord(t *testing.T) { }) } } + +func TestSpell(t *testing.T) { + tests := []struct { + name string + input string + want string + wantErr bool + }{ + { + name: "empty string", + input: "", + want: "", + wantErr: false, + }, + { + name: "single character", + input: "a", + want: "alfa", + wantErr: false, + }, + { + name: "multiple characters", + input: "abc", + want: "alfa/bravo/charlie", + wantErr: false, + }, + { + name: "non-alphabetic character", + input: "1", + want: "ONE", + wantErr: false, + }, + { + name: "mixed alphabetic and non-alphabetic characters", + input: "a1", + want: "alfa/ONE", + wantErr: false, + }, + { + name: "not supported characters", + input: "üäö߀", + want: "", + wantErr: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := Spell(tt.input) + if (err != nil) != tt.wantErr { + t.Errorf("Spell() error = %s, wantErr %t", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("Spell() = %s, want %s", got, tt.want) + } + }) + } +}