git @ Cat's Eye Technologies Falderal / b9f6bdc
Complete the refactor. Still more stuff needs to move. catseye 10 years ago
7 changed file(s) with 35 addition(s) and 36 deletion(s). Raw diff Collapse all Expand all
00 module Test.Falderal.Common where
11
22 --
3 -- Test.Falderal.Common -- Common data and functions for Falderal
3 -- Test.Falderal.Common -- Common data def'n and functions for Falderal
44 -- Copyright (c)2011 Cat's Eye Technologies. All rights reserved.
55 --
66 -- Redistribution and use in source and binary forms, with or without
3131 -- POSSIBILITY OF SUCH DAMAGE.
3232 --
3333
34 import Test.Falderal.Loader
34 import Test.Falderal.Common
3535
3636 --
3737 -- Formatting function which compiles a Falderal file to Haskell source.
4444 formatBlocks [] =
4545 ""
4646
47 format lines =
48 let
49 lines' = coalesceLines lines Placeholder
50 blocks = reDescribeBlocks $ convertLinesToBlocks $ lines'
51 in
52 prelude ++ (formatBlocks blocks) ++ postlude
47 format _ blocks =
48 prelude ++ (formatBlocks blocks) ++ postlude
5349
5450 --
5551 -- XXX this hard-codes some stuff, just to see things running
3131 -- POSSIBILITY OF SUCH DAMAGE.
3232 --
3333
34 import System
35
36 import Test.Falderal.Loader
34 import Test.Falderal.Common
3735
3836 --
3937 -- Formatting function which formats a Falderal file to an identical
5351 formatLine (SectionHeading text) =
5452 text ++ "\n" ++ (take (length text) (repeat '-')) ++ "\n"
5553
56 format = formatLines (formatLine)
54 format lines _ = formatLines (formatLine) lines
00 module Test.Falderal.Formatter.Markdown (format) where
11
22 --
3 -- Test.Falderal.Formatter.Identity -- Markdown formatter for Falderal format
3 -- Test.Falderal.Formatter.Markdown -- Markdown formatter for Falderal format
44 -- Copyright (c)2011 Cat's Eye Technologies. All rights reserved.
55 --
66 -- Redistribution and use in source and binary forms, with or without
3131 -- POSSIBILITY OF SUCH DAMAGE.
3232 --
3333
34 import System
35
36 import Test.Falderal.Loader
34 import Test.Falderal.Common
3735
3836 --
3937 -- Formatting function which formats a Falderal file to vanilla Markdown
5452 formatLine (SectionHeading text) =
5553 text ++ "\n" ++ (take (length text) (repeat '-')) ++ "\n"
5654
57 format = formatLines (formatLine)
55 format lines _ = formatLines (formatLine) lines
3333
3434 import System
3535
36 import Test.Falderal.Common
3637 import Test.Falderal.Loader
3738 import qualified Test.Falderal.Formatter.Identity as Identity
3839 import qualified Test.Falderal.Formatter.Markdown as Markdown
4950 getFormatter "identity" = Identity.format
5051 getFormatter "markdown" = Markdown.format
5152 getFormatter "haskell" = Haskell.format
52 getFormatter "dump" = formatLines (\x -> (show x) ++ "\n")
53 getFormatter "dump" = dumpLines
54
55 dumpLines lines blocks = formatLines (\x -> (show x) ++ "\n") lines
5356
5457 --
5558 -- We format by (coalesced) lines, instead of by blocks, because by the time
5760 --
5861
5962 formatFile format fileName = do
60 testText <- readFile fileName
61 lines <- return $ transformLines $ lines testText
62 outputText <- return $ (getFormatter format) lines
63 (lines, blocks) <- loadFile fileName
64 outputText <- return $ (getFormatter format) lines blocks
6365 putStr outputText
4343
4444 loadFile fileName = do
4545 testText <- readFile fileName
46 lines <- return $ transformLines $ lines testText
47 blocks <- return $ convertLinesToBlocks $ lines
48 return blocks
46 (ls, bs) <- return $ loadText testText
47 return (ls, bs)
4948
50 loadLines fileName = do
51 testText <- readFile fileName
52 lines <- return $ transformLines $ lines testText
53 return lines
49 --
50 -- Returns both the (coaslesced) lines and the (redescribed) blocks,
51 -- allowing the caller to choose which one they want to look at.
52 --
5453
55 transformLines lines =
54 loadText text =
5655 let
57 lines' = map classifyLine lines
58 lines'' = findSectionHeadings lines' Placeholder
59 lines''' = coalesceLines lines'' Placeholder
56 ls = transformLines $ lines text
57 bs = reDescribeBlocks $ convertLinesToBlocks $ ls
6058 in
61 stripPlaceholders lines'''
59 (ls, bs)
60
61 transformLines ls =
62 let
63 ls' = map classifyLine ls
64 ls'' = findSectionHeadings ls' Placeholder
65 ls''' = coalesceLines ls'' Placeholder
66 in
67 stripPlaceholders ls'''
6268
6369 stripPlaceholders [] = []
6470 stripPlaceholders (Placeholder:rest) = stripPlaceholders rest
137143 -- be irrelevant now.
138144 --
139145
140 -- TODO: move this to a common module where Block is defined?
141
142146 reDescribeBlocks blocks = reDescribeBlocks' blocks "" 2
143147
144148 reDescribeBlocks' [] desc n =
3535 import qualified Control.Exception as Exc
3636
3737 import Test.Falderal.Common
38 import Test.Falderal.Loader -- XXX
3839
3940 --
4041 -- Definitions.
6768 run filenames options funMap
6869
6970 loadAndRunTests fileName funMap = do
70 blocks <- loadFile fileName
71 (_, blocks) <- loadFile fileName
7172 tests <- return $ reDescribeBlocks blocks
7273 reportTests funMap tests
7374