From 0cef2960c08ef23eb24acec788de34241f8f6dcc Mon Sep 17 00:00:00 2001 From: Raul Raja Date: Tue, 4 Jul 2017 20:21:37 +0200 Subject: [PATCH] Adds `pressMenu` action to DSL --- .../src/main/kotlin/com/pguardiola/uigesturegen/dsl/dsl.kt | 3 +++ .../main/kotlin/com/pguardiola/uigesturegen/dsl/examples.kt | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/uiagesturegen/src/main/kotlin/com/pguardiola/uigesturegen/dsl/dsl.kt b/uiagesturegen/src/main/kotlin/com/pguardiola/uigesturegen/dsl/dsl.kt index b03e7a5..aa62961 100644 --- a/uiagesturegen/src/main/kotlin/com/pguardiola/uigesturegen/dsl/dsl.kt +++ b/uiagesturegen/src/main/kotlin/com/pguardiola/uigesturegen/dsl/dsl.kt @@ -13,6 +13,7 @@ sealed class GestureDSL : HK { data class Wait(val condition: SearchCondition, val timeout: Long) : GestureDSL() data class FindObject(val selector: UiSelector) : GestureDSL() data class WithDevice(val f: (UiDevice) -> A) : GestureDSL() + object PressMenu : GestureDSL() companion object : FreeMonad @@ -27,6 +28,7 @@ class SafeInterpreter(val M: MonadError, val device: UiDevice) is GestureDSL.Wait<*> -> M.pure(device.wait(g.condition, g.timeout)) is GestureDSL.FindObject -> M.pure(device.findObject(g.selector)) is GestureDSL.WithDevice<*> -> M.pure(g.f(device)) + is GestureDSL.PressMenu -> M.pure(device.pressMenu()) } as HK } } @@ -51,6 +53,7 @@ fun pressHome(): DSLAction = Free.liftF(GestureDSL.PressHome) fun wait(condition: SearchCondition, timeout: Long): DSLAction = Free.liftF(GestureDSL.Wait(condition, timeout)) fun findObject(selector: UiSelector): DSLAction = Free.liftF(GestureDSL.FindObject(selector)) fun withDevice(f: (UiDevice) -> A): DSLAction = Free.liftF(GestureDSL.WithDevice(f)) +fun pressMenu(): DSLAction = Free.liftF(GestureDSL.PressMenu) fun Free.run(device: UiDevice): Try = this.foldMap(SafeInterpreter(Try, device), Try).ev() diff --git a/uiagesturegen/src/main/kotlin/com/pguardiola/uigesturegen/dsl/examples.kt b/uiagesturegen/src/main/kotlin/com/pguardiola/uigesturegen/dsl/examples.kt index 14fa6f2..0ef8fef 100644 --- a/uiagesturegen/src/main/kotlin/com/pguardiola/uigesturegen/dsl/examples.kt +++ b/uiagesturegen/src/main/kotlin/com/pguardiola/uigesturegen/dsl/examples.kt @@ -11,9 +11,10 @@ object GestureDSLExamples { /** * compose multiple actions independently regardless of return types */ - fun independentActionsWorkflow(): DSLAction> = + fun independentActionsWorkflow(): DSLAction> = GestureDSL.tupled( pressHome(), + pressMenu(), findObject(UiSelector().description("1")), findObject(UiSelector().description("2")), findObject(UiSelector().description("3"))).ev()