Skip to content

Commit

Permalink
Make LSP tests less brittle to future changes
Browse files Browse the repository at this point in the history
  • Loading branch information
desplesda committed Dec 16, 2023
1 parent 8b70876 commit 76687e1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
12 changes: 6 additions & 6 deletions YarnSpinner.LanguageServer.Tests/CommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public async Task Server_OnAddNodeCommand_ReturnsTextEdit()

nodeInfo = await GetNodesChangedNotificationAsync(n => n.Uri.ToString().Contains(filePath));

nodeInfo.Nodes.Should().HaveCount(4, "because the file has four nodes");
// Remember how many nodes we had before making the change
var count = nodeInfo.Nodes.Count;

var result = await client.ExecuteCommand(new ExecuteCommandParams<TextDocumentEdit>
{
Expand All @@ -100,7 +101,7 @@ public async Task Server_OnAddNodeCommand_ReturnsTextEdit()

nodeInfo = await nodesChangedAfterChangingText;

nodeInfo.Nodes.Should().HaveCount(5, "because we added a node");
nodeInfo.Nodes.Should().HaveCount(count + 1, "because we added a node");
nodeInfo.Nodes.Should()
.Contain(n => n.Title == "Node",
"because the new node should be called Title")
Expand All @@ -121,7 +122,8 @@ public async Task Server_OnRemoveNodeCommand_ReturnsTextEdit()

NodesChangedParams? nodeInfo = await getInitialNodesChanged;

nodeInfo.Nodes.Should().HaveCount(4, "because the file has four nodes");
// Remember how many nodes we had before making the change
var count = nodeInfo.Nodes.Count;

// Expect to receive a 'nodes changed' notification
Task<NodesChangedParams> nodesChangedAfterRemovingNode = GetNodesChangedNotificationAsync(n => n.Uri.ToString().Contains(filePath));
Expand All @@ -143,7 +145,7 @@ public async Task Server_OnRemoveNodeCommand_ReturnsTextEdit()

nodeInfo = await nodesChangedAfterRemovingNode;

nodeInfo.Nodes.Should().HaveCount(3, "because we removed a node");
nodeInfo.Nodes.Should().HaveCount(count - 1, "because we removed a node");
}

[Fact]
Expand Down Expand Up @@ -330,8 +332,6 @@ public async Task Server_OnGetDebugInfo_ReturnsDebugInfo()
});

// Then
result.Should().HaveCount(3, "there are three projects in the workspace");

var firstProject = result.Should().Contain(info => DocumentUri.GetFileSystemPath(info.SourceProjectUri!) == project1Path).Subject;

firstProject.Variables.Should().NotBeEmpty();
Expand Down
4 changes: 4 additions & 0 deletions YarnSpinner.LanguageServer.Tests/CompletionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public async Task Server_OnCompletingStartOfCommand_ReturnsValidCompletions()

completionResults.Should().NotContain(i => i.Kind == CompletionItemKind.Snippet, "we are in the middle of a command and inserting a snippet is not appropriate");

completionResults.Should().NotBeEmpty();
completionResults.Should().AllSatisfy(item =>
{
item.TextEdit!.TextEdit!.Range.Start.Should().BeEquivalentTo(startOfCommand, "the completion item's range should be the end of the << character");
Expand Down Expand Up @@ -82,6 +83,7 @@ public async Task Server_OnCompletingPartialCommand_ReturnsValidCompletionRange(
// Then
completionResults.Should().Contain(item => item.Kind == CompletionItemKind.Function, "the completion list should contain functions");

completionResults.Should().NotBeEmpty();
completionResults.Should().AllSatisfy(result =>
{
result.TextEdit!.TextEdit!.Range.Start.Should().BeEquivalentTo(startOfCommand, "the completion item's edit should start at the end of the << token");
Expand Down Expand Up @@ -113,6 +115,7 @@ public async Task Server_OnCompletingJumpCommand_ReturnsNodeNames()
});

// Then
completionResults.Should().NotBeEmpty();
completionResults.Should().AllSatisfy(item =>
{
item.Kind.Should().Be(CompletionItemKind.Method, "node names are expected when completing a jump command");
Expand Down Expand Up @@ -149,6 +152,7 @@ public async Task Server_OnCompletingPartialJumpCommand_ReturnsNodeNames()
});

// Then
completionResults.Should().NotBeEmpty();
completionResults.Should().AllSatisfy(item =>
{
item.Kind.Should().Be(CompletionItemKind.Method, "node names are expected when completing a jump command");
Expand Down
6 changes: 3 additions & 3 deletions YarnSpinner.LanguageServer.Tests/WorkspaceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public void Projects_CanOpen()
project.ReloadProjectFromDisk(false);

// Then
project.Files.Should().HaveCount(2);
project.Nodes.Should().HaveCount(5);
project.Files.Should().NotBeEmpty();
project.Nodes.Should().NotBeEmpty();
project.Files.Should().AllSatisfy(file => file.Project.Should().Be(project));

var testFilePath = DocumentUri.FromFileSystemPath(Path.Combine(TestUtility.PathToTestWorkspace, "Project1", "Test.yarn"));
Expand All @@ -43,7 +43,7 @@ public void Workspaces_CanOpen() {

workspace.Projects.SelectMany(p => p.Nodes).Should().NotBeEmpty();

workspace.Projects.Should().HaveCount(3);
workspace.Projects.Should().NotBeEmpty();

// The node NotIncludedInProject is inside a file that is not
// included in a .yarnproject; because we have opened a workspace
Expand Down

0 comments on commit 76687e1

Please sign in to comment.