Skip to content

Commit cfead40

Browse files
CopilotJustinGrote
andauthored
Add transition coverage for workspace open document saved state
Agent-Logs-Url: https://github.com/PowerShell/PowerShellEditorServices/sessions/f6b6da25-a6a1-4158-9738-3a65a7e3008e Co-authored-by: JustinGrote <15258962+JustinGrote@users.noreply.github.com>
1 parent e105ee6 commit cfead40

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

test/PowerShellEditorServices.Test/Extensions/EditorOperationsServiceTests.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,43 @@ public void GetWorkspaceOpenDocumentsReturnsOnlyOpenDocumentsAndCurrentInMemoryS
4646
Assert.DoesNotContain(documents, static document => document.Path.EndsWith("closed.ps1"));
4747
}
4848

49+
[Fact]
50+
public void GetWorkspaceOpenDocumentsTracksEditedAndUntitledSaveStates()
51+
{
52+
WorkspaceService workspaceService = new(NullLoggerFactory.Instance);
53+
54+
ScriptFile openSaved = CreateFileBuffer(workspaceService, "open-saved.ps1");
55+
openSaved.IsOpen = true;
56+
57+
ScriptFile openUntitled = workspaceService.GetFileBuffer("untitled:Untitled-1", initialBuffer: string.Empty);
58+
openUntitled.IsOpen = true;
59+
60+
EditorOperationsService editorOperationsService = new(
61+
psesHost: null,
62+
workspaceService,
63+
languageServer: null);
64+
65+
WorkspaceOpenDocument[] initialDocuments = editorOperationsService.GetWorkspaceOpenDocuments();
66+
Assert.Contains(initialDocuments, static document => document.Path.EndsWith("open-saved.ps1") && document.Saved);
67+
Assert.Contains(initialDocuments, static document => document.Path.StartsWith("untitled:", StringComparison.Ordinal) && !document.Saved);
68+
69+
openSaved.ApplyChange(new FileChange
70+
{
71+
IsReload = true,
72+
InsertString = "Set-StrictMode -Version Latest"
73+
});
74+
75+
WorkspaceOpenDocument[] editedDocuments = editorOperationsService.GetWorkspaceOpenDocuments();
76+
Assert.Contains(editedDocuments, static document => document.Path.EndsWith("open-saved.ps1") && !document.Saved);
77+
78+
openSaved.IsInMemory = openSaved.IsUntitled;
79+
openUntitled.IsInMemory = openUntitled.IsUntitled;
80+
81+
WorkspaceOpenDocument[] savedDocuments = editorOperationsService.GetWorkspaceOpenDocuments();
82+
Assert.Contains(savedDocuments, static document => document.Path.EndsWith("open-saved.ps1") && document.Saved);
83+
Assert.Contains(savedDocuments, static document => document.Path.StartsWith("untitled:", StringComparison.Ordinal) && !document.Saved);
84+
}
85+
4986
private static ScriptFile CreateFileBuffer(WorkspaceService workspaceService, string fileName)
5087
{
5188
string filePath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"), fileName);

0 commit comments

Comments
 (0)