]> Git — Sourcephile - haskell/symantic-plaintext.git/blob - test/HUnit.hs
remove all remaining from AnsiText
[haskell/symantic-plaintext.git] / test / HUnit.hs
1 {-# LANGUAGE OverloadedStrings #-}
2 module HUnit where
3
4 import Test.Tasty
5 import Test.Tasty.HUnit
6
7 import Data.Foldable (Foldable(..))
8 import Data.Function (($), (.))
9 import Data.Functor ((<$>))
10 import Data.Int (Int)
11 import Data.Maybe (Maybe(..))
12 import Data.Monoid (Monoid(..))
13 import Data.Ord (Ord(..))
14 import Data.Semigroup (Semigroup(..))
15 import Data.String (String, IsString(..))
16 import Prelude ((+))
17 import Text.Show (Show(..))
18 import qualified Data.List as List
19
20 import Symantic.Document.API
21 import Symantic.Document.Plain
22
23 -- * Tests
24 hunits :: TestTree
25 hunits = testGroup "HUnit" $
26 [ hunitPlain
27 ]
28
29 hunitPlain :: TestTree
30 hunitPlain = testList "Plain"
31 [ newline ==> "\n"
32 , "hello\nworld" ==> "hello\nworld"
33 , 10`maxWidth` breakpoints ["hello", "world"] ==> "helloworld"
34 , 9`maxWidth` breakpoints ["hello", "world"] ==> "hello\nworld"
35 , 6`maxWidth` breakpoints ["he", "ll", "o!"] ==> "hello!"
36 , 6`maxWidth` breakpoints ["he", "ll", "o!", "wo", "rl", "d!"] ==> "hello!\nworld!"
37 , 5`maxWidth` breakpoints ["hello", "world"] ==> "hello\nworld"
38 , 5`maxWidth` breakpoints ["he", "llo", "world"] ==> "hello\nworld"
39 , 5`maxWidth` breakpoints ["he", "ll", "o!"] ==> "hell\no!"
40 , 4`maxWidth` breakpoints ["hello", "world"] ==> "hello\nworld"
41 , 4`maxWidth` breakpoints ["he", "ll", "o!"] ==> "hell\no!"
42 , 4`maxWidth` breakpoints ["he", "llo", "world"] ==> "he\nllo\nworld"
43 , 4`maxWidth` breakpoints ["he", "llo", "w", "orld"] ==> "he\nllow\norld"
44 , 4`maxWidth` breakpoints ["he", "ll", "o!", "wo", "rl", "d!"] ==> "hell\no!wo\nrld!"
45 , 3`maxWidth` breakpoints ["hello", "world"] ==> "hello\nworld"
46 , 3`maxWidth` breakpoints ["he", "ll"] ==> "he\nll"
47 , 3`maxWidth` breakpoints ["he", "ll", "o!"] ==> "he\nll\no!"
48 , 1`maxWidth` breakpoints ["he", "ll", "o!"] ==> "he\nll\no!"
49 , 4`maxWidth` mconcat ["__", align $ breakpoints ["he", "ll", "o!", "wo", "rl", "d!"]]
50 ==> "__he\n ll\n o!\n wo\n rl\n d!"
51 , 6`maxWidth` mconcat ["__", align $ breakpoints ["he", "ll", "o!", "wo", "rl", "d!"]]
52 ==> "__hell\n o!wo\n rld!"
53 , 16`maxWidth` mconcat ["__", listHorV ["hello", "world"]] ==> "__[hello, world]"
54 , 4`maxWidth` mconcat ["__", listHorV ["hello", "world"]] ==> "__[ hello\n , world\n ]"
55 , 11`maxWidth` breakspaces ["hello", "world"] ==> "hello world"
56 , 10`maxWidth` breakspaces ["hello", "world"] ==> "hello\nworld"
57 , 6`maxWidth` breakspaces ["hel", "lo", "wo", "rld"] ==> "hel lo\nwo rld"
58 , 6`maxWidth` breakspaces ["hel", "lo", "wo", "rld", "HEL", "LO", "WO", "RLD"] ==> "hel lo\nwo rld\nHEL LO\nWO RLD"
59 , 5`maxWidth` breakspaces ["hello", "world"] ==> "hello\nworld"
60 , 19`maxWidth` fun (fun $ fun $ fun $ fun $ listHorV ["abcdefg", "abcdefg"])
61 ==> "function(function(\n function(\n function(\n function(\n [ abcdefg\n , abcdefg\n ]\n )\n )\n )\n ))"
62 , 19`maxWidth` fun (fun $ fun $ fun $ fun $ listHorV ["abcdefgh", "abcdefgh"])
63 ==> "function(\n function(\n function(\n function(\n function(\n [ abcdefgh\n , abcdefgh\n ]\n )\n )\n )\n )\n )"
64 , 7`maxWidth` ("hello"<>breakspace<>"world") ==> "hello\nworld"
65 , 7`maxWidth` ("hello "<>"world") ==> "hello\nworld"
66 , " "<> "hello\nworld\n!" ==> " hello\nworld\n!"
67 , "__"<>align "hello\nworld\n!" ==> "__hello\n world\n !"
68 , hang 2 "hello\nworld\n!" ==> "hello\n world\n !"
69 , hang 2 "hello\nworld\n!"<>"\nhello\n!" ==> "hello\n world\n !\nhello\n!"
70 , "let " <> align (catV $
71 (\(name, typ) -> fill 6 name <+> "::" <+> typ)
72 <$> [ ("abcdef","Doc")
73 , ("abcde","Int -> Doc -> Doc")
74 , ("abcdefghi","Doc") ])
75 ==> "let abcdef :: Doc\n abcde :: Int -> Doc -> Doc\n abcdefghi :: Doc"
76 , "let " <> align (catV $
77 (\(name, typ) -> fillOrBreak 6 name <> " ::" <+> typ)
78 <$> [ ("abcdef","Doc")
79 , ("abcde","Int -> Doc -> Doc")
80 , ("abcdefghi","Doc") ])
81 ==> "let abcdef :: Doc\n abcde :: Int -> Doc -> Doc\n abcdefghi\n :: Doc"
82 , "let " <> align (catV $
83 (\(name, typ) -> fillOrBreak 6 name <> " ::" <+> typ)
84 <$> [("abcdefghi","Doc ->\nDoc")])
85 ==> "let abcdefghi\n :: Doc ->\n Doc"
86 , "let " <> align (catV $
87 (\(name, typ) -> fillOrBreak 6 name <> align (" ::" <+> typ))
88 <$> [("abcdefghi","Doc ->\nDoc")])
89 ==> "let abcdefghi\n :: Doc ->\n Doc"
90 , 10 `maxWidth` "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15" ==> "1 2 3 4 5\n6 7 8 9 10\n11 12 13\n14 15"
91 , 10 `maxWidth` "a b "<>"12"<>align (" 34 5") ==> "a b 12 34\n 5"
92 , 10 `maxWidth` "a b "<>"12"<>align (" 34" <> align "") ==> "a b 12 34"
93 , 10 `maxWidth` "a b "<>"12"<>align (" 34" <> align " ") ==> "a b 12 34 "
94 , 10 `maxWidth` "a b "<>"12"<>align (" 34" <> align " 5") ==> "a b 12 34\n 5"
95 , 10 `maxWidth` "a b "<>"12"<>align (" 34" <> align " 56") ==> "a b 12\n 34\n 56"
96 , 10 `maxWidth` "a b "<>"12"<>align (" 34" <> align " 567") ==> "a b\n12 34 567"
97 , 10 `maxWidth` "a b "<>"12"<>align (" 34" <> align " 5678") ==> "a b\n12 34 5678"
98 , 10 `maxWidth` "a b "<>"12"<>align (" 34" <> align " 56789") ==> "a b\n12 34\n 56789"
99 , 10 `maxWidth` ("1234567890" <> " ") <> "1" ==> "1234567890\n1"
100 , 10 `maxWidth` nestedAlign 6 ==> "1 2 3 4 5\n 6"
101 , 10 `maxWidth` nestedAlign 7 ==> "1 2 3 4\n 5\n 6\n 7"
102 , 10 `maxWidth` nestedAlign 8 ==> "1 2 3\n 4\n 5\n 6\n 7\n 8"
103 , 10 `maxWidth` nestedAlign 9 ==> "1 2\n 3\n 4\n 5\n 6\n 7\n 8\n 9"
104 , 10 `maxWidth` nestedAlign 10 ==> "1\n 2\n 3\n 4\n 5\n 6\n 7\n 8\n 9\n 10"
105 -- justify justifies
106 , 10 `maxWidth` justify "1 2 3 4 5 6" ==> "1 2 3 4 5\n6"
107 -- justify compresses spaces
108 , 10 `maxWidth` justify "1 2 3 4 5 6" ==> "1 2 3 4 5\n6"
109 , 10 `maxWidth` justify " 1 2 3 4 5 6 7 8 9" ==> " 1 2 3 4 5\n6 7 8 9"
110 -- justify respects concatenating words
111 , 10 `maxWidth` justify (setWidth (Just 11) ("1 2 3"<>"4 5 6 7")) ==> "1 2 34 5 6\n7"
112 -- justify flushes the buffer before
113 , 10 `maxWidth` "__" <> align (justify "1 2 3 4 5") ==> "__1 2 3 4\n 5"
114 -- justify does not overflow the alignment
115 , 10 `maxWidth` justify (nestedAlign 6) ==> "1 2 3 4 5\n 6"
116 , 10 `maxWidth` justify ("a b c de " <> nestedAlign 2) ==> "a b c de\n1 2"
117 , 10 `maxWidth` justify (bold ("12 34 56 78 "<> underline "90" <> " 123 456 789"))
118 ==> "\ESC[1m12 34 56\n78 \ESC[4m90\ESC[0;1m 123\n456 789\ESC[0m"
119 -- justify does not justify on explicit newlines
120 , 10 `maxWidth` justify "1 2 3 4 5 6 7\n8 9 1 2 3 4 5" ==> "1 2 3 4 5\n6 7\n8 9 1 2 3\n4 5"
121 -- align flushes the buffer
122 , 10 `maxWidth` justify (ul ["1 2 3 4 5 6 7 8 9"])
123 ==> "- 1 2 3 4\n\
124 \ 5 6 7 8\n\
125 \ 9"
126 -- ul/ol is mempty when no item
127 , ul [] ==> ""
128 , ol [] ==> ""
129 -- ul flushes the buffer
130 , 10 `maxWidth` justify (let i = "1 2 3 4 5 6 7 8 9" in ul [i, i])
131 ==> "- 1 2 3 4\n\
132 \ 5 6 7 8\n\
133 \ 9\n\
134 \- 1 2 3 4\n\
135 \ 5 6 7 8\n\
136 \ 9"
137 , 10 `maxWidth` justify (let i = "1 2 3 4 5 6 7 8 9" in
138 ul [ul [i, i], ul [i, i]])
139 ==> "- - 1 2 3\n\
140 \ 4 5 6\n\
141 \ 7 8 9\n\
142 \ - 1 2 3\n\
143 \ 4 5 6\n\
144 \ 7 8 9\n\
145 \- - 1 2 3\n\
146 \ 4 5 6\n\
147 \ 7 8 9\n\
148 \ - 1 2 3\n\
149 \ 4 5 6\n\
150 \ 7 8 9"
151 , 10 `maxWidth` justify (let i = "1 2 3 4 5 6 7 8 9" in
152 ol [ol [i, i], ol [i, i]])
153 ==> "1. 1. 1 2\n\
154 \ 3 4\n\
155 \ 5 6\n\
156 \ 7 8\n\
157 \ 9\n\
158 \ 2. 1 2\n\
159 \ 3 4\n\
160 \ 5 6\n\
161 \ 7 8\n\
162 \ 9\n\
163 \2. 1. 1 2\n\
164 \ 3 4\n\
165 \ 5 6\n\
166 \ 7 8\n\
167 \ 9\n\
168 \ 2. 1 2\n\
169 \ 3 4\n\
170 \ 5 6\n\
171 \ 7 8\n\
172 \ 9"
173 -- endline breakspaces
174 , 10 `maxWidth` ("a"<>endline<>" b") ==> "a\nb"
175 -- endline does no justify
176 , 10 `maxWidth` justify ("a b"<>endline<>" c") ==> "a b\nc"
177 -- endline works overflowed
178 , 10 `maxWidth` justify ("abcdefghijk"<>endline<>" a") ==> "abcdefghijk\na"
179 -- endline prints no nothing
180 , 10 `maxWidth` justify ("12345678"<>endline<>"90ab"<>align (" cdefghijk cdefghijk"))
181 ==> "1234567890ab\n\
182 \ cdefghijk\n\
183 \ cdefghijk"
184 -- newline stops overflow
185 , 10 `maxWidth` breakalt "fits" "over"<>"\n"<>"12345678901"
186 ==> "fits\n\
187 \12345678901"
188 -- breakalt triggers only if its first argument overflows,
189 -- not if what's next overflows.
190 , 10 `maxWidth` spaces 2<>align(breakalt "fits" "over"<>newline<>"12345678901")
191 ==> " fits\n\
192 \ 12345678901"
193 -- handle escaping correctly over custom indenting
194 , 10 `maxWidth` setIndent (blue "X") 1 (red ("12"<>green "4\n5" <> "6"))
195 ==> "\ESC[31m12\ESC[32m4\n\ESC[34mX\ESC[0;31;32m5\ESC[0;31m6\ESC[0m"
196 , 10 `maxWidth` setIndent (blue "X") 1 (justify (red ("1 2 3 4"<>green " 5 6 " <> "7 ") <> "8"))
197 ==> "\ESC[31m1 2 3 4\ESC[32m 5\n\ESC[34mX\ESC[0;31;32m6 \ESC[0;31m7 \ESC[0m8"
198 -- breakspace backtracking is bounded by the removable indentation
199 -- (hence it can actually wrap a few words in reasonable time).
200 , 80 `maxWidth`
201 "Lorem ipsum dolor sit amet, Nulla nec tortor. Donec id elit quis purus\
202 \ consectetur consequat. Nam congue semper tellus. Sed erat dolor,\
203 \ dapibus sit amet, venenatis ornare, ultrices ut, nisi. Aliquam ante.\
204 \ Suspendisse scelerisque dui nec velit. Duis augue augue, gravida euismod,\
205 \ vulputate ac, facilisis id, sem. Morbi in orci. Nulla purus lacus,\
206 \ pulvinar vel, malesuada ac, mattis nec, quam. Nam molestie scelerisque\
207 \ quam. Nullam feugiat cursus lacus.orem ipsum dolor sit amet, consectetur\
208 \ adipiscing elit. Donec libero risus, commodo vitae, pharetra mollis,\
209 \ posuere eu, pede. Nulla nec tortor. Donec id elit quis purus consectetur\
210 \ consequat. Nam congue semper tellus. Sed erat dolor, dapibus sit\
211 \ amet, venenatis ornare, ultrices ut, nisi. Aliquam ante. Suspendisse\
212 \ scelerisque dui nec velit. Duis augue augue, gravida euismod, vulputate ac,\
213 \ facilisis id, sem. Morbi in orci. Nulla purus lacus, pulvinar vel,\
214 \ malesuada ac, mattis nec, quam. Nam molestie scelerisque quam.\
215 \ Nullam feugiat cursus lacus.orem ipsum dolor sit amet, consectetur\
216 \ adipiscing elit. Donec libero risus, commodo vitae, pharetra mollis,\
217 \ posuere eu, pede. Nulla nec tortor. Donec id elit quis purus consectetur\
218 \ consequat. Nam congue semper tellus. Sed erat dolor, dapibus sit amet,\
219 \ venenatis ornare, ultrices ut, nisi. Aliquam ante. Suspendisse\
220 \ scelerisque dui nec velit. Duis augue augue, gravida euismod, vulputate ac,\
221 \ facilisis id, sem. Morbi in orci. Nulla purus lacus, pulvinar vel,\
222 \ malesuada ac, mattis nec, quam. Nam molestie scelerisque quam. Nullam\
223 \ feugiat cursus lacus.orem ipsum dolor sit amet, consectetur adipiscing\
224 \ elit. Donec libero risus, commodo vitae, pharetra mollis, posuere eu, pede.\
225 \ Nulla nec tortor. Donec id elit quis purus consectetur consequat. Nam\
226 \ congue semper tellus. Sed erat dolor, dapibus sit amet, venenatis ornare,\
227 \ ultrices ut, nisi."
228 ==> "Lorem ipsum dolor sit amet, Nulla nec tortor. Donec id elit quis\
229 \ purus\nconsectetur consequat. Nam congue semper tellus. Sed erat dolor, dapibus\
230 \ sit\namet, venenatis ornare, ultrices ut, nisi. Aliquam ante. Suspendisse\
231 \ scelerisque\ndui nec velit. Duis augue augue, gravida euismod, vulputate ac,\
232 \ facilisis id,\nsem. Morbi in orci. Nulla purus lacus, pulvinar vel, malesuada\
233 \ ac, mattis nec,\nquam. Nam molestie scelerisque quam. Nullam feugiat cursus\
234 \ lacus.orem ipsum\ndolor sit amet, consectetur adipiscing elit. Donec libero\
235 \ risus, commodo vitae,\npharetra mollis, posuere eu, pede. Nulla nec tortor.\
236 \ Donec id elit quis purus\nconsectetur consequat. Nam congue semper tellus. Sed\
237 \ erat dolor, dapibus sit\namet, venenatis ornare, ultrices ut, nisi. Aliquam\
238 \ ante. Suspendisse scelerisque\ndui nec velit. Duis augue augue, gravida\
239 \ euismod, vulputate ac, facilisis id,\nsem. Morbi in orci. Nulla purus lacus,\
240 \ pulvinar vel, malesuada ac, mattis nec,\nquam. Nam molestie scelerisque quam.\
241 \ Nullam feugiat cursus lacus.orem ipsum\ndolor sit amet, consectetur adipiscing\
242 \ elit. Donec libero risus, commodo vitae,\npharetra mollis, posuere eu, pede.\
243 \ Nulla nec tortor. Donec id elit quis purus\nconsectetur consequat. Nam congue\
244 \ semper tellus. Sed erat dolor, dapibus sit\namet, venenatis ornare, ultrices\
245 \ ut, nisi. Aliquam ante. Suspendisse scelerisque\ndui nec velit. Duis augue\
246 \ augue, gravida euismod, vulputate ac, facilisis id,\nsem. Morbi in orci. Nulla\
247 \ purus lacus, pulvinar vel, malesuada ac, mattis nec,\nquam. Nam molestie\
248 \ scelerisque quam. Nullam feugiat cursus lacus.orem ipsum\ndolor sit amet,\
249 \ consectetur adipiscing elit. Donec libero risus, commodo vitae,\npharetra\
250 \ mollis, posuere eu, pede. Nulla nec tortor. Donec id elit quis\
251 \ purus\nconsectetur consequat. Nam congue semper tellus. Sed erat dolor, dapibus\
252 \ sit\namet, venenatis ornare, ultrices ut, nisi."
253 , 80 `maxWidth` justify
254 "Lorem ipsum dolor sit amet, Nulla nec tortor. Donec id elit quis purus\
255 \ consectetur consequat. Nam congue semper tellus. Sed erat dolor,\
256 \ dapibus sit amet, venenatis ornare, ultrices ut, nisi. Aliquam ante.\
257 \ Suspendisse scelerisque dui nec velit. Duis augue augue, gravida euismod,\
258 \ vulputate ac, facilisis id, sem. Morbi in orci. Nulla purus lacus,\
259 \ pulvinar vel, malesuada ac, mattis nec, quam. Nam molestie scelerisque\
260 \ quam. Nullam feugiat cursus lacus.orem ipsum dolor sit amet, consectetur\
261 \ adipiscing elit. Donec libero risus, commodo vitae, pharetra mollis,\
262 \ posuere eu, pede. Nulla nec tortor. Donec id elit quis purus consectetur\
263 \ consequat. Nam congue semper tellus. Sed erat dolor, dapibus sit\
264 \ amet, venenatis ornare, ultrices ut, nisi. Aliquam ante. Suspendisse\
265 \ scelerisque dui nec velit. Duis augue augue, gravida euismod, vulputate ac,\
266 \ facilisis id, sem. Morbi in orci. Nulla purus lacus, pulvinar vel,\
267 \ malesuada ac, mattis nec, quam. Nam molestie scelerisque quam.\
268 \ Nullam feugiat cursus lacus.orem ipsum dolor sit amet, consectetur\
269 \ adipiscing elit. Donec libero risus, commodo vitae, pharetra mollis,\
270 \ posuere eu, pede. Nulla nec tortor. Donec id elit quis purus consectetur\
271 \ consequat. Nam congue semper tellus. Sed erat dolor, dapibus sit amet,\
272 \ venenatis ornare, ultrices ut, nisi. Aliquam ante. Suspendisse\
273 \ scelerisque dui nec velit. Duis augue augue, gravida euismod, vulputate ac,\
274 \ facilisis id, sem. Morbi in orci. Nulla purus lacus, pulvinar vel,\
275 \ malesuada ac, mattis nec, quam. Nam molestie scelerisque quam. Nullam\
276 \ feugiat cursus lacus.orem ipsum dolor sit amet, consectetur adipiscing\
277 \ elit. Donec libero risus, commodo vitae, pharetra mollis, posuere eu, pede.\
278 \ Nulla nec tortor. Donec id elit quis purus consectetur consequat. Nam\
279 \ congue semper tellus. Sed erat dolor, dapibus sit amet, venenatis ornare,\
280 \ ultrices ut, nisi."
281 ==> "Lorem ipsum dolor sit amet, Nulla nec tortor. Donec id elit quis purus\n\
282 \consectetur consequat. Nam congue semper tellus. Sed erat dolor, dapibus sit\n\
283 \amet, venenatis ornare, ultrices ut, nisi. Aliquam ante. Suspendisse scelerisque\n\
284 \dui nec velit. Duis augue augue, gravida euismod, vulputate ac, facilisis id,\n\
285 \sem. Morbi in orci. Nulla purus lacus, pulvinar vel, malesuada ac, mattis nec,\n\
286 \quam. Nam molestie scelerisque quam. Nullam feugiat cursus lacus.orem ipsum\n\
287 \dolor sit amet, consectetur adipiscing elit. Donec libero risus, commodo vitae,\n\
288 \pharetra mollis, posuere eu, pede. Nulla nec tortor. Donec id elit quis purus\n\
289 \consectetur consequat. Nam congue semper tellus. Sed erat dolor, dapibus sit\n\
290 \amet, venenatis ornare, ultrices ut, nisi. Aliquam ante. Suspendisse scelerisque\n\
291 \dui nec velit. Duis augue augue, gravida euismod, vulputate ac, facilisis id,\n\
292 \sem. Morbi in orci. Nulla purus lacus, pulvinar vel, malesuada ac, mattis nec,\n\
293 \quam. Nam molestie scelerisque quam. Nullam feugiat cursus lacus.orem ipsum\n\
294 \dolor sit amet, consectetur adipiscing elit. Donec libero risus, commodo vitae,\n\
295 \pharetra mollis, posuere eu, pede. Nulla nec tortor. Donec id elit quis purus\n\
296 \consectetur consequat. Nam congue semper tellus. Sed erat dolor, dapibus sit\n\
297 \amet, venenatis ornare, ultrices ut, nisi. Aliquam ante. Suspendisse scelerisque\n\
298 \dui nec velit. Duis augue augue, gravida euismod, vulputate ac, facilisis id,\n\
299 \sem. Morbi in orci. Nulla purus lacus, pulvinar vel, malesuada ac, mattis nec,\n\
300 \quam. Nam molestie scelerisque quam. Nullam feugiat cursus lacus.orem ipsum\n\
301 \dolor sit amet, consectetur adipiscing elit. Donec libero risus, commodo vitae,\n\
302 \pharetra mollis, posuere eu, pede. Nulla nec tortor. Donec id elit quis purus\n\
303 \consectetur consequat. Nam congue semper tellus. Sed erat dolor, dapibus sit\n\
304 \amet, venenatis ornare, ultrices ut, nisi."
305 ]
306 where
307 (==>) :: IsString d => d ~ String => Plain d -> d -> Assertion; infix 0 ==>
308 p ==> exp = got @?= exp
309 where got = runPlain p
310
311 testList :: String -> [Assertion] -> TestTree
312 testList n as = testGroup n $ List.zipWith testCase (show <$> [1::Int ..]) as
313
314 breakpoints :: Wrappable d => Monoid d => [d] -> d
315 breakpoints = intercalate breakpoint
316
317 breakspaces :: Wrappable d => Monoid d => [d] -> d
318 breakspaces = intercalate breakspace
319
320 infix 1 `maxWidth`
321 maxWidth :: Wrappable d => Width -> d -> d
322 maxWidth = setWidth . Just
323
324 nestedAlign ::
325 From (Line String) d =>
326 Spaceable d => Indentable d => Wrappable d =>
327 Int -> d
328 nestedAlign n = go 1
329 where
330 go i =
331 from (Line (show i)) <>
332 (if n <= i then mempty
333 else align (breakspace <> go (i+1)))
334
335 listHorV :: IsString d => Indentable d => Wrappable d => [d] -> d
336 listHorV [] = "[]"
337 listHorV [d] = "["<>d<>"]"
338 listHorV ds =
339 breakalt
340 ("[" <> intercalate ("," <> space) ds <> "]")
341 (align $ "[" <> space
342 <> foldr1 (\a acc -> a <> newline <> "," <> space <> acc) ds
343 <> newline <> "]")
344
345 fun :: IsString d => Indentable d => Wrappable d => d -> d
346 fun d = "function(" <> incrIndent (spaces 2) 2 (breakalt d (newline<>d<>newline)) <> ")"
347