Setup
This commit is contained in:
parent
0720f3b719
commit
d4fbcda73b
13 changed files with 412 additions and 169 deletions
|
@ -1,9 +0,0 @@
|
|||
module InteractionSpec where
|
||||
|
||||
import Test.Hspec
|
||||
|
||||
spec :: Spec
|
||||
spec = do
|
||||
describe "Player with Inventory" $ do
|
||||
it "TODO: Simple test" $ do
|
||||
pending
|
|
@ -1,7 +1,7 @@
|
|||
module ParsedToGameSpec where
|
||||
module ParseGameSpec where
|
||||
|
||||
import Test.Hspec
|
||||
import RPGEngine.Internals.Parse.StructureElement
|
||||
import RPGEngine.Parse.StructureElement
|
||||
|
||||
spec :: Spec
|
||||
spec = do
|
282
test/ParseStructureElementSpec.hs
Normal file
282
test/ParseStructureElementSpec.hs
Normal file
|
@ -0,0 +1,282 @@
|
|||
module ParseStructureElementSpec where
|
||||
|
||||
import Test.Hspec
|
||||
|
||||
import RPGEngine.Data
|
||||
import RPGEngine.Parse.Core
|
||||
import RPGEngine.Parse.StructureElement
|
||||
|
||||
spec :: Spec
|
||||
spec = do
|
||||
describe "StructureElement" $ do
|
||||
it "can parse blocks" $ do
|
||||
let input = "{}"
|
||||
correct = Right $ Block []
|
||||
parseWith structureElement input `shouldBe` correct
|
||||
|
||||
let input = "{{}}"
|
||||
correct = Right $ Block [Block []]
|
||||
parseWith structureElement input `shouldBe` correct
|
||||
|
||||
let input = "{{}, {}}"
|
||||
correct = Right $ Block [Block [], Block []]
|
||||
parseWith structureElement input `shouldBe` correct
|
||||
|
||||
let input = "{ id: 1 }"
|
||||
correct = Right (Block [
|
||||
Entry (Tag "id") $ Regular $ Integer 1
|
||||
], "")
|
||||
parseWithRest structureElement input `shouldBe` correct
|
||||
|
||||
let input = "{ id: \"key\", x: 3, y: 1}"
|
||||
correct = Right $ Block [
|
||||
Entry (Tag "id") $ Regular $ String "key",
|
||||
Entry (Tag "x") $ Regular $ Integer 3,
|
||||
Entry (Tag "y") $ Regular $ Integer 1
|
||||
]
|
||||
parseWith structureElement input `shouldBe` correct
|
||||
|
||||
let input = "actions: { [not(inventoryFull())] retrieveItem(key), [] leave()}"
|
||||
correct = Right (Entry (Tag "actions") $ Block [
|
||||
Entry (ConditionList [Not InventoryFull]) $ Regular $ Action $ RetrieveItem "key",
|
||||
Entry (ConditionList []) $ Regular $ Action Leave
|
||||
], "")
|
||||
parseWithRest structureElement input `shouldBe` correct
|
||||
|
||||
let input = "entities: [ { id: \"door\", x: 4, name:\"Secret door\", description: \"This secret door can only be opened with a key\", direction: left, y: 1}]"
|
||||
correct = Right (Entry (Tag "entities") $ Block [ Block [
|
||||
Entry (Tag "id") $ Regular $ String "door",
|
||||
Entry (Tag "x") $ Regular $ Integer 4,
|
||||
Entry (Tag "name") $ Regular $ String "Secret door",
|
||||
Entry (Tag "description") $ Regular $ String "This secret door can only be opened with a key",
|
||||
Entry (Tag "direction") $ Regular $ Direction West,
|
||||
Entry (Tag "y") $ Regular $ Integer 1
|
||||
]], "")
|
||||
parseWithRest structureElement input `shouldBe` correct
|
||||
|
||||
let input = "entities: [ { id: \"door\", x: 4, y: 1, name:\"Secret door\", description: \"This secret door can only be opened with a key\", actions: { [inventoryContains(key)] useItem(key), [] leave() } } ]"
|
||||
correct = Right (Entry (Tag "entities") $ Block [ Block [
|
||||
Entry (Tag "id") $ Regular $ String "door",
|
||||
Entry (Tag "x") $ Regular $ Integer 4,
|
||||
Entry (Tag "y") $ Regular $ Integer 1,
|
||||
Entry (Tag "name") $ Regular $ String "Secret door",
|
||||
Entry (Tag "description") $ Regular $ String "This secret door can only be opened with a key",
|
||||
Entry (Tag "actions") $ Block [
|
||||
Entry (ConditionList [InventoryContains "key"]) $ Regular $ Action $ UseItem "key",
|
||||
Entry (ConditionList []) $ Regular $ Action Leave
|
||||
]
|
||||
]], "")
|
||||
parseWithRest structureElement input `shouldBe` correct
|
||||
|
||||
let input = "entities: [ { id: \"door\", x: 4, y: 1, name:\"Secret door\", description: \"This secret door can only be opened with a key\", direction: left , actions: { [inventoryContains(key)] useItem(key), [] leave() } } ]"
|
||||
correct = Right (Entry (Tag "entities") $ Block [ Block [
|
||||
Entry (Tag "id") $ Regular $ String "door",
|
||||
Entry (Tag "x") $ Regular $ Integer 4,
|
||||
Entry (Tag "y") $ Regular $ Integer 1,
|
||||
Entry (Tag "name") $ Regular $ String "Secret door",
|
||||
Entry (Tag "description") $ Regular $ String "This secret door can only be opened with a key",
|
||||
Entry (Tag "direction") $ Regular $ Direction West,
|
||||
Entry (Tag "actions") $ Block [
|
||||
Entry (ConditionList [InventoryContains "key"]) $ Regular $ Action $ UseItem "key",
|
||||
Entry (ConditionList []) $ Regular $ Action Leave
|
||||
]
|
||||
]], "")
|
||||
parseWithRest structureElement input `shouldBe` correct
|
||||
|
||||
it "can parse entries" $ do
|
||||
let input = "id: \"dagger\""
|
||||
correct = Right $ Entry (Tag "id") $ Regular $ String "dagger"
|
||||
parseWith entry input `shouldBe` correct
|
||||
|
||||
let input = "x: 0"
|
||||
correct = Right $ Entry (Tag "x") $ Regular $ Integer 0
|
||||
parseWith entry input `shouldBe` correct
|
||||
|
||||
let input = "useTimes: infinite"
|
||||
correct = Right $ Entry (Tag "useTimes") $ Regular Infinite
|
||||
parseWith entry input `shouldBe` correct
|
||||
|
||||
let input = "direction: up"
|
||||
correct = Right $ Entry (Tag "direction") $ Regular $ Direction North
|
||||
parseWith entry input `shouldBe` correct
|
||||
|
||||
let input = "actions: { [not(inventoryFull())] retrieveItem(key), [] leave()}"
|
||||
correct = Right (Entry (Tag "actions") $ Block [
|
||||
Entry (ConditionList [Not InventoryFull]) $ Regular $ Action $ RetrieveItem "key",
|
||||
Entry (ConditionList []) $ Regular $ Action Leave
|
||||
], "")
|
||||
parseWithRest structureElement input `shouldBe` correct
|
||||
|
||||
it "can parse regulars" $ do
|
||||
let input = "this is a string"
|
||||
correct = Right $ Regular $ String input
|
||||
parseWith regular ("\"" ++ input ++ "\"") `shouldBe` correct
|
||||
|
||||
let correct = Right $ Regular $ Integer 1
|
||||
parseWith regular "1" `shouldBe` correct
|
||||
|
||||
let correct = Right $ Regular Infinite
|
||||
parseWith regular "infinite" `shouldBe` correct
|
||||
|
||||
let wrong = Right $ Regular Infinite
|
||||
parseWith regular "infinitee" `shouldNotBe` wrong
|
||||
|
||||
let input = "leave()"
|
||||
correct = Right $ Regular $ Action Leave
|
||||
parseWith regular input `shouldBe` correct
|
||||
|
||||
let input = "retrieveItem(firstId)"
|
||||
correct = Right $ Regular $ Action $ RetrieveItem "firstId"
|
||||
parseWith regular input `shouldBe` correct
|
||||
|
||||
let input = "useItem(secondId)"
|
||||
correct = Right $ Regular $ Action $ UseItem "secondId"
|
||||
parseWith regular input `shouldBe` correct
|
||||
|
||||
let input = "decreaseHp(entityId,objectId)"
|
||||
correct = Right $ Regular $ Action $ DecreaseHp "entityId" "objectId"
|
||||
parseWith regular input `shouldBe` correct
|
||||
|
||||
let input = "increasePlayerHp(objectId)"
|
||||
correct = Right $ Regular $ Action $ IncreasePlayerHp "objectId"
|
||||
parseWith regular input `shouldBe` correct
|
||||
|
||||
let input = "up"
|
||||
correct = Right $ Regular $ Direction North
|
||||
parseWith regular input `shouldBe` correct
|
||||
|
||||
let input = "right"
|
||||
correct = Right $ Regular $ Direction East
|
||||
parseWith regular input `shouldBe` correct
|
||||
|
||||
let input = "down"
|
||||
correct = Right $ Regular $ Direction South
|
||||
parseWith regular input `shouldBe` correct
|
||||
|
||||
let input = "left"
|
||||
correct = Right $ Regular $ Direction West
|
||||
parseWith regular input `shouldBe` correct
|
||||
|
||||
describe "Key" $ do
|
||||
it "can parse tags" $ do
|
||||
let input = "simpletag"
|
||||
correct = Right $ Tag "simpletag"
|
||||
parseWith tag input `shouldBe` correct
|
||||
|
||||
it "can parse conditionlists" $ do
|
||||
let input = "[not(inventoryFull())]"
|
||||
correct = Right (ConditionList [Not InventoryFull], "")
|
||||
parseWithRest conditionList input `shouldBe` correct
|
||||
|
||||
let input = "[inventoryFull(), inventoryContains(itemId)]"
|
||||
correct = Right (ConditionList [
|
||||
InventoryFull,
|
||||
InventoryContains "itemId"
|
||||
], "")
|
||||
parseWithRest conditionList input `shouldBe` correct
|
||||
|
||||
let input = "[]"
|
||||
correct = Right $ ConditionList []
|
||||
parseWith conditionList input `shouldBe` correct
|
||||
|
||||
it "can parse conditions" $ do
|
||||
let input = "inventoryFull()"
|
||||
correct = Right (Condition InventoryFull, "")
|
||||
parseWithRest condition input `shouldBe` correct
|
||||
|
||||
let input = "inventoryContains(itemId)"
|
||||
correct = Right (Condition $ InventoryContains "itemId", "")
|
||||
parseWithRest condition input `shouldBe` correct
|
||||
|
||||
let input = "not(inventoryFull())"
|
||||
correct = Right (Condition $ Not InventoryFull, "")
|
||||
parseWithRest condition input `shouldBe` correct
|
||||
|
||||
let input = "not(inventoryContains(itemId))"
|
||||
correct = Right (Condition $ Not $ InventoryContains "itemId", "")
|
||||
parseWithRest condition input `shouldBe` correct
|
||||
|
||||
describe "Value" $ do
|
||||
it "can parse strings" $ do
|
||||
let input = "dit is een string"
|
||||
correct = Right $ String input
|
||||
parseWith string ("\"" ++ input ++ "\"") `shouldBe` correct
|
||||
|
||||
it "can parse integers" $ do
|
||||
let correct = Right $ Integer 1
|
||||
parseWith integer "1" `shouldBe` correct
|
||||
|
||||
it "can parse infinite" $ do
|
||||
let correct = Right Infinite
|
||||
parseWith infinite "infinite" `shouldBe` correct
|
||||
|
||||
let wrong = Right Infinite
|
||||
parseWith infinite "infinitee" `shouldNotBe` wrong
|
||||
|
||||
it "can parse actions" $ do
|
||||
let input = "leave()"
|
||||
correct = Right $ Action Leave
|
||||
parseWith action input `shouldBe` correct
|
||||
|
||||
let input = "retrieveItem(firstId)"
|
||||
correct = Right $ Action $ RetrieveItem "firstId"
|
||||
parseWith action input `shouldBe` correct
|
||||
|
||||
let input = "useItem(secondId)"
|
||||
correct = Right $ Action $ UseItem "secondId"
|
||||
parseWith action input `shouldBe` correct
|
||||
|
||||
let input = "decreaseHp(entityId,objectId)"
|
||||
correct = Right $ Action $ DecreaseHp "entityId" "objectId"
|
||||
parseWith action input `shouldBe` correct
|
||||
|
||||
let input = "increasePlayerHp(objectId)"
|
||||
correct = Right $ Action $ IncreasePlayerHp "objectId"
|
||||
parseWith action input `shouldBe` correct
|
||||
|
||||
it "can parse directions" $ do
|
||||
let input = "up"
|
||||
correct = Right $ Direction North
|
||||
parseWith RPGEngine.Parse.StructureElement.direction input `shouldBe` correct
|
||||
|
||||
let input = "right"
|
||||
correct = Right $ Direction East
|
||||
parseWith RPGEngine.Parse.StructureElement.direction input `shouldBe` correct
|
||||
|
||||
let input = "down"
|
||||
correct = Right $ Direction South
|
||||
parseWith RPGEngine.Parse.StructureElement.direction input `shouldBe` correct
|
||||
|
||||
let input = "left"
|
||||
correct = Right $ Direction West
|
||||
parseWith RPGEngine.Parse.StructureElement.direction input `shouldBe` correct
|
||||
|
||||
it "can parse layouts" $ do
|
||||
let input = "| * * * * * * * *\n| * s . . . . e *\n| * * * * * * * *"
|
||||
correct = Right $ Layout [
|
||||
[Blocked, Blocked, Blocked, Blocked, Blocked, Blocked, Blocked, Blocked],
|
||||
[Blocked, Entrance, Walkable, Walkable, Walkable, Walkable, Exit, Blocked],
|
||||
[Blocked, Blocked, Blocked, Blocked, Blocked, Blocked, Blocked, Blocked]
|
||||
]
|
||||
parseWith RPGEngine.Parse.StructureElement.layout input `shouldBe` correct
|
||||
|
||||
describe "Brackets" $ do
|
||||
it "matches closing <" $ do
|
||||
let input = '<'
|
||||
correct = '>'
|
||||
getMatchingClosingBracket input `shouldBe` correct
|
||||
|
||||
it "matches closing (" $ do
|
||||
let input = '('
|
||||
correct = ')'
|
||||
getMatchingClosingBracket input `shouldBe` correct
|
||||
|
||||
it "matches closing {" $ do
|
||||
let input = '{'
|
||||
correct = '}'
|
||||
getMatchingClosingBracket input `shouldBe` correct
|
||||
|
||||
it "matches closing [" $ do
|
||||
let input = '['
|
||||
correct = ']'
|
||||
getMatchingClosingBracket input `shouldBe` correct
|
|
@ -1,132 +0,0 @@
|
|||
module ParserSpec where
|
||||
|
||||
import Test.Hspec
|
||||
import RPGEngine.Internals.Parse
|
||||
import RPGEngine.Internals.Parse.StructureElement
|
||||
import RPGEngine.Internals.Data.Internals
|
||||
import Data.Either
|
||||
|
||||
spec :: Spec
|
||||
spec = do
|
||||
describe "Basics of entries" $ do
|
||||
it "can parse integers" $ do
|
||||
let correct = Right $ Regular $ Integer 1
|
||||
parseWith regular "1" `shouldBe` correct
|
||||
it "can parse string" $ do
|
||||
let input = "dit is een string"
|
||||
correct = Right $ Regular $ String input
|
||||
parseWith regular ("\"" ++ input ++ "\"") `shouldBe` correct
|
||||
it "can parse infinite" $ do
|
||||
let correct = Right $ Regular Infinite
|
||||
parseWith regular "infinite" `shouldBe` correct
|
||||
|
||||
let wrong = Right $ Regular Infinite
|
||||
parseWith regular "infinitee" `shouldNotBe` wrong
|
||||
|
||||
it "can parse entries" $ do
|
||||
let input = "id: \"dagger\""
|
||||
correct = Right $ Entry (Tag "id") $ Regular $ String "dagger"
|
||||
parseWith entry input `shouldBe` correct
|
||||
|
||||
let input = "x: 0"
|
||||
correct = Right $ Entry (Tag "x") $ Regular $ Integer 0
|
||||
parseWith entry input `shouldBe` correct
|
||||
|
||||
let input = "useTimes: infinite"
|
||||
correct = Right $ Entry (Tag "useTimes") $ Regular Infinite
|
||||
parseWith entry input `shouldBe` correct
|
||||
|
||||
describe "block: {...}" $ do
|
||||
it "can parse a block with a single entry" $ do
|
||||
let input = "{ id: 1}"
|
||||
correct = Right (Block [
|
||||
Entry (Tag "id") $ Regular $ Integer 1
|
||||
], "")
|
||||
parseWithRest structureElement input `shouldBe` correct
|
||||
|
||||
it "can parse a block with entries" $ do
|
||||
let input = "{ id: \"key\", x: 3, y: 1}"
|
||||
correct = Right $ Block [
|
||||
Entry (Tag "id") $ Regular $ String "key",
|
||||
Entry (Tag "x") $ Regular $ Integer 3,
|
||||
Entry (Tag "y") $ Regular $ Integer 1
|
||||
]
|
||||
parseWith structureElement input `shouldBe` correct
|
||||
|
||||
describe "Basics" $ do
|
||||
it "can parse leave()" $ do
|
||||
let input = "leave()"
|
||||
correct = Right $ Action Leave
|
||||
parseWith action input `shouldBe` correct
|
||||
|
||||
it "can parse retrieveItem()" $ do
|
||||
let input = "retrieveItem(firstId)"
|
||||
correct = Right $ Action $ RetrieveItem "firstId"
|
||||
parseWith action input `shouldBe` correct
|
||||
|
||||
it "can parse useItem()" $ do
|
||||
let input = "useItem(secondId)"
|
||||
correct = Right $ Action $ UseItem "secondId"
|
||||
parseWith action input `shouldBe` correct
|
||||
|
||||
it "can parse decreaseHp()" $ do
|
||||
let input = "decreaseHp(entityId,objectId)"
|
||||
correct = Right $ Action $ DecreaseHp "entityId" "objectId"
|
||||
parseWith action input `shouldBe` correct
|
||||
|
||||
it "can parse increasePlayerHp()" $ do
|
||||
let input = "increasePlayerHp(objectId)"
|
||||
correct = Right $ Action $ IncreasePlayerHp "objectId"
|
||||
parseWith action input `shouldBe` correct
|
||||
|
||||
it "can parse inventoryFull()" $ do
|
||||
let input = "inventoryFull()"
|
||||
correct = Right (Condition InventoryFull, "")
|
||||
parseWithRest condition input `shouldBe` correct
|
||||
|
||||
it "can parse inventoryContains()" $ do
|
||||
let input = "inventoryContains(itemId)"
|
||||
correct = Right (Condition $ InventoryContains "itemId", "")
|
||||
parseWithRest condition input `shouldBe` correct
|
||||
|
||||
it "can parse not()" $ do
|
||||
let input = "not(inventoryFull())"
|
||||
correct = Right (Condition $ Not InventoryFull, "")
|
||||
parseWithRest condition input `shouldBe` correct
|
||||
|
||||
let input = "not(inventoryContains(itemId))"
|
||||
correct = Right (Condition $ Not $ InventoryContains "itemId", "")
|
||||
parseWithRest condition input `shouldBe` correct
|
||||
|
||||
it "can parse conditionlists" $ do
|
||||
let input = "[not(inventoryFull())]"
|
||||
correct = Right (ConditionList [Not InventoryFull], "")
|
||||
parseWithRest conditionList input `shouldBe` correct
|
||||
|
||||
let input = "[inventoryFull(), inventoryContains(itemId)]"
|
||||
correct = Right (ConditionList [
|
||||
InventoryFull,
|
||||
InventoryContains "itemId"
|
||||
], "")
|
||||
parseWithRest conditionList input `shouldBe` correct
|
||||
|
||||
let input = "[]"
|
||||
correct = Right $ ConditionList []
|
||||
parseWith conditionList input `shouldBe` correct
|
||||
|
||||
it "can parse actions" $ do
|
||||
let input = "actions: { [not(inventoryFull())] retrieveItem(key), [] leave()}"
|
||||
correct = Right (Entry (Tag "actions") $ Block [
|
||||
Entry (ConditionList [Not InventoryFull]) $ Regular $ Action $ RetrieveItem "key",
|
||||
Entry (ConditionList []) $ Regular $ Action Leave
|
||||
], "")
|
||||
parseWithRest structureElement input `shouldBe` correct
|
||||
|
||||
describe "Layouts" $ do
|
||||
it "can parse layouts" $ do
|
||||
pending
|
||||
|
||||
describe "Lists and blocks" $ do
|
||||
it "can parse entities" $ do
|
||||
pending
|
||||
|
Reference in a new issue