summaryrefslogtreecommitdiff
path: root/tasty/Main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'tasty/Main.hs')
-rw-r--r--tasty/Main.hs61
1 files changed, 61 insertions, 0 deletions
diff --git a/tasty/Main.hs b/tasty/Main.hs
new file mode 100644
index 0000000..3db9a07
--- /dev/null
+++ b/tasty/Main.hs
@@ -0,0 +1,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