From 82c04d7f7205177b1ff3732d374208858ef7c267 Mon Sep 17 00:00:00 2001 From: Romain Edelmann Date: Sat, 26 Apr 2014 09:43:18 +0200 Subject: [PATCH] Added some tests. --- src/Tests.hs | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/src/Tests.hs b/src/Tests.hs index 5f7b1a5..2586b39 100644 --- a/src/Tests.hs +++ b/src/Tests.hs @@ -7,20 +7,50 @@ import Data.ByteString (ByteString) import System.Exit (exitFailure) import Scat +import Scat.Builder +import Scat.Schemas + +seedGithub :: Integer +seedGithub = 7273969660509039708598560774226985084748596416599584268407087707065680457723095089909612048211188783512827089141818809294015697773231266655764062992251214 + +seedFacebook :: Integer +seedFacebook = 13262460002149113723264840055577914239548551696334299511162926224707398066055935936276077079458293092086000192365956813128644769941942691534958728554307440 scatterTest :: String -> ByteString -> ByteString -> ByteString -> Integer -> IO () scatterTest name service password code expected = do putStrLn $ "Testing " ++ name when (scatter service password code /= expected) exitFailure +schemaTest :: String -> Schema -> Integer -> String -> IO () +schemaTest name schema seed expected = do + putStrLn $ "Testing " ++ name + when (evalBuilder (getBuilder schema Nothing) seed /= expected) exitFailure + main :: IO () main = do -- Mainly here for regression testing. - scatterTest "scatter example 1" + scatterTest "scatter test 1 - using github as service" "github" "pony1234" "AGDE2-DGXA4-33DLQ-WEDAP-GYPQ9" - 7273969660509039708598560774226985084748596416599584268407087707065680457723095089909612048211188783512827089141818809294015697773231266655764062992251214 - scatterTest "scatter example 2" + seedGithub + scatterTest "scatter test 2 - using facebook as service" "facebook" "pony1234" "AGDE2-DGXA4-33DLQ-WEDAP-GYPQ9" - 13262460002149113723264840055577914239548551696334299511162926224707398066055935936276077079458293092086000192365956813128644769941942691534958728554307440 + seedFacebook - -- TODO: Test also the schemas. + -- Testing the examples from the README. + schemaTest "schema test 1 - generating from 'safe' schema, with github seed" + safe seedGithub + "k2'8n?QXwmptbJ7D44" + + schemaTest "schema test 2 - generating from 'safe' schema, with facebook seed" + safe seedFacebook + "{g6e2hsKjh#Ra*\\ks(" + + dicewareSchema <- diceware + schemaTest "schema test 3 - generating from 'diceware' schema" + dicewareSchema seedFacebook + "101 dry whoa foil barb" + + pokemonsSchema <- pokemons + schemaTest "schema test 4 - generating from 'pokemons' schema" + pokemonsSchema seedFacebook + "Snorlax 5, Weedle 35, Raichu 27, Alakazam 99"