Skip to content

Commit

Permalink
HHH-17435 Add test for issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mbladel committed Jan 4, 2024
1 parent c0e2483 commit 1453efc
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.dialect.SybaseDialect;
import org.hibernate.dialect.TiDBDialect;
import org.hibernate.query.sqm.produce.function.FunctionArgumentException;

import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.domain.StandardDomainModel;
import org.hibernate.testing.orm.domain.gambit.EntityOfBasics;
Expand Down Expand Up @@ -829,6 +831,43 @@ public void testTrimFunction(SessionFactoryScope scope) {
}
}

@Test
public void testTrimFunctionParameters(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
assertThat( session.createQuery( "select trim(:param)", String.class )
.setParameter( "param", " hello " )
.getSingleResult(), is( "hello" ) );
assertThat( session.createQuery( "select trim(' ' from :param)", String.class )
.setParameter( "param", " hello " )
.getSingleResult(), is( "hello" ) );
assertThat( session.createQuery( "select trim('''' from :param)", String.class )
.setParameter( "param", "''hello'''" )
.getSingleResult(), is( "hello" ) );
assertThat( session.createQuery( "select trim(:param1 from :param2)", String.class )
.setParameter( "param1", '-' )
.setParameter( "param2", "--hello---" )
.getSingleResult(), is( "hello" ) );
assertThat( session.createQuery( "select trim(?1 from ?2)", String.class )
.setParameter( 1, ' ' )
.setParameter( 2, " hello " )
.getSingleResult(), is( "hello" ) );
}
);

try {
scope.inTransaction(
session -> session.createQuery( "select trim(:param from 'hello')", String.class )
.setParameter( "param", 1 )
.getResultList()
);
fail();
}
catch (IllegalArgumentException e) {
assertThat( e.getCause(), is( instanceOf( FunctionArgumentException.class ) ) );
}
}

@Test
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsPadWithChar.class)
public void testPadFunction(SessionFactoryScope scope) {
Expand Down

0 comments on commit 1453efc

Please sign in to comment.