예제 #1
0
        public void MissingOptionalPosition2()
        {
            var markup = "[|first|] {|x:second|}";

            TestFileMarkupParser.GetPositionAndSpans(markup, out _, out int?cursorPosition, out ImmutableDictionary <string, ImmutableArray <TextSpan> > _);
            Assert.Null(cursorPosition);
        }
예제 #2
0
        public void MissingRequiredPosition1()
        {
            var markup = "[|first|] {|x:second|}";
            var ex     = Assert.ThrowsAny <ArgumentException>(() => TestFileMarkupParser.GetPosition(markup, out _, out _));

            Assert.Equal("input", ex.ParamName);
        }
예제 #3
0
        public void MissingOptionalPosition3()
        {
            var markup = "[|first|] {|x:second|}";

            TestFileMarkupParser.GetPositionsAndSpans(markup, out _, out ImmutableArray <int> positions, out ImmutableDictionary <string, ImmutableArray <TextSpan> > _);
            Assert.Empty(positions);
        }
예제 #4
0
        public void MissingRequiredPosition3()
        {
            var markup = "[|first|] {|x:second|}";
            var ex     = Assert.ThrowsAny <ArgumentException>(() => TestFileMarkupParser.GetPositionAndSpans(markup, out _, out int _, out ImmutableArray <TextSpan> _));

            Assert.Equal("input", ex.ParamName);
        }
예제 #5
0
        public void SinglePosition2()
        {
            var markup   = "first$$second[||]";
            var expected = "firstsecond";

            TestFileMarkupParser.GetPositionAndSpan(markup, out var output, out var cursorPosition, out _);
            Assert.Equal(expected, output);
            Assert.Equal(markup.IndexOf("$$"), cursorPosition);
        }
예제 #6
0
        public void SinglePosition6()
        {
            var markup   = "first$$second";
            var expected = "firstsecond";

            TestFileMarkupParser.GetPositionAndSpans(markup, out var output, out int?cursorPosition, out ImmutableDictionary <string, ImmutableArray <TextSpan> > _);
            Assert.Equal(expected, output);
            Assert.Equal(markup.IndexOf("$$"), cursorPosition);
        }
예제 #7
0
        public void MissingOptionalPosition3()
        {
            var markup = "[|first|] {|x:second|}";

            TestFileMarkupParser.GetPositionsAndSpans(markup, out var output, out ImmutableArray <int> positions, out ImmutableDictionary <string, ImmutableArray <TextSpan> > spans);
            Assert.Empty(positions);

            // Test round-trip
            Assert.Equal(markup, TestFileMarkupParser.CreateTestFile(output, positions, spans));
        }
예제 #8
0
        public void MissingOptionalPosition2()
        {
            var markup = "[|first|] {|x:second|}";

            TestFileMarkupParser.GetPositionAndSpans(markup, out var output, out int?cursorPosition, out ImmutableDictionary <string, ImmutableArray <TextSpan> > spans);
            Assert.Null(cursorPosition);

            // Test round-trip
            Assert.Equal(markup, TestFileMarkupParser.CreateTestFile(output, cursorPosition, spans));
        }
예제 #9
0
        public void SinglePosition1()
        {
            var markup   = "first$$second";
            var expected = "firstsecond";

            TestFileMarkupParser.GetPosition(markup, out var output, out var cursorPosition);
            Assert.Equal(expected, output);
            Assert.Equal(markup.IndexOf("$$"), cursorPosition);

            // Test round-trip
            Assert.Equal(markup, TestFileMarkupParser.CreateTestFile(output, cursorPosition));
        }
예제 #10
0
        public void SinglePosition2()
        {
            var markup   = "first$$second[||]";
            var expected = "firstsecond";

            TestFileMarkupParser.GetPositionAndSpan(markup, out var output, out var cursorPosition, out var span);
            Assert.Equal(expected, output);
            Assert.Equal(markup.IndexOf("$$"), cursorPosition);

            // Test round-trip
            Assert.Equal(markup, TestFileMarkupParser.CreateTestFile(output, cursorPosition, ImmutableArray.Create(span)));
        }
예제 #11
0
        public void SinglePosition5()
        {
            var markup   = "first$$second";
            var expected = "firstsecond";

            TestFileMarkupParser.GetPositionAndSpans(markup, out var output, out int?cursorPosition, out ImmutableArray <TextSpan> spans);
            Assert.Equal(expected, output);
            Assert.Equal(markup.IndexOf("$$"), cursorPosition);

            // Test round-trip
            Assert.Equal(markup, TestFileMarkupParser.CreateTestFile(output, cursorPosition, spans));
        }
