1
Fork 0

example how to switch parsing and pretty printing depending on dialect

This commit is contained in:
Jake Wheat 2014-06-28 15:41:11 +03:00
parent 7d63c8f8e5
commit c1c514af35
6 changed files with 206 additions and 157 deletions
tools/Language/SQL/SimpleSQL

View file

@ -18,17 +18,21 @@ limit syntax
[LIMIT {[offset,] row_count | row_count OFFSET offset}]
> backtickQuotes :: TestItem
> backtickQuotes = Group "backtickQuotes" $ map (uncurry (TestValueExpr MySQL))
> backtickQuotes = Group "backtickQuotes" (map (uncurry (TestValueExpr MySQL))
> [("`test`", Iden [DQName "`" "`" "test"])
> ]
> ++ [ParseValueExprFails SQL2011 "`test`"]
> )
> limit :: TestItem
> limit = Group "queries" $ map (uncurry (TestQueryExpr MySQL))
> limit = Group "queries" ( map (uncurry (TestQueryExpr MySQL))
> [("select * from t limit 5"
> ,sel {qeFetchFirst = Just (NumLit "5")}
> )
> ]
> ++ [ParseQueryExprFails MySQL "select a from t fetch next 10 rows only;"
> ,ParseQueryExprFails SQL2011 "select * from t limit 5"]
> )
> where
> sel = makeSelect
> {qeSelectList = [(Star, Nothing)]

View file

@ -18,4 +18,9 @@ intermediate when I'm too lazy to write out the parsed AST. These
should all be TODO to convert to a testqueryexpr test.
> | ParseQueryExpr Dialect String
check that the string given fails to parse
> | ParseQueryExprFails Dialect String
> | ParseValueExprFails Dialect String
> deriving (Eq,Show)

View file

@ -68,6 +68,13 @@ order on the generated documentation.
> itemToTest (ParseQueryExpr d str) =
> toPTest parseQueryExpr prettyQueryExpr d str
> itemToTest (ParseQueryExprFails d str) =
> toFTest parseQueryExpr prettyQueryExpr d str
> itemToTest (ParseValueExprFails d str) =
> toFTest parseValueExpr prettyValueExpr d str
> toTest :: (Eq a, Show a) =>
> (Dialect -> String -> Maybe (Int,Int) -> String -> Either ParseError a)
> -> (Dialect -> a -> String)
@ -109,3 +116,17 @@ order on the generated documentation.
> ++ "\n" ++ str' ++ "\n"
> ++ peFormattedError e'
> Right _got' -> return ()
> toFTest :: (Eq a, Show a) =>
> (Dialect -> String -> Maybe (Int,Int) -> String -> Either ParseError a)
> -> (Dialect -> a -> String)
> -> Dialect
> -> String
> -> Test.Framework.Test
> toFTest parser pp d str = testCase str $ do
> let egot = parser d "" Nothing str
> case egot of
> Left e -> return ()
> Right got ->
> H.assertFailure $ "parse didn't fail: " ++ show d ++ "\n" ++ str