Skip to content

Commit eaa90db

Browse files
Refactor
1 parent 005f322 commit eaa90db

File tree

7 files changed

+35
-29
lines changed

7 files changed

+35
-29
lines changed

generators.new/CanonicalData.cs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,7 @@ internal static class CanonicalData
2121
{
2222
private static readonly JsonSerializerOptions SerializerOptions = new() { PropertyNameCaseInsensitive = true };
2323

24-
static CanonicalData()
25-
{
26-
CloneProbSpecsRepo();
27-
UpdateProbSpecsRepo();
28-
}
29-
30-
private static void CloneProbSpecsRepo()
31-
{
32-
if (!Directory.Exists(Paths.ProbSpecsDir))
33-
Repository.Clone("https://github.com/exercism/problem-specifications.git", Paths.ProbSpecsDir);
34-
}
35-
36-
private static void UpdateProbSpecsRepo()
37-
{
38-
using var repo = new Repository(Paths.ProbSpecsDir);
39-
Commands.Pull(repo, new Signature("Exercism", "[email protected]", DateTimeOffset.Now), new PullOptions());
40-
}
24+
static CanonicalData() => ProbSpecs.Sync();
4125

4226
internal static TestCase[] Parse(Exercise exercise) =>
4327
Parse(JsonNode.Parse(File.ReadAllText(Paths.CanonicalDataFile(exercise)))!.AsObject(), ImmutableQueue<string>.Empty)
@@ -69,4 +53,26 @@ private static TestCase ToTestCase(JsonObject testCaseJson, IEnumerable<string>
6953

7054
return null;
7155
}
72-
}
56+
57+
private static class ProbSpecs
58+
{
59+
internal static void Sync()
60+
{
61+
Clone();
62+
Pull();
63+
}
64+
65+
private static void Clone()
66+
{
67+
if (!Directory.Exists(Paths.ProbSpecsDir))
68+
Repository.Clone("https://github.com/exercism/problem-specifications.git", Paths.ProbSpecsDir);
69+
}
70+
71+
private static void Pull()
72+
{
73+
using var repo = new Repository(Paths.ProbSpecsDir);
74+
Commands.Pull(repo, new Signature("Exercism", "[email protected]", DateTimeOffset.Now), new PullOptions());
75+
}
76+
}
77+
}
78+

generators.new/ExerciseFinder.cs renamed to generators.new/Exercises.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace Generators;
44

55
internal record Exercise(string Slug, string Name);
66

7-
internal static class ExerciseFinder
7+
internal static class Exercises
88
{
99
internal static Exercise[] TemplatedExercises(string? slug) =>
1010
slug is null ? TemplatedExercises() : [TemplatedExercise(slug)];

generators.new/CodeFormatter.cs renamed to generators.new/Formatting.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Generators;
66

7-
internal static class CodeFormatter
7+
internal static class Formatting
88
{
99
private static readonly AdhocWorkspace AdhocWorkspace = new();
1010

generators.new/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ static void Main(string[] args) =>
1414
Parser.Default.ParseArguments<Options>(args)
1515
.WithParsed(options =>
1616
{
17-
foreach (var exercise in ExerciseFinder.TemplatedExercises(options.Exercise))
18-
TestGenerator.GenerateTestsFromTemplate(exercise);
17+
foreach (var exercise in Exercises.TemplatedExercises(options.Exercise))
18+
TestGenerator.GenerateTests(exercise);
1919
});
2020
}

generators.new/TemplateRenderer.cs renamed to generators.new/Templates.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
namespace Generators;
1212

13-
internal static class TemplateRenderer
13+
internal static class Templates
1414
{
1515
private static readonly IHandlebars HandlebarsContext = Handlebars.Create();
1616

17-
static TemplateRenderer()
17+
static Templates()
1818
{
1919
HandlebarsHelpers.Register(HandlebarsContext);
2020
HandlebarsContext.RegisterHelper("method_name", (writer, context, parameters) =>

generators.new/TestsToml.cs renamed to generators.new/TestCaseConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Generators;
55

6-
internal static class TestsToml
6+
internal static class TestCaseConfiguration
77
{
88
internal static HashSet<string> ExcludedTestCaseIds(Exercise exercise) =>
99
Toml.ToModel(File.ReadAllText(Paths.TestsTomlFile(exercise)))

generators.new/TestGenerator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ namespace Generators;
22

33
internal static class TestGenerator
44
{
5-
internal static void GenerateTestsFromTemplate(Exercise exercise)
5+
internal static void GenerateTests(Exercise exercise)
66
{
77
Console.WriteLine($"{exercise.Slug}: generating tests...");
88

9-
var excludedTestCaseIds = TestsToml.ExcludedTestCaseIds(exercise);
9+
var excludedTestCaseIds = TestCaseConfiguration.ExcludedTestCaseIds(exercise);
1010
var testCases = CanonicalData.Parse(exercise)
1111
.Where(testCase => !excludedTestCaseIds.Contains(testCase.Uuid))
1212
.ToArray();
1313

1414
var transformedTestCases = TestCaseTransformer.Transform(exercise, testCases);
1515

16-
var renderedTests = TemplateRenderer.RenderTests(exercise, transformedTestCases);
17-
File.WriteAllText(Paths.TestsFile(exercise), CodeFormatter.FormatCode(renderedTests));
16+
var renderedTests = Templates.RenderTests(exercise, transformedTestCases);
17+
File.WriteAllText(Paths.TestsFile(exercise), Formatting.FormatCode(renderedTests));
1818
}
1919
}

0 commit comments

Comments
 (0)