-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from gvolpe/test-suite
Adding tests for dconf parser
- Loading branch information
Showing
4 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{-# LANGUAGE OverloadedStrings, TemplateHaskell #-} | ||
|
||
module DConfTest | ||
( dconfParserTests | ||
) | ||
where | ||
|
||
import qualified Data.Map as M | ||
import qualified Data.Text as T | ||
import qualified Data.Text.IO as T | ||
import Data.Text ( Text ) | ||
import DConf ( dconfParser ) | ||
import DConf.Data | ||
import Hedgehog | ||
import Text.Parsec ( runParser ) | ||
|
||
prop_simple_parser :: Property | ||
prop_simple_parser = withTests (100 :: TestLimit) simpleParser | ||
|
||
prop_file_parser :: Property | ||
prop_file_parser = withTests (10 :: TestLimit) fileParser | ||
|
||
simpleParser :: Property | ||
simpleParser = | ||
let entries = runParser (dconfParser Normal) () "<test>" testInput | ||
in property $ entries === Right [testOutput] | ||
|
||
fileParser :: Property | ||
fileParser = property $ do | ||
input <- evalIO $ T.readFile "data/dconf.settings" | ||
entries <- evalEither $ runParser (dconfParser Normal) () "<test>" input | ||
length entries === 64 | ||
|
||
testInput :: Text | ||
testInput = T.unlines | ||
[ "[ org/gnome/desktop/peripherals/mouse ]" | ||
, "natural-scroll=false" | ||
, "speed=-0.5" | ||
] | ||
|
||
testOutput :: Entry | ||
testOutput = Entry | ||
{ header = "org/gnome/desktop/peripherals/mouse" | ||
, content = M.fromList | ||
[(Key "natural-scroll", B False), (Key "speed", D (-0.5))] | ||
} | ||
|
||
dconfParserTests :: Group | ||
dconfParserTests = $$(discover) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Main where | ||
|
||
import Control.Monad ( unless ) | ||
import DConfTest | ||
import Hedgehog | ||
import System.Exit | ||
|
||
main :: IO () | ||
main = do | ||
results <- sequence [checkParallel dconfParserTests] | ||
unless (and results) exitFailure |