@@ -3,11 +3,13 @@ namespace lsprotocol_tests;
3
3
using Newtonsoft . Json ;
4
4
using Newtonsoft . Json . Linq ;
5
5
6
+
6
7
public class LSPTests
7
8
{
8
9
public static IEnumerable < object [ ] > JsonTestData ( )
9
10
{
10
- string folderPath = Environment . GetEnvironmentVariable ( "JSON_FOLDER_PATH" ) ;
11
+ string folderPath = "C:\\ GIT\\ LSP\\ lsprotocol\\ packages\\ testdata" ;
12
+
11
13
string [ ] jsonFiles = Directory . GetFiles ( folderPath , "*.json" ) ;
12
14
foreach ( string filePath in jsonFiles )
13
15
{
@@ -22,17 +24,33 @@ public void ValidateLSPTypes(string filePath)
22
24
string original = File . ReadAllText ( filePath ) ;
23
25
24
26
// Get the class name from the file name
25
- // format: <class-name>_<test-id>.json
27
+ // format: <class-name>-<valid>-<test-id>.json
28
+ // classname => Class name of the type to deserialize to
29
+ // valid => true if the file is valid, false if it is invalid
30
+ // test-id => unique id for the test
26
31
string fileName = Path . GetFileNameWithoutExtension ( filePath ) ;
27
- string [ ] nameParts = fileName . Split ( '_ ' ) ;
32
+ string [ ] nameParts = fileName . Split ( '- ' ) ;
28
33
string className = nameParts [ 0 ] ;
34
+ bool valid = nameParts [ 1 ] == "True" ;
29
35
30
- Type type = Type . GetType ( className ) ?? throw new Exception ( $ "Type { className } not found") ;
31
- object ? deserializedObject = JsonConvert . DeserializeObject ( original , type ) ;
32
- string newJson = JsonConvert . SerializeObject ( deserializedObject ) ;
36
+ Type type = Type . GetType ( $ "Microsoft.LanguageServer.Protocol. { className } , lsprotocol" ) ?? throw new Exception ( $ "Type { className } not found") ;
37
+ RunTest ( valid , original , type ) ;
38
+ }
33
39
34
- JToken token1 = JToken . Parse ( original ) ;
35
- JToken token2 = JToken . Parse ( newJson ) ;
36
- Assert . True ( JToken . DeepEquals ( token1 , token2 ) ) ;
40
+ private static void RunTest ( bool valid , string data , Type type )
41
+ {
42
+ if ( valid )
43
+ {
44
+ object ? deserializedObject = JsonConvert . DeserializeObject ( data , type ) ;
45
+ string newJson = JsonConvert . SerializeObject ( deserializedObject ) ;
46
+
47
+ JToken token1 = JToken . Parse ( data ) ;
48
+ JToken token2 = JToken . Parse ( newJson ) ;
49
+ Assert . True ( JToken . DeepEquals ( token1 , token2 ) ) ;
50
+ }
51
+ else
52
+ {
53
+ Assert . Throws < Exception > ( ( ) => JsonConvert . DeserializeObject ( data , type ) ) ;
54
+ }
37
55
}
38
56
}
0 commit comments