forked from facebookincubator/hsthrift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RecursiveTest.hs
66 lines (58 loc) · 1.67 KB
/
RecursiveTest.hs
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
-- Copyright (c) Facebook, Inc. and its affiliates.
module RecursiveTest where
import Test.HUnit
import TestRunner
import qualified Data.Map.Strict as Map
import qualified Data.Text as Text
import Thrift.Compiler.Options
import Thrift.Compiler.Parser
import Thrift.Compiler.Plugins.Haskell
import Thrift.Compiler.Typechecker
import Thrift.Compiler.Types
moduleA :: (String, String)
moduleA = ("A",) $ unlines
[ "include \"B.thrift\""
, ""
, "struct A {}"
, "struct A2 {}"
]
moduleB :: (String, String)
moduleB = ("B",) $ unlines
[ "struct B {}"
, "struct B2 {}"
, "struct B3 {}"
]
parseMod :: String -> String -> (FilePath, ThriftFile SpliceFile Loc)
parseMod name contents = (path,) ThriftFile
{ thriftName = Text.pack name
, thriftPath = path
, thriftHeaders = headers
, thriftDecls = decls
, thriftSplice = Nothing
, thriftComments = []
}
where
path = name ++ ".thrift"
(headers, decls) =
either error id $ runParser parseThrift path contents
recursiveReqSymTest :: Test
recursiveReqSymTest = TestLabel "recursive required symbols" $ TestCase $ do
let
input = Map.fromList $ map (uncurry parseMod) [moduleA, moduleB]
opts = (defaultOptions defaultHsOpts)
{ optsPath = "A.thrift"
, optsRecursive = True
, optsReqSymbols = Just ["A", "B.B"]
}
case typecheck opts input of
Right (p, ps) -> do
let
structs =
[ structName
| Program{..} <- p : ps
, D_Struct Struct{..} <- progDecls
]
assertEqual "req symbols worked" ["A", "B"] structs
Left{} -> assertFailure "type error"
main :: IO ()
main = testRunner $ TestList [ recursiveReqSymTest ]