-
Notifications
You must be signed in to change notification settings - Fork 34
/
PseudoThriftEnumTest.hs
48 lines (39 loc) · 1.44 KB
/
PseudoThriftEnumTest.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
{-
Copyright (c) Meta Platforms, Inc. and affiliates.
All rights reserved.
This source code is licensed under the BSD-style license found in the
LICENSE file in the root directory of this source tree.
-}
module PseudoThriftEnumTest where
import qualified Enum.Types as Enum
import Data.Proxy
import qualified Pseudoenum.Types as Pseudoenum
import Test.HUnit
import TestRunner
import Thrift.Protocol
perfectEnum :: Proxy Enum.PerfectEnum
perfectEnum = Proxy
perfectPseudoenum :: Proxy Pseudoenum.PerfectEnum
perfectPseudoenum = Proxy
sameFromThriftEnumTest :: Test
sameFromThriftEnumTest = TestLabel "same fromThriftEnum" $ TestCase $ do
let
enumValues = allValuesPlusUnknown perfectEnum fromThriftEnum
pseudoenumValues = allValuesPlusUnknown perfectPseudoenum fromThriftEnum
assertEqual "fromThriftEnum" enumValues pseudoenumValues
sameShowTest :: Test
sameShowTest = TestLabel "same show" $ TestCase $ do
let
enumValues = allValuesPlusUnknown perfectEnum show
pseudoenumValues = allValuesPlusUnknown perfectPseudoenum show
assertEqual "show" enumValues pseudoenumValues
allValuesPlusUnknown :: ThriftEnum a => Proxy a -> (a -> b) -> [b]
allValuesPlusUnknown proxy f = map f $ allThriftEnumValues ++ [unknownValue]
where
unknownValue = toThriftEnum $ (+1) $ maximum $
map (fromThriftEnum . (`asProxyTypeOf` proxy)) allThriftEnumValues
main :: IO ()
main = testRunner $ TestList
[ sameFromThriftEnumTest
, sameShowTest
]