From 5f8c37a9ae4342dff0b4e0e8b877cc9f077c956e Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Sat, 8 Feb 2025 14:10:50 +0100 Subject: [PATCH] Remove deprecated generator --- bin/test.ps1 | 1 - docs/GENERATORS_DEPRECATED.md | 262 ------------------ .../Exercises/ExerciseGenerator.cs | 60 ---- .../Exercises/GeneratorRunner.cs | 51 ---- .../Exercises/Generators/GradeSchool.cs | 40 --- .../Exercises/Generators/ListOps.cs | 96 ------- .../Exercises/Generators/Pov.cs | 43 --- .../Exercises/Generators/RestApi.cs | 27 -- .../Exercises/Generators/Zipper.cs | 97 ------- .../Exercises/TestedMethodType.cs | 10 - generators.deprecated/GeneratorStatus.cs | 1 - .../Generators.deprecated.csproj | 24 -- .../Generators.deprecated.sln | 22 -- .../Helpers/ArrayExtensions.cs | 15 - .../Helpers/EnumerableExtensions.cs | 8 - .../Helpers/NameExtensions.cs | 84 ------ .../Input/CanonicalDataJsonParser.cs | 67 ----- generators.deprecated/Input/ExerciseParser.cs | 36 --- generators.deprecated/Input/JTokenHelper.cs | 100 ------- .../Input/PropSpecsRepository.cs | 51 ---- .../Input/TestsTomlParser.cs | 36 --- generators.deprecated/Logging.cs | 11 - generators.deprecated/Options.cs | 18 -- .../Output/Rendering/IndentFilter.cs | 16 -- .../Output/Rendering/MultiLineString.cs | 18 -- .../Output/Rendering/Render.cs | 87 ------ .../Output/Rendering/RenderArray.cs | 26 -- .../Output/Rendering/RenderAssert.cs | 42 --- .../Output/Rendering/RenderCollection.cs | 23 -- .../Output/Rendering/RenderDateTime.cs | 11 - .../Output/Rendering/RenderDictionary.cs | 19 -- .../Output/Rendering/RenderExtensions.cs | 18 -- .../Output/Rendering/RenderHashSet.cs | 14 - .../Output/Rendering/RenderList.cs | 13 - .../Output/Rendering/RenderNumber.cs | 23 -- .../Output/Rendering/RenderString.cs | 34 --- .../Output/Rendering/RenderVariable.cs | 16 -- .../Output/Rendering/Template.cs | 19 -- .../Output/Rendering/Templates/_Act.liquid | 1 - .../Rendering/Templates/_Arrange.liquid | 3 - .../Rendering/Templates/_AssertBoolean.liquid | 1 - .../Rendering/Templates/_AssertEmpty.liquid | 1 - .../Rendering/Templates/_AssertEqual.liquid | 1 - .../Templates/_AssertEqualWithin.liquid | 1 - .../Rendering/Templates/_AssertInRange.liquid | 1 - .../Rendering/Templates/_AssertMatches.liquid | 1 - .../Templates/_AssertNotEqual.liquid | 1 - .../Rendering/Templates/_AssertNull.liquid | 1 - .../Rendering/Templates/_AssertThrows.liquid | 1 - .../Rendering/Templates/_TestClass.liquid | 12 - .../Rendering/Templates/_TestMethod.liquid | 5 - .../Output/Rendering/UnescapedValue.cs | 14 - generators.deprecated/Output/TestClass.cs | 10 - .../Output/TestClassOutput.cs | 50 ---- generators.deprecated/Output/TestMethod.cs | 80 ------ .../Output/TestMethodOutput.cs | 157 ----------- generators.deprecated/Program.cs | 34 --- 57 files changed, 1914 deletions(-) delete mode 100644 docs/GENERATORS_DEPRECATED.md delete mode 100644 generators.deprecated/Exercises/ExerciseGenerator.cs delete mode 100644 generators.deprecated/Exercises/GeneratorRunner.cs delete mode 100644 generators.deprecated/Exercises/Generators/GradeSchool.cs delete mode 100644 generators.deprecated/Exercises/Generators/ListOps.cs delete mode 100644 generators.deprecated/Exercises/Generators/Pov.cs delete mode 100644 generators.deprecated/Exercises/Generators/RestApi.cs delete mode 100644 generators.deprecated/Exercises/Generators/Zipper.cs delete mode 100644 generators.deprecated/Exercises/TestedMethodType.cs delete mode 100644 generators.deprecated/GeneratorStatus.cs delete mode 100644 generators.deprecated/Generators.deprecated.csproj delete mode 100644 generators.deprecated/Generators.deprecated.sln delete mode 100644 generators.deprecated/Helpers/ArrayExtensions.cs delete mode 100644 generators.deprecated/Helpers/EnumerableExtensions.cs delete mode 100644 generators.deprecated/Helpers/NameExtensions.cs delete mode 100644 generators.deprecated/Input/CanonicalDataJsonParser.cs delete mode 100644 generators.deprecated/Input/ExerciseParser.cs delete mode 100644 generators.deprecated/Input/JTokenHelper.cs delete mode 100644 generators.deprecated/Input/PropSpecsRepository.cs delete mode 100644 generators.deprecated/Input/TestsTomlParser.cs delete mode 100644 generators.deprecated/Logging.cs delete mode 100644 generators.deprecated/Options.cs delete mode 100644 generators.deprecated/Output/Rendering/IndentFilter.cs delete mode 100644 generators.deprecated/Output/Rendering/MultiLineString.cs delete mode 100644 generators.deprecated/Output/Rendering/Render.cs delete mode 100644 generators.deprecated/Output/Rendering/RenderArray.cs delete mode 100644 generators.deprecated/Output/Rendering/RenderAssert.cs delete mode 100644 generators.deprecated/Output/Rendering/RenderCollection.cs delete mode 100644 generators.deprecated/Output/Rendering/RenderDateTime.cs delete mode 100644 generators.deprecated/Output/Rendering/RenderDictionary.cs delete mode 100644 generators.deprecated/Output/Rendering/RenderExtensions.cs delete mode 100644 generators.deprecated/Output/Rendering/RenderHashSet.cs delete mode 100644 generators.deprecated/Output/Rendering/RenderList.cs delete mode 100644 generators.deprecated/Output/Rendering/RenderNumber.cs delete mode 100644 generators.deprecated/Output/Rendering/RenderString.cs delete mode 100644 generators.deprecated/Output/Rendering/RenderVariable.cs delete mode 100644 generators.deprecated/Output/Rendering/Template.cs delete mode 100644 generators.deprecated/Output/Rendering/Templates/_Act.liquid delete mode 100644 generators.deprecated/Output/Rendering/Templates/_Arrange.liquid delete mode 100644 generators.deprecated/Output/Rendering/Templates/_AssertBoolean.liquid delete mode 100644 generators.deprecated/Output/Rendering/Templates/_AssertEmpty.liquid delete mode 100644 generators.deprecated/Output/Rendering/Templates/_AssertEqual.liquid delete mode 100644 generators.deprecated/Output/Rendering/Templates/_AssertEqualWithin.liquid delete mode 100644 generators.deprecated/Output/Rendering/Templates/_AssertInRange.liquid delete mode 100644 generators.deprecated/Output/Rendering/Templates/_AssertMatches.liquid delete mode 100644 generators.deprecated/Output/Rendering/Templates/_AssertNotEqual.liquid delete mode 100644 generators.deprecated/Output/Rendering/Templates/_AssertNull.liquid delete mode 100644 generators.deprecated/Output/Rendering/Templates/_AssertThrows.liquid delete mode 100644 generators.deprecated/Output/Rendering/Templates/_TestClass.liquid delete mode 100644 generators.deprecated/Output/Rendering/Templates/_TestMethod.liquid delete mode 100644 generators.deprecated/Output/Rendering/UnescapedValue.cs delete mode 100644 generators.deprecated/Output/TestClass.cs delete mode 100644 generators.deprecated/Output/TestClassOutput.cs delete mode 100644 generators.deprecated/Output/TestMethod.cs delete mode 100644 generators.deprecated/Output/TestMethodOutput.cs delete mode 100644 generators.deprecated/Program.cs diff --git a/bin/test.ps1 b/bin/test.ps1 index 83ce8ba1c..3aa3651ed 100644 --- a/bin/test.ps1 +++ b/bin/test.ps1 @@ -130,7 +130,6 @@ function Parse-Exercises { function Build-Generators { Write-Output "Build generators" & dotnet build generators - & dotnet build generators.deprecated } function Test-Refactoring-Exercise-Default-Implementations { diff --git a/docs/GENERATORS_DEPRECATED.md b/docs/GENERATORS_DEPRECATED.md deleted file mode 100644 index e8881935c..000000000 --- a/docs/GENERATORS_DEPRECATED.md +++ /dev/null @@ -1,262 +0,0 @@ -# Test generators (deprecated) - -Test generators allow tracks to generate tests automatically without having to write them ourselves. Each test generator reads from the exercise's `canonical data`, which defines the name of the test, its inputs, and outputs. You can read more about exercism's approach to test suites [here](https://github.com/exercism/problem-specifications#test-data-canonical-datajson). - -Generating tests automatically removes any sort of user error when creating tests. Furthermore, we want the tests to be accurate with respect to its canonical data. Test generation also makes it much easier to keep tests up to date. As the canonical data changes, the tests will be automatically updated when the generator for that test is run. - -An example of a canonical data file can be found [here](https://github.com/exercism/problem-specifications/blob/master/exercises/bob/canonical-data.json) - -## Common terms - -When looking through the canonical data and the generator code base, we use a lot of common terminology. This list hopefully clarifies what they represent. - -- Canonical Data - Represents the entire test suite. -- Canonical Data Case - A representation of a single test case. -- Description - The name of the test. -- Property - The method to be called when running the test. -- Input - The input for the test case. -- Expected - The expected value when running the test case. - -## Adding a simple generator - -Adding a test generator is straightforward. Simply add a new file to the `Exercises/Generators` folder with the name of the exercise (in PascalCase), and create a class that extends the `GeneratorExercise` class. - -An example of a simple generator would be the Bob exercise. The source is displayed below, but you can freely view it in the repository [here](https://github.com/exercism/csharp/blob/main/generators/Exercises/Generators/Bob.cs). - -```csharp -namespace Exercism.CSharp.Exercises.Generators -{ - public class Bob : GeneratorExercise - { - } -} -``` - -This is a fully working generator, no other code needs to be written! However, it's simplicity stems from the fact that the test suite and the program itself are relatively trivial. - -## Adding a complex generator - -When the generator's default output is not sufficient, you can override the `GeneratorExercise` class' virtual methods to override the default behavior. - -### Method 1: UpdateTestMethod(TestMethod testMethod) - -Update the test method that described the test method being generated. When you are required to customize a test generator, overriding this method is virtually always what you want to do. - -There are many things that can be customized, of which we'll list the more common usages. - -#### Customize test data - -It is not uncommon that a generator has to transform its input data or expected value to a different value/representation. - -An example of this is the [matching-brackets](https://github.com/exercism/csharp/blob/main/generators/Exercises/Generators/MatchingBrackets.cs) generator, which has a `"value"` input value, which is of type `string`. However, this `string` value contains a backslash, which needs to escaped in order for it to be rendered correctly: - -```csharp -protected override void UpdateTestMethod(TestMethod testMethod) -{ - testMethod.Input["value"] = testMethod.Input["value"].Replace("\\", "\\\\"); - // [...] -} -``` - -Another common use case is to handle empty arrays. If an array is empty, its type will default to `JArray`, which doesn't have any type information. To allow the generator to output a correctly typed array, we have to convert the `JArray` to an array first. - -An example of this is the [proverb](https://github.com/exercism/csharp/blob/main/generators/Exercises/Generators/Proverb.cs) generator, which converts the `JArray` to an empty `string` array: - -```csharp -protected override void UpdateTestMethod(TestMethod testMethod) -{ - // [...] - - if (testMethod.Input["strings"] is JArray) - testMethod.Input["strings"] = Array.Empty(); - - if (testMethod.Expected is JArray) - testMethod.Expected = Array.Empty(); -} -``` - -#### Output test data as variables - -Sometimes, it might make sense to not define a test method's data inline, but as variables. - -An example of this is the [crypto-square](https://github.com/exercism/csharp/blob/main/generators/Exercises/Generators/CryptoSquare.cs) generator, which indicates that both the test method input as well as the expected value, should be stored in variables: - -```csharp -protected override void UpdateTestMethod(TestMethod testMethod) -{ - testMethod.UseVariablesForInput = true; - testMethod.UseVariableForExpected = true; -} -``` - -#### Custom tested method type - -By default, the generator will test a static method. However, you can also test for instance methods, extension methods, properties and constructors. - -An example of this is the [roman-numerals](https://github.com/exercism/csharp/blob/main/generators/Exercises/Generators/RomanNumerals.cs) generator, which indicates that it tests an extensions method: - -```csharp -protected override void UpdateTestMethod(TestMethod testMethod) -{ - testMethod.TestedMethodType = TestedMethodType.ExtensionMethod; - testMethod.TestedMethod = "ToRoman"; -} -``` - -#### Change names used - -As we saw in the previous example, you can also customize the name of the tested method. You are also allowed to customize the tested class' name and the test method name. - -An example of this is the [triangle](https://github.com/exercism/csharp/blob/main/generators/Exercises/Generators/Triangle.cs) generator, which by default generates duplicate test method names (which will be a compile-time error), but instead uses the `TestMethodNameWithPath` to use the full path as the test method name (effectively making the test method name unique): - -```csharp -protected override void UpdateTestMethod(TestMethod testMethod) -{ - // [...] - testMethod.TestMethodName = testMethod.TestMethodNameWithPath; - // [...] -} -``` - -#### Test for an exception being thrown - -Some test methods want to verify that an exception is being thrown. - -An example of this is the [rna-transcription](https://github.com/exercism/csharp/blob/main/generators/Exercises/Generators/RnaTranscription.cs) generator, which defines that some of its test methods should throw an `ArgumentException`: - -```csharp -protected override void UpdateTestMethod(TestMethod testMethod) -{ - if (testMethod.Expected is null) - testMethod.ExceptionThrown = typeof(ArgumentException); -} -``` - -Note that `ArgumentException` type's namespace will be automatically added to the list of namespaces used in the test class. - -#### Custom input/constructor parameters - -In some cases, you might want to override the parameters that are used as input parameters. - -An example of this is the [two-fer](https://github.com/exercism/csharp/blob/main/generators/Exercises/Generators/TwoFer.cs) generator, which does not use any input parameters when the `"name"` input parameter is set to `null`: - -```csharp -protected override void UpdateTestMethod(TestMethod testMethod) -{ - // [...] - - if (testMethod.Input["name"] is null) - testMethod.InputParameters = Array.Empty(); -} -``` - -If a test method tests an instance method, you can also specify which parameters to use as constructor parameters (the others will be input parameters, unless specified otherwise). - -An example of this is the [matrix](https://github.com/exercism/csharp/blob/main/generators/Exercises/Generators/Matrix.cs) generator, which specifies that the `"string"` parameter should be passed as a constructor parameter: - -```csharp -protected override void UpdateTestMethod(TestMethod testMethod) -{ - testMethod.TestedMethodType = TestedMethodType.InstanceMethod; - testMethod.ConstructorInputParameters = new[] { "string" }; -} -``` - -#### Custom arrange/act/assert code - -Although this should be used as a last resort, some generators might want to skip the default generation completely and control which arrange, act or assert code the test method should contain. - -An example of this is the [run-length-encoding](https://github.com/exercism/csharp/blob/main/generators/Exercises/Generators/RunLengthEncoding.cs) generator, which uses a custom assertion for one specific property: - -```csharp -protected override void UpdateTestMethod(TestMethod testMethod) -{ - // [...] - - if (testMethod.Property == "consistency") - testMethod.Assert = RenderConsistencyToAssert(testMethod); -} - -private string RenderConsistencyToAssert(TestMethod testMethod) -{ - var expected = Render.Object(testMethod.Expected); - var actual = $"{testMethod.TestedClass}.Decode({testMethod.TestedClass}.Encode({expected}))"; - return Render.AssertEqual(expected, actual); -} -``` - -Note that the `Render` instance is used to render the assertion and the expected value. - -### Method 2: UpdateNamespaces(ISet namespaces) - -Allows additional namespaces to be added to the test suite. - -All tests use the `Xunit` framework, so each test class will automatically include the `Xunit` namespace. However, some test classes may require additional namespaces. - -An example of this is the [gigasecond](https://github.com/exercism/csharp/blob/main/generators/Exercises/Generators/Gigasecond.cs) generator, which uses the `DateTime` class in its test methods, and thus adds its namespace to the list of namespaces: - -```csharp -protected override void UpdateNamespaces(ISet namespaces) -{ - namespaces.Add(typeof(DateTime).Namespace); -} -``` - -Note that as mentioned before, the namespace of any thrown exception types are automatically added to the list of namespaces. - -### Method 3: UpdateTestClass(TestClass testClass) - -This method allows you to customize the output of the test class. Only in rare cases would you want to override this method. The most common use case to override this method, is to add additional (helper) methods to the test suite. - -An example of this is the [tournament](https://github.com/exercism/csharp/blob/main/generators/Exercises/Generators/Tournament.cs) generator, which adds a helper method to the test suite: - -```csharp -protected override void UpdateTestClass(TestClass testClass) -{ - AddRunTallyMethod(testClass); -} - -private static void AddRunTallyMethod(TestClass testClass) -{ - testClass.AdditionalMethods.Add(@" -private string RunTally(string input) -{ - var encoding = new UTF8Encoding(); - - using (var inStream = new MemoryStream(encoding.GetBytes(input))) - using (var outStream = new MemoryStream()) - { - Tournament.Tally(inStream, outStream); - return encoding.GetString(outStream.ToArray()); - } -}"); -} -``` - -Additional methods will be added to the bottom of the test suite. - -## Updating Existing Files - -It is possible that an existing exercise does not match the canonical data. It is OK to update the exercise stub and/or the exercise example to follow the canonical data! An example might be that an exercise is named SumOfMultiples, but the SumOfMultiples.cs and Example.cs files both use `Multiples` as the name of the class. - -Also, if you find an issue with one of the existing generators or test suites simply open up the generator that you would like to update, make your changes, and then run the generators. - -## Running The Generators - -This repository is coded against [.NET Core](https://www.microsoft.com/net/core). To run the generators all you need to do is run the following command in the generators directory: - -`dotnet run` - -This command will take all of the generators that are in the `Exercises` folder, and generate all of the test cases for that exercise. We use reflection to get all of the exercises, so if you are adding a new test, the test will be automatically included when running the generator. - -If you only need to run a single generator, you can do so by running the following command: - -`dotnet run -e ` - -Once the generator has been run, you can view the output of your generation by navigating to the test file for that exercise. As an example, the test suite for the Bob exercise can be found at: - -`exercises/bob/BobTests.cs` - -## Submitting A Generator - -If you are satisfied with the output of your generator, we would love for you to submit a pull request! Please include your generator, updated test suite, and any other corresponding files that you may have changed. diff --git a/generators.deprecated/Exercises/ExerciseGenerator.cs b/generators.deprecated/Exercises/ExerciseGenerator.cs deleted file mode 100644 index d1ed55f83..000000000 --- a/generators.deprecated/Exercises/ExerciseGenerator.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using Exercism.CSharp.Helpers; -using Exercism.CSharp.Input; -using Exercism.CSharp.Output; -using Exercism.CSharp.Output.Rendering; - -namespace Exercism.CSharp.Exercises; - -internal abstract class ExerciseGenerator -{ - public string Name => GetType().ToExerciseName(); - - protected Render Render { get; } = new(); - - public void Regenerate(Exercise exercise, Options options) - { - var testClass = CreateTestClass(exercise); - var testClassOutput = new TestClassOutput(testClass, options); - testClassOutput.WriteToFile(); - } - - private TestClass CreateTestClass(Exercise exercise) - { - var testMethods = CreateTestMethods(exercise); - var testClass = new TestClass( - exercise.Name, - exercise.Name.ToTestClassName(), - testMethods); - UpdateTestClass(testClass); - UpdateNamespaces(testClass.Namespaces); - - return testClass; - } - - protected virtual void UpdateTestClass(TestClass testClass) - { - } - - protected virtual void UpdateNamespaces(ISet namespaces) - { - } - - private TestMethod[] CreateTestMethods(Exercise exercise) => - exercise.TestCases - .Select(canonicalDataCase => CreateTestMethod(exercise, canonicalDataCase)) - .ToArray(); - - private TestMethod CreateTestMethod(Exercise exercise, TestCase testCase) - { - var testMethod = new TestMethod(exercise, testCase); - UpdateTestMethod(testMethod); - - return testMethod; - } - - protected virtual void UpdateTestMethod(TestMethod testMethod) - { - } -} \ No newline at end of file diff --git a/generators.deprecated/Exercises/GeneratorRunner.cs b/generators.deprecated/Exercises/GeneratorRunner.cs deleted file mode 100644 index e51b937e8..000000000 --- a/generators.deprecated/Exercises/GeneratorRunner.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; - -using Exercism.CSharp.Helpers; -using Exercism.CSharp.Input; - -using Serilog; - -namespace Exercism.CSharp.Exercises; - -internal class GeneratorRunner -{ - private readonly Options _options; - private readonly Dictionary _exerciseGeneratorTypes; - private readonly Lazy _exerciseParser; - - public GeneratorRunner(Options options) - { - _options = options; - _exerciseParser = new Lazy(() => ExerciseParser.Create(options)); - _exerciseGeneratorTypes = FindExerciseGeneratorTypes(); - } - - public void RegenerateAllExercises() - { - foreach (var exerciseGeneratorType in _exerciseGeneratorTypes.Values) - RegenerateExercise(exerciseGeneratorType); - } - - public void RegenerateSingleExercise(string exercise) - { - if (_exerciseGeneratorTypes.TryGetValue(exercise, out var exerciseGeneratorType)) - RegenerateExercise(exerciseGeneratorType); - else - Log.Error("Could not find generator for {Name} exercise", exercise); - } - - private void RegenerateExercise(Type exerciseGeneratorType) - { - var exerciseGenerator = Activator.CreateInstance(exerciseGeneratorType) as ExerciseGenerator; - exerciseGenerator!.Regenerate(_exerciseParser.Value.Parse(exerciseGenerator.Name), _options); - Log.Information("{Name}: updated", exerciseGenerator.Name); - } - - private static Dictionary FindExerciseGeneratorTypes() => - Assembly.GetEntryAssembly()!.GetTypes() - .Where(type => typeof(ExerciseGenerator).IsAssignableFrom(type) && !type.IsAbstract) - .ToDictionary(type => type.ToExerciseName(), type => type, StringComparer.OrdinalIgnoreCase); -} \ No newline at end of file diff --git a/generators.deprecated/Exercises/Generators/GradeSchool.cs b/generators.deprecated/Exercises/Generators/GradeSchool.cs deleted file mode 100644 index 747bd18ee..000000000 --- a/generators.deprecated/Exercises/Generators/GradeSchool.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Exercism.CSharp.Output; - -namespace Exercism.CSharp.Exercises.Generators; - -internal class GradeSchool : ExerciseGenerator -{ - protected override void UpdateTestMethod(TestMethod testMethod) - { - testMethod.TestedMethodType = TestedMethodType.InstanceMethod; - testMethod.Act = RenderAct(testMethod); - testMethod.InputParameters.Remove("students"); - - if (testMethod.Property == "add") - testMethod.Assert = ""; - else - testMethod.UseVariableForExpected = true; - } - - private string RenderAct(TestMethod testMethod) - { - var act = new StringBuilder(); - - for (var i = 0; i < testMethod.Input["students"].Count; i++) - { - var student = testMethod.Input["students"][i]; - var add = $"sut.Add({Render.Object((string)student[0])}, {Render.Object(student[1])})"; - if (testMethod.Property == "add") - act.AppendLine(Render.AssertBoolean(testMethod.Expected![i], add)); - else - act.AppendLine($"{add};"); - } - - return act.ToString(); - } - - protected override void UpdateNamespaces(ISet namespaces) => namespaces.Add(typeof(Array).Namespace!); -} \ No newline at end of file diff --git a/generators.deprecated/Exercises/Generators/ListOps.cs b/generators.deprecated/Exercises/Generators/ListOps.cs deleted file mode 100644 index 24316ce21..000000000 --- a/generators.deprecated/Exercises/Generators/ListOps.cs +++ /dev/null @@ -1,96 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using Exercism.CSharp.Output; -using Exercism.CSharp.Output.Rendering; -using Newtonsoft.Json.Linq; - -namespace Exercism.CSharp.Exercises.Generators; - -internal class ListOps : ExerciseGenerator -{ - protected override void UpdateTestMethod(TestMethod testMethod) - { - testMethod.TestMethodName = testMethod.TestMethodNameWithPath; - testMethod.UseVariablesForInput = true; - testMethod.UseVariableForExpected = !(testMethod.Expected is int); - - if (testMethod.Input.TryGetValue("list", out var list)) - testMethod.Input["list"] = ConvertToList(list); - - if (testMethod.Input.TryGetValue("list1", out var list1)) - testMethod.Input["list1"] = ConvertToList(list1); - - if (testMethod.Input.TryGetValue("list2", out var list2)) - testMethod.Input["list2"] = ConvertToList(list2); - - if (testMethod.Input.TryGetValue("lists", out var lists)) - testMethod.Input["lists"] = ConvertToNestedList(lists); - - if (testMethod.Input.TryGetValue("function", out var function)) - testMethod.Input["function"] = ConvertToFunction(testMethod.Property, function); - - if (testMethod.Expected is IEnumerable) - { - testMethod.Expected = ConvertToList(testMethod.Expected); - } - } - - private static UnescapedValue ConvertToFunction(string property, dynamic function) - { - var signature = - property == "filter" ? "" : - property == "map" ? "" : - ""; - - var body = function - .Replace("modulo", "%") - .Replace("->", "=>"); - - return new UnescapedValue($"new Func{signature}({body})"); - } - - private static dynamic ConvertToList(dynamic value) - { - if (IsArrayOfIntegers(value)) - return new List(value); - - if (IsListOfIntegers(value)) - return value.ToObject>(); - - if (IsListOfListOfIntegers(value)) - return value.ToObject>>(); - - if (IsListOfListOfListOfIntegers(value)) - return value.ToObject>>>(); - - throw new ArgumentException("Unsupported list type"); - } - - private static dynamic ConvertToNestedList(dynamic value) - => IsEmptyList(value) - ? new List>() - : ConvertToList(value); - - private static bool IsArrayOfIntegers(dynamic value) - => value is int []; - - private static bool IsListOfIntegers(dynamic value) - => value is JArray jArray && jArray.All(child => child.Type == JTokenType.Integer); - - private static bool IsListOfListOfIntegers(dynamic value) - => value is JArray jArray && jArray.All(IsListOfIntegers); - - private static bool IsListOfListOfListOfIntegers(dynamic value) - => value is JArray jArray && jArray.All(IsListOfListOfIntegers); - - private static bool IsEmptyList(dynamic value) - => value is JArray jArray && jArray.Count == 0; - - protected override void UpdateNamespaces(ISet namespaces) - { - namespaces.Add(typeof(Func).Namespace!); - namespaces.Add(typeof(List).Namespace!); - } -} \ No newline at end of file diff --git a/generators.deprecated/Exercises/Generators/Pov.cs b/generators.deprecated/Exercises/Generators/Pov.cs deleted file mode 100644 index 470a8fcf9..000000000 --- a/generators.deprecated/Exercises/Generators/Pov.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Linq; -using Exercism.CSharp.Output; -using Exercism.CSharp.Output.Rendering; - -namespace Exercism.CSharp.Exercises.Generators; - -internal class Pov : ExerciseGenerator -{ - protected override void UpdateTestMethod(TestMethod testMethod) - { - testMethod.UseVariablesForInput = true; - testMethod.UseVariableForExpected = true; - - if (testMethod.Expected is null) - testMethod.ExceptionThrown = typeof(ArgumentException); - - testMethod.Input["tree"] = RenderTree(testMethod.Input["tree"]); - - if (testMethod.Property == "fromPov") - { - testMethod.Expected = RenderTree(testMethod.Expected); - } - } - - private UnescapedValue? RenderTree(dynamic tree) - { - if (tree == null) - { - return null; - } - - var label = Render.Object(tree["label"]); - - if (tree.ContainsKey("children")) - { - var children = string.Join(", ", ((object[])tree["children"]).Select(RenderTree)); - return new UnescapedValue($"new Tree({label}, {children})"); - } - - return new UnescapedValue($"new Tree({label})"); - } -} \ No newline at end of file diff --git a/generators.deprecated/Exercises/Generators/RestApi.cs b/generators.deprecated/Exercises/Generators/RestApi.cs deleted file mode 100644 index e91764f9c..000000000 --- a/generators.deprecated/Exercises/Generators/RestApi.cs +++ /dev/null @@ -1,27 +0,0 @@ -using Exercism.CSharp.Output; -using Newtonsoft.Json; - -namespace Exercism.CSharp.Exercises.Generators; - -internal class RestApi : ExerciseGenerator -{ - protected override void UpdateTestMethod(TestMethod testMethod) - { - testMethod.UseVariablesForInput = true; - testMethod.UseVariableForTested = true; - testMethod.UseVariableForExpected = true; - testMethod.UseVariablesForConstructorParameters = true; - - testMethod.TestedMethodType = TestedMethodType.InstanceMethod; - testMethod.ConstructorInputParameters = new[] { "database" }; - testMethod.Input["database"] = JsonConvert.SerializeObject(testMethod.Input["database"]["users"]).Replace(".0", ""); - - if (testMethod.Input.ContainsKey("payload")) - testMethod.Input["payload"] = JsonConvert.SerializeObject(testMethod.Input["payload"]).Replace(".0", ""); - - testMethod.Expected = - JsonConvert.SerializeObject(testMethod.Expected!.ContainsKey("users") - ? testMethod.Expected["users"] - : testMethod.Expected).Replace(".0", ""); - } -} \ No newline at end of file diff --git a/generators.deprecated/Exercises/Generators/Zipper.cs b/generators.deprecated/Exercises/Generators/Zipper.cs deleted file mode 100644 index 3d31423ec..000000000 --- a/generators.deprecated/Exercises/Generators/Zipper.cs +++ /dev/null @@ -1,97 +0,0 @@ -using System; -using System.Linq; -using System.Text; -using Exercism.CSharp.Helpers; -using Exercism.CSharp.Output; - -namespace Exercism.CSharp.Exercises.Generators; - -internal class Zipper : ExerciseGenerator -{ - protected override void UpdateTestMethod(TestMethod testMethod) - { - testMethod.Arrange = RenderArrange(testMethod); - testMethod.Assert = RenderAssert(testMethod); - } - - private string RenderArrange(TestMethod testMethod) - { - var arrange = new StringBuilder(); - var tree = RenderTree(testMethod.Input["initialTree"]); - arrange.AppendLine(Render.Variable("tree", tree)); - arrange.AppendLine(Render.Variable("sut", "Zipper.FromTree(tree)")); - - var operations = RenderOperations(testMethod.Input["operations"]); - arrange.AppendLine(Render.Variable("actual", $"sut{operations}")); - return arrange.ToString(); - } - - private string RenderAssert(TestMethod testMethod) - { - var expected = RenderExpected(testMethod.Expected); - if (expected == null) - { - return Render.AssertNull("actual"); - } - - var assert = new StringBuilder(); - assert.AppendLine(Render.Variable("expected", expected)); - assert.AppendLine(Render.AssertEqual("expected", "actual")); - return assert.ToString(); - } - - private static string RenderTree(dynamic tree) - { - if (tree == null) - return "null"; - - return $"new BinTree({tree["value"]}, {RenderTree(tree["left"])}, {RenderTree(tree["right"])})"; - } - - private static string RenderOperations(dynamic operations) - { - if (operations.Length == 0) - return ""; - - return "." + string.Join(".", ((object[])operations).Select(RenderOperation)); - } - - private static string RenderOperation(dynamic operation) - { - var operationType = (string)operation["operation"]; - var operationMethod = operationType.ToMethodName(); - - switch (operationType) - { - case "set_value": - return $"{operationMethod}({operation["item"]})"; - case "set_left": - case "set_right": - return $"{operationMethod}({RenderTree(operation["item"])})"; - default: - return $"{operationMethod}()"; - } - } - - private string? RenderExpected(dynamic expected) - { - switch (expected["type"]) - { - case "int": - return Render.Object(expected["value"]); - case "zipper": - if (expected.TryGetValue("value", out dynamic value) && value == null) - { - return null; - } - - var tree = RenderTree(expected["initialTree"]); - var operations = RenderOperations(expected["operations"]); - return $"Zipper.FromTree({tree}){operations}"; - case "tree": - return RenderTree(expected["value"]); - default: - throw new ArgumentException("Unknown expected type"); - } - } -} \ No newline at end of file diff --git a/generators.deprecated/Exercises/TestedMethodType.cs b/generators.deprecated/Exercises/TestedMethodType.cs deleted file mode 100644 index fa15ca087..000000000 --- a/generators.deprecated/Exercises/TestedMethodType.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Exercism.CSharp.Exercises; - -public enum TestedMethodType -{ - StaticMethod, - InstanceMethod, - ExtensionMethod, - Property, - Constructor -} \ No newline at end of file diff --git a/generators.deprecated/GeneratorStatus.cs b/generators.deprecated/GeneratorStatus.cs deleted file mode 100644 index 5f282702b..000000000 --- a/generators.deprecated/GeneratorStatus.cs +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/generators.deprecated/Generators.deprecated.csproj b/generators.deprecated/Generators.deprecated.csproj deleted file mode 100644 index 3634b40bf..000000000 --- a/generators.deprecated/Generators.deprecated.csproj +++ /dev/null @@ -1,24 +0,0 @@ - - - Exe - net9.0 - Exercism.CSharp - enable - - - - - - - - - - - - - - - - $(MSBuildProjectDirectory) - - \ No newline at end of file diff --git a/generators.deprecated/Generators.deprecated.sln b/generators.deprecated/Generators.deprecated.sln deleted file mode 100644 index 234919335..000000000 --- a/generators.deprecated/Generators.deprecated.sln +++ /dev/null @@ -1,22 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26228.4 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Generators.deprecated", "Generators.deprecated.csproj", "{F310316B-5E18-4E7F-A77D-D26AD8D92307}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {F310316B-5E18-4E7F-A77D-D26AD8D92307}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F310316B-5E18-4E7F-A77D-D26AD8D92307}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F310316B-5E18-4E7F-A77D-D26AD8D92307}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F310316B-5E18-4E7F-A77D-D26AD8D92307}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/generators.deprecated/Helpers/ArrayExtensions.cs b/generators.deprecated/Helpers/ArrayExtensions.cs deleted file mode 100644 index a053efd2c..000000000 --- a/generators.deprecated/Helpers/ArrayExtensions.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Linq; - -namespace Exercism.CSharp.Helpers; - -internal static class ArrayExtensions -{ - public static T[][] Rows(this T[,] array) - { - return Enumerable.Range(0, array.GetLength(0)) - .Select(Row) - .ToArray(); - - T[] Row(int row) => Enumerable.Range(0, array.GetLength(1)).Select(col => array[row, col]).ToArray(); - } -} \ No newline at end of file diff --git a/generators.deprecated/Helpers/EnumerableExtensions.cs b/generators.deprecated/Helpers/EnumerableExtensions.cs deleted file mode 100644 index e6a309476..000000000 --- a/generators.deprecated/Helpers/EnumerableExtensions.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System.Collections.Generic; - -namespace Exercism.CSharp.Helpers; - -internal static class EnumerableExtensions -{ - public static SortedSet ToSortedSet(this IEnumerable source) => new(source); -} \ No newline at end of file diff --git a/generators.deprecated/Helpers/NameExtensions.cs b/generators.deprecated/Helpers/NameExtensions.cs deleted file mode 100644 index 541eab8f3..000000000 --- a/generators.deprecated/Helpers/NameExtensions.cs +++ /dev/null @@ -1,84 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text.RegularExpressions; -using Humanizer; - -namespace Exercism.CSharp.Helpers; - -internal static class NameExtensions -{ - private static readonly HashSet ValueTupleTypes = new(new[] - { - typeof(ValueTuple<>), - typeof(ValueTuple<,>), - typeof(ValueTuple<,,>), - typeof(ValueTuple<,,,>), - typeof(ValueTuple<,,,,>), - typeof(ValueTuple<,,,,,>), - typeof(ValueTuple<,,,,,,>), - typeof(ValueTuple<,,,,,,,>) - }); - - public static string ToExerciseName(this Type exerciseType) => exerciseType.Name.Kebaberize(); - - public static string ToTestClassName(this string input) => $"{input.Dehumanize()}Tests"; - - public static string ToTestedClassName(this string input) => input.Dehumanize(); - - public static string ToTestMethodName(this string input) - { - var methodName = input - .Replace(":", " is") - .Replace("'", ""); - - methodName = Regex.Replace(methodName, @"[^\w]+", "_", RegexOptions.Compiled) - .Transform(To.TitleCase); - - if (char.IsDigit(methodName[0])) - return "Number_" + methodName; - - return !char.IsLetter(methodName[0]) ? "Test_" : methodName; - } - - public static string ToTestedMethodName(this string input) => input.ToMethodName(); - - public static string ToMethodName(this string input) => input.Dehumanize(); - - public static string ToVariableName(this string input) => input.Camelize(); - - public static string ToFriendlyName(this Type type) - { - if (type == typeof(int)) - return "int"; - if (type == typeof(short)) - return "short"; - if (type == typeof(byte)) - return "byte"; - if (type == typeof(bool)) - return "bool"; - if (type == typeof(long)) - return "long"; - if (type == typeof(float)) - return "float"; - if (type == typeof(double)) - return "double"; - if (type == typeof(decimal)) - return "decimal"; - if (type == typeof(string)) - return "string"; - if (type == typeof(char)) - return "char"; - if (type == typeof(object)) - return "object"; - if (type.IsGenericType && ValueTupleTypes.Contains(type.GetGenericTypeDefinition())) - return $"({string.Join(", ", type.GetGenericArguments().Select(ToFriendlyName))})"; - if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)) - return $"{type.GetGenericArguments()[0].ToFriendlyName()}?"; - if (type.IsGenericType) - return $"{type.Name.Split('`')[0]}<{string.Join(", ", type.GetGenericArguments().Select(ToFriendlyName))}>"; - if (type.IsArray) - return $"{type.GetElementType()!.ToFriendlyName()}[]"; - return type.Name; - } -} \ No newline at end of file diff --git a/generators.deprecated/Input/CanonicalDataJsonParser.cs b/generators.deprecated/Input/CanonicalDataJsonParser.cs deleted file mode 100644 index 87358722c..000000000 --- a/generators.deprecated/Input/CanonicalDataJsonParser.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -using Newtonsoft.Json.Linq; - -namespace Exercism.CSharp.Input; - -internal class CanonicalDataJsonParser -{ - private readonly Options _options; - - private CanonicalDataJsonParser(Options options) => _options = options; - - public static CanonicalDataJsonParser Create(Options options) - { - var propSpecsRepository = new PropSpecsRepository(options); - propSpecsRepository.SyncToLatest(); - - return new CanonicalDataJsonParser(options); - } - - public IReadOnlyCollection Parse(string exercise) => - Parse((JArray)ParseCanonicalData(exercise)["cases"]!); - - private JObject ParseCanonicalData(string exercise) => - JObject.Parse(File.ReadAllText(ExerciseCanonicalDataPath(exercise))); - - private string ExerciseCanonicalDataPath(string exercise) => - Path.Combine(_options.ProbSpecsDir, "exercises", exercise, "canonical-data.json"); - - private static IReadOnlyCollection Parse(JToken canonicalDataCaseJToken) => - GetCanonicalDataCaseTokens(canonicalDataCaseJToken) - .Select(ParseWithIndex) - .ToArray(); - - private static IEnumerable GetCanonicalDataCaseTokens(JToken currentJToken) => - currentJToken switch - { - JArray jArray => jArray.SelectMany(GetCanonicalDataCaseTokens), - JObject jObject when jObject.TryGetValue("cases", out var casesJToken) && - casesJToken is JArray childJArray => childJArray.SelectMany( - GetCanonicalDataCaseTokens), - JObject jObject when jObject.ContainsKey("property") => new[] {jObject}, - _ => Enumerable.Empty() - }; - - private static TestCase ParseWithIndex(JToken canonicalDataCaseJToken, int index) => - new TestCase( - index, - canonicalDataCaseJToken.Value("uuid"), - canonicalDataCaseJToken.Value("property"), - JTokenHelper.ConvertJToken(canonicalDataCaseJToken["input"]!), - JTokenHelper.ConvertJToken(canonicalDataCaseJToken["expected"]!), - canonicalDataCaseJToken.Value("description"), - GetDescriptionPath(canonicalDataCaseJToken), - canonicalDataCaseJToken["scenarios"]?.ToObject() ?? Array.Empty()); - - private static string[] GetDescriptionPath(JToken canonicalDataCaseJToken) => - canonicalDataCaseJToken.ParentsAndSelf() - .Where(token => token.Type == JTokenType.Object) - .Select(token => token.Value("description")) - .Where(description => !string.IsNullOrWhiteSpace(description)) - .Reverse() - .ToArray()!; -} \ No newline at end of file diff --git a/generators.deprecated/Input/ExerciseParser.cs b/generators.deprecated/Input/ExerciseParser.cs deleted file mode 100644 index 308cf649c..000000000 --- a/generators.deprecated/Input/ExerciseParser.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -namespace Exercism.CSharp.Input; - -internal record Exercise(string Name, IReadOnlyCollection TestCases); - -internal record TestCase(int Index, string Uuid, string Property, IReadOnlyDictionary Input, - dynamic Expected, string Description, IReadOnlyCollection DescriptionPath, string[] Scenarios); - -internal class ExerciseParser -{ - private readonly CanonicalDataJsonParser _canonicalDataJsonParser; - private readonly TestsTomlParser _testsTomlParser; - - private ExerciseParser(CanonicalDataJsonParser canonicalDataJsonParser, TestsTomlParser testsTomlParser) - { - _canonicalDataJsonParser = canonicalDataJsonParser; - _testsTomlParser = testsTomlParser; - } - - public static ExerciseParser Create(Options options) => - new(CanonicalDataJsonParser.Create(options), new TestsTomlParser(options)); - - public Exercise Parse(string exercise) - { - var allTestCases = _canonicalDataJsonParser.Parse(exercise); - var enabledTests = _testsTomlParser.ParseEnabledTests(exercise); - var enabledTestCases = allTestCases - .Where(testCase => enabledTests.Contains(testCase.Uuid)) - .Select((testCase, index) => testCase with { Index = index }) - .ToArray(); - - return new Exercise(exercise, enabledTestCases); - } -} \ No newline at end of file diff --git a/generators.deprecated/Input/JTokenHelper.cs b/generators.deprecated/Input/JTokenHelper.cs deleted file mode 100644 index f358d47d6..000000000 --- a/generators.deprecated/Input/JTokenHelper.cs +++ /dev/null @@ -1,100 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Newtonsoft.Json.Linq; - -namespace Exercism.CSharp.Input; - -internal static class JTokenHelper -{ - public static IEnumerable ParentsAndSelf(this JToken? jToken) - { - while (jToken != null) - { - yield return jToken; - jToken = jToken.Parent; - } - } - - public static dynamic? ConvertJToken(JToken? jToken) => - jToken switch - { - null => null, - JObject jObject => ConvertJObject(jObject), - JArray jArray => ConvertJArray(jArray), - _ => jToken.Type switch - { - JTokenType.Integer => ConvertJTokenToInteger(jToken), - JTokenType.Float => jToken.ToObject(), - JTokenType.String => jToken.ToObject(), - JTokenType.Boolean => jToken.ToObject(), - JTokenType.Date => jToken.ToObject(), - _ => null - } - }; - - private static dynamic ConvertJObject(JObject jObject) - { - var properties = new Dictionary(jObject.Count, StringComparer.OrdinalIgnoreCase); - - foreach (var (key, value) in jObject) - properties[key] = ConvertJToken(value); - - return properties; - } - - private static dynamic? ConvertJArray(JArray jArray) - { - // We can't determine the type of the array if the array is empty - if (!jArray.Any()) - return jArray; - - // We can only convert when all values have the same type - if (jArray.Select(x => x.Type).Distinct().Count() != 1) - return jArray; - - switch (jArray[0].Type) - { - case JTokenType.Object: - return jArray.Select(ConvertJToken).ToArray(); - case JTokenType.Integer: - var strings = jArray.ToObject()!; - if (strings.All(str => int.TryParse(str, out _))) - return jArray.ToObject(); - - if (strings.All(str => long.TryParse(str, out _))) - return jArray.ToObject(); - - if (strings.All(str => ulong.TryParse(str, out _))) - return jArray.ToObject(); - - return strings; - case JTokenType.Float: - return jArray.ToObject(); - case JTokenType.String: - return jArray.ToObject(); - case JTokenType.Boolean: - return jArray.ToObject(); - case JTokenType.Date: - return jArray.ToObject(); - default: - return jArray; - } - } - - private static dynamic? ConvertJTokenToInteger(JToken jToken) - { - var str = jToken.ToObject(); - - if (int.TryParse(str, out var i)) - return i; - - if (long.TryParse(str, out var l)) - return l; - - if (ulong.TryParse(str, out var ul)) - return ul; - - return str; - } -} \ No newline at end of file diff --git a/generators.deprecated/Input/PropSpecsRepository.cs b/generators.deprecated/Input/PropSpecsRepository.cs deleted file mode 100644 index 03b972adb..000000000 --- a/generators.deprecated/Input/PropSpecsRepository.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System.IO; -using System.Linq; -using LibGit2Sharp; -using Serilog; - -namespace Exercism.CSharp.Input; - -internal class PropSpecsRepository -{ - private const string ProblemSpecificationsGitUrl = "https://github.com/exercism/problem-specifications.git"; - private const string ProblemSpecificationsBranch = "main"; - private const string ProblemSpecificationsRemote = "origin"; - private const string ProblemSpecificationsRemoteBranch = ProblemSpecificationsRemote + "/" + ProblemSpecificationsBranch; - - private readonly Options _options; - - public PropSpecsRepository(Options options) => _options = options; - - public void SyncToLatest() - { - CloneRepository(); - ResetBranchToUpstream(); - } - - private void CloneRepository() - { - if (Directory.Exists(_options.ProbSpecsDir)) - return; - - Log.Debug("Cloning repository..."); - - Repository.Clone(ProblemSpecificationsGitUrl, _options.ProbSpecsDir); - - Log.Debug("Repository cloned."); - } - - private void ResetBranchToUpstream() - { - Log.Debug("Updating repository to latest version..."); - - using (var repository = new Repository(_options.ProbSpecsDir)) - { - Commands.Fetch(repository, ProblemSpecificationsRemote, Enumerable.Empty(), new FetchOptions(), null); - - var remoteBranch = repository.Branches[ProblemSpecificationsRemoteBranch]; - repository.Reset(ResetMode.Hard, remoteBranch.Tip); - } - - Log.Debug("Updated repository to latest version."); - } -} \ No newline at end of file diff --git a/generators.deprecated/Input/TestsTomlParser.cs b/generators.deprecated/Input/TestsTomlParser.cs deleted file mode 100644 index 5643892d6..000000000 --- a/generators.deprecated/Input/TestsTomlParser.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; - -using Tomlyn; -using Tomlyn.Syntax; - -namespace Exercism.CSharp.Input; - -internal class TestsTomlParser -{ - private readonly Options _options; - - public TestsTomlParser(Options options) => _options = options; - - public HashSet ParseEnabledTests(string exercise) - { - static bool IncludeMissingOrTrue (TableSyntaxBase table) - { - var includeKeyValue = table.Items.FirstOrDefault(item => item.Key!.ToString().Trim() == "include"); - return includeKeyValue == null || includeKeyValue.Value!.ToString().Trim() == "true"; - } - - var toml = ParseTestsToml(exercise); - return toml.Tables - .Where(IncludeMissingOrTrue) - .Select(table => table.Name!.ToString()) - .ToHashSet(); - } - - private DocumentSyntax ParseTestsToml(string exercise) => - Toml.Parse(File.ReadAllText(TestsTomlPath(exercise))); - - private string TestsTomlPath(string exercise) => - Path.Combine(_options.PracticeExercisesDir, exercise, ".meta", "tests.toml"); -} \ No newline at end of file diff --git a/generators.deprecated/Logging.cs b/generators.deprecated/Logging.cs deleted file mode 100644 index b457b202e..000000000 --- a/generators.deprecated/Logging.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Serilog; - -namespace Exercism.CSharp; - -internal static class Logging -{ - public static void Setup() => - Log.Logger = new LoggerConfiguration() - .WriteTo.LiterateConsole() - .CreateLogger(); -} \ No newline at end of file diff --git a/generators.deprecated/Options.cs b/generators.deprecated/Options.cs deleted file mode 100644 index bb4386ec3..000000000 --- a/generators.deprecated/Options.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.IO; - -using CommandLine; - -namespace Exercism.CSharp; - -internal class Options -{ - [Option('e', "exercise", Required = false, HelpText = "The exercise to generate.")] - public string? Exercise { get; set; } - - [Option('d', "dir", Required = false, HelpText = "The directory of the problem-specifications repo. If the not specified, the repo will be downloaded.")] - public string ProbSpecsDir { get; set; } = Path.Combine("..", ".problem-specifications"); - - public string PracticeExercisesDir = Path.Combine("..", "exercises", "practice"); - - public static ParserResult Parse(string[] args) => Parser.Default.ParseArguments(args); -} \ No newline at end of file diff --git a/generators.deprecated/Output/Rendering/IndentFilter.cs b/generators.deprecated/Output/Rendering/IndentFilter.cs deleted file mode 100644 index 7ee6d28f4..000000000 --- a/generators.deprecated/Output/Rendering/IndentFilter.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Linq; - -namespace Exercism.CSharp.Output.Rendering; - -internal static class IndentFilter -{ - public static string Indent(string input) - => string.Join(Environment.NewLine, input - .NormalizeLineEndings() - .Split("\n", StringSplitOptions.RemoveEmptyEntries) - .Select(x => x.Indent())); - - private static string NormalizeLineEndings(this string str) => - str.Replace("\r\n", "\n"); -} \ No newline at end of file diff --git a/generators.deprecated/Output/Rendering/MultiLineString.cs b/generators.deprecated/Output/Rendering/MultiLineString.cs deleted file mode 100644 index 37b91b59d..000000000 --- a/generators.deprecated/Output/Rendering/MultiLineString.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using Newtonsoft.Json.Linq; - -namespace Exercism.CSharp.Output.Rendering; - -internal class MultiLineString -{ - public MultiLineString(object obj) => - Lines = obj switch - { - string[] lines => lines, - string line => line.Split("\n"), - JArray _ => Array.Empty(), - _ => throw new ArgumentException("Unsupported multi-line string type", nameof(obj)) - }; - - public string[] Lines { get; } -} \ No newline at end of file diff --git a/generators.deprecated/Output/Rendering/Render.cs b/generators.deprecated/Output/Rendering/Render.cs deleted file mode 100644 index 92a4576da..000000000 --- a/generators.deprecated/Output/Rendering/Render.cs +++ /dev/null @@ -1,87 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Numerics; -using System.Text.RegularExpressions; - -namespace Exercism.CSharp.Output.Rendering; - -internal partial class Render -{ - public string Object(object? val) - { - if (val == null) - return "null"; - - switch (val) - { - case string str: return String(str); - case decimal dec: return Decimal(dec); - case double dbl: return Double(dbl); - case int i: return Int(i); - case uint ui: return Uint(ui); - case float flt: return Float(flt); - case ulong ulng: return Ulong(ulng); - case long l: return Long(l); - case char c: return Char(c); - case DateTime dateTime: return DateTime(dateTime); - case Regex regex: return Regex(regex); - case BigInteger bigInt: return BigInteger(bigInt); - default: - if (IsList(val)) - return List((dynamic)val); - - if (IsHashSet(val)) - return HashSet((dynamic)val); - - if (IsArray(val)) - return Array((dynamic)val); - - if (IsDictionary(val)) - return Dictionary((dynamic)val); - - return val.ToString()!; - } - } - - public string ObjectMultiLine(object val) - { - if (val == null) - return "null"; - - switch (val) - { - case MultiLineString multiLineValue: - return StringMultiLine(multiLineValue); - default: - if (IsDictionary(val)) - return DictionaryMultiLine((dynamic) val); - - if (IsArray(val)) - return RenderArrayAsMultiline((dynamic) val) - ? ArrayMultiLine((dynamic) val) - : Array((dynamic) val); - - return Object(val); - } - } - - private static bool IsList(object obj) - => obj.GetType().IsGenericType && obj.GetType().GetGenericTypeDefinition() == typeof(List<>); - - private static bool IsArray(object obj) - => obj.GetType().IsArray; - - private static bool IsHashSet(object obj) - => obj.GetType().IsGenericType && obj.GetType().GetGenericTypeDefinition() == typeof(HashSet<>); - - private static bool IsDictionary(object obj) - => obj.GetType().IsGenericType && obj.GetType().GetGenericTypeDefinition() == typeof(Dictionary<,>); - - private static bool RenderArrayAsMultiline(T[,] _) => true; - - private static bool RenderArrayAsMultiline(T[] elements) - => IsNestedArray(elements) && elements.Length > 0; - - private static bool IsNestedArray(T[] elements) - => elements.GetType()!.GetElementType()!.IsArray; -} \ No newline at end of file diff --git a/generators.deprecated/Output/Rendering/RenderArray.cs b/generators.deprecated/Output/Rendering/RenderArray.cs deleted file mode 100644 index 5e1543307..000000000 --- a/generators.deprecated/Output/Rendering/RenderArray.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Exercism.CSharp.Helpers; - -namespace Exercism.CSharp.Output.Rendering; - -internal partial class Render -{ - public string Array(T[] elements) => - elements.Length == 0 - ? $"Array.Empty<{typeof(T).ToFriendlyName()}>()" - : $"new[]{CollectionInitializer(elements)}"; - - public string ArrayMultiLine(T[] elements) - => elements.Length == 0 - ? $"Array.Empty<{typeof(T).ToFriendlyName()}>()" - : $"new[]{MultiLineCollectionInitializer(elements)}"; - - public string Array(T[,] elements) - => elements.Length == 0 - ? $"new {typeof(T).ToFriendlyName()}[,] {{ }}" - : $"new[,]{CollectionInitializer(elements.Rows())}"; - - public string ArrayMultiLine(T[,] elements) - => elements.Length == 0 - ? $"new {typeof(T).ToFriendlyName()}[,] {{ }}" - : $"new[,]{MultiLineCollectionInitializer(elements.Rows(), CollectionInitializer)}"; -} \ No newline at end of file diff --git a/generators.deprecated/Output/Rendering/RenderAssert.cs b/generators.deprecated/Output/Rendering/RenderAssert.cs deleted file mode 100644 index cd18aeec5..000000000 --- a/generators.deprecated/Output/Rendering/RenderAssert.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; - -namespace Exercism.CSharp.Output.Rendering; - -internal partial class Render -{ - public string AssertNull(string actual) - => RenderTemplate("AssertNull", new { actual }); - - public string AssertEmpty(string expected, string actual) - => RenderTemplate("AssertEmpty", new { expected, actual }); - - public string AssertEqual(string expected, string actual) - => RenderTemplate("AssertEqual", new { expected, actual }); - - public string AssertEqualWithin(string expected, string actual, int precision) - => RenderTemplate("AssertEqualWithin", new { expected, actual, precision }); - - public string AssertNotEqual(string expected, string actual) - => RenderTemplate("AssertNotEqual", new { expected, actual }); - - public string AssertBoolean(bool expected, string actual) - => RenderTemplate("AssertBoolean", new { expected = expected.ToString(), actual }); - - public string AssertMatches(string expected, string actual) - => RenderTemplate("AssertMatches", new { expected, actual }); - - public string AssertInRange(string expected, int lower, int upper) - => RenderTemplate("AssertInRange", new { expected, lower, upper }); - - public string AssertInRange(string expected, string lower, string upper) - => RenderTemplate("AssertInRange", new { expected, lower, upper }); - - public string AssertThrows(Type expectedException, string actual) - => RenderTemplate("AssertThrows", new { expected = expectedException.Name, actual }); - - public string AssertThrows(string actual) - => AssertThrows(typeof(T), actual); - - private static string RenderTemplate(string template, object parameters) - => Template.Render(template, parameters); -} \ No newline at end of file diff --git a/generators.deprecated/Output/Rendering/RenderCollection.cs b/generators.deprecated/Output/Rendering/RenderCollection.cs deleted file mode 100644 index 22b448cc0..000000000 --- a/generators.deprecated/Output/Rendering/RenderCollection.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Exercism.CSharp.Output.Rendering; - -internal partial class Render -{ - public string CollectionInitializer(IEnumerable elements) - => CollectionInitializer(elements, line => Object(line), " "); - - public string CollectionInitializer(IEnumerable elements, Func render) - => CollectionInitializer(elements, render, " "); - - public string MultiLineCollectionInitializer(IEnumerable elements) - => CollectionInitializer(elements, line => Object(line).Indent(), Environment.NewLine); - - public string MultiLineCollectionInitializer(IEnumerable elements, Func render) - => CollectionInitializer(elements, line => render(line).Indent(), Environment.NewLine); - - private static string CollectionInitializer(IEnumerable elements, Func render, string separator) - => $"{separator}{{{separator}{string.Join($",{separator}", elements.Select(render))}{separator}}}"; -} \ No newline at end of file diff --git a/generators.deprecated/Output/Rendering/RenderDateTime.cs b/generators.deprecated/Output/Rendering/RenderDateTime.cs deleted file mode 100644 index 7cb4943d8..000000000 --- a/generators.deprecated/Output/Rendering/RenderDateTime.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; - -namespace Exercism.CSharp.Output.Rendering; - -internal partial class Render -{ - public string DateTime(DateTime dateTime) => - dateTime.Hour == 0 && dateTime.Minute == 0 && dateTime.Second == 0 - ? $"new DateTime({dateTime.Year}, {dateTime.Month}, {dateTime.Day})" - : $"new DateTime({dateTime.Year}, {dateTime.Month}, {dateTime.Day}, {dateTime.Hour}, {dateTime.Minute}, {dateTime.Second})"; -} \ No newline at end of file diff --git a/generators.deprecated/Output/Rendering/RenderDictionary.cs b/generators.deprecated/Output/Rendering/RenderDictionary.cs deleted file mode 100644 index 606bc53fa..000000000 --- a/generators.deprecated/Output/Rendering/RenderDictionary.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Collections.Generic; -using Exercism.CSharp.Helpers; - -namespace Exercism.CSharp.Output.Rendering; - -internal partial class Render -{ - public string Dictionary(IDictionary dict) => - dict.Count == 0 - ? $"new Dictionary<{typeof(TKey).ToFriendlyName()}, {typeof(TValue).ToFriendlyName()}>()" - : $"new Dictionary<{typeof(TKey).ToFriendlyName()}, {typeof(TValue).ToFriendlyName()}>{CollectionInitializer(dict, KeyValueAssignment)}"; - - public string DictionaryMultiLine(IDictionary dict) => - dict.Count == 0 - ? $"new Dictionary<{typeof(TKey).ToFriendlyName()}, {typeof(TValue).ToFriendlyName()}>()" - : $"new Dictionary<{typeof(TKey).ToFriendlyName()}, {typeof(TValue).ToFriendlyName()}>{MultiLineCollectionInitializer(dict, KeyValueAssignment)}"; - - private string KeyValueAssignment(KeyValuePair kv) => $"[{Object(kv.Key)}] = {Object(kv.Value)}"; -} \ No newline at end of file diff --git a/generators.deprecated/Output/Rendering/RenderExtensions.cs b/generators.deprecated/Output/Rendering/RenderExtensions.cs deleted file mode 100644 index 8ba769b65..000000000 --- a/generators.deprecated/Output/Rendering/RenderExtensions.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace Exercism.CSharp.Output.Rendering; - -internal static class RenderExtensions -{ - private const int IndentSize = 4; - - public static string Indent(this string str) => $"{new string(' ', IndentSize)}{str}"; - - public static string EscapeSpecialCharacters(this string str) - => str.Replace("\n", "\\n") - .Replace("\t", "\\t") - .Replace("\r", "\\r") - .Replace("\"", "\\\""); - - public static string Quote(this string str) => $"\"{str}\""; - - public static string Quote(this char c) => $"'{c}'"; -} \ No newline at end of file diff --git a/generators.deprecated/Output/Rendering/RenderHashSet.cs b/generators.deprecated/Output/Rendering/RenderHashSet.cs deleted file mode 100644 index 69bb19709..000000000 --- a/generators.deprecated/Output/Rendering/RenderHashSet.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -using Exercism.CSharp.Helpers; - -namespace Exercism.CSharp.Output.Rendering; - -internal partial class Render -{ - public string HashSet(HashSet elements) => - elements.Any() - ? $"new HashSet<{typeof(T).ToFriendlyName()}>{CollectionInitializer(elements)}" - : $"new HashSet<{typeof(T).ToFriendlyName()}>()"; -} \ No newline at end of file diff --git a/generators.deprecated/Output/Rendering/RenderList.cs b/generators.deprecated/Output/Rendering/RenderList.cs deleted file mode 100644 index b10e3cc6f..000000000 --- a/generators.deprecated/Output/Rendering/RenderList.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using Exercism.CSharp.Helpers; - -namespace Exercism.CSharp.Output.Rendering; - -internal partial class Render -{ - public string List(List elements) => - elements.Any() - ? $"new List<{typeof(T).ToFriendlyName()}>{CollectionInitializer(elements)}" - : $"new List<{typeof(T).ToFriendlyName()}>()"; -} \ No newline at end of file diff --git a/generators.deprecated/Output/Rendering/RenderNumber.cs b/generators.deprecated/Output/Rendering/RenderNumber.cs deleted file mode 100644 index 952e92eaf..000000000 --- a/generators.deprecated/Output/Rendering/RenderNumber.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Globalization; -using System.Numerics; - -namespace Exercism.CSharp.Output.Rendering; - -internal partial class Render -{ - public string Decimal(decimal dec) => $"{dec.ToString(CultureInfo.InvariantCulture)}m"; - - public string Double(double dbl) => dbl.ToString(CultureInfo.InvariantCulture); - - public string Float(float flt) => flt.ToString(CultureInfo.InvariantCulture); - - public string Int(int i) => i.ToString(CultureInfo.InvariantCulture); - - public string Long(long lng) => $"{lng}L"; - - public string Ulong(ulong ulng) => $"{ulng}UL"; - - public string Uint(uint ui) => string.Format("0x{0:X}u", ui); - - public string BigInteger(BigInteger bigInt) => $"new BigInteger({bigInt.ToString()})"; -} \ No newline at end of file diff --git a/generators.deprecated/Output/Rendering/RenderString.cs b/generators.deprecated/Output/Rendering/RenderString.cs deleted file mode 100644 index 852a40dfb..000000000 --- a/generators.deprecated/Output/Rendering/RenderString.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text.RegularExpressions; -using Humanizer; - -namespace Exercism.CSharp.Output.Rendering; - -internal partial class Render -{ - public UnescapedValue Enum(string enumType, string enumCase) - => new($"{enumType}.{enumCase.ToLower().Dehumanize()}"); - - public string Char(char c) => c.Quote(); - - public string String(string s) => s.EscapeSpecialCharacters().Quote(); - - public string StringMultiLine(MultiLineString multiLineString) - { - return multiLineString.Lines.Length switch - { - 0 => String(string.Empty), - 1 => String(multiLineString.Lines[0]), - _ => $"{Environment.NewLine}{string.Join(Environment.NewLine, RenderLines())}" - }; - - IEnumerable RenderLines() => - multiLineString.Lines.Select((t, i) => i < multiLineString.Lines.Length - 1 - ? $"{String($"{t}\n").Indent()} +" - : $"{String(t).Indent()}"); - } - - public string Regex(Regex regex) => String(regex.ToString()); -} \ No newline at end of file diff --git a/generators.deprecated/Output/Rendering/RenderVariable.cs b/generators.deprecated/Output/Rendering/RenderVariable.cs deleted file mode 100644 index 5b237628b..000000000 --- a/generators.deprecated/Output/Rendering/RenderVariable.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using Exercism.CSharp.Helpers; - -namespace Exercism.CSharp.Output.Rendering; - -internal partial class Render -{ - public IEnumerable Variables(IDictionary variables) - => variables.Select(Variable).ToArray(); - - private string Variable(KeyValuePair variable) - => Variable(variable.Key.ToVariableName(), ObjectMultiLine(variable.Value)); - - public string Variable(string name, string value) => $"var {name} = {value};"; -} \ No newline at end of file diff --git a/generators.deprecated/Output/Rendering/Template.cs b/generators.deprecated/Output/Rendering/Template.cs deleted file mode 100644 index 5bd9e2a99..000000000 --- a/generators.deprecated/Output/Rendering/Template.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Reflection; -using DotLiquid; -using DotLiquid.FileSystems; - -namespace Exercism.CSharp.Output.Rendering; - -internal static class Template -{ - private static readonly string EmbeddedTemplatesNamespace = $"{typeof(Template).Namespace}.Templates"; - - static Template() - { - DotLiquid.Template.RegisterFilter(typeof(IndentFilter)); - DotLiquid.Template.FileSystem = new EmbeddedFileSystem(Assembly.GetEntryAssembly(), EmbeddedTemplatesNamespace); - } - - public static string Render(string template, object parameters) - => DotLiquid.Template.Parse($"{{% include \"{template}\" %}}").Render(Hash.FromAnonymousObject(parameters)); -} \ No newline at end of file diff --git a/generators.deprecated/Output/Rendering/Templates/_Act.liquid b/generators.deprecated/Output/Rendering/Templates/_Act.liquid deleted file mode 100644 index 5f282702b..000000000 --- a/generators.deprecated/Output/Rendering/Templates/_Act.liquid +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/generators.deprecated/Output/Rendering/Templates/_Arrange.liquid b/generators.deprecated/Output/Rendering/Templates/_Arrange.liquid deleted file mode 100644 index dbfb04947..000000000 --- a/generators.deprecated/Output/Rendering/Templates/_Arrange.liquid +++ /dev/null @@ -1,3 +0,0 @@ -{%- for variable in Variables -%} -{{ variable }} -{%- endfor -%} \ No newline at end of file diff --git a/generators.deprecated/Output/Rendering/Templates/_AssertBoolean.liquid b/generators.deprecated/Output/Rendering/Templates/_AssertBoolean.liquid deleted file mode 100644 index 09377ab8b..000000000 --- a/generators.deprecated/Output/Rendering/Templates/_AssertBoolean.liquid +++ /dev/null @@ -1 +0,0 @@ -Assert.{{ expected }}({{ actual }}); \ No newline at end of file diff --git a/generators.deprecated/Output/Rendering/Templates/_AssertEmpty.liquid b/generators.deprecated/Output/Rendering/Templates/_AssertEmpty.liquid deleted file mode 100644 index e9c3bd6d5..000000000 --- a/generators.deprecated/Output/Rendering/Templates/_AssertEmpty.liquid +++ /dev/null @@ -1 +0,0 @@ -Assert.Empty({{ actual }}); \ No newline at end of file diff --git a/generators.deprecated/Output/Rendering/Templates/_AssertEqual.liquid b/generators.deprecated/Output/Rendering/Templates/_AssertEqual.liquid deleted file mode 100644 index 2333a5bfe..000000000 --- a/generators.deprecated/Output/Rendering/Templates/_AssertEqual.liquid +++ /dev/null @@ -1 +0,0 @@ -Assert.Equal({{ expected }}, {{ actual }}); \ No newline at end of file diff --git a/generators.deprecated/Output/Rendering/Templates/_AssertEqualWithin.liquid b/generators.deprecated/Output/Rendering/Templates/_AssertEqualWithin.liquid deleted file mode 100644 index 3bb7756cf..000000000 --- a/generators.deprecated/Output/Rendering/Templates/_AssertEqualWithin.liquid +++ /dev/null @@ -1 +0,0 @@ -Assert.Equal({{ expected }}, {{ actual }}, precision: {{ precision }}); \ No newline at end of file diff --git a/generators.deprecated/Output/Rendering/Templates/_AssertInRange.liquid b/generators.deprecated/Output/Rendering/Templates/_AssertInRange.liquid deleted file mode 100644 index b425bdae8..000000000 --- a/generators.deprecated/Output/Rendering/Templates/_AssertInRange.liquid +++ /dev/null @@ -1 +0,0 @@ -Assert.InRange({{ expected }}, {{ lower }}, {{ upper }}); \ No newline at end of file diff --git a/generators.deprecated/Output/Rendering/Templates/_AssertMatches.liquid b/generators.deprecated/Output/Rendering/Templates/_AssertMatches.liquid deleted file mode 100644 index d84f82b6e..000000000 --- a/generators.deprecated/Output/Rendering/Templates/_AssertMatches.liquid +++ /dev/null @@ -1 +0,0 @@ -Assert.Matches({{ expected }}, {{ actual }}); \ No newline at end of file diff --git a/generators.deprecated/Output/Rendering/Templates/_AssertNotEqual.liquid b/generators.deprecated/Output/Rendering/Templates/_AssertNotEqual.liquid deleted file mode 100644 index b3af0ab81..000000000 --- a/generators.deprecated/Output/Rendering/Templates/_AssertNotEqual.liquid +++ /dev/null @@ -1 +0,0 @@ -Assert.NotEqual({{ expected }}, {{ actual }}); \ No newline at end of file diff --git a/generators.deprecated/Output/Rendering/Templates/_AssertNull.liquid b/generators.deprecated/Output/Rendering/Templates/_AssertNull.liquid deleted file mode 100644 index 3b88555e7..000000000 --- a/generators.deprecated/Output/Rendering/Templates/_AssertNull.liquid +++ /dev/null @@ -1 +0,0 @@ -Assert.Null({{ actual }}); \ No newline at end of file diff --git a/generators.deprecated/Output/Rendering/Templates/_AssertThrows.liquid b/generators.deprecated/Output/Rendering/Templates/_AssertThrows.liquid deleted file mode 100644 index 5c700c93e..000000000 --- a/generators.deprecated/Output/Rendering/Templates/_AssertThrows.liquid +++ /dev/null @@ -1 +0,0 @@ -Assert.Throws<{{ expected }}>(() => {{ actual }}); \ No newline at end of file diff --git a/generators.deprecated/Output/Rendering/Templates/_TestClass.liquid b/generators.deprecated/Output/Rendering/Templates/_TestClass.liquid deleted file mode 100644 index c0671b1a8..000000000 --- a/generators.deprecated/Output/Rendering/Templates/_TestClass.liquid +++ /dev/null @@ -1,12 +0,0 @@ -{%- for namespace in Namespaces -%} -using {{ namespace }}; -{%- endfor -%} - -public class {{ClassName}}{% if IsDisposable %} : IDisposable{% endif %} -{ -{%- for method in Methods -%} -{{ method | indent }} -{%- if forloop.last == false %} -{% endif -%} -{%- endfor -%} -} diff --git a/generators.deprecated/Output/Rendering/Templates/_TestMethod.liquid b/generators.deprecated/Output/Rendering/Templates/_TestMethod.liquid deleted file mode 100644 index bb6048bc6..000000000 --- a/generators.deprecated/Output/Rendering/Templates/_TestMethod.liquid +++ /dev/null @@ -1,5 +0,0 @@ -[Fact{% if Skip %}(Skip = "Remove this Skip property to run this test"){% endif %}] -public void {{ Name }}() -{ -{{ Body | indent }} -} \ No newline at end of file diff --git a/generators.deprecated/Output/Rendering/UnescapedValue.cs b/generators.deprecated/Output/Rendering/UnescapedValue.cs deleted file mode 100644 index 4037b03d0..000000000 --- a/generators.deprecated/Output/Rendering/UnescapedValue.cs +++ /dev/null @@ -1,14 +0,0 @@ -using DotLiquid; - -namespace Exercism.CSharp.Output.Rendering; - -internal class UnescapedValue : ILiquidizable -{ - private readonly string _value; - - public UnescapedValue(string value) => _value = value; - - public override string ToString() => _value; - - public object ToLiquid() => _value; -} \ No newline at end of file diff --git a/generators.deprecated/Output/TestClass.cs b/generators.deprecated/Output/TestClass.cs deleted file mode 100644 index 2db75294e..000000000 --- a/generators.deprecated/Output/TestClass.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Collections.Generic; - -namespace Exercism.CSharp.Output; - -internal record TestClass(string Exercise, string ClassName, IReadOnlyCollection TestMethods) -{ - public ICollection AdditionalMethods { get; } = new List(); - public ISet Namespaces { get; } = new SortedSet(); - public bool IsDisposable { get; set; } -} \ No newline at end of file diff --git a/generators.deprecated/Output/TestClassOutput.cs b/generators.deprecated/Output/TestClassOutput.cs deleted file mode 100644 index d3cd93c9c..000000000 --- a/generators.deprecated/Output/TestClassOutput.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Exercism.CSharp.Helpers; -using Exercism.CSharp.Output.Rendering; - -namespace Exercism.CSharp.Output; - -internal class TestClassOutput -{ - private readonly TestClass _testClass; - private readonly Options _options; - - public TestClassOutput(TestClass testClass, Options options) - { - _testClass = testClass; - _options = options; - } - - public void WriteToFile() - { - Directory.CreateDirectory(Path.GetDirectoryName(FilePath)!); - File.WriteAllText(FilePath, Render()); - } - - private string FilePath => Path.Combine(_options.PracticeExercisesDir, _testClass.Exercise, $"{_testClass.ClassName}.cs"); - - private string Render() => Template.Render("TestClass", RenderParameters); - - private object RenderParameters => new - { - _testClass.ClassName, - _testClass.IsDisposable, - Methods, - Namespaces - }; - - private IEnumerable Methods => - _testClass.TestMethods - .Select(testMethod => new TestMethodOutput(testMethod).Render()) - .Concat(_testClass.AdditionalMethods); - - private SortedSet Namespaces => - _testClass.TestMethods - .Where(x => x.ExceptionThrown != null) - .Select(x => x.ExceptionThrown!.Namespace!) - .Concat(_testClass.Namespaces) - .Append("Xunit") - .ToSortedSet(); -} \ No newline at end of file diff --git a/generators.deprecated/Output/TestMethod.cs b/generators.deprecated/Output/TestMethod.cs deleted file mode 100644 index a00306602..000000000 --- a/generators.deprecated/Output/TestMethod.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Exercism.CSharp.Exercises; -using Exercism.CSharp.Helpers; -using Exercism.CSharp.Input; - -namespace Exercism.CSharp.Output; - -internal class TestMethod -{ - private readonly HashSet _inputParameters = new(StringComparer.OrdinalIgnoreCase); - private readonly HashSet _constructorInputParameters = new(StringComparer.OrdinalIgnoreCase); - - public TestMethod(Exercise exercise, TestCase testCase) - { - Input = new Dictionary(testCase.Input, StringComparer.OrdinalIgnoreCase); - Expected = testCase.Expected; - Property = testCase.Property; - Description = testCase.Description; - Scenarios = testCase.Scenarios; - TestMethodName = testCase.Description.ToTestMethodName(); - TestMethodNameWithPath = string.Join(" - ", testCase.DescriptionPath).ToTestMethodName(); - TestedClass = exercise.Name.ToTestedClassName(); - TestedMethod = testCase.Property.ToTestedMethodName(); - Skip = testCase.Index > 0; - - InputParameters = testCase.Input.Keys.ToArray(); - } - - public string? Act { get; set; } - public string? Arrange { get; set; } - public string? Assert { get; set; } - - public IDictionary Input { get; } - public dynamic? Expected { get; set; } - public string Property { get; } - public string Description { get; } - public string[] Scenarios { get; } - public bool Skip { get; set; } - - public bool UseVariablesForInput { get; set; } - public bool UseVariableForExpected { get; set; } - public bool UseVariablesForConstructorParameters { get; set; } - public bool UseVariableForTested { get; set; } - public bool UseVariableForSut => TestedMethodType is TestedMethodType.InstanceMethod or TestedMethodType.Property; - public bool ForceEvaluation { get; set; } - - public string TestMethodName { get; set; } - public string TestMethodNameWithPath { get; } - public string TestedClass { get; set; } - public string TestedMethod { get; set; } - public TestedMethodType TestedMethodType { get; set; } - public Type? ExceptionThrown { get; set; } - public bool ExpectedIsError => Expected is Dictionary dict && dict.ContainsKey("error"); - - public ICollection InputParameters - { - get => _inputParameters; - set - { - _inputParameters.Clear(); - _inputParameters.UnionWith(value); - - _constructorInputParameters.ExceptWith(value); - } - } - - public ICollection ConstructorInputParameters - { - get => _constructorInputParameters; - set - { - _constructorInputParameters.Clear(); - _constructorInputParameters.UnionWith(value); - - _inputParameters.ExceptWith(value); - } - } -} \ No newline at end of file diff --git a/generators.deprecated/Output/TestMethodOutput.cs b/generators.deprecated/Output/TestMethodOutput.cs deleted file mode 100644 index e55fd3874..000000000 --- a/generators.deprecated/Output/TestMethodOutput.cs +++ /dev/null @@ -1,157 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Text.RegularExpressions; -using Exercism.CSharp.Exercises; -using Exercism.CSharp.Helpers; -using Exercism.CSharp.Output.Rendering; - -namespace Exercism.CSharp.Output; - -internal class TestMethodOutput -{ - private const string SutVariableName = "sut"; - private const string TestedVariableName = "actual"; - private const string ExpectedVariableName = "expected"; - - private static readonly Render Renderer = new(); - private readonly TestMethod _testMethod; - - public TestMethodOutput(TestMethod testMethod) => _testMethod = testMethod; - - public IEnumerable Variables - { - get - { - var lines = new List(); - - if (_testMethod.UseVariablesForInput) - lines.AddRange(InputVariables); - - if (_testMethod.UseVariablesForConstructorParameters) - lines.AddRange(ConstructorVariables); - - if (_testMethod.UseVariableForSut) - lines.Add(SutVariableDeclaration); - - if (_testMethod.UseVariableForTested) - lines.Add(TestedVariable); - - if (_testMethod.UseVariableForExpected) - lines.Add(ExpectedVariable); - - return lines; - } - } - - public IEnumerable InputVariables => Renderer.Variables(_testMethod.InputParameters.ToDictionary(key => key, key => _testMethod.Input[key])); - public string InputValues => string.Join(", ", _testMethod.InputParameters.Select(key => _testMethod.UseVariablesForInput ? key.ToVariableName() : Renderer.Object(_testMethod.Input[key]))); - - public IEnumerable ConstructorVariables => Renderer.Variables(_testMethod.ConstructorInputParameters.ToDictionary(key => key, key => _testMethod.Input[key])); - public string ConstructorValues => string.Join(", ", _testMethod.ConstructorInputParameters.Select(key => _testMethod.UseVariablesForConstructorParameters ? key.ToVariableName() : Renderer.Object(_testMethod.Input[key]))); - - public string SutVariableDeclaration => Renderer.Variable(SutVariableName, SutParameter); - public string SutParameter => _testMethod.UseVariableForSut ? $"new {_testMethod.TestedClass}({ConstructorValues})" : SutVariableName; - - public string TestedVariable => Renderer.Variable(TestedVariableName, TestedMethodInvocation); - public string TestedValue - { - get - { - var value = _testMethod.UseVariableForTested ? TestedVariableName : TestedMethodInvocation; - return _testMethod.ForceEvaluation ? $"{value}.ToArray()" : value; - } - } - - public string ExpectedVariable => Renderer.Variable(ExpectedVariableName, Renderer.ObjectMultiLine(_testMethod.Expected)); - public string ExpectedValue => _testMethod.UseVariableForExpected ? ExpectedVariableName : Renderer.Object(_testMethod.Expected); - - public string TestedMethodInvocation => - _testMethod.TestedMethodType switch - { - TestedMethodType.StaticMethod => $"{_testMethod.TestedClass}.{_testMethod.TestedMethod}({InputValues})", - TestedMethodType.ExtensionMethod => $"{InputValues}.{_testMethod.TestedMethod}()", - TestedMethodType.InstanceMethod => $"{SutVariableName}.{_testMethod.TestedMethod}({InputValues})", - TestedMethodType.Property => $"{SutVariableName}.{_testMethod.TestedMethod}", - TestedMethodType.Constructor => $"new {_testMethod.TestedClass}({ConstructorValues})", - _ => throw new ArgumentOutOfRangeException() - }; - - public string Render() - { - Update(); - - _testMethod.Arrange ??= RenderArrange(); - _testMethod.Act ??= RenderAct(); - _testMethod.Assert ??= RenderAssert(); - - return Template.Render("TestMethod", RenderValues); - } - - public string RenderArrange() => Template.Render("Arrange", new { Variables }); - - public string RenderAct() => Template.Render("Act", new { }); - - public string RenderAssert() => - CurrentAssertType switch - { - AssertType.Equal => Renderer.AssertEqual(ExpectedValue, TestedValue), - AssertType.Empty => Renderer.AssertEmpty(ExpectedValue, TestedValue), - AssertType.Null => Renderer.AssertNull(TestedValue), - AssertType.Throws => Renderer.AssertThrows(_testMethod.ExceptionThrown!, TestedValue), - AssertType.Boolean => Renderer.AssertBoolean(Convert.ToBoolean(_testMethod.Expected), TestedValue), - AssertType.Matches => Renderer.AssertMatches(ExpectedValue, TestedValue), - _ => throw new ArgumentOutOfRangeException() - }; - - private object RenderValues => new - { - Name = _testMethod.TestMethodName, _testMethod.Skip, - Body = string.Join(Environment.NewLine, [_testMethod.Arrange, _testMethod.Act, _testMethod.Assert]) - }; - - private void Update() - { - switch (CurrentAssertType) - { - case AssertType.Empty: - _testMethod.UseVariableForExpected = false; - break; - case AssertType.Throws: - _testMethod.UseVariableForExpected = false; - _testMethod.UseVariableForTested = false; - break; - } - } - - private AssertType CurrentAssertType - { - get - { - if (_testMethod.ExceptionThrown != null) - return AssertType.Throws; - - return _testMethod.Expected switch - { - null => AssertType.Null, - bool _ => AssertType.Boolean, - Regex _ => AssertType.Matches, - _ => UseEmptyAssertion ? AssertType.Empty : AssertType.Equal - }; - } - } - - private bool UseEmptyAssertion - => !(_testMethod.Expected is string) && _testMethod.Expected is IEnumerable enumerable && enumerable.GetEnumerator().MoveNext() == false; - - private enum AssertType - { - Equal, - Empty, - Null, - Throws, - Boolean, - Matches - } -} \ No newline at end of file diff --git a/generators.deprecated/Program.cs b/generators.deprecated/Program.cs deleted file mode 100644 index c32e002b9..000000000 --- a/generators.deprecated/Program.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System.Collections.Generic; - -using CommandLine; -using Exercism.CSharp.Exercises; - -using Serilog; - -namespace Exercism.CSharp; - -public static class Program -{ - public static void Main(string[] args) - { - Logging.Setup(); - - Options.Parse(args) - .WithParsed(OnParseSuccess) - .WithNotParsed(OnParseError); - } - - private static void OnParseSuccess(Options options) - { - var generatorRunner = new GeneratorRunner(options); - - // TODO: enable nullable - if (options.Exercise == null) - generatorRunner.RegenerateAllExercises(); - else - generatorRunner.RegenerateSingleExercise(options.Exercise); - } - - private static void OnParseError(IEnumerable errors) => - Log.Error("Errors: {Errors}", errors); -} \ No newline at end of file