Esempio n. 1
0
        public BufferingTextReader([NotNull] TextReader source)
        {
            InnerReader = source;
            _locationTracker = new SourceLocationTracker();

            UpdateCurrentCharacter();
        }
        public void UpdateLocationDoesNotAdvanceLineIndexOnNonNewlineCharacter()
        {
            // Arrange
            var tracker = new SourceLocationTracker(TestStartLocation);

            // Act
            tracker.UpdateLocation('f', 'o');

            // Assert
            Assert.Equal(42, tracker.CurrentLocation.LineIndex);
        }
        public void UpdateLocationAdvancesLineIndexOnSlashN()
        {
            // Arrange
            var tracker = new SourceLocationTracker(TestStartLocation);

            // Act
            tracker.UpdateLocation('\n', 'o');

            // Assert
            Assert.Equal(43, tracker.CurrentLocation.LineIndex);
        }
Esempio n. 4
0
        public void UpdateLocationAdvancesAbsoluteIndexOnNonNewlineCharacter()
        {
            // Arrange
            SourceLocationTracker tracker = new SourceLocationTracker(TestStartLocation);

            // Act
            tracker.UpdateLocation('f', 'o');

            // Assert
            Assert.Equal(11, tracker.CurrentLocation.AbsoluteIndex);
        }
Esempio n. 5
0
 internal void CalculateStart(Span prev)
 {
     if (prev == null)
     {
         Start = SourceLocation.Zero;
     }
     else
     {
         Start = new SourceLocationTracker(prev.Start).UpdateLocation(prev.Content).CurrentLocation;
     }
 }
Esempio n. 6
0
        public BufferingTextReader(TextReader source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            InnerReader      = source;
            _locationTracker = new SourceLocationTracker();

            UpdateCurrentCharacter();
        }
Esempio n. 7
0
        public BufferingTextReader(TextReader source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            InnerReader = source;
            _locationTracker = new SourceLocationTracker();

            UpdateCurrentCharacter();
        }
        public void UpdateLocationAdvancesCorrectlyForMultiLineString()
        {
            // Arrange
            var tracker = new SourceLocationTracker(TestStartLocation);

            // Act
            tracker.UpdateLocation("foo\nbar\rbaz\r\nbox");

            // Assert
            Assert.Equal(26, tracker.CurrentLocation.AbsoluteIndex);
            Assert.Equal(45, tracker.CurrentLocation.LineIndex);
            Assert.Equal(3, tracker.CurrentLocation.CharacterIndex);
        }
        public void UpdateLocationAdvancesCharacterIndexOnSlashRFollowedBySlashN()
        {
            // Arrange
            var tracker = new SourceLocationTracker(TestStartLocation);

            // Act
            tracker.UpdateLocation('\r', '\n');

            // Assert
            Assert.Equal(46, tracker.CurrentLocation.CharacterIndex);
        }
        public void UpdateLocationResetsCharacterIndexOnSlashRFollowedByNonNewlineCharacter()
        {
            // Arrange
            var tracker = new SourceLocationTracker(TestStartLocation);

            // Act
            tracker.UpdateLocation('\r', 'o');

            // Assert
            Assert.Equal(0, tracker.CurrentLocation.CharacterIndex);
        }
Esempio n. 11
0
 public void ChangeStart(SourceLocation newStart)
 {
     _start = newStart;
     var current = this;
     var tracker = new SourceLocationTracker(newStart);
     tracker.UpdateLocation(Content);
     while ((current = current.Next) != null)
     {
         current._start = tracker.CurrentLocation;
         tracker.UpdateLocation(current.Content);
     }
 }
Esempio n. 12
0
 public SpanFactory()
 {
     LocationTracker = new SourceLocationTracker();
 }
Esempio n. 13
0
        public void UpdateLocationDoesNotAdvanceLineIndexOnSlashRFollowedBySlashN()
        {
            // Arrange
            SourceLocationTracker tracker = new SourceLocationTracker(TestStartLocation);

            // Act
            tracker.UpdateLocation('\r', '\n');

            // Assert
            Assert.Equal(42, tracker.CurrentLocation.LineIndex);
        }
Esempio n. 14
0
        public void UpdateLocationAdvancesLineIndexOnSlashRFollowedByNonNewlineCharacter()
        {
            // Arrange
            SourceLocationTracker tracker = new SourceLocationTracker(TestStartLocation);

            // Act
            tracker.UpdateLocation('\r', 'o');

            // Assert
            Assert.Equal(43, tracker.CurrentLocation.LineIndex);
        }
Esempio n. 15
0
        public void UpdateLocationResetsCharacterIndexOnSlashN()
        {
            // Arrange
            SourceLocationTracker tracker = new SourceLocationTracker(TestStartLocation);

            // Act
            tracker.UpdateLocation('\n', 'o');

            // Assert
            Assert.Equal(0, tracker.CurrentLocation.CharacterIndex);
        }