Skip to content

Commit

Permalink
Code-assist now works between modules
Browse files Browse the repository at this point in the history
darcs-hash:20060512143103-49d33-9db4bb2f8dc9617165fd4c3e8655497c6bbd497b.gz
  • Loading branch information
thiagoarrais committed May 12, 2006
1 parent 5b138d9 commit 22159c0
Show file tree
Hide file tree
Showing 15 changed files with 307 additions and 544 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#Wed Jan 25 11:43:35 GMT-03:00 2006
eclipse.preferences.version=1
internal.default.compliance=default
#Fri May 12 09:34:09 BRT 2006
eclipse.preferences.version=1
internal.default.compliance=default
org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8"?><templates/>
4 changes: 3 additions & 1 deletion net.sf.eclipsefp.haskell.core.test/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ Bundle-SymbolicName: net.sf.eclipsefp.haskell.core.test
Bundle-Version: 0.10.0
Bundle-Vendor: eclipsefp.sourceforge.net
Bundle-Localization: plugin
Require-Bundle: org.junit,
Require-Bundle: org.antlr,
org.easymock,
org.junit,
org.eclipse.jface.text,
org.eclipse.core.resources,
org.eclipse.core.runtime,
org.eclipse.swt,
net.sf.eclipsefp.haskell.core,
net.sf.eclipsefp.test.util,
net.sf.eclipsefp.haskell.core.jparser,
net.sf.eclipsefp.haskell.core.parser.test
Export-Package: net.sf.eclipsefp.haskell.core.test,
net.sf.eclipsefp.haskell.core.test.util
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
package net.sf.eclipsefp.haskell.core.test.halamo;


import java.io.StringReader;
import java.util.List;

import org.eclipse.core.resources.IFile;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;

import org.eclipse.core.runtime.CoreException;

import static org.easymock.EasyMock.*;

import net.sf.eclipsefp.haskell.core.halamo.Halamo;
import net.sf.eclipsefp.haskell.core.halamo.IDeclaration;
import net.sf.eclipsefp.haskell.core.halamo.IModule;
import net.sf.eclipsefp.haskell.core.halamo.Scope;
import net.sf.eclipsefp.haskell.core.jparser.HaskellParser;

import net.sf.eclipsefp.haskell.core.test.util.HalamoAssert;
import net.sf.eclipsefp.test.util.common.MockFile;
import net.sf.eclipsefp.test.util.haskell.HaskellProject_PDETestCase;

