Browse Source

Implement EnvDTE.EditPoint.ReplaceText.

pull/28/head
Matt Ward 13 years ago
parent
commit
ab45879b9f
  1. 11
      src/AddIns/Misc/PackageManagement/Project/PackageManagement.csproj
  2. 23
      src/AddIns/Misc/PackageManagement/Project/Src/DocumentLoader.cs
  3. 21
      src/AddIns/Misc/PackageManagement/Project/Src/DomRegionExtensions.cs
  4. 11
      src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeFunction.cs
  5. 11
      src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeVariable.cs
  6. 29
      src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/EditPoint.cs
  7. 25
      src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/TextPoint.cs
  8. 13
      src/AddIns/Misc/PackageManagement/Project/Src/IDocumentLoader.cs
  9. 21
      src/AddIns/Misc/PackageManagement/Project/Src/IFieldExtensions.cs
  10. 21
      src/AddIns/Misc/PackageManagement/Project/Src/IMethodOrPropertyExtensions.cs
  11. 158
      src/AddIns/Misc/PackageManagement/Project/Src/ThreadSafeDocument.cs
  12. 1
      src/AddIns/Misc/PackageManagement/Test/PackageManagement.Tests.csproj
  13. 26
      src/AddIns/Misc/PackageManagement/Test/Src/EnvDTE/CodeFunctionTests.cs
  14. 34
      src/AddIns/Misc/PackageManagement/Test/Src/EnvDTE/CodeVariableTests.cs
  15. 118
      src/AddIns/Misc/PackageManagement/Test/Src/EnvDTE/EditPointTests.cs
  16. 20
      src/AddIns/Misc/PackageManagement/Test/Src/Helpers/FieldHelper.cs
  17. 39
      src/AddIns/Misc/PackageManagement/Test/Src/Helpers/MethodHelper.cs

11
src/AddIns/Misc/PackageManagement/Project/PackageManagement.csproj

@ -74,6 +74,8 @@ @@ -74,6 +74,8 @@
<Compile Include="Src\Design\DesignTimeSelectProjectsViewModel.cs" />
<Compile Include="Src\Design\FakePackageOperation.cs" />
<Compile Include="Src\Design\FakeSelectedProject.cs" />
<Compile Include="Src\DocumentLoader.cs" />
<Compile Include="Src\DomRegionExtensions.cs" />
<Compile Include="Src\EnvDTE\CodeAttribute.cs" />
<Compile Include="Src\EnvDTE\CodeAttribute2.cs" />
<Compile Include="Src\EnvDTE\CodeAttributeArgument.cs" />
@ -122,6 +124,9 @@ @@ -122,6 +124,9 @@
<Compile Include="Src\EnvDTE\vsCMInfoLocation.cs" />
<Compile Include="Src\EnvDTE\vsCMPropertyKind.cs" />
<Compile Include="Src\EnvDTE\vsEPReplaceTextOptions.cs" />
<Compile Include="Src\IFieldExtensions.cs" />
<Compile Include="Src\IDocumentLoader.cs" />
<Compile Include="Src\IMethodOrPropertyExtensions.cs" />
<Compile Include="Src\InstalledPackageViewModel.cs" />
<Compile Include="Src\InstalledPackageViewModelFactory.cs" />
<Compile Include="Src\IPackageManagementSelectedProject.cs" />
@ -364,6 +369,7 @@ @@ -364,6 +369,7 @@
<Compile Include="Src\EnvDTE\Project.cs" />
<Compile Include="Src\Scripting\RunPackageScriptsAction.cs" />
<Compile Include="Src\SolutionPackageRepository.cs" />
<Compile Include="Src\ThreadSafeDocument.cs" />
<Compile Include="Src\ThreadSafePackageManagementEvents.cs" />
<Compile Include="Src\UninstallPackageAction.cs" />
<Compile Include="Src\UpdateAllPackagesInProject.cs" />
@ -442,6 +448,11 @@ @@ -442,6 +448,11 @@
<Name>ICSharpCode.AvalonEdit</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Libraries\NRefactory\Project\NRefactory.csproj">
<Project>{3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}</Project>
<Name>NRefactory</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj">
<Project>{2748AD25-9C63-4E12-877B-4DCE96FBED54}</Project>
<Name>ICSharpCode.SharpDevelop</Name>

