summaryrefslogtreecommitdiff
path: root/tasty/Main.hs
blob: 3db9a07737155125367d94aae43db0060ebad639 (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
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
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards   #-}

module Main where

import Dhall.JSON (Conversion(..))
import Test.Tasty (TestTree)

import qualified Control.Exception
import qualified Data.Aeson
import qualified Data.Text.IO
import qualified Dhall.Import
import qualified Dhall.JSON
import qualified Dhall.Parser
import qualified Test.Tasty
import qualified Test.Tasty.HUnit

main :: IO ()
main = Test.Tasty.defaultMain testTree

testTree :: TestTree
testTree =
    Test.Tasty.testGroup "dhall-json"
        [ issue48
        ]

issue48 :: TestTree
issue48 = Test.Tasty.HUnit.testCase "Issue #48" assertion
  where
    assertion = do
        let file = "./tasty/data/issue48.dhall"

        code <- Data.Text.IO.readFile file

        parsedExpression <- case Dhall.Parser.exprFromText file code of
            Left  exception        -> Control.Exception.throwIO exception
            Right parsedExpression -> return parsedExpression

        resolvedExpression <- Dhall.Import.load parsedExpression

        let mapKey     = "mapKey"
        let mapValue   = "mapValue"
        let conversion = Conversion {..}

        let convertedExpression =
                Dhall.JSON.convertToHomogeneousMaps conversion resolvedExpression

        actualValue <- case Dhall.JSON.dhallToJSON convertedExpression of
            Left  exception   -> Control.Exception.throwIO exception
            Right actualValue -> return actualValue

        result <- Data.Aeson.eitherDecodeFileStrict "./tasty/data/issue48.json"

        expectedValue <- case result of
            Left  string        -> fail string
            Right expectedValue -> return expectedValue

        let message =
                "Conversion to homogeneous maps did not generate the expected JSON output"

        Test.Tasty.HUnit.assertEqual message expectedValue actualValue