-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CLI flags to output well-formatted optional question attributes. (#…
…123) * Add CLI flags to output well-formatted optional question attributes. This change is backward compatible with the current learn interface. This commit adds three new flags to the `learn md` command: - `--with-explanation/-e` (bool) which creates explanation attributes for correct and incorrect responses - `--with-rubric/-r` (bool) which creates rubric attributes - `--with-hints/-n` (int) which creates the indicated number of hint attributes Without the minimal flag, the comments are preserved in the question as it previously worked. If a user specifies one of the above flags, then the corresponding comment is removed from the final output. * Simplify difference between minimal and maximal output --------- Co-authored-by: Curtis Schlak <[email protected]>
- Loading branch information
1 parent
b1f669d
commit ef65ac2
Showing
3 changed files
with
373 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
package cmd | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
var questionTypes = []string{ | ||
"mc", | ||
"cb", | ||
"tl", | ||
"sa", | ||
"nb", | ||
"pg", | ||
"or", | ||
"js", | ||
"ja", | ||
"py", | ||
"sq", | ||
"rb", | ||
"up", | ||
"cs", | ||
"pr", | ||
"tpr", | ||
} | ||
|
||
func Test_AttributesCommentsOccurInMaximalWithNoAttributes(t *testing.T) { | ||
PrintTemplate = false | ||
Minimal = false | ||
WithExplanation = false | ||
WithRubric = false | ||
WithHints = 0 | ||
|
||
for _, command := range questionTypes { | ||
t.Run(command, func(t2 *testing.T) { | ||
template, _ := getTemp(command) | ||
rendered := template.renderTemplate() | ||
|
||
if !strings.Contains(rendered, blockHeader) { | ||
t2.Errorf("%s did not have block header", command) | ||
} | ||
if !strings.Contains(rendered, hintTemplateSilent) { | ||
t2.Errorf("%s did not have hint comment", command) | ||
} | ||
if !strings.Contains(rendered, rubricTemplateSilent) { | ||
t2.Errorf("%s did not have rubric comment", command) | ||
} | ||
if !strings.Contains(rendered, explanationTemplateSilent) { | ||
t2.Errorf("%s did not have explanation comment", command) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func Test_ExplanationBlockAppearsWhenTrueInMaximal(t *testing.T) { | ||
PrintTemplate = false | ||
Minimal = false | ||
WithExplanation = true | ||
WithRubric = false | ||
WithHints = 0 | ||
|
||
for _, command := range questionTypes { | ||
t.Run(command, func(t2 *testing.T) { | ||
template, _ := getTemp(command) | ||
rendered := template.renderTemplate() | ||
|
||
if !strings.Contains(rendered, explanationTemplate) { | ||
t2.Errorf("%s did not have explanation block", command) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func Test_RubricBlockAppearsWhenTrueInMaximal(t *testing.T) { | ||
PrintTemplate = false | ||
Minimal = false | ||
WithExplanation = false | ||
WithRubric = true | ||
WithHints = 0 | ||
|
||
for _, command := range questionTypes { | ||
t.Run(command, func(t2 *testing.T) { | ||
template, _ := getTemp(command) | ||
rendered := template.renderTemplate() | ||
|
||
if !strings.Contains(rendered, rubricTemplate) { | ||
t2.Errorf("%s did not have rubric block", command) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func Test_HintBlockAppearsWhenTrueInMaximal(t *testing.T) { | ||
PrintTemplate = false | ||
Minimal = false | ||
WithExplanation = false | ||
WithRubric = true | ||
WithHints = 1 | ||
|
||
for _, command := range questionTypes { | ||
t.Run(command, func(t2 *testing.T) { | ||
template, _ := getTemp(command) | ||
rendered := template.renderTemplate() | ||
|
||
if !strings.Contains(rendered, hintTemplate) { | ||
t2.Errorf("%s did not have hint block", command) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func Test_AttributesCommentsAbsentInMinimalWithNoAttributes(t *testing.T) { | ||
PrintTemplate = false | ||
Minimal = true | ||
WithExplanation = false | ||
WithRubric = false | ||
WithHints = 0 | ||
|
||
for _, command := range questionTypes { | ||
t.Run(command, func(t2 *testing.T) { | ||
template, _ := getTemp(command) | ||
rendered := template.renderTemplate() | ||
|
||
if strings.Contains(rendered, blockHeader) { | ||
t2.Errorf("%s did have block header", command) | ||
} | ||
if strings.Contains(rendered, hintTemplateSilent) { | ||
t2.Errorf("%s did have hint comment", command) | ||
} | ||
if strings.Contains(rendered, rubricTemplateSilent) { | ||
t2.Errorf("%s did have rubric comment", command) | ||
} | ||
if strings.Contains(rendered, explanationTemplateSilent) { | ||
t2.Errorf("%s did have explanation comment", command) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func Test_ExplanationBlockAppearsWhenTrueInMinimal(t *testing.T) { | ||
PrintTemplate = false | ||
Minimal = true | ||
WithExplanation = true | ||
WithRubric = false | ||
WithHints = 0 | ||
|
||
for _, command := range questionTypes { | ||
t.Run(command, func(t2 *testing.T) { | ||
template, _ := getTemp(command) | ||
rendered := template.renderTemplate() | ||
|
||
if !strings.Contains(rendered, explanationTemplateMin) { | ||
t2.Errorf("%s did not have explanation block", command) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func Test_RubricBlockAppearsWhenTrueInMinimal(t *testing.T) { | ||
PrintTemplate = false | ||
Minimal = true | ||
WithExplanation = false | ||
WithRubric = true | ||
WithHints = 0 | ||
|
||
for _, command := range questionTypes { | ||
t.Run(command, func(t2 *testing.T) { | ||
template, _ := getTemp(command) | ||
rendered := template.renderTemplate() | ||
|
||
if !strings.Contains(rendered, rubricTemplateMin) { | ||
t2.Errorf("%s did not have rubric block", command) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func Test_HintBlockAppearsWhenTrueInMinimal(t *testing.T) { | ||
PrintTemplate = false | ||
Minimal = true | ||
WithExplanation = false | ||
WithRubric = true | ||
WithHints = 1 | ||
|
||
for _, command := range questionTypes { | ||
t.Run(command, func(t2 *testing.T) { | ||
template, _ := getTemp(command) | ||
rendered := template.renderTemplate() | ||
|
||
if !strings.Contains(rendered, hintTemplateMin) { | ||
t2.Errorf("%s did not have hint block", command) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.