|
From: David C. <dc...@us...> - 2005-10-02 21:31:46
|
Update of /cvsroot/rubyeclipse/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/core/builder In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8729/src/org/rubypeople/rdt/internal/core/builder Added Files: TC_TaskCompiler.java IndexUpdater_UT.java ShamMarkerManager.java ShamRubyParser.java TS_CoreBuilder.java TC_RdtCompiler.java Log Message: Refactored RubyBuilder into several smaller classes. Wrote UTs for a few of them. Began work on a SymbolIndex. --- NEW FILE: TC_TaskCompiler.java --- package org.rubypeople.rdt.internal.core.builder; import java.io.IOException; import java.io.Reader; import java.util.ArrayList; import java.util.Collections; import java.util.List; import junit.framework.TestCase; import org.rubypeople.eclipse.shams.resources.ShamFile; import org.rubypeople.eclipse.shams.runtime.ShamPreferences; import org.rubypeople.rdt.internal.core.parser.TaskParser; import org.rubypeople.rdt.internal.core.parser.TaskTag; public class TC_TaskCompiler extends TestCase { private static final TaskTag TASK_TAG = new TaskTag("",0,0,0,0); private ShamMarkerManager markerManager; private ShamTaskParser taskParser; private TaskCompiler taskCompiler; private ShamFile file; private static class ShamTaskParser extends TaskParser { private String contents; private List tasks = new ArrayList(); public ShamTaskParser() { super(new ShamPreferences()); } public void parse(Reader reader) throws IOException { contents = IoUtils.readAll(reader); } public List getTasks() { return tasks; } public void assertFileContents(String expectedContents) { assertEquals(expectedContents, contents); } public void addTaskToReturn(TaskTag taskTag) { tasks.add(taskTag); } } public void setUp() { markerManager = new ShamMarkerManager(); taskParser = new ShamTaskParser(); taskCompiler = new TaskCompiler(markerManager, taskParser); file = new ShamFile(""); file.setContents("fileContents"); } public void testCompile() throws Exception { taskParser.addTaskToReturn(TASK_TAG); taskCompiler.compileFile(file); taskParser.assertFileContents("fileContents"); markerManager.assertTasksCreated(file, Collections.singletonList(TASK_TAG)); } } --- NEW FILE: ShamRubyParser.java --- package org.rubypeople.rdt.internal.core.builder; import java.io.Reader; import junit.framework.Assert; import org.eclipse.core.resources.IFile; import org.jruby.ast.Node; import org.jruby.lexer.yacc.SyntaxException; import org.rubypeople.rdt.internal.core.parser.RubyParser; public class ShamRubyParser extends RubyParser { private IFile fileArg; private String contentArg; private SyntaxException syntaxException; private Node parseResult; public Node parse(IFile file, Reader reader) { fileArg = file; contentArg = IoUtils.readAllQuietly(reader); if (syntaxException != null) throw syntaxException; return parseResult; } public void assertParsed(IFile expectedFile, String expectedContent) { Assert.assertEquals("File", expectedFile, fileArg); Assert.assertEquals("Content", expectedContent, contentArg); } public void setExceptionToThrow(SyntaxException syntaxException) { this.syntaxException = syntaxException; } public void setParseResult(Node parseResult) { this.parseResult = parseResult; } } --- NEW FILE: TC_RdtCompiler.java --- package org.rubypeople.rdt.internal.core.builder; import junit.framework.TestCase; import org.eclipse.core.resources.IFile; import org.jruby.ast.Node; import org.jruby.ast.visitor.NodeVisitor; import org.jruby.lexer.yacc.SyntaxException; import org.rubypeople.eclipse.shams.resources.ShamFile; import org.rubypeople.rdt.internal.core.symbols.SymbolIndex; public class TC_RdtCompiler extends TestCase { private static final String FILE_CONTENTS = "file Contents"; private static final String FILENAME = "testFile.rb"; private ShamFile file; private ShamMarkerManager markerManager; private ShamRubyParser parser; private RdtCompiler compiler; private MockIndexUpdater indexUpdater; private Node rootNode; public void setUp() { file = new ShamFile(FILENAME); file.setContents(FILE_CONTENTS); rootNode = new Node() { public void accept(NodeVisitor visitor) { } }; markerManager = new ShamMarkerManager(); parser = new ShamRubyParser(); parser.setParseResult(rootNode); indexUpdater = new MockIndexUpdater(); compiler = new RdtCompiler(markerManager, parser, indexUpdater); } public void testParserInvocation() throws Exception { compiler.compileFile(file); parser.assertParsed(file, FILE_CONTENTS); file.assertContentStreamClosed(); // DSC // indexUpdater.assertUpdated(file, rootNode); } public void testSyntaxException() throws Exception { SyntaxException syntaxException = new SyntaxException(null, ""); parser.setExceptionToThrow(syntaxException); compiler.compileFile(file); file.assertContentStreamClosed(); markerManager.assertErrorCreated(file, syntaxException); } private static final class MockIndexUpdater extends IndexUpdater { public MockIndexUpdater() { super(null); } private Node rootNodeArg; private IFile fileArg; public void update(IFile file, Node rootNode) { fileArg = file; rootNodeArg = rootNode; } public void assertUpdated(IFile expectedFile, Node expectedRootNode) { assertEquals("File", expectedFile, fileArg); assertEquals("Node", expectedRootNode, rootNodeArg); } } } --- NEW FILE: ShamMarkerManager.java --- /** * */ package org.rubypeople.rdt.internal.core.builder; import java.util.List; import junit.framework.Assert; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.jruby.lexer.yacc.SyntaxException; import org.rubypeople.eclipse.shams.resources.ShamFile; public class ShamMarkerManager implements IMarkerManager { private IFile fileArg; private List tasksArg; private String messageArg; private int lineArg; private int startOffsetArg; private int endOffsetArg; private SyntaxException syntaxExceptionArg; public void removeProblemsAndTasksFor(IResource resource) { } public void createSyntaxError(IFile file, SyntaxException syntaxException) { fileArg = file; syntaxExceptionArg = syntaxException; } public void assertErrorCreated(ShamFile expectedFile, SyntaxException expectedSyntaxException) { Assert.assertEquals("file", expectedFile, fileArg); Assert.assertEquals("syntaxException", expectedSyntaxException, syntaxExceptionArg); } public void createTasks(IFile file, List tasks) throws CoreException { fileArg = file; tasksArg = tasks; } public void assertTasksCreated(IFile expectedFile, List expectedTasks) { Assert.assertEquals("file", expectedFile, fileArg); Assert.assertEquals("tasks", expectedTasks, tasksArg); } public void assertWarningAdded(IFile file, String message) { Assert.assertEquals("File", file, fileArg); Assert.assertEquals("Warning Message", message, messageArg); } public void addWarning(IFile file, String message) { fileArg = file; messageArg = message; } public void assertWarningAdded(IFile file, String message, int line, int startOffset, int endOffset) { Assert.assertEquals("File", file, fileArg); Assert.assertEquals("Warning Message", message, messageArg); Assert.assertEquals("line", line, lineArg); Assert.assertEquals("startOffset", startOffset, startOffsetArg); Assert.assertEquals("endOffset", endOffset, endOffsetArg); } public void addWarning(IFile file, String message, int line, int startOffset, int endOffset) { fileArg = file; messageArg = message; lineArg = line; startOffsetArg = startOffset; endOffsetArg = endOffset; } } --- NEW FILE: IndexUpdater_UT.java --- package org.rubypeople.rdt.internal.core.builder; import junit.framework.TestCase; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IPath; import org.jruby.ast.ClassNode; import org.jruby.ast.Node; import org.jruby.ast.TrueNode; import org.jruby.lexer.yacc.ISourcePosition; import org.rubypeople.eclipse.shams.resources.ShamFile; import org.rubypeople.rdt.internal.core.parser.RdtPosition; import org.rubypeople.rdt.internal.core.symbols.ClassSymbol; import org.rubypeople.rdt.internal.core.symbols.SymbolIndex; public class IndexUpdater_UT extends TestCase { private static final RdtPosition POSITION_1 = new RdtPosition(1,2,3); private static final String TEST_CLASS_NAME = "TestClassName"; private IndexUpdater updater; private ShamFile file; private MockSymbolIndex symbolIndex; public void setUp() { file = new ShamFile("TestFile.rb"); symbolIndex = new MockSymbolIndex(); updater = new IndexUpdater(symbolIndex); } public void testIrrelevantNodes() { Node node = new TrueNode(POSITION_1); updater.update(file, node); symbolIndex.assertFlushed(file.getFullPath()); symbolIndex.assertAddNotCalled(); } public void testSimple() { Node node = new ClassNode(POSITION_1, TEST_CLASS_NAME, null, null); updater.update(file, node); symbolIndex.assertFlushed(file.getFullPath()); symbolIndex.assertAdded(new ClassSymbol(TEST_CLASS_NAME), file, POSITION_1); } private static class MockSymbolIndex extends SymbolIndex { private IFile fileArg; private ClassSymbol symbolArg; private ISourcePosition positionArg; private IPath flushedPathArg; public void flush(IPath path) { flushedPathArg = path; } public void assertFlushed(IPath expectedPath) { assertEquals("Flushed path", expectedPath, flushedPathArg); } public void assertAddNotCalled() { assertNull("Unexpected call to assertAddNotCalled()", fileArg); } public void assertAdded(ClassSymbol expectedSymbol, IFile expectedFile, ISourcePosition expectedPosition) { assertEquals("Symbol", expectedSymbol, symbolArg); assertEquals("File", expectedFile, fileArg); assertEquals("Position", expectedPosition, positionArg); } public void add(ClassSymbol symbol, IFile file, ISourcePosition position) { symbolArg = symbol; fileArg = file; positionArg = position; } } } --- NEW FILE: TS_CoreBuilder.java --- package org.rubypeople.rdt.internal.core.builder; import junit.framework.Test; import junit.framework.TestSuite; public class TS_CoreBuilder { public static Test suite() { TestSuite suite = new TestSuite(); suite.addTestSuite(TC_TaskCompiler.class); suite.addTestSuite(TC_RdtCompiler.class); return suite; } } |