Beispiel #1
0
        public void OwnsChangeReturnsFalseIfChangeIsReplacementOrDeleteAtSpanEnd() {
            // Arrange
            Span span = new CodeSpan(new SourceLocation(42, 0, 42), "FooBarBaz");
            TextChange change = new TextChange(51, 2, new StringTextBuffer("BooBarBaz"), 3, new StringTextBuffer("Foo"));

            // Act/Assert
            Assert.IsFalse(span.OwnsChange(change));
        }
Beispiel #2
0
        public void OwnsChangeReturnsFalseIfChangeStartsAfterSpanEnds() {
            // Arrange
            Span span = new CodeSpan(new SourceLocation(42, 0, 42), "FooBarBaz");
            TextChange change = new TextChange(52, 3, new StringTextBuffer("BooBarBaz"), 3, new StringTextBuffer("Foo"));

            // Act/Assert
            Assert.IsFalse(span.OwnsChange(change));
        }
Beispiel #3
0
        public void OwnsChangeReturnsTrueIfChangeIsInsertionAtSpanEndAndCanGrowIsTrue() {
            // Arrange
            Span span = new CodeSpan(new SourceLocation(42, 0, 42), "FooBarBaz");
            TextChange change = new TextChange(51, 0, new StringTextBuffer("BooBarBaz"), 3, new StringTextBuffer("Foo"));

            // Act/Assert
            Assert.IsTrue(span.OwnsChange(change));
        }
Beispiel #4
0
        public void OwnsChangeReturnsTrueIfSpanContentEntirelyContainsOldSpan() {
            // Arrange
            Span span = new CodeSpan(new SourceLocation(42, 0, 42), "FooBarBaz");
            TextChange change = new TextChange(45, 3, new StringTextBuffer("BooBarBaz"), 3, new StringTextBuffer("Foo"));

            // Act/Assert
            Assert.IsTrue(span.OwnsChange(change));
        }
        public void ApplyChangeReturnsRejectedIfTerminatorStringNull() {
            // Arrange
            var span = new CodeSpan(new SourceLocation(0, 0, 0), "foo");
            var change = new TextChange(0, 0, new StringTextBuffer("foo"), 1, new StringTextBuffer("bfoo"));

            // Act
            PartialParseResult result = span.ApplyChange(change);

            // Assert
            Assert.AreEqual(PartialParseResult.Rejected, result);
        }
        public void GetAutoCompleteStringReturnsAutoCompleteString() {
            // Arrange
            var span = new CodeSpan(new SourceLocation(0, 0, 0), "foo\r\nbar\r\nbaz") {
                AutoCompleteString = "Foo"
            };
            
            // Act
            string actual = span.AutoCompleteString;

            // Assert
            Assert.AreEqual("Foo", actual);
        }
        public void ApplyChangeReturnsRejectedWithoutAutoCompleteBlockIfTerminatorStringNonNullAndEditIsNewlineInsertOnSecondLine() {
            // Arrange
            var span = new CodeSpan(new SourceLocation(0, 0, 0), "foo\r\nbar\r\nbaz") {
                AutoCompleteString = "}"
            };
            var change = new TextChange(8, 0, new StringTextBuffer("foo\r\nbar\r\nbaz"), 2, new StringTextBuffer("foo\r\nb\r\nar\r\nbaz"));

            // Act
            PartialParseResult result = span.ApplyChange(change);

            // Assert
            Assert.AreEqual(PartialParseResult.Rejected, result);
        }
Beispiel #8
0
        public void LocateOwnerReturnsSpanWhichReturnsTrueForOwnsSpan() {
            // Arrange
            Span expected = new CodeSpan(new SourceLocation(5, 0, 5), "bar");
            Block block = new MarkupBlock(new SyntaxTreeNode[] {
                new MarkupSpan(SourceLocation.Zero, "Foo "),
                new StatementBlock(new SyntaxTreeNode[] {
                    new TransitionSpan(new SourceLocation(4, 0, 4), "@"),
                    expected,
                }),
                new MarkupSpan(new SourceLocation(8,0,8), " Baz")
            });
            TextChange change = new TextChange(6, 1, new StringTextBuffer("Foo @bar Baz"), 1, new StringTextBuffer("Foo @bor Baz"));

            // Act
            Span actual = block.LocateOwner(change);

            // Assert
            Assert.AreSame(expected, actual);
        }
