@@ -13,7 +13,10 @@ internal static class Templates
1313 public static string RenderTestsCode ( CanonicalData canonicalData )
1414 {
1515 var scriptObject = new ScriptObject ( ) ;
16- scriptObject . Import ( "enum" , new Func < string , string , string > ( ( text , enumType ) => $ "{ enumType . Pascalize ( ) } .{ text . Pascalize ( ) } ") ) ; ;
16+ scriptObject . Import ( "enum" , new Func < string , string , string > ( ( text , enumType ) =>
17+ $ "{ enumType . Pascalize ( ) } .{ text . Pascalize ( ) } ") ) ;
18+ scriptObject . Import ( "property" , new Func < ScriptArray , string , ScriptArray > ( ( testCases , name ) =>
19+ new ScriptArray ( testCases . Cast < ScriptObject > ( ) . Where ( testCase => testCase [ "property" ] . ToString ( ) == name ) ) ) ) ;
1720 scriptObject . Import ( TemplateData . ForCanonicalData ( canonicalData ) ) ;
1821
1922 var context = new TemplateContext ( ) ;
@@ -25,13 +28,8 @@ public static string RenderTestsCode(CanonicalData canonicalData)
2528
2629 private static class TemplateData
2730 {
28- internal static JsonElement ForCanonicalData ( CanonicalData canonicalData )
29- {
30- var testCases = canonicalData . TestCases . Select ( Create ) . ToArray ( ) ;
31- var testCasesByProperty = GroupTestCasesByProperty ( testCases ) ;
32-
33- return JsonSerializer . SerializeToElement ( new { testCases , testCasesByProperty } ) ;
34- }
31+ internal static JsonElement ForCanonicalData ( CanonicalData canonicalData ) =>
32+ JsonSerializer . SerializeToElement ( new { testCases = canonicalData . TestCases . Select ( Create ) . ToArray ( ) } ) ;
3533
3634 private static JsonElement Create ( JsonNode testCase )
3735 {
@@ -40,10 +38,5 @@ private static JsonElement Create(JsonNode testCase)
4038
4139 return JsonSerializer . SerializeToElement ( testCase ) ;
4240 }
43-
44- private static Dictionary < string , JsonElement [ ] > GroupTestCasesByProperty ( IEnumerable < JsonElement > testCases ) =>
45- testCases
46- . GroupBy ( testCase => testCase . GetProperty ( "property" ) . GetString ( ) ! )
47- . ToDictionary ( kv => kv . Key , kv => kv . ToArray ( ) ) ;
4841 }
4942}
0 commit comments