23
src/AddIns/Misc/PackageManagement/Project/Src/DocumentLoader.cs

@ -0,0 +1,23 @@ @@ -0,0 +1,23 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.PackageManagement
{
public class DocumentLoader : IDocumentLoader
{
public IDocument LoadDocument(string fileName)
{
if (WorkbenchSingleton.InvokeRequired) {
return WorkbenchSingleton.SafeThreadFunction(() => LoadDocument(fileName));
} else {
var textEditorProvider = FileService.OpenFile(fileName) as ITextEditorProvider;
return new ThreadSafeDocument(textEditorProvider.TextEditor.Document);
}
}
}
}

21
src/AddIns/Misc/PackageManagement/Project/Src/DomRegionExtensions.cs

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.SharpDevelop.Dom;
namespace ICSharpCode.PackageManagement
{
public static class DomRegionExtensions
{
public static FilePosition ToStartPosition(this DomRegion region, ICompilationUnit compilationUnit)
{
return new FilePosition(compilationUnit, region.BeginLine, region.BeginColumn);
}
public static FilePosition ToEndPosition(this DomRegion region, ICompilationUnit compilationUnit)
{
return new FilePosition(compilationUnit, region.EndLine, region.EndColumn);
}
}
}

11
src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeFunction.cs

@ -9,11 +9,18 @@ namespace ICSharpCode.PackageManagement.EnvDTE @@ -9,11 +9,18 @@ namespace ICSharpCode.PackageManagement.EnvDTE
public class CodeFunction : CodeElement
{
IMethodOrProperty method;
IDocumentLoader documentLoader;
public CodeFunction(IMethod method)
: this(method, new DocumentLoader())
{
}
public CodeFunction(IMethod method, IDocumentLoader documentLoader)
: base(method)
{
this.method = method;
this.documentLoader = documentLoader;
}
public CodeFunction()
@ -36,12 +43,12 @@ namespace ICSharpCode.PackageManagement.EnvDTE @@ -36,12 +43,12 @@ namespace ICSharpCode.PackageManagement.EnvDTE
public override TextPoint GetStartPoint()
{
return TextPoint.CreateStartPoint(method.Region);
return new TextPoint(method.GetStartPosition(), documentLoader);
}
public override TextPoint GetEndPoint()
{
return TextPoint.CreateEndPoint(method.BodyRegion);
return new TextPoint(method.GetEndPosition(), documentLoader);
}
}
}

11
src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeVariable.cs

@ -9,15 +9,22 @@ namespace ICSharpCode.PackageManagement.EnvDTE @@ -9,15 +9,22 @@ namespace ICSharpCode.PackageManagement.EnvDTE
public class CodeVariable : CodeElement
{
IField field;
IDocumentLoader documentLoader;
public CodeVariable()
{
}
public CodeVariable(IField field)
: this(field, new DocumentLoader())
{
}
public CodeVariable(IField field, IDocumentLoader documentLoader)
: base(field)
{
this.field = field;
this.documentLoader = documentLoader;
}
public override vsCMElement Kind {
@ -31,12 +38,12 @@ namespace ICSharpCode.PackageManagement.EnvDTE @@ -31,12 +38,12 @@ namespace ICSharpCode.PackageManagement.EnvDTE
public override TextPoint GetStartPoint()
{
return TextPoint.CreateStartPoint(field.Region);
return new TextPoint(field.GetStartPosition(), documentLoader);
}
public override TextPoint GetEndPoint()
{
return TextPoint.CreateEndPoint(field.Region);
return new TextPoint(field.GetEndPosition(), documentLoader);
}
}
}

29
src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/EditPoint.cs

@ -2,12 +2,17 @@ @@ -2,12 +2,17 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Editor;
namespace ICSharpCode.PackageManagement.EnvDTE
{
public class EditPoint : TextPoint
{
public EditPoint()
IDocument document;
internal EditPoint(FilePosition filePosition, IDocumentLoader documentLoader)
: base(filePosition, documentLoader)
{
}
@ -16,9 +21,27 @@ namespace ICSharpCode.PackageManagement.EnvDTE @@ -16,9 +21,27 @@ namespace ICSharpCode.PackageManagement.EnvDTE
ReplaceText((TextPoint)pointOrCount, text, (vsEPReplaceTextOptions)flags);
}
void ReplaceText(TextPoint point, string text, vsEPReplaceTextOptions textFormatOptions)
void ReplaceText(TextPoint endPoint, string text, vsEPReplaceTextOptions textFormatOptions)
{
OpenDocument();
int offset = GetStartOffset();
int endOffset = GetEndOffset(endPoint);
document.Replace(offset, endOffset - offset, text);
}
void OpenDocument()
{
document = DocumentLoader.LoadDocument(FilePosition.FileName);
}
int GetStartOffset()
{
return document.PositionToOffset(Line, LineCharOffset);
}
int GetEndOffset(TextPoint endPoint)
{
return document.PositionToOffset(endPoint.Line, endPoint.LineCharOffset);
}
}
}

