Skip to content
Snippets Groups Projects
Commit 424f0251 authored by Ammar Ahmed's avatar Ammar Ahmed :speech_balloon:
Browse files

add prefix check for isolation prompts

parent 2ecca693
No related branches found
No related tags found
No related merge requests found
...@@ -75,7 +75,6 @@ func TestGetOllamaResponse(t *testing.T) { ...@@ -75,7 +75,6 @@ func TestGetOllamaResponse(t *testing.T) {
} }
// Test for prompts. // Test for prompts.
var promptTestCases = []struct { var promptTestCases = []struct {
name string name string
prompt string prompt string
...@@ -91,24 +90,22 @@ var promptTestCases = []struct { ...@@ -91,24 +90,22 @@ var promptTestCases = []struct {
{"Reverse the string rust.", "Reverse the string 'ammar'", extraction.RustPrompt, []string{"```rust", "```"}}, {"Reverse the string rust.", "Reverse the string 'ammar'", extraction.RustPrompt, []string{"```rust", "```"}},
} }
// Test function to verify the prefix and suffix of responses from GetOllamaResponse
func TestGetOllamaResponsePrompts(t *testing.T) { func TestGetOllamaResponsePrompts(t *testing.T) {
for _, tc := range promptTestCases { for _, tc := range promptTestCases {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
// Call the function to get the response
response, _, _ := GetOllamaResponse(tc.prompt+tc.suffixStr, []int{}) response, _, _ := GetOllamaResponse(tc.prompt+tc.suffixStr, []int{})
var prefix string
if tc.shouldContain[0] == "```go" { // Check if the response starts with the expected prefix
prefix = response[0:5] if strings.HasPrefix(response, tc.shouldContain[0]) {
if prefix != tc.shouldContain[0] { // Check if the response ends with "```"
t.Errorf("Test faild expected %v got %v", tc.shouldContain[0], response[0:5]) if !strings.HasSuffix(response, "```") {
t.Errorf("Test %s failed: expected response to end with ```; got %q", tc.name, response)
} }
} else { } else {
prefix = response[0:7] t.Errorf("Test %s failed: expected response to start with %q; got %q", tc.name, tc.shouldContain[0], response)
if prefix != tc.shouldContain[1] {
t.Errorf("Test faild expected %v got %v", tc.shouldContain[0], response[0:7])
}
} }
}) })
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment