|
From: <bl...@us...> - 2003-05-16 19:55:08
|
Update of /cvsroot/cpptool/rfta/src/rfta
In directory sc8-pr-cvs1:/tmp/cvs-serv32133/src/rfta
Modified Files:
LineBasedTextDocument.cpp MockTextDocument.cpp
MockTextDocument.h PlainTextDocument.cpp
ReplaceTextTransform.cpp ReplaceTextTransformTest.cpp
ReplaceTextTransformTest.h TextDocument.cpp
TransformListTest.cpp
Log Message:
* Made the interface of TextDocument simpler. It now has only 3 methods: getAllText(), getTextRange() and replaceTextRange().
Index: LineBasedTextDocument.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/LineBasedTextDocument.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** LineBasedTextDocument.cpp 10 May 2003 07:49:37 -0000 1.6
--- LineBasedTextDocument.cpp 16 May 2003 19:55:02 -0000 1.7
***************
*** 75,78 ****
--- 75,95 ----
+ std::string
+ LineBasedTextDocument::getTextRange( const Refactoring::SourceRange &range )
+ {
+ setSelectionRange( range );
+ return getSelection();
+ }
+
+
+ void
+ LineBasedTextDocument::replaceTextRange( const Refactoring::SourceRange &range,
+ const std::string &text )
+ {
+ setSelectionRange( range );
+ replaceSelection( text );
+ }
+
+
void
LineBasedTextDocument::replaceSelection( const std::string &text )
Index: MockTextDocument.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/MockTextDocument.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** MockTextDocument.cpp 22 Dec 2002 16:03:52 -0000 1.6
--- MockTextDocument.cpp 16 May 2003 19:55:02 -0000 1.7
***************
*** 13,17 ****
MockTextDocument::MockTextDocument()
! : expectations_( "MockTextDocument" )
{
}
--- 13,17 ----
MockTextDocument::MockTextDocument()
! : Mock::Expectations( "MockTextDocument" )
{
}
***************
*** 26,38 ****
MockTextDocument::getAllText() const
{
! expectations_.throwNotImplemented( "getAllText" );
return "";
}
! const std::string
! MockTextDocument::getSelection() const
{
! expectations_.throwNotImplemented( "getSelection" );
return "";
}
--- 26,38 ----
MockTextDocument::getAllText() const
{
! throwNotImplemented( "getAllText" );
return "";
}
! std::string
! MockTextDocument::getTextRange( const Refactoring::SourceRange &range )
{
! addCall( "MockTextDocument::getTextRange( " + range.toString() + ")" );
return "";
}
***************
*** 40,89 ****
void
! MockTextDocument::replaceSelection( const std::string &text )
! {
! expectations_.addActual( "replaceSelection => " + text );
! }
!
!
! void
! MockTextDocument::expectReplaceSelection( const std::string &text )
! {
! expectations_.addExpected( "replaceSelection => " + text );
! }
!
!
! SourceRange
! MockTextDocument::getSelectionRange() const
! {
! expectations_.throwNotImplemented( "getSelectionRange" );
! return SourceRange();
! }
!
!
! void
! MockTextDocument::setSelectionRange( const SourceRange &selection )
! {
! expectations_.addActual( "setSelectionRange => " + selection.toString() );
! }
!
!
! void
! MockTextDocument::expectSetSelectionRange( const SourceRange &selection )
! {
! expectations_.addExpected( "setSelectionRange => " + selection.toString() );
! }
!
!
! void
! MockTextDocument::expectNothing()
! {
! expectations_.expectNothing();
! }
!
!
! void
! MockTextDocument::verify()
{
! expectations_.verify();
}
--- 40,48 ----
void
! MockTextDocument::replaceTextRange( const Refactoring::SourceRange &range,
! const std::string &text )
{
! addCall( "MockTextDocument::replaceTextRange( " + range.toString()
! + ", " + text + ")" );
}
Index: MockTextDocument.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/MockTextDocument.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** MockTextDocument.h 22 Dec 2002 16:03:52 -0000 1.6
--- MockTextDocument.h 16 May 2003 19:55:02 -0000 1.7
***************
*** 19,22 ****
--- 19,23 ----
class MockTextDocument : public TextDocument
, public boost::noncopyable
+ , public Mock::Expectations
{
public:
***************
*** 30,49 ****
const std::string getAllText() const;
! const std::string getSelection() const;
!
! void replaceSelection( const std::string &text );
! void expectReplaceSelection( const std::string &text );
!
! SourceRange getSelectionRange() const;
!
! void setSelectionRange( const SourceRange &selection );
! void expectSetSelectionRange( const SourceRange &selection );
!
! void expectNothing();
!
! void verify();
! private:
! Mock::Expectations expectations_;
};
--- 31,38 ----
const std::string getAllText() const;
! std::string getTextRange( const Refactoring::SourceRange &range );
! void replaceTextRange( const Refactoring::SourceRange &range,
! const std::string &text );
};
Index: PlainTextDocument.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/PlainTextDocument.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** PlainTextDocument.cpp 22 Dec 2002 16:03:52 -0000 1.5
--- PlainTextDocument.cpp 16 May 2003 19:55:02 -0000 1.6
***************
*** 13,17 ****
PlainTextDocument::PlainTextDocument()
- : selection_( SourceRange(0,0) )
{
}
--- 13,16 ----
***************
*** 19,24 ****
PlainTextDocument::PlainTextDocument( const std::string &content )
! : selection_( SourceRange(0,0) )
! , content_( content )
{
}
--- 18,22 ----
PlainTextDocument::PlainTextDocument( const std::string &content )
! : content_( content )
{
}
***************
*** 37,70 ****
! const std::string
! PlainTextDocument::getSelection() const
! {
! return content_.substr( selection_.getStartIndex(),
! selection_.getLength() );
! }
!
!
! void
! PlainTextDocument::replaceSelection( const std::string &text )
! {
! std::string::iterator it = content_.begin() + selection_.getStartIndex();
! content_.replace( it, it + selection_.getLength(), text );
! selection_ =
! SourceRange( selection_.getStartIndex() + text.length(), 0 );
! }
!
!
! SourceRange
! PlainTextDocument::getSelectionRange() const
{
! return selection_;
}
-
void
! PlainTextDocument::setSelectionRange( const SourceRange &selection )
{
! selection_ = selection;
}
--- 35,52 ----
! std::string
! PlainTextDocument::getTextRange( const Refactoring::SourceRange &range )
{
! return content_.substr( range.getStartIndex(),
! range.getLength() );
}
void
! PlainTextDocument::replaceTextRange( const Refactoring::SourceRange &range,
! const std::string &text )
{
! std::string::iterator it = content_.begin() + range.getStartIndex();
! content_.replace( it, it + range.getLength(), text );
}
Index: ReplaceTextTransform.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/ReplaceTextTransform.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** ReplaceTextTransform.cpp 22 Dec 2002 16:03:52 -0000 1.5
--- ReplaceTextTransform.cpp 16 May 2003 19:55:02 -0000 1.6
***************
*** 30,35 ****
{
int lengthDelta = text_.length() - range_.getLength();
! document.setSelectionRange( range_ );
! document.replaceSelection( text_ );
return lengthDelta;
--- 30,34 ----
{
int lengthDelta = text_.length() - range_.getLength();
! document.replaceTextRange( range_, text_ );
return lengthDelta;
Index: ReplaceTextTransformTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/ReplaceTextTransformTest.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** ReplaceTextTransformTest.cpp 22 Dec 2002 16:03:52 -0000 1.4
--- ReplaceTextTransformTest.cpp 16 May 2003 19:55:02 -0000 1.5
***************
*** 5,9 ****
#include "stdafx.h"
- #include "MockTextDocument.h"
#include "ReplaceTextTransform.h"
#include "ReplaceTextTransformTest.h"
--- 5,8 ----
***************
*** 30,33 ****
--- 29,34 ----
ReplaceTextTransformTest::setUp()
{
+ document_.reset( new MockTextDocument() );
+ document_->setRecordMode();
}
***************
*** 36,39 ****
--- 37,41 ----
ReplaceTextTransformTest::tearDown()
{
+ document_.reset();
}
***************
*** 43,53 ****
{
ReplaceTextTransform transform( SourceRange( 0,0 ), "" );
! MockTextDocument document;
! document.expectSetSelectionRange( SourceRange( 0,0 ) );
! document.expectReplaceSelection( "" );
! RFTA_ASSERT_EQUAL( 0, transform.apply( document ) );
! document.verify();
}
--- 45,54 ----
{
ReplaceTextTransform transform( SourceRange( 0,0 ), "" );
! document_->replaceTextRange( SourceRange( 0,0 ), "" );
! document_->setVerifyMode();
! RFTA_ASSERT_EQUAL( 0, transform.apply( *document_ ) );
! document_->verify();
}
***************
*** 57,67 ****
{
ReplaceTextTransform transform( SourceRange( 0,10 ), "123" );
! MockTextDocument document;
! document.expectSetSelectionRange( SourceRange( 0,10 ) );
! document.expectReplaceSelection( "123" );
! RFTA_ASSERT_EQUAL( -7, transform.apply( document ) );
! document.verify();
}
--- 58,67 ----
{
ReplaceTextTransform transform( SourceRange( 0,10 ), "123" );
! document_->replaceTextRange( SourceRange( 0,10 ), "123" );
! document_->setVerifyMode();
! RFTA_ASSERT_EQUAL( -7, transform.apply( *document_ ) );
! document_->verify();
}
***************
*** 71,81 ****
{
ReplaceTextTransform transform( SourceRange( 0,5 ), "1234567890" );
! MockTextDocument document;
! document.expectSetSelectionRange( SourceRange( 0,5 ) );
! document.expectReplaceSelection( "1234567890" );
! RFTA_ASSERT_EQUAL( 5, transform.apply( document ) );
! document.verify();
}
--- 71,80 ----
{
ReplaceTextTransform transform( SourceRange( 0,5 ), "1234567890" );
! document_->replaceTextRange( SourceRange( 0,5 ), "1234567890" );
! document_->setVerifyMode();
! RFTA_ASSERT_EQUAL( 5, transform.apply( *document_ ) );
! document_->verify();
}
***************
*** 85,95 ****
{
ReplaceTextTransform transform( SourceRange( 0,4 ), "1234" );
! MockTextDocument document;
! document.expectSetSelectionRange( SourceRange( 0,4 ) );
! document.expectReplaceSelection( "1234" );
! RFTA_ASSERT_EQUAL( 0, transform.apply( document ) );
! document.verify();
}
--- 84,93 ----
{
ReplaceTextTransform transform( SourceRange( 0,4 ), "1234" );
! document_->replaceTextRange( SourceRange( 0,4 ), "1234" );
! document_->setVerifyMode();
! RFTA_ASSERT_EQUAL( 0, transform.apply( *document_ ) );
! document_->verify();
}
Index: ReplaceTextTransformTest.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/ReplaceTextTransformTest.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** ReplaceTextTransformTest.h 26 Oct 2002 20:39:56 -0000 1.1
--- ReplaceTextTransformTest.h 16 May 2003 19:55:02 -0000 1.2
***************
*** 7,10 ****
--- 7,12 ----
#include "UnitTesting.h"
+ #include "MockTextDocument.h"
+ #include <boost/shared_ptr.hpp>
***************
*** 47,50 ****
--- 49,53 ----
private:
+ boost::shared_ptr<MockTextDocument> document_;
};
Index: TextDocument.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/TextDocument.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** TextDocument.cpp 22 Dec 2002 16:03:52 -0000 1.5
--- TextDocument.cpp 16 May 2003 19:55:02 -0000 1.6
***************
*** 16,20 ****
}
!
void
TextDocument::moveTo( int toLocation )
--- 16,20 ----
}
! #if 0
void
TextDocument::moveTo( int toLocation )
***************
*** 22,25 ****
--- 22,26 ----
setSelectionRange( SourceRange( toLocation, toLocation ) );
}
+ #endif
Index: TransformListTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rfta/TransformListTest.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** TransformListTest.cpp 6 Mar 2003 22:18:41 -0000 1.5
--- TransformListTest.cpp 16 May 2003 19:55:02 -0000 1.6
***************
*** 15,19 ****
TransformListTest::TransformListTest()
- : CppUnit::TestFixture()
{
}
--- 15,18 ----
***************
*** 30,33 ****
--- 29,33 ----
transforms_.reset( new TransformList() );
document_.reset( new MockTextDocument() );
+ document_->setRecordMode();
}
***************
*** 45,48 ****
--- 45,49 ----
{
document_->expectNothing();
+ document_->setVerifyMode();
transforms_->apply( *document_ );
***************
*** 55,62 ****
TransformListTest::testApplyOne()
{
! transforms_->add( *new ReplaceTextTransform(
! SourceRange(3,6), "1" ) );
! document_->expectSetSelectionRange( SourceRange( 3,6 ) );
! document_->expectReplaceSelection( "1" );
transforms_->apply( *document_ );
--- 56,62 ----
TransformListTest::testApplyOne()
{
! transforms_->add( *new ReplaceTextTransform( SourceRange(3,6), "1" ) );
! document_->replaceTextRange( SourceRange( 3,6 ), "1" );
! document_->setVerifyMode();
transforms_->apply( *document_ );
***************
*** 69,80 ****
TransformListTest::testApplyTwoMissordered()
{
! transforms_->add( *new ReplaceTextTransform(
! SourceRange(30,7), "1456" ) );
! transforms_->add( *new ReplaceTextTransform(
! SourceRange(3,20), "aze" ) );
! document_->expectSetSelectionRange( SourceRange( 3,20 ) );
! document_->expectReplaceSelection( "aze" );
! document_->expectSetSelectionRange( SourceRange( 30-20+3,7 ) );
! document_->expectReplaceSelection( "1456" );
transforms_->apply( *document_ );
--- 69,77 ----
TransformListTest::testApplyTwoMissordered()
{
! transforms_->add( *new ReplaceTextTransform( SourceRange(30,7), "1456" ) );
! transforms_->add( *new ReplaceTextTransform( SourceRange(3,20), "aze" ) );
! document_->replaceTextRange( SourceRange( 3,20 ), "aze" );
! document_->replaceTextRange( SourceRange( 30-20+3,7 ), "1456" );
! document_->setVerifyMode();
transforms_->apply( *document_ );
***************
*** 87,98 ****
TransformListTest::testApplyTwoOrdered()
{
! transforms_->add( *new ReplaceTextTransform(
! SourceRange(3,20), "aze" ) );
! transforms_->add( *new ReplaceTextTransform(
! SourceRange(30,7), "1456" ) );
! document_->expectSetSelectionRange( SourceRange( 3,20 ) );
! document_->expectReplaceSelection( "aze" );
! document_->expectSetSelectionRange( SourceRange( 30-20+3,7 ) );
! document_->expectReplaceSelection( "1456" );
transforms_->apply( *document_ );
--- 84,92 ----
TransformListTest::testApplyTwoOrdered()
{
! transforms_->add( *new ReplaceTextTransform( SourceRange(3,20), "aze" ) );
! transforms_->add( *new ReplaceTextTransform( SourceRange(30,7), "1456" ) );
! document_->replaceTextRange( SourceRange( 3,20 ), "aze" );
! document_->replaceTextRange( SourceRange( 30-20+3,7 ), "1456" );
! document_->setVerifyMode();
transforms_->apply( *document_ );
***************
*** 105,120 ****
TransformListTest::testApplyThreeMissordered()
{
! transforms_->add( *new ReplaceTextTransform(
! SourceRange(30,7), "1456" ) );
! transforms_->add( *new ReplaceTextTransform(
! SourceRange(3,20), "aze" ) );
! transforms_->add( *new ReplaceTextTransform(
! SourceRange(25,3), "a" ) );
! document_->expectSetSelectionRange( SourceRange( 3,20 ) );
! document_->expectReplaceSelection( "aze" );
! document_->expectSetSelectionRange( SourceRange( 25-20+3,3 ) );
! document_->expectReplaceSelection( "a" );
! document_->expectSetSelectionRange( SourceRange( 30-20+3-3+1,7 ) );
! document_->expectReplaceSelection( "1456" );
transforms_->apply( *document_ );
--- 99,109 ----
TransformListTest::testApplyThreeMissordered()
{
! transforms_->add( *new ReplaceTextTransform( SourceRange(30,7), "1456" ) );
! transforms_->add( *new ReplaceTextTransform( SourceRange(3,20), "aze" ) );
! transforms_->add( *new ReplaceTextTransform( SourceRange(25,3), "a" ) );
! document_->replaceTextRange( SourceRange( 3,20 ), "aze" );
! document_->replaceTextRange( SourceRange( 25-20+3,3 ), "a" );
! document_->replaceTextRange( SourceRange( 30-20+3-3+1,7 ), "1456" );
! document_->setVerifyMode();
transforms_->apply( *document_ );
***************
*** 131,140 ****
transforms_->add( *new ReplaceTextTransform( SourceRange( 0,0 ), line1 ) );
transforms_->add( *new ReplaceTextTransform( SourceRange( 0,0 ), "}" ) );
! document_->expectSetSelectionRange( SourceRange( 0,0 ) );
! document_->expectReplaceSelection( "{" );
! document_->expectSetSelectionRange( SourceRange( 1,0 ) );
! document_->expectReplaceSelection( line1 );
! document_->expectSetSelectionRange( SourceRange( 1+line1.length(),0 ) );
! document_->expectReplaceSelection( "}" );
transforms_->apply( *document_ );
--- 120,127 ----
transforms_->add( *new ReplaceTextTransform( SourceRange( 0,0 ), line1 ) );
transforms_->add( *new ReplaceTextTransform( SourceRange( 0,0 ), "}" ) );
! document_->replaceTextRange( SourceRange( 0,0 ), "{" );
! document_->replaceTextRange( SourceRange( 1,0 ), line1 );
! document_->replaceTextRange( SourceRange( 1+line1.length(),0 ), "}" );
! document_->setVerifyMode();
transforms_->apply( *document_ );
|