Skip to content

Commit

Permalink
reindent everything
Browse files Browse the repository at this point in the history
  • Loading branch information
mengwong committed Oct 18, 2021
1 parent 4645a59 commit 84c7fca
Showing 1 changed file with 122 additions and 121 deletions.
243 changes: 122 additions & 121 deletions mengwong/mp/test/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,130 +14,131 @@ import System.Environment (lookupEnv)


main :: IO ()
main = do
main = do
mpd <- lookupEnv "MP_DEBUG"
let runConfig = RC (maybe False (read :: String -> Bool) mpd) 0
let parseR p = parse (runReaderT p runConfig)

hspec $ do
describe "Nothing Test" $ do
it "should be nothing" $ do
(Nothing :: Maybe ()) `shouldBe` (Nothing :: Maybe ())
describe "megaparsing" $ do

it "should parse an unconditional" $ do
parseR (pRule <* eof) "" (exampleStream ",,,,\n,EVERY,person,,\n,MUST,,,\n,->,sing,,\n")
`shouldParse`
[ Regulative {
every = "person"
, who = Nothing
, cond = Nothing
, deontic = DMust
, action = ("sing",[])
, temporal = Nothing
} ]

it "should parse a single OtherVal" $ do
parseR (pRule <* eof) "" (exampleStream ",,,,\n,EVERY,person,,\n,WHO,walks,,\n,MUST,,,\n,->,sing,,\n")
`shouldParse`
[ Regulative {
every = "person"
, who = Just (Leaf "walks")
, cond = Nothing
, deontic = DMust
, action = ("sing",[])
, temporal = Nothing
} ]

it "should parse dummySing" $ do
parseR (pRule <* eof) "" (exampleStream ",,,,\n,EVERY,person,,\n,WHO,walks,// comment,continued comment should be ignored\n,AND,runs,,\n,AND,eats,,\n,OR,drinks,,\n,MUST,,,\n,->,sing,,\n")
`shouldParse`
[ Regulative {
every = "person"
, who = Just (All
( Pre "Who" )
[ Leaf "walks"
, Leaf "runs"
, Any
( Pre "any of:" )
[ Leaf "eats"
, Leaf "drinks"
]
])
, cond = Nothing
, deontic = DMust
, action = ("sing", [])
, temporal = Nothing
} ]

let imbibeRule = [ Regulative {
every = "person"
, who = Just (Any
( Pre "Who" )
[ Leaf "walks"
, Leaf "runs"
, Leaf "eats"
, All ( Pre "all of:" )
[ Leaf "drinks"
, Leaf "swallows" ]
])
, cond = Nothing
, deontic = DMust
, action = ("sing", [])
, temporal = Nothing
} ]

it "should parse indentedDummySing" $ do
parseR (pRule <* eof) "" (exampleStream ",,,,\n,EVERY,person,,\n,WHO,walks,// comment,continued comment should be ignored\n,OR,runs,,\n,OR,eats,,\n,OR,,drinks,\n,,AND,swallows,\n,MUST,,,\n,->,sing,,\n")
`shouldParse` imbibeRule

it "should parse indented-1.csv (inline boolean expression)" $ do
mycsv <- BS.readFile "test/indented-1.csv"
parseR (pRule <* eof) "" (exampleStream mycsv) `shouldParse` imbibeRule


it "should parse indented-1-checkboxes.csv (with checkboxes)" $ do
mycsv <- BS.readFile "test/indented-1-checkboxes.csv"
parseR (pRule <* eof) "" (exampleStream mycsv) `shouldParse` imbibeRule

let degustates = Constitutive
{ term = "degustates"
, cond = Just $ Any ( Pre "any of:" ) [ Leaf "eats", Leaf "drinks" ]
}

it "should parse a simple constitutive rule" $ do
mycsv <- BS.readFile "test/simple-constitutive-1.csv"
parseR (pRule <* eof) "" (exampleStream mycsv) `shouldParse` [degustates]

it "should parse a simple constitutive rule with checkboxes" $ do
mycsv <- BS.readFile "test/simple-constitutive-1-checkboxes.csv"
parseR (pRule <* eof) "" (exampleStream mycsv) `shouldParse` [degustates]

let imbibeRule2 = [ Regulative
{ every = "person"
, who = Just $ All
( Pre "Who" )
[ Leaf "walks"
, Leaf "degustates"
]
, cond = Nothing
, deontic = DMust
, action = ("sing", [])
, temporal = Nothing
}
, Constitutive
{ term = "degustates"
, cond = Just $ Any ( Pre "any of:" ) [ Leaf "eats", Leaf "drinks" ]
}
]

