packages feed

boilerplate-0.0.1: test/Boilerplate/GhcParserTests.hs

{-# LANGUAGE OverloadedStrings #-}

module Boilerplate.GhcParserTests where

import Boilerplate.GhcParser
import Boilerplate.Types
import Test.Tasty.Hspec

spec_ghc :: Spec
spec_ghc = do
  it "should parse the example data" $ do
    (types, markers) <- parseHaskell "test/Boilerplate/Example.hs"

    types `shouldBe` [
      ProductType "Coord1" [] "Coordy1" ["Double","Double"],
      RecordType "Coord2" [] "Coordy2" [("a","Double"),("b","Double")],
      SumType "Union" [] [("Wales",["String"]),("England",["Int","Int"]),("Scotland",[])],
      ProductType "Things" ["a","b"] "T" ["a","b","Double"],
      RecordType "Logger" ["m"] "Logger" [("log","Text -> m ()")],
      SumType "Action" ["a"] [("Admin",["[a]","Text"]),("User",["a","Text"])],
      ProductType "InfixProd" [] ":|" ["Text","Text"],
      SumType "InfixSum" [] [(":||",["Text","Text"]),(":|||",["Text","Text"])]]

    markers `shouldBe` [
      Comment "{-# LANGUAGE KindSignatures #-}" (Pos 1 1) (Pos 1 32),
      Comment "-- $foo" (Pos 3 1) (Pos 3 8),
      Comment "{- this is a\n   block comment\n-}" (Pos 8 1) (Pos 10 3),
      Comment "-- | BOILERPLATE This is a doc string" (Pos 12 1) (Pos 12 38),
      Comment "{- BOILERPLATE Coord1 FromJSON, ToJSON -}" (Pos 14 1) (Pos 14 42),
      Comment "-- BOILERPLATE Coord FromJSON, ToJSON field={a:x, b:y}" (Pos 17 1) (Pos 17 55),
      Comment "-- BOILERPLATE END" (Pos 18 1) (Pos 18 19)]