From fd582b4e191e7ad1ad1627e986e45fcb01e45b43 Mon Sep 17 00:00:00 2001 From: Alex Mickelson Date: Tue, 12 Dec 2023 12:13:25 -0700 Subject: [PATCH] more fixes for matching --- .../Markdown/Quiz/MatchingTests.cs | 21 +++++++++++++++++++ .../Local/Quiz/LocalQuizQuestionAnswer.cs | 15 ++++++++----- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/Management.Test/Markdown/Quiz/MatchingTests.cs b/Management.Test/Markdown/Quiz/MatchingTests.cs index 48d2dea..4e85155 100644 --- a/Management.Test/Markdown/Quiz/MatchingTests.cs +++ b/Management.Test/Markdown/Quiz/MatchingTests.cs @@ -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"); + } } \ No newline at end of file diff --git a/Management/Models/Local/Quiz/LocalQuizQuestionAnswer.cs b/Management/Models/Local/Quiz/LocalQuizQuestionAnswer.cs index 13ef8a1..e98c676 100644 --- a/Management/Models/Local/Quiz/LocalQuizQuestionAnswer.cs +++ b/Management/Models/Local/Quiz/LocalQuizQuestionAnswer.cs @@ -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) + 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,