summaryrefslogtreecommitdiff
path: root/testsuite/tests/ghc-api/T11579.hs
blob: f2beeb303501b45c43e7ce073d73f0a99d50c98d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import System.Environment
import GHC.Driver.Session
import GHC.Driver.Config
import GHC.Data.FastString
import GHC
import GHC.Data.StringBuffer
import GHC.Parser.Lexer
import GHC.Types.SrcLoc
import Data.Foldable (toList)

main :: IO ()
main = do
    [libdir] <- getArgs

    let stringBuffer = stringToStringBuffer "-- $bar some\n-- named chunk"
        loc = mkRealSrcLoc (mkFastString "Foo.hs") 1 1

    hdk_comments <- runGhc (Just libdir) $ do
        dflags <- getSessionDynFlags
        let opts   = initParserOpts (dflags `gopt_set` Opt_Haddock)
            pstate = initParserState opts stringBuffer loc
        case unP (lexer False return) pstate of
            POk s (L _ ITeof) -> return (map unLoc (toList (hdk_comments s)))
            _                 -> error "No token"

    -- #11579
    -- Expected:                    "ITdocCommentNamed "bar some\n named chunk"
    -- Actual (with ghc-8.0.1-rc2): "ITdocCommentNamed "bar some"
    mapM_ print hdk_comments