11using System . Collections . Immutable ;
2- using System . Text . Json ;
3- using System . Text . Json . Nodes ;
2+ using System . Dynamic ;
43
54using LibGit2Sharp ;
65
6+ using Newtonsoft . Json ;
7+ using Newtonsoft . Json . Linq ;
8+
79namespace Generators ;
810
911internal record TestCase (
@@ -17,41 +19,40 @@ internal record TestCase(
1719
1820internal static class CanonicalData
1921{
20- private static readonly JsonSerializerOptions SerializerOptions = new ( ) { PropertyNameCaseInsensitive = true } ;
21-
2222 static CanonicalData ( ) => ProbSpecs . Sync ( ) ;
2323
2424 internal static TestCase [ ] Parse ( Exercise exercise )
2525 {
2626 var json = File . ReadAllText ( Paths . CanonicalDataFile ( exercise ) ) ;
27- var jsonNode = JsonNode . Parse ( json ) ! . AsObject ( ) ;
28- return Parse ( jsonNode , ImmutableQueue < string > . Empty )
27+ var jsonObject = JObject . Parse ( json ) ;
28+ return Parse ( jsonObject , ImmutableQueue < string > . Empty )
2929 . ToArray ( ) ;
3030 }
3131
32- private static IEnumerable < TestCase > Parse ( JsonObject jsonObject , ImmutableQueue < string > path )
32+ private static IEnumerable < TestCase > Parse ( JObject jsonObject , ImmutableQueue < string > path )
3333 {
34- var updatedPath = jsonObject . TryGetPropertyValue ( "description" , out var description )
35- ? path . Enqueue ( description . Deserialize < string > ( ) ! )
34+ var updatedPath = jsonObject . TryGetValue ( "description" , out var description )
35+ ? path . Enqueue ( description . Value < string > ( ) ! )
3636 : path ;
37+
38+ if ( jsonObject . TryGetValue ( "cases" , out var cases ) )
39+ return ( ( JArray ) cases ) . Cast < JObject > ( ) . SelectMany ( child => Parse ( child , updatedPath ) ) ;
3740
38- return jsonObject . TryGetPropertyValue ( "cases" , out var cases )
39- ? cases ! . AsArray ( ) . SelectMany ( child => Parse ( child ! . AsObject ( ) , updatedPath ) )
40- : [ ToTestCase ( jsonObject , updatedPath ) ] ;
41+ return [ ToTestCase ( jsonObject , updatedPath ) ] ;
4142 }
4243
43- private static TestCase ToTestCase ( JsonObject testCaseJson , IEnumerable < string > path )
44+ private static TestCase ToTestCase ( JObject testCaseJson , IEnumerable < string > path )
4445 {
45- testCaseJson [ "path" ] = JsonValue . Create ( path ) ;
46+ testCaseJson [ "path" ] = JArray . FromObject ( path ) ;
4647 testCaseJson [ "error" ] = ToError ( testCaseJson ) ;
47- return testCaseJson . Deserialize < TestCase > ( SerializerOptions ) ! ;
48+ return JsonConvert . DeserializeObject < TestCase > ( testCaseJson . ToString ( ) ) ! ;
4849 }
4950
50- private static JsonNode ? ToError ( JsonObject testCaseJson )
51+ private static JToken ? ToError ( JObject testCaseJson )
5152 {
52- if ( testCaseJson [ "expected" ] is JsonObject expectedJson &&
53- expectedJson . TryGetPropertyValue ( "error" , out var error ) )
54- return error ! . DeepClone ( ) ;
53+ if ( testCaseJson [ "expected" ] is JObject expectedJson &&
54+ expectedJson . TryGetValue ( "error" , out var error ) )
55+ return error . DeepClone ( ) ;
5556
5657 return null ;
5758 }
0 commit comments