it "should parse indented-2.csv (inline constitutive rule)" $ do
mycsv <- BS.readFile "test/indented-2.csv"
parseR (pRule <* eof) "" (exampleStream mycsv) `shouldParse` imbibeRule2

it "should render a box" $ do
asBoxes <$> asCSV indentedDummySing
`shouldBe` Right "abc\n"

-- upgrade single OR group to bypass the top level AND group
describe "Nothing Test" $ do
it "should be nothing" $ do
(Nothing :: Maybe ()) `shouldBe` (Nothing :: Maybe ())
describe "megaparsing" $ do

it "should parse an unconditional" $ do
parseR (pRule <* eof) "" (exampleStream ",,,,\n,EVERY,person,,\n,MUST,,,\n,->,sing,,\n")
`shouldParse`
[ Regulative {
every = "person"
, who = Nothing
, cond = Nothing
, deontic = DMust
, action = ("sing",[])
, temporal = Nothing
} ]

it "should parse a single OtherVal" $ do
parseR (pRule <* eof) "" (exampleStream ",,,,\n,EVERY,person,,\n,WHO,walks,,\n,MUST,,,\n,->,sing,,\n")
`shouldParse`
[ Regulative {
every = "person"
, who = Just (Leaf "walks")
, cond = Nothing
, deontic = DMust
, action = ("sing",[])
, temporal = Nothing
} ]

it "should parse dummySing" $ do
parseR (pRule <* eof) "" (exampleStream ",,,,\n,EVERY,person,,\n,WHO,walks,// comment,continued comment should be ignored\n,AND,runs,,\n,AND,eats,,\n,OR,drinks,,\n,MUST,,,\n,->,sing,,\n")
`shouldParse`
[ Regulative {
every = "person"
, who = Just (All
( Pre "Who" )
[ Leaf "walks"
, Leaf "runs"
, Any
( Pre "any of:" )
[ Leaf "eats"
, Leaf "drinks"
]
])
, cond = Nothing
, deontic = DMust
, action = ("sing", [])
, temporal = Nothing
} ]

let imbibeRule = [ Regulative {
every = "person"
, who = Just (Any
( Pre "Who" )
[ Leaf "walks"
, Leaf "runs"
, Leaf "eats"
, All ( Pre "all of:" )
[ Leaf "drinks"
, Leaf "swallows" ]
])
, cond = Nothing
, deontic = DMust
, action = ("sing", [])
, temporal = Nothing
} ]

it "should parse indentedDummySing" $ do
parseR (pRule <* eof) "" (exampleStream ",,,,\n,EVERY,person,,\n,WHO,walks,// comment,continued comment should be ignored\n,OR,runs,,\n,OR,eats,,\n,OR,,drinks,\n,,AND,swallows,\n,MUST,,,\n,->,sing,,\n")
`shouldParse` imbibeRule

it "should parse indented-1.csv (inline boolean expression)" $ do
mycsv <- BS.readFile "test/indented-1.csv"
parseR (pRule <* eof) "" (exampleStream mycsv) `shouldParse` imbibeRule


it "should parse indented-1-checkboxes.csv (with checkboxes)" $ do
mycsv <- BS.readFile "test/indented-1-checkboxes.csv"
parseR (pRule <* eof) "" (exampleStream mycsv) `shouldParse` imbibeRule

let degustates = Constitutive
{ term = "degustates"
, cond = Just $ Any ( Pre "any of:" ) [ Leaf "eats", Leaf "drinks" ]
}

it "should parse a simple constitutive rule" $ do
mycsv <- BS.readFile "test/simple-constitutive-1.csv"
parseR (pRule <* eof) "" (exampleStream mycsv) `shouldParse` [degustates]

it "should parse a simple constitutive rule with checkboxes" $ do
mycsv <- BS.readFile "test/simple-constitutive-1-checkboxes.csv"
parseR (pRule <* eof) "" (exampleStream mycsv) `shouldParse` [degustates]

let imbibeRule2 = [ Regulative
{ every = "person"
, who = Just $ All
( Pre "Who" )
[ Leaf "walks"
, Leaf "degustates"
]
, cond = Nothing
, deontic = DMust
, action = ("sing", [])
, temporal = Nothing
}
, Constitutive
{ term = "degustates"
, cond = Just $ Any ( Pre "any of:" ) [ Leaf "eats", Leaf "drinks" ]
}
]

it "should parse indented-2.csv (inline constitutive rule)" $ do
mycsv <- BS.readFile "test/indented-2.csv"
parseR (pRule <* eof) "" (exampleStream mycsv) `shouldParse` imbibeRule2

it "should render a box" $ do
asBoxes <$> asCSV indentedDummySing
`shouldBe` Right "abc\n"

-- upgrade single OR group to bypass the top level AND group


0 comments on commit 84c7fca

Please sign in to comment.