public void NestedNamedSpansWithDifferentNames() { const string code = "{|test1:clas{|test2:s C {|} }|}"; var markupCode = TestContent.Parse(code); Assert.Equal("class C { }", markupCode.Code); var spans1 = markupCode.GetSpans("test1"); Assert.Equal(1, spans1.Count); Assert.Equal(TextSpan.FromBounds(0, markupCode.Code.Length), spans1[0]); var spanText1 = markupCode.Code.Substring(spans1[0].Start, spans1[0].Length); Assert.Equal("class C { }", spanText1); var spans2 = markupCode.GetSpans("test2"); Assert.Equal(1, spans2.Count); Assert.Equal(TextSpan.FromBounds(4, 9), spans2[0]); var spanText2 = markupCode.Code.Substring(spans2[0].Start, spans2[0].Length); Assert.Equal("s C {", spanText2); }
public void Should_Parse_Locations_2() { var content = TestContent.Parse( @"0 1 2 $$3 4 5 6 7 8 9" ); content.Code.Should().Be( @"0 1 2 3 4 5 6 7 8 9".NormalizeLineEndings() ); content.Index.Should().Be(6); content.Lines.Should().HaveCount(10); content.GetPositionAtIndex().Should().Be(new Position(3, 0)); content.GetIndexAtPosition(new Position(4, 0)).Should().Be(8); }
public void Position_Marker_Should_be_configurable(char first, char end) { var content = $"hello {first}{end}this is a test"; var testContent = TestContent.Parse(content, new TestContentOptions() { PositionMarker = (first, end) });
public void PositionAtEndShouldBeSameAsCodeLength() { const string code = "class C { }$$"; var markupCode = TestContent.Parse(code); Assert.Equal("class C { }", markupCode.Code); Assert.True(markupCode.HasPosition); Assert.Equal(markupCode.Code.Length, markupCode.Position); }
public void PositionWithInterpolatedString() { const string code = @"class C { string s = $$$""Hello""; }"; var markupCode = TestContent.Parse(code); Assert.Equal(@"class C { string s = $""Hello""; }", markupCode.Code); Assert.True(markupCode.HasPosition); Assert.Equal(21, markupCode.Position); }
public void PositionAtStartShouldBeZero() { const string code = "$$class C { }"; var markupCode = TestContent.Parse(code); Assert.Equal("class C { }", markupCode.Code); Assert.True(markupCode.HasPosition); Assert.Equal(0, markupCode.Position); }
private static void AssertFormatTargetKind(SyntaxKind kind, string input) { var content = TestContent.Parse(input); var tree = SyntaxFactory.ParseSyntaxTree(content.Code); var root = tree.GetRoot(); var target = FormattingWorker.FindFormatTarget(root, content.Position); Assert.Equal(kind, target.Kind()); }
public void Should_Parse_Locations_1() { var content = TestContent.Parse(@"012$$3456789"); content.Code.Should().Be("0123456789"); content.Index.Should().Be(3); content.Lines.Should().HaveCount(1); content.GetPositionAtIndex().Should().Be(new Position(0, 3)); content.GetIndexAtPosition(new Position(0, 5)).Should().Be(5); }
public void EmptyNamedSpanAtEnd() { const string code = "class C { }{|test:|}"; var markupCode = TestContent.Parse(code); Assert.Equal("class C { }", markupCode.Code); var spans = markupCode.GetSpans("test"); Assert.Single(spans); Assert.Equal(TextSpan.FromBounds(markupCode.Code.Length, markupCode.Code.Length), spans[0]); }
public void EmptySpanAtStart() { const string code = "[||]class C { }"; var markupCode = TestContent.Parse(code); Assert.Equal("class C { }", markupCode.Code); var spans = markupCode.GetSpans(); Assert.Equal(1, spans.Count); Assert.Equal(TextSpan.FromBounds(0, 0), spans[0]); }
public void EmptySpanAtEnd() { const string code = "class C { }[||]"; var markupCode = TestContent.Parse(code); Assert.Equal("class C { }", markupCode.Code); var spans = markupCode.GetSpans(); Assert.Equal(1, spans.Count); Assert.Equal(TextSpan.FromBounds(markupCode.Code.Length, markupCode.Code.Length), spans[0]); }
public void NoMarkupHasNoPositionAndNoSpans() { const string code = "class C { }"; var markupCode = TestContent.Parse(code); Assert.Equal("class C { }", markupCode.Code); Assert.False(markupCode.HasPosition); Assert.Throws <InvalidOperationException>(() => { var _ = markupCode.Position; }); var spans = markupCode.GetSpans(); Assert.Equal(0, spans.Count); }
public void NamedSpanAroundInnerCode() { const string code = "clas{|test:s C {|} }"; var markupCode = TestContent.Parse(code); Assert.Equal("class C { }", markupCode.Code); var spans = markupCode.GetSpans("test"); Assert.Equal(1, spans.Count); Assert.Equal(TextSpan.FromBounds(4, 9), spans[0]); var spanText = markupCode.Code.Substring(spans[0].Start, spans[0].Length); Assert.Equal("s C {", spanText); }
public void NamedSpanAroundAllCode() { const string code = "{|test:class C { }|}"; var markupCode = TestContent.Parse(code); Assert.Equal("class C { }", markupCode.Code); var spans = markupCode.GetSpans("test"); Assert.Single(spans); Assert.Equal(TextSpan.FromBounds(0, markupCode.Code.Length), spans[0]); var spanText = markupCode.Code.Substring(spans[0].Start, spans[0].Length); Assert.Equal("class C { }", spanText); }
public void SpanAroundAllCode() { const string code = "[|class C { }|]"; var markupCode = TestContent.Parse(code); Assert.Equal("class C { }", markupCode.Code); var spans = markupCode.GetSpans(); Assert.Equal(1, spans.Count); Assert.Equal(TextSpan.FromBounds(0, markupCode.Code.Length), spans[0]); var spanText = markupCode.Code.Substring(spans[0].Start, spans[0].Length); Assert.Equal("class C { }", spanText); }
public void SpanAroundInnerCode() { const string code = "clas[|s C {|] }"; var markupCode = TestContent.Parse(code); Assert.Equal("class C { }", markupCode.Code); var spans = markupCode.GetSpans(); Assert.Single(spans); Assert.Equal(TextSpan.FromBounds(4, 9), spans[0]); var spanText = markupCode.Code.Substring(spans[0].Start, spans[0].Length); Assert.Equal("s C {", spanText); }
public void NestedSpans() { const string code = "[|clas[|s C {|] }|]"; var markupCode = TestContent.Parse(code); Assert.Equal("class C { }", markupCode.Code); var spans = markupCode.GetSpans(); Assert.Equal(2, spans.Count); Assert.Equal(TextSpan.FromBounds(0, markupCode.Code.Length), spans[0]); Assert.Equal(TextSpan.FromBounds(4, 9), spans[1]); var spanText = markupCode.Code.Substring(spans[0].Start, spans[0].Length); Assert.Equal("class C { }", spanText); spanText = markupCode.Code.Substring(spans[1].Start, spans[1].Length); Assert.Equal("s C {", spanText); }
public async Task FixUsings_ReturnsAmbiguousResult() { const string code = @" namespace nsA { public class classX{} } namespace nsB { public class classX{} } namespace OmniSharp { public class class1 { public method1() { var c1 = new $$classX(); } } }"; var content = TestContent.Parse(code); var point = content.GetPointFromPosition(); var expectedUnresolved = new[] { new QuickFix() { Line = point.Line, Column = point.Offset, FileName = TestFileName, Text = "`classX` is ambiguous" } }; await AssertUnresolvedReferencesAsync(content.Code, expectedUnresolved); }
public void Throw_Error_On_Range(string text, string message) { Action a = () => TestContent.Parse(text); a.Should().Throw <ArgumentException>().WithMessage(message); }
public TestFile(string fileName, string content) : this(fileName, TestContent.Parse(content)) { }