package bluej.parser;
import java.io.File;
import java.io.StringReader;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
import bluej.parser.symtab.ClassInfo;
import bluej.parser.symtab.Selection;
| Run sample source file(s) containing Java 1.5 specific features
| eg. generics, enums, static imports, foreach, varargs etc.
|
| @author Bruce Quig
|
public class Parse15Test
extends junit.framework.TestCase{
| Get a data or result file from our hidden stash..
| NOTE: the stash of data files is in the ast/data directory.
| This is because eventually, we want all parsing in bluej to
| be done by the AST routines, and we can get rid of this
| parser. So we share the data file until then.
|
| @param name
| @return
|
private File getFile(String name)
{
URL url = getClass().getResource("/bluej/parser/ast/data/" + name);
if (url == null || url.getFile().equals(""))
return null;
else{ return new File(url.getFile());
}
}
| Sets up the test fixture.
|
| Called before every test case method.
|
protected void setUp()
{
}
| Tears down the test fixture.
|
| Called after every test case method.
|
protected void tearDown()
{
}
| Lots of sample files, none of which should cause exceptions
| in our parser. Needs to be run under jdk1.5 or later.
|
| @throws Exception
|
public void testNoParseExceptions()
throws Exception
{
InfoParser.parse(getFile("15_generic.dat"));
}
public void testSelections()
throws Exception
{
ClassInfo info = InfoParser.parse(getFile("generic_selections.dat"));
Selection testSel = info.getSuperReplaceSelection();
assertEquals(3, testSel.getLine());
assertEquals(49, testSel.getColumn());
assertEquals(4, testSel.getEndLine());
assertEquals(31, testSel.getEndColumn());
List<Selection> l = info.getInterfaceSelections();
assertEquals(4, l.size());
Iterator<Selection> i = l.iterator();
i.next();
testSel = (Selection) i.next();
assertEquals(5, testSel.getLine());
assertEquals(16, testSel.getColumn());
assertEquals(5, testSel.getEndLine());
assertEquals(28, testSel.getEndColumn());
i.next();
testSel = (Selection) i.next();
assertEquals(5, testSel.getLine());
assertEquals(30, testSel.getColumn());
assertEquals(5, testSel.getEndLine());
assertEquals(39, testSel.getEndColumn());
}
public void testStaticImport()
{
boolean success = true;
try {
InfoParser.parse(new StringReader(
"import static java.awt.Color.BLACK;\n" +
"class A { }"),
null, null);
}
catch (Exception e) {
success = false;
}
assertTrue(success);
}
}
top,
use,
map,
class Parse15Test
. getFile
. setUp
. tearDown
. testNoParseExceptions
. testSelections
. testStaticImport
114 neLoCode
+ 17 LoComm