-
Notifications
You must be signed in to change notification settings - Fork 0
/
FStatsSpec.hs
57 lines (49 loc) · 2.71 KB
/
FStatsSpec.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
module Poseidon.FStatsSpec (spec) where
import Poseidon.CLI.FStats (FStatSpec (..), PopSpec (..),
fStatSpecParser, readStatSpecsFromFile,
runParser)
import qualified Data.ByteString.Char8 as B
import System.IO (IOMode (..), withFile)
import Test.Hspec
import Text.RawString.QQ
spec :: Spec
spec = do
testParseStatSpec
testParseStatSpecFromFile
testParseStatSpec :: Spec
testParseStatSpec = describe "Poseidon.FStatsSpec.fStatSpecParser" $ do
it "should parse F4 correctly" $
let f = F4Spec (PopSpecGroup "aa") (PopSpecInd "bb") (PopSpecGroup "cc") (PopSpecGroup "dd")
in runParser fStatSpecParser () "" "F4(aa,<bb>,cc,dd)" `shouldBe` Right f
it "should parse F3 correctly" $
let f = F3Spec (PopSpecGroup "aa") (PopSpecInd "bb") (PopSpecGroup "cc")
in runParser fStatSpecParser () "" "F3(aa,<bb>,cc)" `shouldBe` Right f
it "should parse F2 correctly" $
let f = F2Spec (PopSpecGroup "aa") (PopSpecInd "bb")
in runParser fStatSpecParser () "" "F2(aa,<bb>)" `shouldBe` Right f
it "should parse PWM correctly" $
let f = PWMspec (PopSpecGroup "aa") (PopSpecInd "bb")
in runParser fStatSpecParser () "" "PWM(aa,<bb>)" `shouldBe` Right f
it "should not parse wrong header" $
show (runParser fStatSpecParser () "" "BlaBla(aa,<bb>)") `shouldBe` "Left (line 1, column 1):\nunexpected \"B\"\nexpecting \"F4\", \"F3\", \"F2\" or \"PWM\""
it "should not parse too few args" $
show (runParser fStatSpecParser () "" "F4(aa,<bb>,cc)") `shouldBe` "Left (line 1, column 14):\nunexpected \")\"\nexpecting \",\""
it "should not parse too many args" $
show (runParser fStatSpecParser () "" "F4(aa,<bb>,cc,dd,ee)") `shouldBe` "Left (line 1, column 17):\nunexpected \",\"\nexpecting \")\""
fStatTestSpec :: B.ByteString
fStatTestSpec = [r|
F4(English, French, Mbuti, Saami)
F3(English, French, <German1>)
PWM(English, <French1>)|]
testParseStatSpecFromFile :: Spec
testParseStatSpecFromFile = describe "Poseidon.FStatsSpec.readStatSpecsFromFile" $ do
let fn = "/tmp/fstats_test.txt"
it "should parse a set of Fstats correctly from a file" $ do
withFile fn WriteMode $ \h -> B.hPutStr h fStatTestSpec
stats <- readStatSpecsFromFile fn
stats `shouldBe` [
F4Spec (PopSpecGroup "English") (PopSpecGroup "French") (PopSpecGroup "Mbuti") (PopSpecGroup "Saami"),
F3Spec (PopSpecGroup "English") (PopSpecGroup "French") (PopSpecInd "German1"),
PWMspec (PopSpecGroup "English") (PopSpecInd "French1")]