public class LanguageModel_PDETestCase extends HaskellProject_PDETestCase {
public class LanguageModel_PDETestCase extends TestCase {

private Halamo fLangModelEngine = Halamo.getInstance();;
private Halamo fLangModelEngine = Halamo.getInstance();

@Override
protected void setUpMore() throws Exception {
protected void setUp() throws Exception {
final String fibContents = "module Fibonacci where\n" +
"\n" +
"fib 1 = 0\n" +
Expand All @@ -30,8 +34,8 @@ protected void setUpMore() throws Exception {
"\n" +
"fac 0 = 1\n" +
"fac n = n * (fac (n - 1))\n";
createSourceFile(fibContents, "Fibonacci.hs");
createSourceFile(facContents, "Factorial.hs");
createModule(fibContents);
createModule(facContents);
}

public void testExtendedScopeWithImport() throws CoreException {
Expand All @@ -40,9 +44,9 @@ public void testExtendedScopeWithImport() throws CoreException {
"import Fibonacci\n" +
"\n" +
"main = putStr $ show $ fib 5";
IFile mainFile = createSourceFile(mainContents, "Main.hs");
IModule mainModule = createModule(mainContents);

Scope scope = fLangModelEngine.getScopeFor(mainFile);
Scope scope = fLangModelEngine.getScopeFor(mainModule);
assertNotNull(scope);

List<IModule> modules = scope.getAvailableModules();
Expand All @@ -55,9 +59,9 @@ public void testUnitWithNoImports() throws CoreException {
final String contents = "module WrongFactorial where\n" +
"\n" +
"fat 0 = 1";
IFile file = createSourceFile(contents, "WrongFactorial.hs");
IModule module = createModule(contents);

Scope scope = fLangModelEngine.getScopeFor(file);
Scope scope = fLangModelEngine.getScopeFor(module);
assertNotNull(scope);
}

Expand All @@ -69,9 +73,9 @@ public void testWithMoreThanOneImport() throws CoreException {
"\n" +
"main = putStr $ show $ fib $ fac 3";

IFile file = createSourceFile(contents, "Main.hs");
IModule module = createModule(contents);

Scope scope = fLangModelEngine.getScopeFor(file);
Scope scope = fLangModelEngine.getScopeFor(module);

assertNotNull(scope);

Expand All @@ -87,15 +91,45 @@ public void testWithMoreThanOneImport() throws CoreException {
}

public void testFailGracefullyWithFileOusideProject() {
final String contents = "module Main where\n" +
"\n" +
"main = putStr \"Hello, world!\\n\"";
MockFile file = new MockFile(contents);

file.setProject(null);
//TODO check this edge case
// final String contents = "module Main where\n" +
// "\n" +
// "main = putStr \"Hello, world!\\n\"";
// MockFile file = new MockFile(contents);
//
// file.setProject(null);
//
// Scope scope = fLangModelEngine.getScopeFor(file);
// assertNotNull(scope);
}

public void testAddingModules() {
IModule myModule = createModuleByName("MyModule");
IModule otherModule = createModuleByName("OtherModule");
fLangModelEngine.putModule(myModule);
fLangModelEngine.putModule(otherModule);

Scope scope = fLangModelEngine.getScopeFor(file);
assertNotNull(scope);
assertSame(otherModule, fLangModelEngine.getModule("OtherModule"));
assertSame(myModule, fLangModelEngine.getModule("MyModule"));
}

private IModule createModuleByName(String name) {
IModule module = createMock(IModule.class);
expect(module.getName()).
andReturn(name).
anyTimes();
replay(module);
return module;
}

private IModule createModule(final String contents) {
try {
IModule module = new HaskellParser(new StringReader(contents)).parseModule();
fLangModelEngine.putModule(module);
return module;
} catch (Exception e) {
throw new AssertionFailedError(e.getMessage());
}
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package net.sf.eclipsefp.haskell.core.test.halamo;

import java.io.StringBufferInputStream;

import net.sf.eclipsefp.haskell.core.halamo.IHaskellModel;
import net.sf.eclipsefp.haskell.core.halamo.IModule;
import net.sf.eclipsefp.haskell.core.halamo.ResourceChangeMonitor;
import net.sf.eclipsefp.test.util.haskell.HaskellProject_PDETestCase;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
Expand Down Expand Up @@ -37,7 +40,7 @@ private IWorkspace getWorkspace() {
}

public void testAddModule() throws CoreException {
getLanguageModel().addModule((IModule) anyObject());
getLanguageModel().putModule((IModule) anyObject());
expectLastCall().atLeastOnce();
replay(getLanguageModel());

Expand All @@ -46,6 +49,19 @@ public void testAddModule() throws CoreException {
verify(getLanguageModel());
}

@SuppressWarnings("deprecation")
public void testChangeModule() throws CoreException {
getLanguageModel().putModule((IModule) anyObject());
expectLastCall().times(2);
replay(getLanguageModel());

IFile file = createSourceFile("module QuickSort where\n\n", "QuickSort.hs");

file.setContents(new StringBufferInputStream("module QuickSort where\n\n"), true, false, null);

verify(getLanguageModel());
}

//TODO test multiple projects

private IHaskellModel getLanguageModel() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package net.sf.eclipsefp.haskell.core.test.internal.doubles;

import org.eclipse.core.resources.IFile;

import net.sf.eclipsefp.haskell.core.halamo.Halamo;
import net.sf.eclipsefp.haskell.core.halamo.IModule;
import net.sf.eclipsefp.haskell.core.halamo.Scope;
Expand All @@ -18,7 +16,7 @@ public void setModulesInScope(IModule... modules) {
}

@Override
public Scope getScopeFor(IFile file) {
public Scope getScopeFor(IModule file) {
return fScope;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Convenience assertions for the Haskell Language Model tests.
*
* @author thiagob
* @author Thiago Arrais - thiago.arrais@gmail.com
*/
public class HalamoAssert extends Assert {

Expand Down
Loading

0 comments on commit 22159c0

Please sign in to comment.