25
src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/TextPoint.cs

@ -8,25 +8,36 @@ namespace ICSharpCode.PackageManagement.EnvDTE @@ -8,25 +8,36 @@ namespace ICSharpCode.PackageManagement.EnvDTE
{
public class TextPoint : MarshalByRefObject
{
public TextPoint()
internal TextPoint(FilePosition filePosition, IDocumentLoader documentLoader)
{
this.FilePosition = filePosition;
this.DocumentLoader = documentLoader;
}
public int LineCharOffset { get; private set; }
protected IDocumentLoader DocumentLoader { get; private set; }
protected FilePosition FilePosition { get; private set; }
public int LineCharOffset {
get { return FilePosition.Column; }
}
public int Line {
get { return FilePosition.Line; }
}
public EditPoint CreateEditPoint()
{
throw new NotImplementedException();
return new EditPoint(FilePosition, DocumentLoader);
}
internal static TextPoint CreateStartPoint(DomRegion region)
internal static TextPoint CreateStartPoint(FilePosition position, IDocumentLoader documentLoader)
{
return new TextPoint { LineCharOffset = region.BeginColumn };
return new TextPoint(position, documentLoader);
}
internal static TextPoint CreateEndPoint(DomRegion region)
internal static TextPoint CreateEndPoint(FilePosition position, IDocumentLoader documentLoader)
{
return new TextPoint { LineCharOffset = region.EndColumn };
return new TextPoint(position, documentLoader);
}
}
}

13
src/AddIns/Misc/PackageManagement/Project/Src/IDocumentLoader.cs

@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.SharpDevelop.Editor;
namespace ICSharpCode.PackageManagement
{
public interface IDocumentLoader
{
IDocument LoadDocument(string fileName);
}
}

21
src/AddIns/Misc/PackageManagement/Project/Src/IFieldExtensions.cs

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.SharpDevelop.Dom;
namespace ICSharpCode.PackageManagement
{
public static class IFieldExtensions
{
public static FilePosition GetStartPosition(this IField field)
{
return field.Region.ToStartPosition(field.CompilationUnit);
}
public static FilePosition GetEndPosition(this IField field)
{
return field.Region.ToEndPosition(field.CompilationUnit);
}
}
}

21
src/AddIns/Misc/PackageManagement/Project/Src/IMethodOrPropertyExtensions.cs

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.SharpDevelop.Dom;
namespace ICSharpCode.PackageManagement
{
public static class IMethodOrPropertyExtensions
{
public static FilePosition GetStartPosition(this IMethodOrProperty method)
{
return method.Region.ToStartPosition(method.CompilationUnit);
}
public static FilePosition GetEndPosition(this IMethodOrProperty method)
{
return method.BodyRegion.ToEndPosition(method.CompilationUnit);
}
}
}

158
src/AddIns/Misc/PackageManagement/Project/Src/ThreadSafeDocument.cs

