60 | 60 |
loadText text =
|
61 | 61 |
let
|
62 | 62 |
ls = transformLines $ lines text
|
63 | |
fds = collectFunctionalityDefinitions ls
|
64 | |
bs = convertLinesToBlocks ls [] fds
|
|
63 |
ls' = resolvePragmas ls
|
|
64 |
fds = collectFunctionalityDefinitions ls'
|
|
65 |
bs = convertLinesToBlocks ls' [] fds
|
65 | 66 |
bs' = reDescribeBlocks bs
|
66 | 67 |
in
|
67 | |
(ls, bs)
|
|
68 |
(ls', bs)
|
68 | 69 |
|
69 | 70 |
transformLines ls =
|
70 | 71 |
let
|
|
83 | 84 |
| prefix == "= " = ExpectedResult suffix
|
84 | 85 |
| prefix == "? " = ExpectedError suffix
|
85 | 86 |
| prefix == "> " = QuotedCode suffix
|
86 | |
| prefix == "->" = Pragma suffix
|
|
87 |
| prefix == "->" = Pragma suffix Nothing
|
87 | 88 |
| otherwise = LiteralText line
|
88 | 89 |
where
|
89 | 90 |
prefix = take 2 line
|
|
119 | 120 |
coalesceLines lines (LiteralText (last ++ "\n" ++ more))
|
120 | 121 |
coalesceLines ((QuotedCode more):lines) (QuotedCode last) =
|
121 | 122 |
coalesceLines lines (QuotedCode (last ++ "\n" ++ more))
|
122 | |
coalesceLines ((Pragma more):lines) (Pragma last) =
|
123 | |
coalesceLines lines (Pragma (last ++ "\n" ++ more))
|
|
123 |
coalesceLines ((Pragma more Nothing):lines) (Pragma last Nothing) =
|
|
124 |
coalesceLines lines (Pragma (last ++ "\n" ++ more) Nothing)
|
124 | 125 |
coalesceLines (line:lines) (LiteralText last) =
|
125 | 126 |
((LiteralText (last ++ "\n")):coalesceLines lines line)
|
126 | 127 |
coalesceLines (line:lines) last =
|
127 | 128 |
(last:coalesceLines lines line)
|
|
129 |
|
|
130 |
resolvePragmas ((Pragma text Nothing):rest) =
|
|
131 |
((Pragma text $ Just $ parsePragma text):resolvePragmas rest)
|
|
132 |
resolvePragmas (other:rest) = (other:resolvePragmas rest)
|
|
133 |
resolvePragmas [] = []
|
128 | 134 |
|
129 | 135 |
--
|
130 | 136 |
-- Convert (coalesced) lines to blocks.
|
|
142 | 148 |
((Test fns "(undescribed output test)" testText (Exception expected)):(convertLinesToBlocks rest fns fnMap))
|
143 | 149 |
convertLinesToBlocks ((SectionHeading text):rest) fn fnMap =
|
144 | 150 |
((Section text):(convertLinesToBlocks rest fn fnMap))
|
145 | |
convertLinesToBlocks ((Pragma text):rest) fns fnMap =
|
146 | |
case parsePragma text of
|
147 | |
TestsFor (NamedFunctionality name) ->
|
148 | |
case map (snd) $ filter (\(s,fn) -> s == name) fnMap of
|
149 | |
[] -> error ("Can't find " ++ name ++ " in " ++ (show fnMap))
|
150 | |
fns' -> convertLinesToBlocks rest fns' fnMap
|
151 | |
TestsFor fn ->
|
152 | |
convertLinesToBlocks rest [fn] fnMap
|
153 | |
_ ->
|
154 | |
convertLinesToBlocks rest fns fnMap
|
|
151 |
convertLinesToBlocks ((Pragma _ (Just (TestsFor (NamedFunctionality name)))):rest) fns fnMap =
|
|
152 |
case map (snd) $ filter (\(s,fn) -> s == name) fnMap of
|
|
153 |
[] -> error ("Can't find " ++ name ++ " in " ++ (show fnMap))
|
|
154 |
fns' -> convertLinesToBlocks rest fns' fnMap
|
|
155 |
convertLinesToBlocks ((Pragma _ (Just (TestsFor fn))):rest) fns fnMap =
|
|
156 |
convertLinesToBlocks rest [fn] fnMap
|
|
157 |
convertLinesToBlocks ((Pragma _ Nothing):rest) fns fnMap =
|
|
158 |
error $ "should have resolved all pragmas to directives by now"
|
|
159 |
convertLinesToBlocks ((Pragma _ _):rest) fns fnMap =
|
|
160 |
convertLinesToBlocks rest fns fnMap
|
155 | 161 |
convertLinesToBlocks ((LiteralText _):(SectionHeading text):rest) fns fnMap =
|
156 | 162 |
((Section text):(convertLinesToBlocks rest fns fnMap))
|
157 | 163 |
|
|
159 | 165 |
convertLinesToBlocks rest fns fnMap
|
160 | 166 |
convertLinesToBlocks [] _ _ = []
|
161 | 167 |
|
162 | |
collectFunctionalityDefinitions ((Pragma text):rest) =
|
163 | |
case parsePragma text of
|
164 | |
FunctionalityDefinition name functionality ->
|
165 | |
((name, functionality):collectFunctionalityDefinitions rest)
|
166 | |
_ ->
|
167 | |
collectFunctionalityDefinitions rest
|
|
168 |
collectFunctionalityDefinitions ((Pragma _ (Just (FunctionalityDefinition name functionality))):rest) =
|
|
169 |
((name, functionality):collectFunctionalityDefinitions rest)
|
|
170 |
collectFunctionalityDefinitions ((Pragma _ Nothing):rest) =
|
|
171 |
error $ "should have resolved all pragmas to directives by now"
|
168 | 172 |
collectFunctionalityDefinitions (_:rest) =
|
169 | 173 |
collectFunctionalityDefinitions rest
|
170 | 174 |
collectFunctionalityDefinitions [] =
|