mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
more fixes for matching
This commit is contained in:
@@ -59,4 +59,25 @@ Match the following terms & definitions
|
||||
^ keyword - reserved word that has special meaning in a program (e.g. class, void, static, etc.)";
|
||||
questionMarkdown.Should().Contain(expectedMarkdown);
|
||||
}
|
||||
[Test]
|
||||
public void WhitespaceIsOptional()
|
||||
{
|
||||
var rawMarkdownQuiz = @"
|
||||
Name: Test Quiz
|
||||
ShuffleAnswers: true
|
||||
OneQuestionAtATime: false
|
||||
DueAt: 2023-08-21T23:59:00
|
||||
LockAt: 2023-08-21T23:59:00
|
||||
AssignmentGroup: Assignments
|
||||
AllowedAttempts: -1
|
||||
Description:
|
||||
---
|
||||
Match the following terms & definitions
|
||||
|
||||
^statement - a single command to be executed
|
||||
";
|
||||
|
||||
var quiz = LocalQuiz.ParseMarkdown(rawMarkdownQuiz);
|
||||
quiz.Questions.First().Answers.First().Text.Should().Be("statement");
|
||||
}
|
||||
}
|
||||
@@ -15,17 +15,22 @@ public record LocalQuizQuestionAnswer
|
||||
public static LocalQuizQuestionAnswer ParseMarkdown(string input, string questionType)
|
||||
{
|
||||
var isCorrect = input[0] == '*' || input[1] == '*';
|
||||
string startingQuestionPattern = @"^(\*?[a-z]?\))|\[\s*\]|\[\*\]|\^ ";
|
||||
var text = Regex.Replace(input, startingQuestionPattern, string.Empty).Trim();
|
||||
|
||||
if (questionType == QuestionType.MATCHING)
|
||||
{
|
||||
|
||||
string matchingPattern = @"^\^ ?";
|
||||
var textWithoutMatchDelimiter = Regex.Replace(input, matchingPattern, string.Empty).Trim();
|
||||
return new LocalQuizQuestionAnswer()
|
||||
{
|
||||
Correct = true,
|
||||
Text = text.Split('-')[0].Trim(),
|
||||
MatchedText = string.Join("-", text.Split('-')[1..]).Trim(),
|
||||
Text = textWithoutMatchDelimiter.Split('-')[0].Trim(),
|
||||
MatchedText = string.Join("-", textWithoutMatchDelimiter.Split('-')[1..]).Trim(),
|
||||
};
|
||||
}
|
||||
|
||||
string startingQuestionPattern = @"^(\*?[a-z]?\))|\[\s*\]|\[\*\]|\^ ";
|
||||
var text = Regex.Replace(input, startingQuestionPattern, string.Empty).Trim();
|
||||
return new LocalQuizQuestionAnswer()
|
||||
{
|
||||
Correct = isCorrect,
|
||||
|
||||
Reference in New Issue
Block a user