@ -0,0 +1,158 @@ @@ -0,0 +1,158 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.IO;
using ICSharpCode.NRefactory;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.PackageManagement
{
public class ThreadSafeDocument : IDocument
{
IDocument document;
public ThreadSafeDocument(IDocument document)
{
this.document = document;
}
#pragma warning disable 0067
public event EventHandler<TextChangeEventArgs> Changing;
public event EventHandler<TextChangeEventArgs> Changed;
public event EventHandler TextChanged;
#pragma warning restore 0067
public string Text {
get {
throw new NotImplementedException();
}
set {
throw new NotImplementedException();
}
}
public int TotalNumberOfLines {
get {
throw new NotImplementedException();
}
}
public ITextBufferVersion Version {
get {
throw new NotImplementedException();
}
}
public int TextLength {
get {
throw new NotImplementedException();
}
}
public IDocumentLine GetLine(int lineNumber)
{
throw new NotImplementedException();
}
public IDocumentLine GetLineForOffset(int offset)
{
throw new NotImplementedException();
}
public int PositionToOffset(int line, int column)
{
if (WorkbenchSingleton.InvokeRequired) {
return WorkbenchSingleton.SafeThreadFunction(() => PositionToOffset(line, column));
} else {
return document.PositionToOffset(line, column);
}
}
public Location OffsetToPosition(int offset)
{
throw new NotImplementedException();
}
public void Insert(int offset, string text)
{
throw new NotImplementedException();
}
public void Insert(int offset, string text, AnchorMovementType defaultAnchorMovementType)
{
throw new NotImplementedException();
}
public void Remove(int offset, int length)
{
throw new NotImplementedException();
}
public void Replace(int offset, int length, string newText)
{
if (WorkbenchSingleton.InvokeRequired) {
WorkbenchSingleton.SafeThreadAsyncCall(() => Replace(offset, length, newText));
} else {
document.Replace(offset, length, newText);
}
}
public void StartUndoableAction()
{
throw new NotImplementedException();
}
public void EndUndoableAction()
{
throw new NotImplementedException();
}
public IDisposable OpenUndoGroup()
{
throw new NotImplementedException();
}
public ITextAnchor CreateAnchor(int offset)
{
throw new NotImplementedException();
}
public ICSharpCode.SharpDevelop.ITextBuffer CreateSnapshot()
{
throw new NotImplementedException();
}
public ICSharpCode.SharpDevelop.ITextBuffer CreateSnapshot(int offset, int length)
{
throw new NotImplementedException();
}
public System.IO.TextReader CreateReader()
{
throw new NotImplementedException();
}
public TextReader CreateReader(int offset, int length)
{
throw new NotImplementedException();
}
public char GetCharAt(int offset)
{
throw new NotImplementedException();
}
public string GetText(int offset, int length)
{
throw new NotImplementedException();
}
public object GetService(Type serviceType)
{
throw new NotImplementedException();
}
}
}

1
src/AddIns/Misc/PackageManagement/Test/PackageManagement.Tests.csproj

@ -87,6 +87,7 @@ @@ -87,6 +87,7 @@
<Compile Include="Src\EnvDTE\CodeTypeRef2Tests.cs" />
<Compile Include="Src\EnvDTE\CodeTypeTests.cs" />
<Compile Include="Src\EnvDTE\CodeVariableTests.cs" />
<Compile Include="Src\EnvDTE\EditPointTests.cs" />
<Compile Include="Src\EnvDTE\NamespaceNameTests.cs" />
<Compile Include="Src\EnvDTE\SolutionTests.cs" />
<Compile Include="Src\Helpers\AttributeHelper.cs" />

26
src/AddIns/Misc/PackageManagement/Test/Src/EnvDTE/CodeFunctionTests.cs

