2013-12-13 11:39:26 +01:00
|
|
|
|
2013-12-19 10:46:51 +01:00
|
|
|
This is the main tests module which exposes the test data plus the
|
|
|
|
Test.Framework tests. It also contains the code which converts the
|
|
|
|
test data to the Test.Framework tests.
|
2013-12-16 12:33:05 +01:00
|
|
|
|
2013-12-14 19:42:01 +01:00
|
|
|
> module Language.SQL.SimpleSQL.Tests
|
|
|
|
> (testData
|
|
|
|
> ,tests
|
|
|
|
> ,TestItem(..)
|
|
|
|
> ) where
|
2013-12-13 11:39:26 +01:00
|
|
|
|
2013-12-14 19:42:01 +01:00
|
|
|
> import Test.Framework
|
|
|
|
> import Test.Framework.Providers.HUnit
|
2013-12-17 10:40:31 +01:00
|
|
|
> import qualified Test.HUnit as H
|
2013-12-13 11:39:26 +01:00
|
|
|
|
2013-12-17 11:16:03 +01:00
|
|
|
> --import Language.SQL.SimpleSQL.Syntax
|
2013-12-17 10:40:31 +01:00
|
|
|
> import Language.SQL.SimpleSQL.Pretty
|
|
|
|
> import Language.SQL.SimpleSQL.Parser
|
2013-12-16 09:03:46 +01:00
|
|
|
|
2013-12-17 10:40:31 +01:00
|
|
|
> import Language.SQL.SimpleSQL.TestTypes
|
2013-12-13 23:58:12 +01:00
|
|
|
|
2013-12-17 10:40:31 +01:00
|
|
|
> import Language.SQL.SimpleSQL.FullQueries
|
2013-12-17 18:17:03 +01:00
|
|
|
> import Language.SQL.SimpleSQL.GroupBy
|
2013-12-17 10:40:31 +01:00
|
|
|
> import Language.SQL.SimpleSQL.Postgres
|
2013-12-17 10:48:40 +01:00
|
|
|
> import Language.SQL.SimpleSQL.QueryExprComponents
|
|
|
|
> import Language.SQL.SimpleSQL.QueryExprs
|
2013-12-17 10:40:31 +01:00
|
|
|
> import Language.SQL.SimpleSQL.TableRefs
|
2013-12-19 10:46:51 +01:00
|
|
|
> import Language.SQL.SimpleSQL.ValueExprs
|
2013-12-17 10:40:31 +01:00
|
|
|
> import Language.SQL.SimpleSQL.Tpch
|
2013-12-13 23:58:12 +01:00
|
|
|
|
2013-12-16 09:03:46 +01:00
|
|
|
|
2013-12-13 11:39:26 +01:00
|
|
|
|
2013-12-17 10:48:40 +01:00
|
|
|
Order the tests to start from the simplest first. This is also the
|
|
|
|
order on the generated documentation.
|
2013-12-13 17:50:41 +01:00
|
|
|
|
2013-12-13 11:39:26 +01:00
|
|
|
> testData :: TestItem
|
|
|
|
> testData =
|
|
|
|
> Group "parserTest"
|
2013-12-19 10:46:51 +01:00
|
|
|
> [valueExprTests
|
2013-12-17 10:48:40 +01:00
|
|
|
> ,queryExprComponentTests
|
|
|
|
> ,queryExprsTests
|
2013-12-17 18:17:03 +01:00
|
|
|
> ,tableRefTests
|
|
|
|
> ,groupByTests
|
2013-12-17 10:48:40 +01:00
|
|
|
> ,fullQueriesTests
|
|
|
|
> ,postgresTests
|
2013-12-13 23:07:45 +01:00
|
|
|
> ,tpchTests
|
2013-12-13 19:24:20 +01:00
|
|
|
> ]
|
2013-12-13 13:08:33 +01:00
|
|
|
|
2013-12-14 19:42:01 +01:00
|
|
|
> tests :: Test.Framework.Test
|
|
|
|
> tests = itemToTest testData
|
2013-12-13 13:08:33 +01:00
|
|
|
|
2013-12-14 19:42:01 +01:00
|
|
|
> --runTests :: IO ()
|
|
|
|
> --runTests = void $ H.runTestTT $ itemToTest testData
|
2013-12-13 13:08:33 +01:00
|
|
|
|
2013-12-14 19:42:01 +01:00
|
|
|
> itemToTest :: TestItem -> Test.Framework.Test
|
2013-12-13 13:08:33 +01:00
|
|
|
> itemToTest (Group nm ts) =
|
2013-12-14 19:42:01 +01:00
|
|
|
> testGroup nm $ map itemToTest ts
|
2013-12-19 10:46:51 +01:00
|
|
|
> itemToTest (TestValueExpr str expected) =
|
|
|
|
> toTest parseValueExpr prettyValueExpr str expected
|
2013-12-13 13:08:33 +01:00
|
|
|
> itemToTest (TestQueryExpr str expected) =
|
2013-12-13 14:05:32 +01:00
|
|
|
> toTest parseQueryExpr prettyQueryExpr str expected
|
2013-12-14 10:59:29 +01:00
|
|
|
> itemToTest (TestQueryExprs str expected) =
|
|
|
|
> toTest parseQueryExprs prettyQueryExprs str expected
|
2013-12-13 17:50:41 +01:00
|
|
|
> itemToTest (ParseQueryExpr str) =
|
|
|
|
> toPTest parseQueryExpr prettyQueryExpr str
|
2013-12-13 13:08:33 +01:00
|
|
|
|
2013-12-13 18:21:44 +01:00
|
|
|
> toTest :: (Eq a, Show a) =>
|
|
|
|
> (String -> Maybe (Int,Int) -> String -> Either ParseError a)
|
2013-12-13 14:05:32 +01:00
|
|
|
> -> (a -> String)
|
|
|
|
> -> String
|
|
|
|
> -> a
|
2013-12-14 19:42:01 +01:00
|
|
|
> -> Test.Framework.Test
|
|
|
|
> toTest parser pp str expected = testCase str $ do
|
2013-12-13 13:08:33 +01:00
|
|
|
> let egot = parser "" Nothing str
|
|
|
|
> case egot of
|
2013-12-13 18:21:44 +01:00
|
|
|
> Left e -> H.assertFailure $ peFormattedError e
|
2013-12-13 14:05:32 +01:00
|
|
|
> Right got -> do
|
|
|
|
> H.assertEqual "" expected got
|
|
|
|
> let str' = pp got
|
|
|
|
> let egot' = parser "" Nothing str'
|
|
|
|
> case egot' of
|
2014-04-15 12:47:34 +02:00
|
|
|
> Left e' -> H.assertFailure $ "pp roundtrip"
|
|
|
|
> ++ "\n" ++ str'
|
2013-12-16 09:03:46 +01:00
|
|
|
> ++ peFormattedError e'
|
2014-04-15 12:47:34 +02:00
|
|
|
> Right got' -> H.assertEqual
|
|
|
|
> ("pp roundtrip" ++ "\n" ++ str')
|
|
|
|
> expected got'
|
2013-12-13 17:50:41 +01:00
|
|
|
|
2013-12-13 18:21:44 +01:00
|
|
|
> toPTest :: (Eq a, Show a) =>
|
|
|
|
> (String -> Maybe (Int,Int) -> String -> Either ParseError a)
|
2013-12-13 17:50:41 +01:00
|
|
|
> -> (a -> String)
|
|
|
|
> -> String
|
2013-12-14 19:42:01 +01:00
|
|
|
> -> Test.Framework.Test
|
|
|
|
> toPTest parser pp str = testCase str $ do
|
2013-12-13 17:50:41 +01:00
|
|
|
> let egot = parser "" Nothing str
|
|
|
|
> case egot of
|
2013-12-13 18:21:44 +01:00
|
|
|
> Left e -> H.assertFailure $ peFormattedError e
|
2013-12-13 17:50:41 +01:00
|
|
|
> Right got -> do
|
|
|
|
> let str' = pp got
|
|
|
|
> let egot' = parser "" Nothing str'
|
|
|
|
> case egot' of
|
2013-12-16 09:03:46 +01:00
|
|
|
> Left e' -> H.assertFailure $ "pp roundtrip "
|
2014-04-15 12:47:34 +02:00
|
|
|
> ++ "\n" ++ str' ++ "\n"
|
2013-12-16 09:03:46 +01:00
|
|
|
> ++ peFormattedError e'
|
2013-12-13 18:21:44 +01:00
|
|
|
> Right _got' -> return ()
|