Skip to content

Commit

Permalink
Fixes #616 Visual Studio runs out of memory
Browse files Browse the repository at this point in the history
Moves "escape" update outside of condition to ensure we always advance even when colour codes are invalid.
Adds test for printing all characters.
  • Loading branch information
zooba committed Jul 18, 2015
1 parent e1289e9 commit e3c7ae5
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
3 changes: 1 addition & 2 deletions Common/Product/ReplWindow/Repl/OutputBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,9 @@ private void AppendEscapedText(string text, bool isError, int escape) {
break;
}
}

escape = text.IndexOf('\x1b', escape + 1);
}// else not an escape sequence, process as text

escape = text.IndexOf('\x1b', escape + 1);
} while (escape != -1);
if (start != text.Length) {
AppendText(text.Substring(start), kind, color);
Expand Down
14 changes: 11 additions & 3 deletions Common/Tests/Utilities.UI/UI/ReplWindowProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,19 @@ private bool MatchTextInternal(IList<string> expected, bool matchAtStart, bool m
// Resplit lines to handle cases where linebreaks are embedded in
// a single string. This helps ensure the comparison is correct and
// the output is sensible.
expected = expected.SelectMany(l => l.Split('\n')).Select(l => l.TrimEnd('\r', '\n')).ToList();
var lines = Window.TextView.TextBuffer.CurrentSnapshot.Lines;
expected = expected.SelectMany(l => l.Split('\n')).Select(l => l.TrimEnd('\r', '\n', ' ')).ToList();
var snapshot = Window.TextView.TextBuffer.CurrentSnapshot;
var lines = snapshot.Lines;
// Cap the number of lines we'll ever look at to avoid breaking here
// when tests get stuck in infinite loops
if (matchAtStart && !matchAtEnd) {
lines = lines.Take(expected.Count + 1);
} else if (!matchAtStart && matchAtEnd) {
lines = lines.Skip(snapshot.LineCount - expected.Count - 2);
}
var actual = lines
.SelectMany(l => l.GetText().Split('\n'))
.Select(l => l.TrimEnd('\r', '\n'))
.Select(l => l.TrimEnd('\r', '\n', ' '))
.ToList();

bool isMatch = true;
Expand Down
3 changes: 1 addition & 2 deletions Common/Tests/Utilities/Mocks/MockReplWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,9 @@ private void AppendEscapedText(string text) {
break;
}
}

escape = text.IndexOf('\x1b', escape + 1);
}// else not an escape sequence, process as text

escape = text.IndexOf('\x1b', escape + 1);
} while (escape != -1);
if (start != text.Length - 1) {
_output.Append(text.Substring(start));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2035,9 +2035,9 @@ public static void AppendEscapedText(this IInteractiveWindow window, string text
break;
}
}

escape = text.IndexOf('\x1b', escape + 1);
}// else not an escape sequence, process as text

escape = text.IndexOf('\x1b', escape + 1);
}

if (start != text.Length) {
Expand Down
16 changes: 16 additions & 0 deletions Python/Tests/ReplWindowUITests/ReplWindowPythonSmokeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*
* ***************************************************************************/

using System;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.PythonTools;
Expand Down Expand Up @@ -148,6 +150,20 @@ public virtual void QuitAndReset() {
}
}

[TestMethod, Priority(0)]
[HostType("VSTestHost")]
public virtual void PrintAllCharacters() {
using (var interactive = Prepare()) {
interactive.SubmitCode("print(\"" +
string.Join("", Enumerable.Range(0, 256).Select(i => string.Format("\\x{0:X2}", i))) +
"\\nDONE\")",
timeout: TimeSpan.FromSeconds(10.0)
);

interactive.WaitForTextEnd("DONE", ">");
}
}

[TestMethod, Priority(0)]
[HostType("VSTestHost")]
public virtual void AttachReplTest() {
Expand Down

0 comments on commit e3c7ae5

Please sign in to comment.