1 Commits

Author SHA1 Message Date
Robin Olsen
5d3fa86627 make this work again 2026-04-03 11:59:19 +02:00

View File

@@ -3,7 +3,6 @@ package tasks
import ( import (
"context" "context"
"os" "os"
"strings"
"time" "time"
"charm.land/huh/v2" "charm.land/huh/v2"
@@ -23,9 +22,7 @@ Your task:
const desc = `There is a major logical error in this code, you need to fix it. const desc = `There is a major logical error in this code, you need to fix it.
Change the function logic so that it correctly adds two numbers together instead of subtracting them.` Change the function logic so that it correctly adds two numbers together instead of subtracting them.`
var textFileDescription = ` var textFileDescription = `# Instructions for the coding task
# Instructions for the coding task
` + desc + ` ` + desc + `
############################################################` ############################################################`
@@ -36,7 +33,7 @@ function Add(a, b int) int {
} }
` `
var textFileContent = codingDescription + textFileDescription + "\n" + code var textFileContent = textFileDescription + "\n" + code
type CodingTask struct { type CodingTask struct {
done bool done bool
@@ -160,19 +157,13 @@ func (t *CodingTask) Validate(ctx context.Context) ValidationFeedback {
return expect.ValidationFeedback return expect.ValidationFeedback
} }
fileContent, err := os.ReadFile("./code.txt") code, err := os.ReadFile("./code.txt")
if err != nil { if err != nil {
expect.Fail("Error reading code.txt file: " + err.Error()) expect.Fail("Error reading code.txt file: " + err.Error())
return expect.ValidationFeedback return expect.ValidationFeedback
} }
code, ok := strings.CutPrefix(string(fileContent), textFileDescription+"\n") expect.Contains(string(code), "a + b", "Function logic")
if !ok {
expect.Fail("The content of code.txt does not match the expected format.")
return expect.ValidationFeedback
}
expect.Contains(code, "a + b", "Function logic")
if !expect.Valid() { if !expect.Valid() {
return expect.ValidationFeedback return expect.ValidationFeedback
} }