Skip to content

Commit

Permalink
Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aperfilyev authored and AlecKazakova committed Apr 20, 2022
1 parent 95de86b commit 9cdb929
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ internal class RunSqlAction(
if (p.value.isEmpty()) {
return@mapNotNull null
}
p.range to "'${p.value}'"
p.range to p.value
}
if (replacements.isEmpty()) {
return null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package app.cash.sqldelight.intellij.run

import com.intellij.openapi.project.Project

internal class FakeDialogViewFactory(
val values: List<String> = emptyList(),
val okPressed: Boolean = true,
) : ArgumentsInputDialog.Factory {

override fun create(project: Project, parameters: List<SqlParameter>): ArgumentsInputDialog {
return object : ArgumentsInputDialog {
override val result: List<SqlParameter>
get() = parameters.zip(values) { a, b ->
a.copy(value = b)
}

override fun showAndGet(): Boolean {
return okPressed
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package app.cash.sqldelight.intellij.run

internal class FakeStatementExecutor : SqlDelightStatementExecutor {

var statement = ""
private set

override fun execute(sqlStmt: String) {
statement = sqlStmt
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package app.cash.sqldelight.intellij.run

import app.cash.sqldelight.core.lang.SqlDelightFileType
import app.cash.sqldelight.intellij.SqlDelightFixtureTestCase
import com.google.common.truth.Truth.assertThat
import com.intellij.icons.AllIcons

class RunSqliteAnnotatorTest : SqlDelightFixtureTestCase() {

fun testGutterIconVisibleInSqlite() {
ConnectionOptions(project).apply {
connectionType = ConnectionType.FILE
filePath = "/path/to/file"
}
myFixture.configureByText(
SqlDelightFileType, """
|CREATE TABLE test ( <caret>
| id INTEGER
|);
""".trimMargin()
)

val guttersAtCaret = myFixture.findGuttersAtCaret()
assertThat(guttersAtCaret.first().icon).isEqualTo(AllIcons.RunConfigurations.TestState.Run)
}

fun testGutterIconInvisibleWhenConnectionTypeNotSpecified() {
ConnectionOptions(project).apply {
connectionType = ConnectionType.NONE
}
myFixture.configureByText(
SqlDelightFileType, """
|CREATE TABLE test ( <caret>
| id INTEGER
|);
""".trimMargin()
)
assertThat(myFixture.findGuttersAtCaret()).isEmpty()
}
}

0 comments on commit 9cdb929

Please sign in to comment.