Permalink
Browse files

fix import removal when a superstring exists

  • Loading branch information...
1 parent 92b3bb5 commit 73157b37081c4ce6042396350b096509e0decedf @JPMoresmau committed Dec 8, 2012
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Haskell UI Test Plug-in
Bundle-SymbolicName: net.sf.eclipsefp.haskell.ui.test
-Bundle-Version: 2.3.0
+Bundle-Version: 2.3.3
Bundle-Vendor: eclipsefp.sourceforge.net
Require-Bundle: org.junit4,
org.easymock;bundle-version="[2.2.0,3.0.0)",
@@ -1,149 +1,173 @@
-/**
- * Copyright (c) 2012 by JP Moresmau
- * This code is made available under the terms of the Eclipse Public License,
- * version 1.0 (EPL). See http://www.eclipse.org/legal/epl-v10.html
- */
-package net.sf.eclipsefp.haskell.ui.internal.editors.haskell.imports;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import java.util.ArrayList;
-import net.sf.eclipsefp.haskell.buildwrapper.types.ImportDef;
-import net.sf.eclipsefp.haskell.buildwrapper.types.ImportExportType;
-import net.sf.eclipsefp.haskell.buildwrapper.types.ImportSpecDef;
-import net.sf.eclipsefp.haskell.buildwrapper.types.Location;
-import net.sf.eclipsefp.haskell.core.cabalmodel.TestDocument;
-import net.sf.eclipsefp.haskell.util.PlatformUtil;
-import org.eclipse.jface.text.contentassist.CompletionProposal;
-import org.junit.Test;
-
-
-/**
- * @author JP Moresmau
- *
- */
-public class AnImportTest {
-
- @Test
- public void testRemoveSimple(){
- // test in middle
- TestDocument td=new TestDocument( "module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (Seq, singleton, empty)"+PlatformUtil.NL );
- Location loc=new Location( "TestSimpleRemove.hs",2,0,2,44);
- ImportDef def=new ImportDef( "Data.Sequence", loc, false, false, null );
- AnImport ai=new AnImport( def, false );
- CompletionProposal cp=ai.removeItem( td, "singleton" , "remove" );
- assertNotNull( cp );
- cp.apply( td );
- // test at end
- assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (Seq, empty)"+PlatformUtil.NL,td.get());
- td=new TestDocument( "module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (Seq, singleton, empty)"+PlatformUtil.NL );
- cp=ai.removeItem( td, "empty" , "remove" );
- assertNotNull( cp );
- cp.apply( td );
- // test at start + a name that appears in the module
- assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (Seq, singleton)"+PlatformUtil.NL,td.get());
- td=new TestDocument( "module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (Seq, singleton, empty)"+PlatformUtil.NL );
- cp=ai.removeItem( td, "Seq" , "remove" );
- assertNotNull( cp );
- cp.apply( td );
- assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (singleton, empty)"+PlatformUtil.NL,td.get());
- }
-
- @Test
- public void testRemoveLast(){
- TestDocument td=new TestDocument( "module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (Seq)"+PlatformUtil.NL );
- Location loc=new Location( "TestSimpleRemove.hs",2,0,2,26);
- ImportDef def=new ImportDef( "Data.Sequence", loc, false, false, null );
- AnImport ai=new AnImport( def, false );
- CompletionProposal cp=ai.removeItem( td, "Seq" , "remove" );
- assertNotNull( cp );
- cp.apply( td );
- assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence ()"+PlatformUtil.NL,td.get());
- td=new TestDocument( "module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (Seq )"+PlatformUtil.NL );
- loc=new Location( "TestSimpleRemove.hs",2,0,2,27);
- def=new ImportDef( "Data.Sequence", loc, false, false, null );
- ai=new AnImport( def, false );
- cp=ai.removeItem( td, "Seq" , "remove" );
- assertNotNull( cp );
- cp.apply( td );
- assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence ()"+PlatformUtil.NL,td.get());
- td=new TestDocument( "module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence ( Seq)"+PlatformUtil.NL );
- cp=ai.removeItem( td, "Seq" , "remove" );
- assertNotNull( cp );
- cp.apply( td );
- assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence ()"+PlatformUtil.NL,td.get());
- }
-
- @Test
- public void testRemoveOperator(){
- TestDocument td=new TestDocument( "module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence ((><), Seq)"+PlatformUtil.NL );
- Location loc=new Location( "TestSimpleRemove.hs",2,0,2,32);
- ImportDef def=new ImportDef( "Data.Sequence", loc, false, false, null );
- AnImport ai=new AnImport( def, false );
- CompletionProposal cp=ai.removeItem( td, "><" , "remove" );
- assertNotNull( cp );
- cp.apply( td );
- assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (Seq)"+PlatformUtil.NL,td.get());
- }
-
- @Test
- public void testAddSimple(){
- TestDocument td=new TestDocument( "module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence ((><), Seq)"+PlatformUtil.NL );
- Location loc=new Location( "TestSimpleRemove.hs",2,0,2,32);
- ImportDef def=new ImportDef( "Data.Sequence", loc, false, false, null );
- ImportSpecDef sp1=new ImportSpecDef( "><", new Location( "TestSimpleRemove.hs",2,22,2,26), ImportExportType.IEVar );
- ImportSpecDef sp2=new ImportSpecDef( "Seq", new Location( "TestSimpleRemove.hs",2,27,2,31), ImportExportType.IEVar );
- def.setChildren( new ArrayList<ImportSpecDef>() );
- def.getChildren().add(sp1);
- def.getChildren().add(sp2);
- AnImport ai=new AnImport( def, false );
- CompletionProposal cp=ai.addItem(td, "singleton" , "add" );
- assertNotNull( cp );
- cp.apply( td );
- assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence ((><), Seq, singleton)"+PlatformUtil.NL,td.get());
- }
-
- /**
- * this should never happen, if we import everything we're not missing one item, but ensure it's ok
- */
- @Test
- public void testAddToNoChildren(){
- TestDocument td=new TestDocument( "module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence"+PlatformUtil.NL );
- Location loc=new Location( "TestSimpleRemove.hs",2,0,2,20);
- ImportDef def=new ImportDef( "Data.Sequence", loc, false, false, null );
- AnImport ai=new AnImport( def, false );
- CompletionProposal cp=ai.addItem(td, "singleton" , "add" );
- assertNotNull( cp );
- cp.apply( td );
- assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (singleton)"+PlatformUtil.NL,td.get());
- }
-
- @Test
- public void testAddToEmptyChildren(){
- TestDocument td=new TestDocument( "module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence ()"+PlatformUtil.NL );
- Location loc=new Location( "TestSimpleRemove.hs",2,0,2,23);
- ImportDef def=new ImportDef( "Data.Sequence", loc, false, false, null );
- def.setChildren( new ArrayList<ImportSpecDef>() );
- AnImport ai=new AnImport( def, false );
- CompletionProposal cp=ai.addItem(td, "singleton" , "add" );
- assertNotNull( cp );
- cp.apply( td );
- assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (singleton)"+PlatformUtil.NL,td.get());
- }
-
- @Test
- public void testAddOperator(){
- TestDocument td=new TestDocument( "module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (Seq)"+PlatformUtil.NL );
- Location loc=new Location( "TestSimpleRemove.hs",2,0,2,26);
- ImportDef def=new ImportDef( "Data.Sequence", loc, false, false, null );
- ImportSpecDef sp1=new ImportSpecDef( "Seq", new Location( "TestSimpleRemove.hs",2,24,2,25), ImportExportType.IEVar );
- def.setChildren( new ArrayList<ImportSpecDef>() );
- def.getChildren().add(sp1);
- AnImport ai=new AnImport( def, false );
- CompletionProposal cp=ai.addItem(td, "><" , "add" );
- assertNotNull( cp );
- cp.apply( td );
- assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (Seq, (><))"+PlatformUtil.NL,td.get());
- }
-
-}
+/**
+ * Copyright (c) 2012 by JP Moresmau
+ * This code is made available under the terms of the Eclipse Public License,
+ * version 1.0 (EPL). See http://www.eclipse.org/legal/epl-v10.html
+ */
+package net.sf.eclipsefp.haskell.ui.internal.editors.haskell.imports;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import java.util.ArrayList;
+import net.sf.eclipsefp.haskell.buildwrapper.types.ImportDef;
+import net.sf.eclipsefp.haskell.buildwrapper.types.ImportExportType;
+import net.sf.eclipsefp.haskell.buildwrapper.types.ImportSpecDef;
+import net.sf.eclipsefp.haskell.buildwrapper.types.Location;
+import net.sf.eclipsefp.haskell.core.cabalmodel.TestDocument;
+import net.sf.eclipsefp.haskell.util.PlatformUtil;
+import org.eclipse.jface.text.contentassist.CompletionProposal;
+import org.junit.Test;
+
+
+/**
+ * @author JP Moresmau
+ *
+ */
+public class AnImportTest {
+
+ @Test
+ public void testRemoveSimple(){
+ // test in middle
+ TestDocument td=new TestDocument( "module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (Seq, singleton, empty)"+PlatformUtil.NL );
+ Location loc=new Location( "TestSimpleRemove.hs",2,0,2,44);
+ ImportDef def=new ImportDef( "Data.Sequence", loc, false, false, null );
+ AnImport ai=new AnImport( def, false );
+ CompletionProposal cp=ai.removeItem( td, "singleton" , "remove" );
+ assertNotNull( cp );
+ cp.apply( td );
+ // test at end
+ assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (Seq, empty)"+PlatformUtil.NL,td.get());
+ td=new TestDocument( "module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (Seq, singleton, empty)"+PlatformUtil.NL );
+ cp=ai.removeItem( td, "empty" , "remove" );
+ assertNotNull( cp );
+ cp.apply( td );
+ // test at start + a name that appears in the module
+ assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (Seq, singleton)"+PlatformUtil.NL,td.get());
+ td=new TestDocument( "module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (Seq, singleton, empty)"+PlatformUtil.NL );
+ cp=ai.removeItem( td, "Seq" , "remove" );
+ assertNotNull( cp );
+ cp.apply( td );
+ assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (singleton, empty)"+PlatformUtil.NL,td.get());
+ }
+
+ @Test
+ public void testRemoveLast(){
+ TestDocument td=new TestDocument( "module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (Seq)"+PlatformUtil.NL );
+ Location loc=new Location( "TestSimpleRemove.hs",2,0,2,26);
+ ImportDef def=new ImportDef( "Data.Sequence", loc, false, false, null );
+ AnImport ai=new AnImport( def, false );
+ CompletionProposal cp=ai.removeItem( td, "Seq" , "remove" );
+ assertNotNull( cp );
+ cp.apply( td );
+ assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence ()"+PlatformUtil.NL,td.get());
+ td=new TestDocument( "module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (Seq )"+PlatformUtil.NL );
+ loc=new Location( "TestSimpleRemove.hs",2,0,2,27);
+ def=new ImportDef( "Data.Sequence", loc, false, false, null );
+ ai=new AnImport( def, false );
+ cp=ai.removeItem( td, "Seq" , "remove" );
+ assertNotNull( cp );
+ cp.apply( td );
+ assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence ()"+PlatformUtil.NL,td.get());
+ td=new TestDocument( "module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence ( Seq)"+PlatformUtil.NL );
+ cp=ai.removeItem( td, "Seq" , "remove" );
+ assertNotNull( cp );
+ cp.apply( td );
+ assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence ()"+PlatformUtil.NL,td.get());
+ }
+
+ @Test
+ public void testRemoveOperator(){
+ TestDocument td=new TestDocument( "module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence ((><), Seq)"+PlatformUtil.NL );
+ Location loc=new Location( "TestSimpleRemove.hs",2,0,2,32);
+ ImportDef def=new ImportDef( "Data.Sequence", loc, false, false, null );
+ AnImport ai=new AnImport( def, false );
+ CompletionProposal cp=ai.removeItem( td, "><" , "remove" );
+ assertNotNull( cp );
+ cp.apply( td );
+ assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (Seq)"+PlatformUtil.NL,td.get());
+ }
+
+ @Test
+ public void testRemoveSuperStringBefore(){
+ TestDocument td=new TestDocument( "module TestSimpleRemove where"+PlatformUtil.NL+"import Control.Monad.Trans.Reader (runReaderT,runReader)"+PlatformUtil.NL );
+ Location loc=new Location( "testRemoveSuperString.hs",2,0,2,56);
+ ImportDef def=new ImportDef( "Control.Monad.Trans.Reader", loc, false, false, null );
+ AnImport ai=new AnImport( def, false );
+ CompletionProposal cp=ai.removeItem( td, "runReader" , "remove" );
+ assertNotNull( cp );
+ cp.apply( td );
+ assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Control.Monad.Trans.Reader (runReaderT)"+PlatformUtil.NL,td.get());
+ }
+
+ @Test
+ public void testRemoveSuperStringAfter(){
+ TestDocument td=new TestDocument( "module TestSimpleRemove where"+PlatformUtil.NL+"import Control.Monad.Trans.Reader (runReader,runReaderT)"+PlatformUtil.NL );
+ Location loc=new Location( "testRemoveSuperString.hs",2,0,2,56);
+ ImportDef def=new ImportDef( "Control.Monad.Trans.Reader", loc, false, false, null );
+ AnImport ai=new AnImport( def, false );
+ CompletionProposal cp=ai.removeItem( td, "runReader" , "remove" );
+ assertNotNull( cp );
+ cp.apply( td );
+ assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Control.Monad.Trans.Reader (runReaderT)"+PlatformUtil.NL,td.get());
+ }
+
+ @Test
+ public void testAddSimple(){
+ TestDocument td=new TestDocument( "module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence ((><), Seq)"+PlatformUtil.NL );
+ Location loc=new Location( "TestSimpleRemove.hs",2,0,2,32);
+ ImportDef def=new ImportDef( "Data.Sequence", loc, false, false, null );
+ ImportSpecDef sp1=new ImportSpecDef( "><", new Location( "TestSimpleRemove.hs",2,22,2,26), ImportExportType.IEVar );
+ ImportSpecDef sp2=new ImportSpecDef( "Seq", new Location( "TestSimpleRemove.hs",2,27,2,31), ImportExportType.IEVar );
+ def.setChildren( new ArrayList<ImportSpecDef>() );
+ def.getChildren().add(sp1);
+ def.getChildren().add(sp2);
+ AnImport ai=new AnImport( def, false );
+ CompletionProposal cp=ai.addItem(td, "singleton" , "add" );
+ assertNotNull( cp );
+ cp.apply( td );
+ assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence ((><), Seq, singleton)"+PlatformUtil.NL,td.get());
+ }
+
+ /**
+ * this should never happen, if we import everything we're not missing one item, but ensure it's ok
+ */
+ @Test
+ public void testAddToNoChildren(){
+ TestDocument td=new TestDocument( "module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence"+PlatformUtil.NL );
+ Location loc=new Location( "TestSimpleRemove.hs",2,0,2,20);
+ ImportDef def=new ImportDef( "Data.Sequence", loc, false, false, null );
+ AnImport ai=new AnImport( def, false );
+ CompletionProposal cp=ai.addItem(td, "singleton" , "add" );
+ assertNotNull( cp );
+ cp.apply( td );
+ assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (singleton)"+PlatformUtil.NL,td.get());
+ }
+
+ @Test
+ public void testAddToEmptyChildren(){
+ TestDocument td=new TestDocument( "module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence ()"+PlatformUtil.NL );
+ Location loc=new Location( "TestSimpleRemove.hs",2,0,2,23);
+ ImportDef def=new ImportDef( "Data.Sequence", loc, false, false, null );
+ def.setChildren( new ArrayList<ImportSpecDef>() );
+ AnImport ai=new AnImport( def, false );
+ CompletionProposal cp=ai.addItem(td, "singleton" , "add" );
+ assertNotNull( cp );
+ cp.apply( td );
+ assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (singleton)"+PlatformUtil.NL,td.get());
+ }
+
+ @Test
+ public void testAddOperator(){
+ TestDocument td=new TestDocument( "module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (Seq)"+PlatformUtil.NL );
+ Location loc=new Location( "TestSimpleRemove.hs",2,0,2,26);
+ ImportDef def=new ImportDef( "Data.Sequence", loc, false, false, null );
+ ImportSpecDef sp1=new ImportSpecDef( "Seq", new Location( "TestSimpleRemove.hs",2,24,2,25), ImportExportType.IEVar );
+ def.setChildren( new ArrayList<ImportSpecDef>() );
+ def.getChildren().add(sp1);
+ AnImport ai=new AnImport( def, false );
+ CompletionProposal cp=ai.addItem(td, "><" , "add" );
+ assertNotNull( cp );
+ cp.apply( td );
+ assertEquals("module TestSimpleRemove where"+PlatformUtil.NL+"import Data.Sequence (Seq, (><))"+PlatformUtil.NL,td.get());
+ }
+
+}
Oops, something went wrong.

0 comments on commit 73157b3

Please sign in to comment.