1
Fork 0
simple-sql-parser/tools/Language/SQL/SimpleSQL/Tests.lhs

107 lines
3.2 KiB
Plaintext
Raw Normal View History

2013-12-13 11:39:26 +01:00
TODO:
split into multiple files:
scalar expressions
tablerefs
other queryexpr parts: not enough to split into multiple files
full queries
tpch tests
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
> import qualified Test.HUnit as H
2013-12-13 11:39:26 +01:00
> --import Language.SQL.SimpleSQL.Syntax
> import Language.SQL.SimpleSQL.Pretty
> import Language.SQL.SimpleSQL.Parser
2013-12-16 09:03:46 +01:00
> import Language.SQL.SimpleSQL.TestTypes
> import Language.SQL.SimpleSQL.FullQueries
> import Language.SQL.SimpleSQL.Postgres
2013-12-17 10:48:40 +01:00
> import Language.SQL.SimpleSQL.QueryExprComponents
> import Language.SQL.SimpleSQL.QueryExprs
> import Language.SQL.SimpleSQL.TableRefs
> import Language.SQL.SimpleSQL.ScalarExprs
> import Language.SQL.SimpleSQL.Tpch
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 11:39:26 +01:00
> testData :: TestItem
> testData =
> Group "parserTest"
2013-12-17 10:48:40 +01:00
> [scalarExprTests
> ,queryExprComponentTests
> ,tableRefTests
2013-12-17 10:48:40 +01:00
> ,queryExprsTests
> ,fullQueriesTests
> ,postgresTests
> ,tpchTests
> ]
2013-12-14 19:42:01 +01:00
> tests :: Test.Framework.Test
> tests = itemToTest testData
2013-12-14 19:42:01 +01:00
> --runTests :: IO ()
> --runTests = void $ H.runTestTT $ itemToTest testData
2013-12-14 19:42:01 +01:00
> itemToTest :: TestItem -> Test.Framework.Test
> itemToTest (Group nm ts) =
2013-12-14 19:42:01 +01:00
> testGroup nm $ map itemToTest ts
> itemToTest (TestScalarExpr str expected) =
> toTest parseScalarExpr prettyScalarExpr str expected
> itemToTest (TestQueryExpr str expected) =
> toTest parseQueryExpr prettyQueryExpr str expected
2013-12-14 10:59:29 +01:00
> itemToTest (TestQueryExprs str expected) =
> toTest parseQueryExprs prettyQueryExprs str expected
> itemToTest (ParseQueryExpr str) =
> toPTest parseQueryExpr prettyQueryExpr str
2013-12-13 18:21:44 +01:00
> toTest :: (Eq a, Show a) =>
> (String -> Maybe (Int,Int) -> String -> Either ParseError a)
> -> (a -> String)
> -> String
> -> a
2013-12-14 19:42:01 +01:00
> -> Test.Framework.Test
> toTest parser pp str expected = testCase str $ do
> let egot = parser "" Nothing str
> case egot of
2013-12-13 18:21:44 +01:00
> Left e -> H.assertFailure $ peFormattedError e
> Right got -> do
> H.assertEqual "" expected got
> 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 "
> ++ peFormattedError e'
> Right got' -> H.assertEqual "pp roundtrip" expected got'
2013-12-13 18:21:44 +01:00
> toPTest :: (Eq a, Show a) =>
> (String -> Maybe (Int,Int) -> String -> Either ParseError a)
> -> (a -> String)
> -> String
2013-12-14 19:42:01 +01:00
> -> Test.Framework.Test
> toPTest parser pp str = testCase str $ do
> let egot = parser "" Nothing str
> case egot of
2013-12-13 18:21:44 +01:00
> Left e -> H.assertFailure $ peFormattedError e
> 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 "
> ++ peFormattedError e'
2013-12-13 18:21:44 +01:00
> Right _got' -> return ()