We wrote that customer test, and sure enough it didn t work. No surprise there. I was all for fixing it, but Chet asked, Should we write a failing programmer unit test first? Well, of course we should. So we looked at our SetInput method, the one that reads the input from the input stream and sets it into the TextModel. It goes like this:
private void SetInput(StringReader reader) {
String[] input = ArrayToEnd(reader);
model.Lines = input;
}
We figured it needed to go something like this:
private void SetInput(StringReader reader) {
String[] input = ArrayToEnd(reader);
model.Lines = CleanLines(input);
model.SelectionStart = CursorLocation(input);
}
CleanLines would return a new array of lines with the line containing the vertical bar fixed. And CursorLocation would return the cursor location by counting characters up to the vertical bar. No problem.