git @ Cat's Eye Technologies Falderal / 1299813
Add embryonic Formatter module. Chris Pressey 11 years ago
2 changed file(s) with 66 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 module Test.Falderal.Formatter where
1
2 -- TODO: export a more restricted interface
3
4 --
5 -- Test.Falderal.Formatter -- The Falderal Test Suite Formatter
6 -- Copyright (c)2011 Cat's Eye Technologies. All rights reserved.
7 --
8 -- Redistribution and use in source and binary forms, with or without
9 -- modification, are permitted provided that the following conditions
10 -- are met:
11 --
12 -- 1. Redistributions of source code must retain the above copyright
13 -- notices, this list of conditions and the following disclaimer.
14 -- 2. Redistributions in binary form must reproduce the above copyright
15 -- notices, this list of conditions, and the following disclaimer in
16 -- the documentation and/or other materials provided with the
17 -- distribution.
18 -- 3. Neither the names of the copyright holders nor the names of their
19 -- contributors may be used to endorse or promote products derived
20 -- from this software without specific prior written permission.
21 --
22 -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 -- ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 -- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 -- COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 -- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 -- BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 -- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 -- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 -- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 -- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 -- POSSIBILITY OF SUCH DAMAGE.
34 --
35
36 import System
37
38 import Test.Falderal.Loader
39
40 --
41 -- File formatting functions. Just a crude throughput for now,
42 -- to show what we can do.
43 --
44
45 formatFile fileName = do
46 testText <- readFile fileName
47 lines <- return $ transformLines $ lines testText
48 blocks <- return $ convertLinesToBlocks $ lines
49 outputText <- return $ formatBlocks blocks
50 putStr outputText
51
52 formatBlocks [] = ""
53 formatBlocks ((Section sectionText):rest) =
54 sectionText ++ (formatBlocks rest)
55 formatBlocks ((Test literalText inputText expected):rest) =
56 literalText ++ inputText ++ (show expected) ++ (formatBlocks rest)
00 module Test.Falderal.Loader where
1
2 -- TODO: export a more restricted interface
13
24 --
35 -- Test.Falderal.Loader -- The Falderal Test Loader
4446 | QuotedCode String
4547 | SectionHeading String
4648 deriving (Show, Eq, Ord)
49
50 -- TODO: move these datatypes to a common module?
4751
4852 data Expectation = Output String
4953 | Exception String
157161 -- be irrelevant now.
158162 --
159163
164 -- TODO: move this to a common module where Block is defined?
165
160166 reDescribeBlocks blocks = reDescribeBlocks' blocks "" 2
161167
162168 reDescribeBlocks' [] desc n =
172178 -- This could use Char.isSpace
173179 --
174180
181 -- TODO: move these to a common utility module?
182 -- TODO: can these be replaced by standard Haskell functions?
183
175184 allWhitespace [] = True
176185 allWhitespace (' ':rest) = allWhitespace rest
177186 allWhitespace ('\n':rest) = allWhitespace rest