mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 19:17:10 +00:00
test(sidecar): assert InputText types at cursor without clearing
Captures the adb command stream and verifies a single input-text call with no preceding delete keyevents, plus the adb escaping cases.
This commit is contained in:
1 parent
4d497cce56
commit
9f7f2f5b21
1 file changed
+38
@@ -0,0 +1,38 @@
|
||||
package dev.sanderling.sidecar
|
||||
|
||||
import org.junit.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class InputTextTest {
|
||||
|
||||
@Test fun inputTextTypesAtCursorWithoutClearing() {
|
||||
val commands = mutableListOf<List<String>>()
|
||||
val backend = StubDriverBackend("android") { commands.add(it) }
|
||||
|
||||
backend.inputText("Emergency Fund")
|
||||
|
||||
assertEquals(listOf(listOf("shell", "input", "text", "Emergency%sFund")), commands)
|
||||
}
|
||||
|
||||
@Test fun escapeForAdbInputTextSubstitutesSpaces() {
|
||||
assertEquals("hello%sworld", StubDriverBackend.escapeForAdbInputText("hello world"))
|
||||
}
|
||||
|
||||
@Test fun escapeForAdbInputTextEscapesShellMetacharacters() {
|
||||
val escaped = StubDriverBackend.escapeForAdbInputText("a&b|c;d\$e`f")
|
||||
assertEquals("a\\&b\\|c\\;d\\\$e\\`f", escaped)
|
||||
}
|
||||
|
||||
@Test fun escapeForAdbInputTextEscapesQuotesAndBackslash() {
|
||||
assertEquals("\\'", StubDriverBackend.escapeForAdbInputText("'"))
|
||||
assertEquals("\\\"", StubDriverBackend.escapeForAdbInputText("\""))
|
||||
assertEquals("\\\\", StubDriverBackend.escapeForAdbInputText("\\"))
|
||||
}
|
||||
|
||||
@Test fun escapeForAdbInputTextLeavesSimpleTextAlone() {
|
||||
assertEquals("12.34", StubDriverBackend.escapeForAdbInputText("12.34"))
|
||||
assertEquals("Coffee", StubDriverBackend.escapeForAdbInputText("Coffee"))
|
||||
assertTrue("-5" == StubDriverBackend.escapeForAdbInputText("-5"))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user