Skip to content

Commit

Permalink
Adds sessionized tests
Browse files Browse the repository at this point in the history
  • Loading branch information
solomon-b authored and masaeedu committed Jan 7, 2023
1 parent 53c9457 commit 7e8616f
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions test/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
<<<Are you talking to me, punk?
|]
result <- runTestScript scenario $ fixBot helloSimpleBot ()
result <- runTestScript scenario $ fixBot bot ()
result `shouldBe` scenario

it "responds to its trigger phrase embedded in a sentence" $ do
Expand All @@ -39,12 +44,13 @@ helloBotSpec =
>>>hows it going cofree-bot
<<<Are you talking to me, punk?
|]
result <- runTestScript scenario $ fixBot helloSimpleBot ()
result <- runTestScript scenario $ fixBot bot ()
result `shouldBe` scenario

calculatorBotSpec :: Spec
calculatorBotSpec =
describe "Calculator Bot" $ do
let bot = simplifyCalculatorBot calculatorBot
it "performs arithmetic" $ do
let scenario =
[mkScript|
Expand All @@ -55,7 +61,7 @@ calculatorBotSpec =
>>>((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
Expand All @@ -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
<<<Session Started: '0'.
|]
result <- runTestScript scenario $ fixBot bot mempty
result `shouldBe` scenario

it "can delete a session" $ do
let scenario =
[mkScript|
>>>new
<<<Session Started: '0'.
>>>end 0
<<<Session Ended: '0'.
|]
result <- runTestScript scenario $ fixBot bot mempty
result `shouldBe` scenario

0 comments on commit 7e8616f

Please sign in to comment.