Skip to content

Commit

Permalink
improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
filipw committed Nov 29, 2019
1 parent 96af533 commit 704fef5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/OmniSharp.Roslyn.CSharp/Helpers/LocationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public static QuickFix GetQuickFix(this Location location, OmniSharpWorkspace wo
Text = text.Trim(),
FileName = path,
Line = line,
Column = lineSpan.StartLinePosition.Character,
Column = lineSpan.HasMappedPath ? 0 : lineSpan.StartLinePosition.Character, // when a #line directive maps into a separate file, assume columns (0,0)
EndLine = lineSpan.EndLinePosition.Line,
EndColumn = lineSpan.EndLinePosition.Character,
EndColumn = lineSpan.HasMappedPath ? 0 : lineSpan.EndLinePosition.Character,
Projects = documents.Select(document => document.Project.Name).ToArray()
};
}
Expand Down
31 changes: 24 additions & 7 deletions tests/OmniSharp.Roslyn.CSharp.Tests/FindReferencesFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public FooConsumer()
}

[Fact]
public async Task CanFindReferencesWithLineRemapping()
public async Task CanFindReferencesWithLineMapping()
{
const string code = @"
public class Foo
Expand All @@ -137,12 +137,19 @@ public FooConsumer()

var usages = await FindUsagesAsync(code);
Assert.Equal(2, usages.QuickFixes.Count());
Assert.True(usages.QuickFixes.Count(x => x.Line == 0) == 1, "One result should be resolve to line 0");
Assert.True(usages.QuickFixes.Count(x => x.Line == 3) == 1, "One result should be resolve to line 3");

var mappedResult = usages.QuickFixes.FirstOrDefault(x => x.Line == 0);
var regularResult = usages.QuickFixes.FirstOrDefault(x => x.Line == 3);
Assert.NotNull(mappedResult);
Assert.NotNull(regularResult);

// regular result has regular postition
Assert.Equal(32, regularResult.Column);
Assert.Equal(35, regularResult.EndColumn);
}

[Fact]
public async Task CanFindReferencesWithLineRemappingAcrossFiles()
public async Task CanFindReferencesWithLineMappingAcrossFiles()
{
var testFiles = new[]
{
Expand All @@ -167,9 +174,19 @@ public FooConsumer()

var usages = await FindUsagesAsync(testFiles, onlyThisFile: false);
Assert.Equal(2, usages.QuickFixes.Count());
Assert.True(usages.QuickFixes.Count(x => x.Line == 0) == 1, "One result should be resolved to line 1");
Assert.True(usages.QuickFixes.Count(x => x.FileName == "b.cs") == 1, "One result should be resolved to 'b'cs");
Assert.True(usages.QuickFixes.Count(x => x.Line == 3) == 1, "One result should be resolved to line 4");

var mappedResult = usages.QuickFixes.FirstOrDefault(x => x.Line == 0 && x.FileName == "b.cs");
var regularResult = usages.QuickFixes.FirstOrDefault(x => x.Line == 3 && x.FileName == "a.cs");
Assert.NotNull(mappedResult);
Assert.NotNull(regularResult);

// regular result has regular postition
Assert.Equal(32, regularResult.Column);
Assert.Equal(35, regularResult.EndColumn);

// mapped result has column 0,0
Assert.Equal(0, mappedResult.Column);
Assert.Equal(0, mappedResult.EndColumn);
}

[Fact]
Expand Down

0 comments on commit 704fef5

Please sign in to comment.