コード例 #1
0
        public BufferingTextReader(TextReader source) {
            if (source == null) { throw new ArgumentNullException("source"); }

            InnerReader = source;
            _locationTracker = new SourceLocationTracker();

            UpdateCurrentCharacter();
        }
コード例 #2
0
        public void UpdateLocationAdvancesAbsoluteIndexOnSlashN() {
            // Arrange
            SourceLocationTracker tracker = new SourceLocationTracker(TestStartLocation);

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

            // Assert
            Assert.AreEqual(11, tracker.CurrentLocation.AbsoluteIndex);
        }
コード例 #3
0
        public void UpdateLocationDoesNotAdvanceLineIndexOnNonNewlineCharacter() {
            // Arrange
            SourceLocationTracker tracker = new SourceLocationTracker(TestStartLocation);

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

            // Assert
            Assert.AreEqual(42, tracker.CurrentLocation.LineIndex);
        }
コード例 #4
0
        public void UpdateLocationAdvancesCharacterIndexOnNonNewlineCharacter()
        {
            // Arrange
            SourceLocationTracker tracker = new SourceLocationTracker(TestStartLocation);

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

            // Assert
            Assert.Equal(46, tracker.CurrentLocation.CharacterIndex);
        }
コード例 #5
0
        public void UpdateLocationAdvancesLineIndexOnSlashN()
        {
            // Arrange
            SourceLocationTracker tracker = new SourceLocationTracker(TestStartLocation);

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

            // Assert
            Assert.Equal(43, tracker.CurrentLocation.LineIndex);
        }
コード例 #6
0
 internal void CalculateStart(Span prev)
 {
     if (prev == null)
     {
         Start = SourceLocation.Zero;
     }
     else
     {
         Start = new SourceLocationTracker(prev.Start).UpdateLocation(prev.Content).CurrentLocation;
     }
 }
コード例 #7
0
        public void UpdateLocationAdvancesCorrectlyForMultiLineString()
        {
            // Arrange
            SourceLocationTracker 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);
        }
コード例 #8
0
        public void UpdateLocationAdvancesAbsoluteIndexOnSlashRFollowedByNonNewlineCharacter()
        {
            // Arrange
            SourceLocationTracker tracker = new SourceLocationTracker(TestStartLocation);

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

            // Assert
            Assert.Equal(11, tracker.CurrentLocation.AbsoluteIndex);
        }
コード例 #9
0
ファイル: Span.cs プロジェクト: marojeri/aspnetwebstack
 public void ChangeStart(SourceLocation newStart)
 {
     _start = newStart;
     Span current = this;
     SourceLocationTracker tracker = new SourceLocationTracker(newStart);
     tracker.UpdateLocation(Content);
     while ((current = current.Next) != null)
     {
         current._start = tracker.CurrentLocation;
         tracker.UpdateLocation(current.Content);
     }
 }
コード例 #10
0
 public SpanFactory()
 {
     LocationTracker = new SourceLocationTracker();
 }
コード例 #11
0
ファイル: Span.cs プロジェクト: jesshaw/ASP.NET-Mvc-3
 private void UpdateOffset() {
     SourceLocationTracker tracker = new SourceLocationTracker();
     tracker.UpdateLocation(Content);
     Offset = tracker.CurrentLocation;
 }
コード例 #12
0
 private static void EvaluateSpan(ErrorCollector collector, SourceLocationTracker tracker, Span actual, Span expected) {
     if (!actual.Equals(expected)) {
         AddMismatchError(collector, tracker, actual, expected);
     }
     else {
         AddPassedMessage(collector, tracker, expected);
     }
 }
コード例 #13
0
 private static void AddMismatchError(ErrorCollector collector, SourceLocationTracker tracker, SyntaxTreeNode actual, SyntaxTreeNode expected) {
     collector.AddError("{0} - FAILED :: Actual: {1}", expected, actual);
 }
コード例 #14
0
        private static void EvaluateSyntaxTreeNode(ErrorCollector collector, SourceLocationTracker tracker, SyntaxTreeNode actual, SyntaxTreeNode expected) {
            if (actual == null) {
                AddNullActualError(collector, tracker, actual, expected);
            }

            if (actual.IsBlock != expected.IsBlock) {
                AddMismatchError(collector, tracker, actual, expected);
            }
            else {
                if (expected.IsBlock) {
                    EvaluateBlock(collector, tracker, (Block)actual, (Block)expected);
                }
                else {
                    EvaluateSpan(collector, tracker, (Span)actual, (Span)expected);
                }
            }
        }
コード例 #15
0
        public void UpdateLocationResetsCharacterIndexOnSlashRFollowedByNonNewlineCharacter() {
            // Arrange
            SourceLocationTracker tracker = new SourceLocationTracker(TestStartLocation);

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

            // Assert
            Assert.AreEqual(0, tracker.CurrentLocation.CharacterIndex);
        }