예제 #12
0
        public void MissingOptionalPosition1()
        {
            var markup = "[|first|] {|x:second|}";

            TestFileMarkupParser.GetPositionAndSpans(markup, out var output, out int?cursorPosition, out ImmutableArray <TextSpan> spans);
            Assert.Null(cursorPosition);

            // Test round-trip. In this case, named spans are ignored due to the API used for parsing the original
            // markup string.
            var equivalentMarkup = "[|first|] second";

            Assert.Equal(equivalentMarkup, TestFileMarkupParser.CreateTestFile(output, cursorPosition, spans));
        }
예제 #13
0
        public void MarkupSpanSplitsEndOfLine()
        {
            var markup   = "class C { }\r{|b:\n|}";
            var expected = "class C { }\r\n";

            TestFileMarkupParser.GetPositionsAndSpans(markup, out var result, out var positions, out ImmutableDictionary <string, ImmutableArray <TextSpan> > spans);
            Assert.Equal(expected, result);

            Assert.Empty(positions);
            Assert.Single(spans);

            Assert.True(spans.TryGetValue("b", out var named));
            Assert.Equal(new[] { new TextSpan(12, 1) }, named);

            Assert.False(spans.TryGetValue(string.Empty, out _));
        }
예제 #14
0
        public void CDataMarkup()
        {
            var markup   = "{|X:[|<![CDATA[|]|}text[|]]>|]";
            var expected = "<![CDATA[text]]>";

            TestFileMarkupParser.GetPositionsAndSpans(markup, out var result, out var positions, out ImmutableDictionary <string, ImmutableArray <TextSpan> > spans);
            Assert.Equal(expected, result);

            Assert.Empty(positions);
            Assert.Equal(2, spans.Count);

            Assert.True(spans.TryGetValue("X", out var named));
            Assert.Equal(new[] { new TextSpan(0, 9) }, named);

            Assert.True(spans.TryGetValue(string.Empty, out var unnamed));
            Assert.Equal(new[] { new TextSpan(0, 9), new TextSpan(13, 3) }, unnamed);
        }
예제 #15
0
        public void OverlappingSpans4C()
        {
            var markup = "{|x:first {|#0:seco|}nd|#0}";

            TestFileMarkupParser.GetPositionsAndSpans(markup, out _, out ImmutableArray <int> _, out ImmutableDictionary <string, ImmutableArray <TextSpan> > spans);
            Assert.Equal(2, spans.Count);

            Assert.True(spans.TryGetValue("x", out var xs));
            var x = Assert.Single(xs);

            Assert.Equal(TextSpan.FromBounds(0, 10), x);

            Assert.True(spans.TryGetValue("#0", out var ys));
            var y = Assert.Single(ys);

            Assert.Equal(TextSpan.FromBounds(6, 12), y);
        }
예제 #16
0
        public void OverlappingSpans3A()
        {
            var markup = "{|#0:first {|y:seco|}nd|}";

            TestFileMarkupParser.GetPositionsAndSpans(markup, out var output, out ImmutableArray <int> positions, out ImmutableDictionary <string, ImmutableArray <TextSpan> > spans);
            Assert.Equal(2, spans.Count);

            Assert.True(spans.TryGetValue("#0", out var xs));
            var x = Assert.Single(xs);

            Assert.Equal(TextSpan.FromBounds(0, 12), x);

            Assert.True(spans.TryGetValue("y", out var ys));
            var y = Assert.Single(ys);

            Assert.Equal(TextSpan.FromBounds(6, 10), y);

            // Test round-trip
            Assert.Equal(markup, TestFileMarkupParser.CreateTestFile(output, positions, spans));
        }
예제 #17
0
        public void OverlappingSpans4C()
        {
            var markup = "{|x:first {|#0:seco|}nd|#0}";

            TestFileMarkupParser.GetPositionsAndSpans(markup, out var output, out ImmutableArray <int> positions, out ImmutableDictionary <string, ImmutableArray <TextSpan> > spans);
            Assert.Equal(2, spans.Count);

            Assert.True(spans.TryGetValue("x", out var xs));
            var x = Assert.Single(xs);

            Assert.Equal(TextSpan.FromBounds(0, 10), x);

            Assert.True(spans.TryGetValue("#0", out var ys));
            var y = Assert.Single(ys);

            Assert.Equal(TextSpan.FromBounds(6, 12), y);

            // Test round-trip
            // https://github.com/dotnet/roslyn-sdk/issues/505
            var unexpectedMarkup = "{|x:first {|#0:seco|}nd|}";

            Assert.Equal(unexpectedMarkup, TestFileMarkupParser.CreateTestFile(output, positions, spans));
        }