The Tag

The <pre> Tag</pre>

The <pre> Tag

The <pre> tag is pretty simple; just insert it like a <P> tag. Here s the first test:

 [Test] public void InsertPre() { 
model.SetLines (new String[1] {"<P></P>"});
model.SelectionStart = 7; model.InsertPreTag();
AssertEquals("<pre></pre>", model.Lines[1]);
AssertEquals(14, model.SelectionStart);
}

It doesn t compile, of course, so I code it up, copying from the InsertParagraphTag method:

 public void InsertPreTag() { 
InsertTags(newPre, preSkip);
}

And using the requisite new definitions:

 private static string[] newPre = { "<pre></pre>" }; 
private static string paragraphSkip = "<pre>";

Oops, not as smart as I thought. Can you tell I was using cut and paste? That last line should read

 private static string preSkip = "<pre>"; 

That works just fine, and I realize that the normal insert of a tag is already after the previous line, so there s no need to do anything special about searching to the end. I decide to rename the test to InsertPre and let it go at that. Time to write a new Customer Acceptance Test. It looks like this:

 *input 
<P>This is the first paragraph.</P>
<P>This is the second paragraph.</P>
*end
*AltP
*output
<P>This is the first paragraph.</P>
<pre></pre>
<P>This is the second paragraph.</P>

That test won t run, of course, since AltP isn t defined anywhere . This reminds me of that confusion we still have between the menu or keyboard command and the real command. Also, while I was scavenging tests to copy, I didn t find a customer test for inserting a section. I think Chet and I are going to have to work on beefing up the customer tests today, both so that they test more end to end and to add the missing ones. First, though, let s make this one work. We have to add a line to the InterpretCommands method of CustomerTest:

 private void InterpretCommands(String commands, String message) { 
StringReader reader = new StringReader(commands);
String line = reader.ReadLine();
CreateModel();
while ( line != null) {
if ( line == "*enter")
model.Enter();
if ( line == "*altS")
model.AltS();
if ( line == "*altP")
model.AltP();
if (line == "*display")
Console.WriteLine("display\r\n{0}\r\nend", model.TestText);
if (line == "*output")
CompareOutput(reader, message);
if (line == "*input")
SetInput(reader);
line = reader.ReadLine();
}

Now this confuses me! Notice that an altS command is defined ”that means the tests must know how to do InsertSection. Maybe I just didn t see the test.

Lesson  

When I m confused , especially when I have no pair to sort me out, I find it s usually best to get unconfused ASAP. So I m going to comment out the implementation of AltS in the TextModel. If there s a test for it, that test should break, and I ll find out what its name is. While I m at it ”this is risky, doing two things at once, but since I ve written it down here I probably won t forget ”I ll implement the AltP method. Here s both:

 public void AltS() { 
// InsertSectionTags();
}
public void AltP() {
InsertPreTag();
}

OK, good news. There is a section test, named sect1.test. Somehow I just didn t see it. I ll fix that commented line and see what happens.

Well, the test for pre failed, as did a couple of Programmer Unit Tests. I m not surprised by the programmer tests, but it appears that the pre test didn t insert anything at all. Do you see why? I accidentally capitalized AltP in the test, and the code checks for lowercase. If that happens many more times, I think we might have to beef up our testing, but for now, I ll just fix the test.

Now you remember ”and fortunately I remember as well ”that Alt+P shouldn t really work because I haven t put the AltP stuff in the GUI. That has to be done using a menu now, but no test exists to check whether it s there, so I ll fix the Form while I m thinking of it. I know we need that test but I want help to do it, and I can certainly make this work...I think. Here s the new menu code and handlers:

 MenuItem insertSection = new MenuItem ( 
"Insert &Section",
new EventHandler(MenuInsertSection));
MenuItem insertPre = new MenuItem (
"Insert & Pre",
new EventHandler(MenuInsertPre));
this.Menu = new MainMenu(new MenuItem[] {insertPre, insertSection} );
...

void MenuInsertSection(object obj, EventArgs ea) {
model.SetLines(textbox.Lines);
model.SelectionStart = textbox.SelectionStart;
model.InsertSectionTags();
PutText(textbox, model.LinesArray(), model.SelectionStart);
}

void MenuInsertPre(object obj, EventArgs ea) {
model.SetLines(textbox.Lines); model.SelectionStart = textbox.SelectionStart; model.InsertPreTag(); PutText(textbox, model.LinesArray(), model.SelectionStart);
}

I gave you both those handlers so that you can see the duplication I was concerned about. I knew this was going to happen. But we ll deal with that later. The tool works; here s an image:




Extreme Programming Adventures in C#
Javaв„ў EE 5 Tutorial, The (3rd Edition)
ISBN: 735619492
EAN: 2147483647
Year: 2006
Pages: 291

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net