@ -72,7 +72,19 @@ namespace PackageManagement.Tests.EnvDTE @@ -72,7 +72,19 @@ namespace PackageManagement.Tests.EnvDTE
}
[Test]
public void GetEndPoint_FunctionBodyAtColumn4_ReturnsPointWithOffset4()
public void GetStartPoint_FunctionStartsAtLine2_ReturnsPointWithLine2()
{
CreatePublicFunction("Class1.MyFunction");
helper.FunctionStartsAtLine(2);
TextPoint point = codeFunction.GetStartPoint();
int line = point.Line;
Assert.AreEqual(2, line);
}
[Test]
public void GetEndPoint_FunctionBodyEndsAtColumn4_ReturnsPointWithOffset4()
{
CreatePublicFunction("Class1.MyFunction");
helper.FunctionBodyEndsAtColumn(4);
@ -83,6 +95,18 @@ namespace PackageManagement.Tests.EnvDTE @@ -83,6 +95,18 @@ namespace PackageManagement.Tests.EnvDTE
Assert.AreEqual(4, offset);
}
[Test]
public void GetEndPoint_FunctionBodyEndsAtLine4_ReturnsPointWithLine4()
{
CreatePublicFunction("Class1.MyFunction");
helper.FunctionBodyEndsAtLine(4);
TextPoint point = codeFunction.GetEndPoint();
int line = point.Line;
Assert.AreEqual(4, line);
}
[Test]
public void Kind_PublicFunction_ReturnsFunction()
{

34
src/AddIns/Misc/PackageManagement/Test/Src/EnvDTE/CodeVariableTests.cs

@ -44,11 +44,21 @@ namespace PackageManagement.Tests.EnvDTE @@ -44,11 +44,21 @@ namespace PackageManagement.Tests.EnvDTE
helper.VariableStartsAtColumn(column);
}
void VariableStartsAtLine(int line)
{
helper.VariableStartsAtLine(line);
}
void VariableEndsAtColumn(int column)
{
helper.VariableEndsAtColumn(column);
}
void VariableEndsAtLine(int line)
{
helper.VariableEndsAtLine(line);
}
[Test]
public void Access_PublicVariable_ReturnsPublic()
{
@ -81,6 +91,18 @@ namespace PackageManagement.Tests.EnvDTE @@ -81,6 +91,18 @@ namespace PackageManagement.Tests.EnvDTE
Assert.AreEqual(5, offset);
}
[Test]
public void GetStartPoint_VariableStartsAtLine1_ReturnsTextPointWithLine1()
{
CreatePublicVariable("MyVariable");
VariableStartsAtLine(1);
TextPoint point = codeVariable.GetStartPoint();
int line = point.Line;
Assert.AreEqual(1, line);
}
[Test]
public void GetEndPoint_VariableEndsAtColumn10_ReturnsTextPointWithLineCharOffset10()
{
@ -93,6 +115,18 @@ namespace PackageManagement.Tests.EnvDTE @@ -93,6 +115,18 @@ namespace PackageManagement.Tests.EnvDTE
Assert.AreEqual(10, offset);
}
[Test]
public void GetEndPoint_VariableEndsAtLine2_ReturnsTextPointWithLine2()
{
CreatePublicVariable("MyVariable");
VariableEndsAtLine(2);
TextPoint point = codeVariable.GetEndPoint();
int line = point.Line;
Assert.AreEqual(2, line);
}
[Test]
public void Kind_PublicVariable_ReturnsVariable()
{

118
src/AddIns/Misc/PackageManagement/Test/Src/EnvDTE/EditPointTests.cs

@ -0,0 +1,118 @@ @@ -0,0 +1,118 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.PackageManagement;
using ICSharpCode.PackageManagement.EnvDTE;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Editor;
using NUnit.Framework;
using PackageManagement.Tests.Helpers;
using Rhino.Mocks;
namespace PackageManagement.Tests.EnvDTE
{
[TestFixture]
public class EditPointTests
{
FieldHelper fieldHelper;
MethodHelper methodHelper;
TextPoint endPoint;
EditPoint editPoint;
IDocument document;
IDocumentLoader documentLoader;
[SetUp]
public void Init()
{
fieldHelper = new FieldHelper();
methodHelper = new MethodHelper();
CreateDocumentLoader();
}
void CreateDocumentLoader()
{
document = MockRepository.GenerateStub<IDocument>();
documentLoader = MockRepository.GenerateStub<IDocumentLoader>();
}
void CreateField(string fileName, DomRegion region)
{
fieldHelper.CreateField("Class1.MyField");
fieldHelper.SetRegion(region);
fieldHelper.SetCompilationUnitFileName(fileName);
}
void CreateMethod(string fileName, DomRegion region, DomRegion bodyRegion)
{
methodHelper.CreateMethod("Class1.MyMethod");
methodHelper.SetRegion(region);
methodHelper.SetBodyRegion(bodyRegion);
methodHelper.SetCompilationUnitFileName(fileName);
}
void DocumentOffsetToReturn(int line, int column, int offset)
{
document.Stub(d => d.PositionToOffset(line, column)).Return(offset);
}
void CreateFieldEditPoint()
{
var codeVariable = new CodeVariable(fieldHelper.Field, documentLoader);
TextPoint startPoint = codeVariable.GetStartPoint();
endPoint = codeVariable.GetEndPoint();
editPoint = startPoint.CreateEditPoint();
}
void CreateMethodEditPoint()
{
var codeFunction = new CodeFunction(methodHelper.Method, documentLoader);
TextPoint startPoint = codeFunction.GetStartPoint();
endPoint = codeFunction.GetEndPoint();
editPoint = startPoint.CreateEditPoint();
}
void ReplaceText(string text)
{
editPoint.ReplaceText(endPoint, text, (int)vsEPReplaceTextOptions.vsEPReplaceTextAutoformat);
}
void DocumentFileName(string fileName)
{
documentLoader.Stub(loader => loader.LoadDocument(fileName)).Return(document);
}
[Test]
public void ReplaceText_FieldEndPointCreatedFromStartPoint_ReplacesTextBetweenStartAndEndPoint()
{
string fileName = @"d:\projects\test.cs";
var fieldRegion = new DomRegion(1, 5, 3, 12);
CreateField(fileName, fieldRegion);
DocumentOffsetToReturn(line: 1, column: 5, offset: 5);
DocumentOffsetToReturn(line: 3, column: 12, offset: 20);
DocumentFileName(fileName);
CreateFieldEditPoint();
ReplaceText("Test");
document.AssertWasCalled(d => d.Replace(5, 15, "Test"));
}
[Test]
public void ReplaceText_MethodEndPointCreatedFromStartPoint_ReplacesTextBetweenStartAndEndPoint()
{
string fileName = @"d:\projects\test.cs";
var methodRegion = new DomRegion(1, 5, 1, 10);
var methodBodyRegion = new DomRegion(1, 10, 3, 12);
CreateMethod(fileName, methodRegion, methodBodyRegion);
DocumentOffsetToReturn(line: 1, column: 5, offset: 5);
DocumentOffsetToReturn(line: 3, column: 12, offset: 20);
DocumentFileName(fileName);
CreateMethodEditPoint();
ReplaceText("Test");
document.AssertWasCalled(d => d.Replace(5, 15, "Test"));
}
}
}

20
src/AddIns/Misc/PackageManagement/Test/Src/Helpers/FieldHelper.cs

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.PackageManagement;
using ICSharpCode.SharpDevelop.Dom;
using Rhino.Mocks;
@ -46,10 +47,29 @@ namespace PackageManagement.Tests.Helpers @@ -46,10 +47,29 @@ namespace PackageManagement.Tests.Helpers
SetRegion(region);
}
public void VariableStartsAtLine(int line)
{
var region = new DomRegion(line, 1);
SetRegion(region);
}
public void VariableEndsAtColumn(int column)
{
var region = new DomRegion(1, 1, 1, column);
SetRegion(region);
}
public void VariableEndsAtLine(int line)
{
var region = new DomRegion(1, 1, line, 1);
SetRegion(region);
}
public void SetCompilationUnitFileName(string fileName)
{
ICompilationUnit unit = MockRepository.GenerateStub<ICompilationUnit>();
unit.FileName = fileName;
Field.Stub(f => f.CompilationUnit).Return(unit);
}
}
}

