Skip to content

Commit 62850e6

Browse files
committed
Fix tests
1 parent 6d675bf commit 62850e6

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33

4-
from .testdata_utils import generate_from_spec as generate
4+
from .testdata_utils import generate_from_spec as generate

tests/dotnet/lsprotocol_tests/LSPTests.cs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ namespace lsprotocol_tests;
33
using Newtonsoft.Json;
44
using Newtonsoft.Json.Linq;
55

6+
67
public class LSPTests
78
{
89
public static IEnumerable<object[]> JsonTestData()
910
{
10-
string folderPath = Environment.GetEnvironmentVariable("JSON_FOLDER_PATH");
11+
string folderPath = "C:\\GIT\\LSP\\lsprotocol\\packages\\testdata";
12+
1113
string[] jsonFiles = Directory.GetFiles(folderPath, "*.json");
1214
foreach (string filePath in jsonFiles)
1315
{
@@ -22,17 +24,33 @@ public void ValidateLSPTypes(string filePath)
2224
string original = File.ReadAllText(filePath);
2325

2426
// 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
2631
string fileName = Path.GetFileNameWithoutExtension(filePath);
27-
string[] nameParts = fileName.Split('_');
32+
string[] nameParts = fileName.Split('-');
2833
string className = nameParts[0];
34+
bool valid = nameParts[1] == "True";
2935

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+
}
3339

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+
}
3755
}
3856
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
global using Xunit;
2+
global using Microsoft.LanguageServer.Protocol;

0 commit comments

Comments
 (0)