Skip to content

Commit 7eb9330

Browse files
committedJun 18, 2024
fix some bugs in the editor; catch parse failures in the path host; add a bunch of path lessons
1 parent 0da51e1 commit 7eb9330

File tree

3 files changed

+732
-21
lines changed

3 files changed

+732
-21
lines changed
 

‎LearnJsonEverything.LessonEditor/Controls/Editor.xaml.cs

+12-5
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,19 @@ private void ValidateSolution(object sender, RoutedEventArgs e)
9696
{
9797
if (SelectedLesson is null) return;
9898

99-
SelectedLesson.Save();
99+
try
100+
{
101+
SelectedLesson.Save();
100102

101-
SelectedLesson.Lesson.UserCode = SelectedLesson.Solution;
102-
var output = LessonHost.Run(SelectedLesson.Lesson);
103-
ValidationOutput = string.Join(Environment.NewLine, output);
104-
CanSave = output.All(x => x.StartsWith(Iconography.SuccessIcon));
103+
SelectedLesson.Lesson.UserCode = SelectedLesson.Solution;
104+
var output = LessonHost.Run(SelectedLesson.Lesson);
105+
ValidationOutput = string.Join(Environment.NewLine, output);
106+
CanSave = output.All(x => x.StartsWith(Iconography.SuccessIcon));
107+
}
108+
catch (Exception exception)
109+
{
110+
ValidationOutput = exception.Message + Environment.NewLine + exception.StackTrace;
111+
}
105112
}
106113

107114
private void SaveChanges(object sender, RoutedEventArgs e)

‎LearnJsonEverything/Services/Hosts/PathHost.cs

+10-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@ public string[] Run(LessonData lesson)
1717
foreach (var test in lesson.Tests)
1818
{
1919
var expectedResult = test!["result"];
20-
var result = runner.Run(test.AsObject());
20+
PathResult? result = null;
21+
try
22+
{
23+
result = runner.Run(test.AsObject());
24+
}
25+
catch
26+
{
27+
// ignored
28+
}
29+
2130
var localResult = expectedResult.IsEquivalentTo(result?.Matches?.Select(x => x.Value).ToJsonArray());
2231
correct &= localResult;
2332
results.Add($"{(localResult ? Iconography.SuccessIcon : Iconography.ErrorIcon)} {test.Print()}");

0 commit comments

Comments
 (0)