From 7e8616f6ee6e2439a98d5aad2652180001ac736e Mon Sep 17 00:00:00 2001 From: solomon Date: Sun, 27 Nov 2022 14:35:03 -0800 Subject: [PATCH] Adds sessionized tests --- test/Spec.hs | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/test/Spec.hs b/test/Spec.hs index 5b0eb85..469da2f 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -5,11 +5,14 @@ module Main where -------------------------------------------------------------------------------- import CofreeBot.Bot (fixBot) -import CofreeBot.Bot.Behaviors.Calculator +import CofreeBot.Bot.Behaviors ( calculatorBot, + helloSimpleBot, + printCalcOutput, simplifyCalculatorBot, ) -import CofreeBot.Bot.Behaviors.Hello (helloSimpleBot) +import CofreeBot.Bot.Behaviors.Calculator.Language (statementP) +import CofreeBot.Bot.Context (sessionize, simplifySessionBot) import Scripts (mkScript) import Test.Hspec (Spec, describe, hspec, it, shouldBe) import TestServer (runTestScript) @@ -20,17 +23,19 @@ main :: IO () main = hspec $ do helloBotSpec calculatorBotSpec + sessionizedBotSpec helloBotSpec :: Spec helloBotSpec = describe "Hello Bot" $ do + let bot = helloSimpleBot it "responds to precisely its trigger phrase" $ do let scenario = [mkScript| >>>cofree-bot <<>>hows it going cofree-bot <<>>((2 * 3) + 1) <<<2 * 3 + 1 = 7 |] - result <- runTestScript scenario $ fixBot (simplifyCalculatorBot calculatorBot) mempty + result <- runTestScript scenario $ fixBot bot mempty result `shouldBe` scenario it "can store values in state" $ do @@ -66,5 +72,29 @@ calculatorBotSpec = >>>x <<<"x" = 3 |] - result <- runTestScript scenario $ fixBot (simplifyCalculatorBot calculatorBot) mempty + result <- runTestScript scenario $ fixBot bot mempty + result `shouldBe` scenario + +sessionizedBotSpec :: Spec +sessionizedBotSpec = + describe "Sessionized Bot" $ do + let bot = simplifySessionBot printCalcOutput statementP $ sessionize mempty $ calculatorBot + it "can instantiate a session" $ do + let scenario = + [mkScript| + >>>new + <<>>new + <<>>end 0 + <<