Update of /cvsroot/cpptool/rfta/src/rfta In directory sc8-pr-cvs1:/tmp/cvs-serv20545/src/rfta Modified Files: LineBasedTextDocument.cpp LineBasedTextDocumentTest.cpp LineBasedTextDocumentTest.h MockLineBasedTextDocument.cpp Log Message: * added support for tab within line based document Index: LineBasedTextDocument.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/LineBasedTextDocument.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** LineBasedTextDocument.cpp 25 Dec 2002 22:39:46 -0000 1.5 --- LineBasedTextDocument.cpp 10 May 2003 07:49:37 -0000 1.6 *************** *** 179,185 **** } ! index += location.columnNumber_; ! if ( index > content_.length() ) ! index = content_.length(); return index; --- 179,190 ---- } ! int column = 0; ! while ( column < location.columnNumber_ && index < content_.length() ) ! { ! if ( content_[index++] == '\t' ) ! column = ((column + tabSize_) / tabSize_) * tabSize_; ! else ! ++column; ! } return index; *************** *** 213,218 **** --- 218,229 ---- int columnNumber = index; int lastEOLIndex = content_.find_last_of( '\n', index-1 ); + const char *lineStart = start; if ( lastEOLIndex != std::string::npos ) + { columnNumber -= lastEOLIndex + 1; + lineStart += lastEOLIndex + 1; + } + + columnNumber += std::count( lineStart, lineStart + columnNumber, '\t' ) * (tabSize_-1); return Location( lineNumber, columnNumber ); Index: LineBasedTextDocumentTest.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/LineBasedTextDocumentTest.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** LineBasedTextDocumentTest.cpp 25 Dec 2002 22:39:46 -0000 1.5 --- LineBasedTextDocumentTest.cpp 10 May 2003 07:49:37 -0000 1.6 *************** *** 15,19 **** LineBasedTextDocumentTest::LineBasedTextDocumentTest() ! : CppUnit::TestFixture() { } --- 15,19 ---- LineBasedTextDocumentTest::LineBasedTextDocumentTest() ! : tabSize_( 8 ) { } *************** *** 28,32 **** LineBasedTextDocumentTest::setUp() { ! document_.reset( new MockLineBasedTextDocument( 3 ) ); } --- 28,32 ---- LineBasedTextDocumentTest::setUp() { ! document_.reset( new MockLineBasedTextDocument( tabSize_ ) ); } *************** *** 48,52 **** expectedSelectionEnd ); document_->setSelectionRange( SourceRange( selectionStartIndex, ! selectionLength ) ); document_->verify(); } --- 48,52 ---- expectedSelectionEnd ); document_->setSelectionRange( SourceRange( selectionStartIndex, ! selectionLength ) ); document_->verify(); } *************** *** 88,91 **** --- 88,140 ---- line2Index-1, line3Index-(line2Index-1)+4 ); // checkSetSelection( Location( 0,0 ), Location(4,0), 0,line4Index ); + } + + + void + LineBasedTextDocumentTest::testSetSelectionAfterTab() + { + std::string source( "\t\tSome Text\n" ); + int line1Index = source.length(); + source += "li\tne 2\n"; + int line2Index = source.length(); + source += "\tline3"; + document_->setContent( source ); + + checkSetSelection( Location( 0,0 ), Location(0,tabSize_), 0,1 ); + checkSetSelection( Location( 0,0 ), Location(0,tabSize_*2), 0,2 ); + checkSetSelection( Location( 0,0 ), Location(0,tabSize_*2+4), 0,2+4 ); + checkSetSelection( Location( 0,tabSize_ ), Location(0,tabSize_*2+5), 1,1+5 ); + + checkSetSelection( Location( 1,0 ), Location(1,6+tabSize_), line1Index,1+6 ); + checkSetSelection( Location( 1,2+tabSize_ ), Location(2,tabSize_+4), + line1Index+3, line2Index - (line1Index+3) + 1 + 4 ); + } + + + void + LineBasedTextDocumentTest::testGetSelectionAfterTab() + { + std::string source( "\t\tSome Text\n" ); + int line1Index = source.length(); + source += "li\tne 2\n"; + int line2Index = source.length(); + source += "\tline3"; + document_->setContent( source ); + + checkGetSelection( SourceRange(0,3), Location(0,0), Location(0,tabSize_*2+1) ); + checkGetSelection( SourceRange(0,3), Location(0,0), Location(0,tabSize_*2+1) ); + checkGetSelection( SourceRange(1,1+4), Location(0,tabSize_), Location(0,tabSize_*2+4) ); + checkGetSelection( SourceRange(1,line1Index-1+5), Location(0,tabSize_), Location(1,tabSize_+2) ); + } + + + void + LineBasedTextDocumentTest::checkGetSelection( const SourceRange &expectedSelectionRange, + const Location &selectionStart, + const Location &selectionEnd ) + { + document_->setExpectedSelectionRange( selectionStart, selectionEnd ); + SourceRange actualRange = document_->getSelectionRange(); + RFTA_ASSERT_EQUAL( expectedSelectionRange, actualRange ); } Index: LineBasedTextDocumentTest.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/LineBasedTextDocumentTest.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** LineBasedTextDocumentTest.h 6 Nov 2002 20:49:15 -0000 1.1 --- LineBasedTextDocumentTest.h 10 May 2003 07:49:37 -0000 1.2 *************** *** 21,24 **** --- 21,26 ---- CPPUNIT_TEST( testSetSelectionOnFirstLine ); CPPUNIT_TEST( testSetSelectionOnManyLines ); + CPPUNIT_TEST( testSetSelectionAfterTab ); + CPPUNIT_TEST( testGetSelectionAfterTab ); CPPUNIT_TEST_SUITE_END(); *************** *** 37,40 **** --- 39,46 ---- void testSetSelectionOnManyLines(); + void testSetSelectionAfterTab(); + + void testGetSelectionAfterTab(); + private: typedef MockLineBasedTextDocument::Location Location; *************** *** 45,49 **** --- 51,60 ---- int selectionLength ); + void checkGetSelection( const SourceRange &expectedSelectionRange, + const Location &selectionStart, + const Location &selectionEnd ); + boost::shared_ptr<MockLineBasedTextDocument> document_; + const int tabSize_; }; Index: MockLineBasedTextDocument.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rfta/MockLineBasedTextDocument.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MockLineBasedTextDocument.cpp 25 Dec 2002 22:39:46 -0000 1.2 --- MockLineBasedTextDocument.cpp 10 May 2003 07:49:37 -0000 1.3 *************** *** 33,37 **** void MockLineBasedTextDocument::setExpectedSelectionRange( const Location &selectionStart, ! const Location &selectionEnd ) { selectionStart_ = selectionStart; --- 33,37 ---- void MockLineBasedTextDocument::setExpectedSelectionRange( const Location &selectionStart, ! const Location &selectionEnd ) { selectionStart_ = selectionStart; *************** *** 54,58 **** { selectionStart_ = selectionStart; ! selectionEnd_ = selectionEnd_; addActual( "doSetSelectionRange(): start=" + selectionStart.toString() + --- 54,58 ---- { selectionStart_ = selectionStart; ! selectionEnd_ = selectionEnd; addActual( "doSetSelectionRange(): start=" + selectionStart.toString() + |