Exemple #1
0
        public void FromSpanNotStartOfLineThrows()
        {
            var text = SourceText.From("abcdef");

            Assert.Throws <ArgumentOutOfRangeException>(
                () => TextLine.FromSpan(text, new TextSpan(1, 5))
                );
        }
Exemple #2
0
        public void FromSpanZeroLengthWithLineBreak()
        {
            var text = SourceText.From(Environment.NewLine);
            var line = TextLine.FromSpan(text, new TextSpan(0, 0));

            Assert.Equal("", line.ToString());
            Assert.Equal(Environment.NewLine.Length, line.SpanIncludingLineBreak.Length);
        }
Exemple #3
0
        public void FromSpanNoBreaksBeforeOrAfter()
        {
            var text = SourceText.From("foo");
            var line = TextLine.FromSpan(text, new TextSpan(0, 3));

            Assert.Equal("foo", line.ToString());
            Assert.Equal(0, line.LineNumber);
        }
Exemple #4
0
        public void FromSpanZeroLengthNotEndOfLineThrows()
        {
            var text = SourceText.From("abcdef");

            Assert.Throws <ArgumentOutOfRangeException>(
                () => TextLine.FromSpan(text, new TextSpan(0, 0))
                );
        }
Exemple #5
0
        public void FromSpanStartsBeforeZeroThrows()
        {
            var text = SourceText.From("abcdef");

            Assert.Throws <ArgumentOutOfRangeException>(
                () => TextLine.FromSpan(text, new TextSpan(-1, 2))
                );
        }
Exemple #6
0
        public void FromSpanLengthGreaterThanTextThrows()
        {
            var text = SourceText.From("abcdef");

            Assert.Throws <ArgumentOutOfRangeException>(
                () => TextLine.FromSpan(text, new TextSpan(1, 10))
                );
        }
Exemple #7
0
        public void FromSpanIncludingBreaks()
        {
            var text = SourceText.From("foo" + Environment.NewLine + "bar");
            var span = TextSpan.FromBounds(0, 5);
            var line = TextLine.FromSpan(text, span);

            Assert.Equal(span, line.SpanIncludingLineBreak);
            Assert.Equal(3, line.End);
            Assert.Equal(0, line.LineNumber);
        }
Exemple #8
0
        public void FromSpanNotIncludingBreaks()
        {
            var text = SourceText.From("foo" + Environment.NewLine);
            var span = new TextSpan(0, 3);
            var line = TextLine.FromSpan(text, span);

            Assert.Equal(span, line.Span);
            Assert.Equal(5, line.EndIncludingLineBreak);
            Assert.Equal(0, line.LineNumber);
        }
Exemple #9
0
        public void FromSpanZeroLengthAtEnd()
        {
            var text  = SourceText.From("foo" + Environment.NewLine);
            var start = text.Length;
            var line  = TextLine.FromSpan(text, new TextSpan(start, 0));

            Assert.Equal("", line.ToString());
            Assert.Equal(0, line.Span.Length);
            Assert.Equal(0, line.SpanIncludingLineBreak.Length);
            Assert.Equal(start, line.Start);
            Assert.Equal(start, line.Span.Start);
            Assert.Equal(start, line.SpanIncludingLineBreak.Start);
            Assert.Equal(1, line.LineNumber);
        }
Exemple #10
0
            public override TextLine this[int index]
            {
                get
                {
                    if (index < 0 || index >= starts.Length)
                    {
                        throw new ArgumentOutOfRangeException(nameof(index));
                    }

                    var start = starts[index];
                    if (index == starts.Length - 1)
                    {
                        return(TextLine.FromSpan(text, TextSpan.FromBounds(start, text.Length)));
                    }

                    var end = starts[index + 1];
                    return(TextLine.FromSpan(text, TextSpan.FromBounds(start, end)));
                }
            }
 public override TextLine this[int index] {
     get {
         var line = sourceText.TextSnapshot.GetLineFromLineNumber(index);
         return(TextLine.FromSpan(sourceText, TextSpan.FromBounds(line.Start, line.End)));
     }
 }
Exemple #12
0
            public override TextLine GetLineFromPosition(int position)
            {
                var line = textDoc.GetLineByOffset(position);

                return(TextLine.FromSpan(parent, new TextSpan(line.Offset, line.Length)));
            }
Exemple #13
0
 public override TextLine this [int index] {
     get {
         var line = textDoc.GetLine(index + 1);
         return(TextLine.FromSpan(parent, new TextSpan(line.Offset, line.Length)));
     }
 }
Exemple #14
0
        public void FromSpanTextNullThrows()
        {
            var text = SourceText.From("abcdef");

            Assert.Throws <ArgumentNullException>(() => TextLine.FromSpan(null, new TextSpan(0, 2)));
        }