Permalink
Browse files

- Fixed little bug in World parser.

- Added new tests for RawParser.
  • Loading branch information...
1 parent 92df92f commit 8664a248690b3e1392c6532a28ec0d8832a75650 @graninas committed Feb 9, 2014
Showing with 29 additions and 16 deletions.
  1. +1 −1 Amoeba/GameLogic/Language/Parsers/WorldParser.hs
  2. +2 −10 Amoeba/Test/Data/Raws/World1.arf
  3. +26 −5 Amoeba/Test/ParsingTest.hs
@@ -50,7 +50,7 @@ object = do
cellsProperty :: String -> GenParser Char st PropertyToken
cellsProperty name = do
- cs <- trueSpaces >> eol >> many1 cell
+ cs <- assignment >> eol >> many1 cell
return $ CellsProperty name cs
cell :: GenParser Char st PropertyToken
@@ -3,15 +3,7 @@
World "Pandora"
width = 20
height = 20
- defaultCell = Object "Empty"
+ defaultCell = Object "Empty" "Player0"
cells =
(10, 10): Object "Karyon" "Player1"
- (9, 9): Object "Plasma" "Player1"
- (9, 10): Object "Plasma" "Player1"
- (9, 11): Object "Plasma" "Player1"
- (10, 9): Object "Plasma" "Player1"
- (10, 11): Object "Plasma" "Player1"
- (11, 9): Object "Plasma" "Player1"
- (11, 10): Object "Plasma" "Player1"
- (11, 11): Object "Plasma" "Player1"
- (15, 15): Object "Karyon" "Player2"
+ (9, 9): Object "Plasma" "Player1"
View
@@ -5,8 +5,8 @@ import Test.QuickCheck
import Test.QuickCheck.Property
import Test.QuickCheck.Monadic (assert, monadicIO, run)
import Test.QuickCheck.All
+import Control.Monad (liftM)
-import GameLogic.Data.Facade
import GameLogic.Language.RawToken
import GameLogic.Language.Parsers.ItemParser
import GameLogic.Language.Parsers.WorldParser
@@ -17,15 +17,36 @@ import GameLogic.Language.Parsers.RawParser
items1 = ("Items1", "./Data/Raws/Items.arf",
parseRawTokens,
Right [Comment " General items",EmptyToken,Item "Karyon" [IntResource "lifebound" (0,5000),IntResource "durability" (100,100),IntResource "energy" (300,2000)],EmptyToken,Comment " Conductor",Item "Conductor" [IntResource "lifebound" (0,1000),IntResource "durability" (100,100),IntResource "energy" (0,100)]])
+items2 = ("Items2", "./Data/Raws/Item.arf",
+ parseRawTokens,
+ Right [Item "Karyon" [IntResource "lifebound" (0,5000), IntResource "durability" (100,100), IntResource "energy" (300,2000)]])
+world1 = ("World1", "./Data/Raws/World1.arf",
+ parseRawTokens,
+ Right [ Comment " World definition file"
+ , EmptyToken
+ , World "Pandora" [ IntProperty "width" 20, IntProperty "height" 20, ObjectProperty "defaultCell" (Object "Empty" "Player0")
+ , CellsProperty "cells" [ CellProperty (10, 10) (Object "Karyon" "Player1")
+ , CellProperty (9, 9) (Object "Plasma" "Player1")]]
+ ])
-parseExample (testName, dataFile, parser, res) = do
- d <- readFile dataFile
- return $ parser d == res
+parseExample parser dataFile = liftM parser (readFile dataFile)
+testExample ex@(testName, dataFile, parser, res) = do
+ parsed <- parseExample parser dataFile
+ return $ res == parsed
prop_parseItems1 = monadicIO $ do
- res <- run $ parseExample items1
+ res <- run $ testExample items1
+ assert res
+
+prop_parseItems2 = monadicIO $ do
+ res <- run $ testExample items2
assert res
+
+prop_parseWorld1 = monadicIO $ do
+ res <- run $ testExample world1
+ assert res
+
tests :: IO Bool
tests = $quickCheckAll

0 comments on commit 8664a24

Please sign in to comment.