public void testHeadFunction()
{
final TestElement element = TestElement.TYPE.instantiate();
final FunctionContext context = new ModelElementFunctionContext( element );
FunctionResult fr = ExpressionLanguageParser.parse( "${ Value.Head( 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.Head( 0 ) }" ).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.Head( -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();
}
}