expand coding task example

This commit is contained in:
Robin Olsen
2026-02-19 10:43:58 +01:00
parent 28ff6716a1
commit cf0c9a1880

View File

@@ -2,6 +2,9 @@ package tasks
import (
"context"
"fmt"
"os"
"strings"
"github.com/LazyBachelor/LazyPM/internal/service"
"github.com/LazyBachelor/LazyPM/pkg/task"
@@ -13,6 +16,11 @@ const codingDescription = `You are tasked with writing a simple function.
Write a function that takes two integers and returns their sum.
The function should be named "Add" and be part of the "coding" package.`
var textFileContent = codingDescription + `
Please write your code below this line!
############################################################
`
type CodingTask struct {
svc *service.Services
}
@@ -41,9 +49,48 @@ func (t *CodingTask) Questions(interfaceType task.InterfaceType) (questions task
}
func (t *CodingTask) Setup(ctx context.Context) error {
if err := t.svc.DeleteIssues(); err != nil {
return err
}
content := textFileContent
if err := os.WriteFile("./code.txt", []byte(content), 0644); err != nil {
return err
}
return nil
}
func (t *CodingTask) Validate(ctx context.Context) (bool, error) {
file, err := os.ReadFile("./code.txt")
if err != nil {
return false, err
}
if string(file) == "" {
return false, fmt.Errorf("the file is empty")
}
code, ok := strings.CutPrefix(string(file), textFileContent)
if !ok {
return false, fmt.Errorf("the file content is not in the expected format")
}
code = strings.TrimSpace(code)
if !strings.Contains(code, "package coding") {
return false, fmt.Errorf("the code does not belong to the 'coding' package")
}
if !strings.Contains(code, "func Add") {
return false, fmt.Errorf("the function 'Add' is not defined")
}
if !strings.Contains(code, "return") {
return false, fmt.Errorf("the function does not contain a return statement")
}
return true, nil
}