public void testFragmentFunction()
{
final TestElement element = TestElement.TYPE.instantiate();
final FunctionContext context = new ModelElementFunctionContext( element );
FunctionResult fr = ExpressionLanguageParser.parse( "${ Value.Fragment( 0, 3 ) }" ).evaluate( context );
try
{
assertEquals( "", fr.value() );
element.setValue( "ab" );
assertEquals( "ab", fr.value() );
element.setValue( "abcdefg" );
assertEquals( "abc", fr.value() );
}
finally
{
fr.dispose();
}
fr = ExpressionLanguageParser.parse( "${ Value.Fragment( 3, 6 ) }" ).evaluate( context );
try
{
element.setValue( null );
assertEquals( "", fr.value() );
element.setValue( "ab" );
assertEquals( "", fr.value() );
element.setValue( "abcdefg" );
assertEquals( "def", fr.value() );
}
finally
{
fr.dispose();
}
fr = ExpressionLanguageParser.parse( "${ Value.Fragment( 6, 3 ) }" ).evaluate( context );
try
{
element.setValue( null );
assertEquals( "", fr.value() );
element.setValue( "ab" );
assertEquals( "", fr.value() );
element.setValue( "abcdefg" );
assertEquals( "", fr.value() );
}
finally
{
fr.dispose();
}
fr = ExpressionLanguageParser.parse( "${ Value.Fragment( -3, 3 ) }" ).evaluate( context );
try
{
element.setValue( null );
assertEquals( "", fr.value() );
element.setValue( "ab" );
assertEquals( "ab", fr.value() );
element.setValue( "abcdefg" );
assertEquals( "abc", fr.value() );
}
finally
{
fr.dispose();
}
}