Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Add strip margin functionality to SQL-interpolated strings
- Loading branch information
1 parent
3b3bd36
commit 9e88a9baeb960c2e0a02b9fec665baaed9f66f60
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package slick.test.jdbc | ||
|
||
import org.junit.Test | ||
import slick.jdbc.JdbcProfile | ||
import org.junit.Assert._ | ||
|
||
class SqlActionBuilderTest { | ||
|
||
@Test | ||
def testStripMargin: Unit = { | ||
val driver = new JdbcProfile {} | ||
import driver.api.actionBasedSQLInterpolation | ||
|
||
val id = 0 | ||
val s1 = sql"select * from SUPPLIERS where SUP_ID = ${id}" | ||
val s2 = sql"""select * | ||
|from SUPPLIERS | ||
|where SUP_ID = ${id}""".stripMargin | ||
val s3 = sql"""select * | ||
!from SUPPLIERS | ||
!where SUP_ID = ${id}""".stripMargin('!') | ||
val s4 = sql"""select * | ||
#from SUPPLIERS | ||
#where SUP_ID = ${id}""".stripMargin('#') | ||
|
||
def dropNewLineChars(queryParts: Seq[Any]): Seq[Any] = queryParts.map(_.asInstanceOf[String].replace('\n', ' ')) | ||
|
||
assertEquals(s1.queryParts, dropNewLineChars(s2.queryParts)) | ||
assertEquals(s1.queryParts, dropNewLineChars(s3.queryParts)) | ||
assertEquals(s1.queryParts, dropNewLineChars(s4.queryParts)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters