public void UpdateLocationRestsCharacterIndexOnSlashN()
		{
			var tracker = new SourceLocationTracker(TestStartLocation);

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

			Assert.Equal(0, tracker.CurrentLocation.Character);
		}
		public void UpdateLocationDoesNotAdvancedLineIndexOnNonNewlineCharacter()
		{
			var tracker = new SourceLocationTracker(TestStartLocation);

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

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

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

			Assert.Equal(43, tracker.CurrentLocation.Line);
		}
		public void UpdateLocationAdvancesCharacterIndexOnNonNewlineCharacter()
		{
			var tracker = new SourceLocationTracker(TestStartLocation);

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

			Assert.Equal(46, tracker.CurrentLocation.Character);
		}
		public void UpdateLocationAdvancesCorrectlyForMultilineString()
		{
			var tracker = new SourceLocationTracker(TestStartLocation);
			const string text = "foo\nbar\rbaz\r\nbox";

			tracker.UpdateLocation(text);

			Assert.Equal(26, tracker.CurrentLocation.Absolute);
			Assert.Equal(45, tracker.CurrentLocation.Line);
			Assert.Equal(3, tracker.CurrentLocation.Character);
		}
Example #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BufferingTextReader"/> class.
        /// </summary>
        /// <param name="source">The source.</param>
        public BufferingTextReader(TextReader source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            InnerReader = source;
            _tracker    = new SourceLocationTracker();

            UpdateCurrentCharacter();
        }
Example #7
0
		/// <summary>
		/// Initializes a new instance of the <see cref="BufferingTextReader"/> class.
		/// </summary>
		/// <param name="source">The source.</param>
		public BufferingTextReader(TextReader source)
		{
			if (source == null)
			{
				throw new ArgumentNullException("source");
			}

			InnerReader = source;
			_tracker = new SourceLocationTracker();

			UpdateCurrentCharacter();
		}
		public void UpdateLocationAdvancesLineIndexOnSlashRFollowedByNonNewlineCharacter()
		{
			var tracker = new SourceLocationTracker(TestStartLocation);

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

			Assert.Equal(43, tracker.CurrentLocation.Line);
		}
		public void ConstructorWithSourceLocationSetsCurrentLocationToSpecifiedValue()
		{
			var tracker = new SourceLocationTracker(TestStartLocation);

			Assert.Equal(TestStartLocation, tracker.CurrentLocation);
		}
		public void UpdateLocationAdvancesCharacterIndexOnSlashRFollowedBySlashN()
		{
			var tracker = new SourceLocationTracker(TestStartLocation);

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

			Assert.Equal(46, tracker.CurrentLocation.Character);
		}
		public void UpdateLocationAdvancesAbsoluteIndexOnSlashRFollowedBySlashN()
		{
			var tracker = new SourceLocationTracker(TestStartLocation);

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

			Assert.Equal(11, tracker.CurrentLocation.Absolute);
		}
		public void ConstructorSetsCurrentLocationToZero()
		{
			var tracker = new SourceLocationTracker();

			Assert.Equal(SourceLocation.Zero, tracker.CurrentLocation);
		}
		public void UpdateLocationDoesNotAdvancedLineIndexOnSlashRFollowedBySlashN()
		{
			var tracker = new SourceLocationTracker(TestStartLocation);

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

			Assert.Equal(42, tracker.CurrentLocation.Line);
		}
		public void UpdateLocationResetsCharacterIndexOnSlashRFollowedByNonNewlineCharacter()
		{
			var tracker = new SourceLocationTracker(TestStartLocation);

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

			Assert.Equal(0, tracker.CurrentLocation.Character);
		}
Example #15
0
		/// <summary>
		/// Changes the start position of the current span.
		/// </summary>
		/// <param name="newStart">The new start location.</param>
		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);
			}
		}