I added a new class, SourceBuilder which helps writing tests. I already
refactored ScopeHolderTest and ScopeGeneratorTest to use it. I also added a
few helper methods to ScopeGeneratorTestBase,getVariableNode(), and
SourceBasedTestBase, getIdentifierNode().
SourceBuilder is used to construct the source string, and memorise
ranges of text, keying them with a string. For example:
source_ = " int y = 456;"
" int ";
int index1 = source_.length();
source_ += "x=3;"
" ";
int index2 = source_.length();
source_ += "x+= 3;";
Becomes
builder_->add( " int y = 456;" );
builder_->add3( " int ", "x", "=3;", "x.1" );
builder_->add3( "", "x", "+=3;", "x.2" );
Where "x.1" and "x.2" are keys used to retreive the middle string passed to
add3():
int index1 = builder_->getStartIndex( "x.1" );
int index2 = bulider_->getStartIndex( "x.2" );
It is also possible to mark a range of text and extends it to the 'current'
position using mark() and extend(). See ScopeHolderTest for examples.
I expect this class to also be of used in rftaparser tests. Should
probably rename the add3() method though, but I can not think of a good
name.
Baptiste.
|