Repository navigation
Expand file tree
/
Copy pathFileContextTests.cs
More file actions
68 lines (57 loc) · 2.55 KB
/
Copy pathFileContextTests.cs
File metadata and controls
68 lines (57 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using Microsoft.PowerShell.EditorServices.Extensions;
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
using Microsoft.PowerShell.EditorServices.Test.Shared;
using Xunit;
namespace PowerShellEditorServices.Test.Extensions
{
[Trait("Category", "Extensions")]
public class FileContextTests
{
private static EditorContext CreateEditorContext(string content, BufferRange selectedRange)
{
string filePath = TestUtilities.NormalizePath(@"C:\Temp\Test.ps1");
ScriptFile scriptFile = ScriptFile.Create(new Uri(filePath), content, new Version("7.0"));
return new EditorContext(
editorOperations: null,
scriptFile,
new BufferPosition(line: 1, column: 1),
selectedRange);
}
// Regression test for https://github.com/PowerShell/PowerShellEditorServices/issues/1496
// where $Context.CurrentFile.GetText($Context.SelectedRange) failed because GetText only
// accepted the concrete FileRange type rather than the IFileRange that SelectedRange returns.
[Fact]
public void CanGetTextFromSelectedRange()
{
EditorContext editorContext = CreateEditorContext(
"Line One\nLine Two\nLine Three",
new BufferRange(2, 1, 2, 9));
IFileRange selectedRange = editorContext.SelectedRange;
string text = editorContext.CurrentFile.GetText(selectedRange);
Assert.Equal("Line Two", text);
}
[Fact]
public void CanGetTextLinesFromSelectedRange()
{
EditorContext editorContext = CreateEditorContext(
"Line One\nLine Two\nLine Three",
new BufferRange(1, 1, 2, 9));
string[] lines = editorContext.CurrentFile.GetTextLines(editorContext.SelectedRange);
Assert.Equal(new[] { "Line One", "Line Two" }, lines);
}
[Fact]
public void CanGetTextFromConstructedFileRange()
{
EditorContext editorContext = CreateEditorContext(
"Line One\nLine Two\nLine Three",
BufferRange.None);
IFileRange range = new FileRange(
new Microsoft.PowerShell.EditorServices.Extensions.FilePosition(3, 1),
new Microsoft.PowerShell.EditorServices.Extensions.FilePosition(3, 11));
Assert.Equal("Line Three", editorContext.CurrentFile.GetText(range));
}
}
}