37 | 37 |
-- Formatting function which compiles a Falderal file to Haskell source.
|
38 | 38 |
--
|
39 | 39 |
|
40 | |
formatBlocks (test@(Test desc text expectation):rest) =
|
41 | |
" " ++ (show test) ++ ",\n" ++ (formatBlocks rest)
|
|
40 |
formatBlocks ((functionName, test@(Test desc text expectation)):rest) =
|
|
41 |
" (" ++ functionName ++ ", " ++ (show test) ++ "),\n" ++ (formatBlocks rest)
|
42 | 42 |
formatBlocks (_:rest) =
|
43 | 43 |
formatBlocks rest
|
44 | 44 |
formatBlocks [] =
|
45 | 45 |
""
|
46 | 46 |
|
47 | 47 |
format _ blocks =
|
48 | |
(prelude blocks) ++ (formatBlocks blocks) ++ postlude
|
|
48 |
(prelude blocks) ++ (formatBlocks (transformBlocks blocks "")) ++ postlude
|
49 | 49 |
|
50 | 50 |
gatherImports ((HaskellDirective moduleName functionName):rest) =
|
51 | |
"import " ++ moduleName ++ "\n" ++ gatherImports rest
|
|
51 |
"import qualified " ++ moduleName ++ "\n" ++ gatherImports rest
|
52 | 52 |
gatherImports (_:rest) =
|
53 | 53 |
gatherImports rest
|
54 | 54 |
gatherImports [] =
|
55 | 55 |
""
|
56 | 56 |
|
57 | |
--
|
58 | |
-- XXX this hard-codes some stuff, just to see things running
|
59 | |
-- XXX instead, scan list for HaskellDirectives, pluck out module
|
60 | |
-- names and turn them into imports. Put function names in
|
61 | |
-- list somehow.
|
62 | |
--
|
|
57 |
transformBlocks ((HaskellDirective moduleName functionName):rest) _ =
|
|
58 |
transformBlocks rest (moduleName ++ "." ++ functionName)
|
|
59 |
transformBlocks (test@(Test _ _ _):rest) functionName =
|
|
60 |
(functionName, test):(transformBlocks rest functionName)
|
|
61 |
transformBlocks (_:rest) functionName =
|
|
62 |
transformBlocks rest functionName
|
|
63 |
transformBlocks [] _ =
|
|
64 |
[]
|
63 | 65 |
|
64 | 66 |
prelude blocks =
|
65 | 67 |
"module GeneratedFalderalTests where\n\
|
|
67 | 69 |
\import Test.Falderal.Common\n\
|
68 | 70 |
\import Test.Falderal.Runner\n" ++ (gatherImports blocks) ++ "\
|
69 | 71 |
\\n\
|
70 | |
\testModule = runTests [] (everySecond) [\n"
|
|
72 |
\testModule = runTests' [\n"
|
71 | 73 |
|
72 | 74 |
postlude =
|
73 | |
" (Section \"DONE\")\n\
|
|
75 |
" (id, (Section \"DONE\"))\n\
|
74 | 76 |
\ ]\n"
|