Skip to content

Commit fd70851

Browse files
authored
Merge pull request #159 from layer5io/copilot/prevent-negative-marks-validation
Add validation to prevent negative or zero marks in test questions
2 parents 3736423 + fd9de3e commit fd70851

File tree

5 files changed

+12
-1
lines changed

5 files changed

+12
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ resources/
2424

2525
#hugo
2626
.hugo_build.lock
27+
content/
2728

2829
.DS_Store

archetypes/final-test.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ final: true # Indicates that this test is the final exam and must be completed t
1010

1111
questions:
1212
# Multiple Choice Question (Single Answer)
13+
# NOTE: The 'marks' field must be a positive number (greater than 0). Negative or zero values will cause a build error.
1314
- id: "q1"
1415
text: "What keyword is used to define a function in Go?"
1516
type: "multiple_answers"

archetypes/optional-test.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ is_optional: true # Indicates that this test is optional and does not need to be
1010

1111
questions:
1212
# Multiple Choice Question (Single Answer)
13+
# NOTE: The 'marks' field must be a positive number (greater than 0). Negative or zero values will cause a build error.
1314
- id: "q1"
1415
text: "What keyword is used to define a function in Go?"
1516
type: "multiple_answers"

archetypes/test.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ questions:
1212
# Multiple Choice Question (Single Answer)
1313
- id: "q1"
1414
text: "What keyword is used to define a function in Go?"
15-
type: "multiple-answers"
15+
type: "multiple_answers"
1616
marks: 2
1717
explanation: "The 'func' keyword is used to declare functions in Go, similar to how 'function' is used in JavaScript."
1818
options:

layouts/partials/test/single.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@
2020
{{- $questionIds = $questionIds | append (string $id) -}}
2121
{{- end -}}
2222

23+
<!-- Validate: marks must be positive (greater than 0) -->
24+
{{- range $index, $question := $p.questions -}}
25+
{{- $marks := or $question.marks 0 -}}
26+
{{- if le $marks 0 -}}
27+
{{- errorf "Question %d (id: %s) has invalid marks value '%v'. Marks must be greater than 0. Please update the 'marks' field with a positive number. [ %s ]" (add $index 1) $question.id $marks $.File.Path -}}
28+
{{- end -}}
29+
{{- end -}}
30+
2331
{{- $numberOfQuestionSets := div (len $p.questions) $totalQuestionsPerSet -}}
2432

2533
{{- $total := 0 -}}

0 commit comments

Comments
 (0)