Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Turn a source code comment into specs

  • Loading branch information...
commit dfc006ad2b8f5cb27570ac02c77aa63c5c027cd9 1 parent fc7fd18
Simon Hengel authored February 22, 2014
2  src/Haddock/Parser.hs
@@ -306,8 +306,6 @@ birdtracks = DocCodeBlock . DocString . intercalate "\n" . stripSpace <$> many1
306 306
   where
307 307
     line = skipHorizontalSpace *> ">" *> takeLine
308 308
 
309  
--- | Strip leading spaces, but ignore blank lines. If any of the lines don't
310  
---   start with a ' ', however, we don't touch the block.
311 309
 stripSpace :: [String] -> [String]
312 310
 stripSpace = fromMaybe <*> mapM strip
313 311
   where
17  test/Haddock/ParserSpec.hs
@@ -360,23 +360,26 @@ spec = before initStaticOpts $ do
360 360
           ]
361 361
         `shouldParseTo` DocCodeBlock "foo\nbar\nbaz"
362 362
 
363  
-      it "ignores single leading spaces" $ do
  363
+      it "strips one leading space from each line of the block" $ do
364 364
         unlines [
365 365
             "> foo"
366  
-          , "> bar"
  366
+          , ">  bar"
367 367
           , "> baz"
368  
-          ] `shouldParseTo` DocCodeBlock "foo\nbar\nbaz"
  368
+          ] `shouldParseTo` DocCodeBlock "foo\n bar\nbaz"
369 369
 
  370
+      it "ignores empty lines when stripping spaces" $ do
370 371
         unlines [
371 372
             "> foo"
372 373
           , ">"
373 374
           , "> bar"
374 375
           ] `shouldParseTo` DocCodeBlock "foo\n\nbar"
375 376
 
376  
-        unlines [
377  
-            ">foo"
378  
-          , ">  bar"
379  
-          ] `shouldParseTo` DocCodeBlock "foo\n  bar"
  377
+      context "when any non-empty line does not start with a space" $ do
  378
+        it "does not strip any spaces" $ do
  379
+          unlines [
  380
+              ">foo"
  381
+            , ">  bar"
  382
+            ] `shouldParseTo` DocCodeBlock "foo\n  bar"
380 383
 
381 384
       it "ignores nested markup" $ do
382 385
         unlines [

0 notes on commit dfc006a

Please sign in to comment.
Something went wrong with that request. Please try again.