39
src/AddIns/Misc/PackageManagement/Test/Src/Helpers/MethodHelper.cs

@ -38,13 +38,52 @@ namespace PackageManagement.Tests.Helpers @@ -38,13 +38,52 @@ namespace PackageManagement.Tests.Helpers
public void FunctionStartsAtColumn(int column)
{
var region = new DomRegion(1, column);
FunctionStartsAt(region);
}
public void FunctionStartsAt(DomRegion region)
{
Method.Stub(m => m.Region).Return(region);
}
public void FunctionStartsAtLine(int line)
{
var region = new DomRegion(line, 1);
FunctionStartsAt(region);
}
public void FunctionBodyEndsAtColumn(int column)
{
var region = new DomRegion(1, 1, 1, column);
FunctionBodyEndsAt(region);
}
void FunctionBodyEndsAt(DomRegion region)
{
Method.Stub(m => m.BodyRegion).Return(region);
}
public void FunctionBodyEndsAtLine(int line)
{
var region = new DomRegion(1, 1, line, 1);
FunctionBodyEndsAt(region);
}
public void SetRegion(DomRegion region)
{
Method.Stub(m => m.Region).Return(region);
}
public void SetBodyRegion(DomRegion region)
{
Method.Stub(m => m.BodyRegion).Return(region);
}
public void SetCompilationUnitFileName(string fileName)
{
ICompilationUnit unit = MockRepository.GenerateStub<ICompilationUnit>();
unit.FileName = fileName;
Method.Stub(m => m.CompilationUnit).Return(unit);
}
}
}

Loading…
Cancel
Save