#18 #14 Inital parser commit

Added basic parser functionality & tests for these functionalites.
Split tests in several files
This commit is contained in:
Tibo De Peuter 2022-12-17 23:14:04 +01:00
parent 4c1f25e49d
commit 83659e69b4
9 changed files with 504 additions and 12 deletions

9
test/InteractionSpec.hs Normal file
View file

@ -0,0 +1,9 @@
module InteractionSpec where
import Test.Hspec
spec :: Spec
spec = do
describe "Player with Inventory" $ do
it "TODO: Simple test" $ do
pending

52
test/ParsedToGameSpec.hs Normal file
View file

@ -0,0 +1,52 @@
module ParsedToGameSpec where
import Test.Hspec
import Parse
spec :: Spec
spec = do
describe "Game" $ do
it "TODO: Simple game" $ do
pending
it "TODO: More complex game" $ do
pending
it "TODO: Game with multiple levels" $ do
pending
describe "Player" $ do
it "TODO: Simple player" $ do
pending
describe "Inventory" $ do
it "TODO: Empty inventory" $ do
pending
it "TODO: Singleton inventory" $ do
pending
it "TODO: Filled inventory" $ do
pending
describe "Items" $ do
it "TODO: Simple item" $ do
pending
-- Check id
-- Check x
-- Check y
-- Check name
-- Check description
-- Check useTimes
-- Check value
-- Check actions
describe "Actions" $ do
it "TODO: Simple action" $ do
pending
describe "Entities" $ do
it "TODO: Simple entity" $ do
pending
describe "Level" $ do
it "TODO: Simple layout" $ do
pending
it "TODO: Complex layout" $ do
pending

52
test/ParserSpec.hs Normal file
View file

@ -0,0 +1,52 @@
module ParserSpec where
import Test.Hspec
import Parse
import Data.Either
spec :: Spec
spec = do
describe "Basics of entries" $ do
it "can parse integers" $ do
let correct = Right $ Regular $ Integer 1
correct `shouldBe` parseWith regular "1"
it "can parse string" $ do
let input = "dit is een string"
correct = Right $ Regular $ String input
correct `shouldBe` parseWith regular ("\"" ++ input ++ "\"")
it "can parse infinite" $ do
let correct = Right $ Regular Infinite
correct `shouldBe` parseWith regular "infinite"
let wrong = Right $ Regular Infinite
wrong `shouldNotBe` parseWith regular "infinitee"
it "can parse entries" $ do
let input = "id : \"dagger\""
correct = Right $ Entry "id" $ Regular $ String "dagger"
correct `shouldBe` parseWith entry input
let input = "x: 0"
correct = Right $ Entry "x" $ Regular $ Integer 0
correct `shouldBe` parseWith entry input
let input = "useTimes: infinite"
correct = Right $ Entry "useTimes" $ Regular Infinite
correct `shouldBe` parseWith entry input
describe "Special kinds" $ do
it "can parse actions" $ do
let input = "actions: {}"
correct = Right $ Entry "actions" $ Regular Infinite -- TODO Change this
correct `shouldBe` parseWith action input
it "can parse conditions" $ do
pending
it "can parse layouts" $ do
pending
describe "Lists and blocks" $ do
it "can parse entities" $ do
pending

View file

@ -1,7 +0,0 @@
import Test.Hspec
main :: IO()
main = hspec $ do
describe "Dummy category" $ do
it "Dummy test" $ do
0 `shouldBe` 0

1
test/RPGEngineSpec.hs Normal file
View file

@ -0,0 +1 @@
{-# OPTIONS_GHC -F -pgmF hspec-discover #-}