Beispiel #9
0
        internal bool VisitCodeSpan(CodeSpan code, TextWriter output)
        {
            if (code == null) return false;

            if (code is HelperHeaderSpan)
            {
                log.InfoFormat(HELPER_UNSUPPORTED, code); // TODO: support @Helper methods.
                return true;
            }
            if (code is HelperFooterSpan)
            {
                return true;
            }
            if (code is ImplicitExpressionSpan)
            {
                output.WriteLine("    buffer.push({0});", code.Content);
            }
            else
            {
                StringBuilder codeContent = new StringBuilder(code.Content);
                codeContent.Replace("\r", string.Empty);
                codeContent.Replace("\n", string.Empty);

                string translatedCode = TranslateCodeBlock(codeContent.ToString());
                output.WriteLine(translatedCode);
            }

            return true;
        }
        protected virtual bool VisitCodeSpan(CodeSpan code, TextWriter output)
        {
            if (code == null) return false;

            if (code is HelperHeaderSpan)
            {
                // TODO: Helper support
                Trace.WriteLine(string.Format("Ignoring {0} - Helpers not currently supported", code));
                return true;
            }
            if (code is HelperFooterSpan)
            {
                return true;
            }

            if (code is ImplicitExpressionSpan)
            {
                output.Write("_buf.push(");
                output.Write(code.Content);
                output.Write(");");
            }
            else
            {
                var codeContent = new StringBuilder(code.Content);
                codeContent.Replace("\r", string.Empty);
                codeContent.Replace("\n", string.Empty);

                var translatedCode = TranslateCodeBlock(codeContent.ToString());
                output.Write(translatedCode);
            }

            return true;
        }
Beispiel #11
0
        public void OwnsChangeReturnsFalseIfOldSpanOverlapsNeighbouringSpan() {
            // Arrange
            Span span = new CodeSpan(new SourceLocation(42, 0, 42), "FooBarBaz");
            TextChange change = new TextChange(44, 50, new StringTextBuffer("BooBarBaz"), 3, new StringTextBuffer("Foo"));

            // Act/Assert
            Assert.IsFalse(span.OwnsChange(change)); 
        }
Beispiel #12
0
        public void OwnsChangeReturnsFalseIfChangeIsInsertionAtSpanEndAndCanGrowIsFalse() {
            // Arrange
            Span span = new CodeSpan(new SourceLocation(42, 0, 42), "FooBarBaz", hidden: false, acceptedCharacters: AcceptedCharacters.None);
            TextChange change = new TextChange(51, 0, new StringTextBuffer("BooBarBaz"), 3, new StringTextBuffer("Foo"));

            // Act/Assert
            Assert.IsFalse(span.OwnsChange(change));
        }
Beispiel #13
0
        public void TryMergeWithReturnsTrueAndCorrectlyMergesWhenMergingRightIntoLeftIfSpansAreAdjacent() {
            // Arrange
            Span left = new CodeSpan(new SourceLocation(3, 0, 0), "Foo");
            Span right = new CodeSpan(SourceLocation.Zero, "Bar");

            // Act
            bool success = left.TryMergeWith(right);

            // Assert
            Assert.IsTrue(success);
            Assert.AreEqual("BarFoo", left.Content);
            Assert.AreEqual(SourceLocation.Zero, left.Start);
        }
Beispiel #14
0
        public void TryMergeWithLeavesTypeVisibilityAndTrackingModeUnchanged() {
            // Arrange
            Span left = new CodeSpan(SourceLocation.Zero, "Foo", hidden: true, acceptedCharacters: AcceptedCharacters.None);
            Span right = new MetaCodeSpan(new SourceLocation(3, 0, 0), "Bar");

            // Act
            bool success = left.TryMergeWith(right);

            // Assert
            Assert.IsTrue(success);
            Assert.AreEqual(SpanKind.Code, left.Kind);
            Assert.IsTrue(left.Hidden);
        }
Beispiel #15
0
        public void TryMergeWithReturnsFalseWhenMergingRightIntoLeftIfSpansNotAdjacent() {
            // Arrange
            Span left = new CodeSpan(new SourceLocation(100, 0, 0), "Foo");
            Span right = new CodeSpan(SourceLocation.Zero, "Bar");

            // Act/Assert
            Assert.IsFalse(left.TryMergeWith(right));
        }
        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;
        }