コード例 #16
0
        private void HandleWhitespaceRewriting() {
            Debug.Assert(!String.IsNullOrEmpty(_nextSpanToOutput.Content));

            // Check the last span for trailing whitespace
            int endOfWhitespaceToCapture = _nextSpanToOutput.Content.Length;
            for (int i = _nextSpanToOutput.Content.Length - 1; i >= 0; i--) {
                char c = _nextSpanToOutput.Content[i];
                if (CharUtils.IsNewLine(c)) {
                    break;
                }
                else if (!Char.IsWhiteSpace(c)) {
                    return; // Saw non-whitespace before newline, markup owns this whitespace so don't touch it
                }
                else {
                    endOfWhitespaceToCapture = i;
                }
            }

            // Ok, endOfWhitespaceToCapture is now at the offset of the first whitespace character after the newline
            string oldContent = _nextSpanToOutput.Content;
            _nextSpanToOutput.Content = oldContent.Substring(0, endOfWhitespaceToCapture);

            SourceLocationTracker tracker = new SourceLocationTracker();
            tracker.CurrentLocation = _nextSpanToOutput.Start;
            tracker.UpdateLocation(_nextSpanToOutput.Content);
            Span whitespaceSpan = new CodeSpan(tracker.CurrentLocation, oldContent.Substring(endOfWhitespaceToCapture));

            Visitor.VisitSpan(_nextSpanToOutput);
            _nextSpanToOutput = whitespaceSpan;
        }
コード例 #17
0
 private static void AddNullActualError(ErrorCollector collector, SourceLocationTracker tracker, SyntaxTreeNode actual, SyntaxTreeNode expected) {
     collector.AddError("{0} - FAILED :: Actual: << Null >>", expected);
 }
コード例 #18
0
        public void UpdateLocationAdvancesCharacterIndexOnSlashRFollowedBySlashN()
        {
            // Arrange
            SourceLocationTracker tracker = new SourceLocationTracker(TestStartLocation);

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

            // Assert
            Assert.Equal(46, tracker.CurrentLocation.CharacterIndex);
        }
コード例 #19
0
 private static void EvaluateBlock(ErrorCollector collector, SourceLocationTracker tracker, Block actual, Block expected) {
     if (actual.Type != expected.Type) {
         AddMismatchError(collector, tracker, actual, expected);
     }
     else {
         AddPassedMessage(collector, tracker, expected);
         using (collector.Indent()) {
             IEnumerator<SyntaxTreeNode> expectedNodes = expected.Children.GetEnumerator();
             IEnumerator<SyntaxTreeNode> actualNodes = actual.Children.GetEnumerator();
             while (expectedNodes.MoveNext()) {
                 if (!actualNodes.MoveNext()) {
                     collector.AddError("{0} - FAILED :: No more elements at this node", expectedNodes.Current);
                 }
                 else {
                     EvaluateSyntaxTreeNode(collector, tracker, actualNodes.Current, expectedNodes.Current);
                 }
             }
             while (actualNodes.MoveNext()) {
                 collector.AddError("End of Node - FAILED :: Found Node: {0}", actualNodes.Current);
             }
         }
     }
 }
コード例 #20
0
        public void UpdateLocationDoesNotAdvanceLineIndexOnSlashRFollowedBySlashN() {
            // Arrange
            SourceLocationTracker tracker = new SourceLocationTracker(TestStartLocation);

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

            // Assert
            Assert.AreEqual(42, tracker.CurrentLocation.LineIndex);
        }
コード例 #21
0
 private static void AddPassedMessage(ErrorCollector collector, SourceLocationTracker tracker, SyntaxTreeNode expected) {
     collector.AddMessage("{0} - PASSED", expected);
 }
コード例 #22
0
        public void UpdateLocationResetsCharacterIndexOnSlashN()
        {
            // Arrange
            SourceLocationTracker tracker = new SourceLocationTracker(TestStartLocation);

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

            // Assert
            Assert.Equal(0, tracker.CurrentLocation.CharacterIndex);
        }
コード例 #23
0
        public static void EvaluateParseTree(TestContext context, Block actualRoot, Block expectedRoot) {
            // Evaluate the result
            ErrorCollector collector = new ErrorCollector();
            SourceLocationTracker tracker = new SourceLocationTracker();

            // Link all the nodes
            Span first = null;
            Span previous = null;
            foreach (Span span in expectedRoot.Flatten()) {
                if(first == null) {
                    first = span;
                }
                span.Previous = previous;
                if (previous != null) {
                    previous.Next = span;
                }
                previous = span;
            }
            Span.ClearCachedStartPoints(first);

            if (expectedRoot == null) {
                Assert.IsNull(actualRoot, "Expected an empty document.  Actual: {0}", actualRoot);
            }
            else {
                Assert.IsNotNull(actualRoot, "Expected a valid document, but it was empty");
                EvaluateSyntaxTreeNode(collector, tracker, actualRoot, expectedRoot);
                if (collector.Success) {
                    if (context != null) {
                        context.WriteLine("Parse Tree Validation Succeeded:\r\n{0}", collector.Message);
                    }
                }
                else {
                    Assert.Fail("\r\n{0}", collector.Message);
                }
            }
        }