1
Fork 0

get rid of the string overloads in the tests

This commit is contained in:
Jake Wheat 2014-04-19 11:45:45 +03:00
parent fea6e347bd
commit 4fa21ceea8
8 changed files with 314 additions and 331 deletions

View file

@ -8,7 +8,7 @@ license: BSD3
license-file: LICENSE
author: Jake Wheat
maintainer: jakewheatmail@gmail.com
copyright: Copyright Jake Wheat 2013
copyright: Copyright Jake Wheat 2013, 2014
category: Database,Language
build-type: Simple
extra-source-files: README,LICENSE,changelog
@ -35,7 +35,7 @@ library
-- hs-source-dirs:
default-language: Haskell2010
ghc-options: -Wall
other-extensions: TupleSections,DeriveDataTypeable
Test-Suite Tests
type: exitcode-stdio-1.0
main-is: RunTests.lhs

View file

@ -1,7 +1,6 @@
Some tests for parsing full queries.
> {-# LANGUAGE OverloadedStrings #-}
> module Language.SQL.SimpleSQL.FullQueries (fullQueriesTests) where
> import Language.SQL.SimpleSQL.TestTypes
@ -12,8 +11,8 @@ Some tests for parsing full queries.
> fullQueriesTests = Group "queries" $ map (uncurry TestQueryExpr)
> [("select count(*) from t"
> ,makeSelect
> {qeSelectList = [(App "count" [Star], Nothing)]
> ,qeFrom = [TRSimple "t"]
> {qeSelectList = [(App [Name "count"] [Star], Nothing)]
> ,qeFrom = [TRSimple [Name "t"]]
> }
> )
@ -24,16 +23,17 @@ Some tests for parsing full queries.
> \ having count(1) > 5\n\
> \ order by s"
> ,makeSelect
> {qeSelectList = [(Iden "a", Nothing)
> ,(App "sum" [BinOp (Iden "c")
> "+" (Iden "d")]
> ,Just "s")]
> ,qeFrom = [TRSimple "t", TRSimple "u"]
> ,qeWhere = Just $ BinOp (Iden "a") ">" (NumLit "5")
> ,qeGroupBy = [SimpleGroup $ Iden "a"]
> ,qeHaving = Just $ BinOp (App "count" [NumLit "1"])
> ">" (NumLit "5")
> ,qeOrderBy = [SortSpec (Iden "s") DirDefault NullsOrderDefault]
> {qeSelectList = [(Iden [Name "a"], Nothing)
> ,(App [Name "sum"]
> [BinOp (Iden [Name "c"])
> [Name "+"] (Iden [Name "d"])]
> ,Just $ Name "s")]
> ,qeFrom = [TRSimple [Name "t"], TRSimple [Name "u"]]
> ,qeWhere = Just $ BinOp (Iden [Name "a"]) [Name ">"] (NumLit "5")
> ,qeGroupBy = [SimpleGroup $ Iden [Name "a"]]
> ,qeHaving = Just $ BinOp (App [Name "count"] [NumLit "1"])
> [Name ">"] (NumLit "5")
> ,qeOrderBy = [SortSpec (Iden [Name "s"]) DirDefault NullsOrderDefault]
> }
> )
> ]

View file

@ -1,7 +1,6 @@
Here are the tests for the group by component of query exprs
> {-# LANGUAGE OverloadedStrings #-}
> module Language.SQL.SimpleSQL.GroupBy (groupByTests) where
> import Language.SQL.SimpleSQL.TestTypes
@ -18,19 +17,19 @@ Here are the tests for the group by component of query exprs
> simpleGroupBy :: TestItem
> simpleGroupBy = Group "simpleGroupBy" $ map (uncurry TestQueryExpr)
> [("select a,sum(b) from t group by a"
> ,makeSelect {qeSelectList = [(Iden "a",Nothing)
> ,(App "sum" [Iden "b"],Nothing)]
> ,qeFrom = [TRSimple "t"]
> ,qeGroupBy = [SimpleGroup $ Iden "a"]
> ,makeSelect {qeSelectList = [(Iden [Name "a"],Nothing)
> ,(App [Name "sum"] [Iden [Name "b"]],Nothing)]
> ,qeFrom = [TRSimple [Name "t"]]
> ,qeGroupBy = [SimpleGroup $ Iden [Name "a"]]
> })
> ,("select a,b,sum(c) from t group by a,b"
> ,makeSelect {qeSelectList = [(Iden "a",Nothing)
> ,(Iden "b",Nothing)
> ,(App "sum" [Iden "c"],Nothing)]
> ,qeFrom = [TRSimple "t"]
> ,qeGroupBy = [SimpleGroup $ Iden "a"
> ,SimpleGroup $ Iden "b"]
> ,makeSelect {qeSelectList = [(Iden [Name "a"],Nothing)
> ,(Iden [Name "b"],Nothing)
> ,(App [Name "sum"] [Iden [Name "c"]],Nothing)]
> ,qeFrom = [TRSimple [Name "t"]]
> ,qeGroupBy = [SimpleGroup $ Iden [Name "a"]
> ,SimpleGroup $ Iden [Name "b"]]
> })
> ]
@ -42,15 +41,15 @@ sure which sql version they were introduced, 1999 or 2003 I think).
> [("select * from t group by ()", ms [GroupingParens []])
> ,("select * from t group by grouping sets ((), (a))"
> ,ms [GroupingSets [GroupingParens []
> ,GroupingParens [SimpleGroup $ Iden "a"]]])
> ,GroupingParens [SimpleGroup $ Iden [Name "a"]]]])
> ,("select * from t group by cube(a,b)"
> ,ms [Cube [SimpleGroup $ Iden "a", SimpleGroup $ Iden "b"]])
> ,ms [Cube [SimpleGroup $ Iden [Name "a"], SimpleGroup $ Iden [Name "b"]]])
> ,("select * from t group by rollup(a,b)"
> ,ms [Rollup [SimpleGroup $ Iden "a", SimpleGroup $ Iden "b"]])
> ,ms [Rollup [SimpleGroup $ Iden [Name "a"], SimpleGroup $ Iden [Name "b"]]])
> ]
> where
> ms g = makeSelect {qeSelectList = [(Star,Nothing)]
> ,qeFrom = [TRSimple "t"]
> ,qeFrom = [TRSimple [Name "t"]]
> ,qeGroupBy = g}
> randomGroupBy :: TestItem

View file

@ -5,7 +5,6 @@ table refs which are in a separate file.
These are a few misc tests which don't fit anywhere else.
> {-# LANGUAGE OverloadedStrings #-}
> module Language.SQL.SimpleSQL.QueryExprComponents (queryExprComponentTests) where
> import Language.SQL.SimpleSQL.TestTypes
@ -37,8 +36,8 @@ These are a few misc tests which don't fit anywhere else.
> where
> ms d = makeSelect
> {qeSetQuantifier = d
> ,qeSelectList = [(Iden "a",Nothing)]
> ,qeFrom = [TRSimple "t"]}
> ,qeSelectList = [(Iden [Name "a"],Nothing)]
> ,qeFrom = [TRSimple [Name "t"]]}
> selectLists :: TestItem
> selectLists = Group "selectLists" $ map (uncurry TestQueryExpr)
@ -46,29 +45,29 @@ These are a few misc tests which don't fit anywhere else.
> makeSelect {qeSelectList = [(NumLit "1",Nothing)]})
> ,("select a"
> ,makeSelect {qeSelectList = [(Iden "a",Nothing)]})
> ,makeSelect {qeSelectList = [(Iden [Name "a"],Nothing)]})
> ,("select a,b"
> ,makeSelect {qeSelectList = [(Iden "a",Nothing)
> ,(Iden "b",Nothing)]})
> ,makeSelect {qeSelectList = [(Iden [Name "a"],Nothing)
> ,(Iden [Name "b"],Nothing)]})
> ,("select 1+2,3+4"
> ,makeSelect {qeSelectList =
> [(BinOp (NumLit "1") "+" (NumLit "2"),Nothing)
> ,(BinOp (NumLit "3") "+" (NumLit "4"),Nothing)]})
> [(BinOp (NumLit "1") [Name "+"] (NumLit "2"),Nothing)
> ,(BinOp (NumLit "3") [Name "+"] (NumLit "4"),Nothing)]})
> ,("select a as a, /*comment*/ b as b"
> ,makeSelect {qeSelectList = [(Iden "a", Just "a")
> ,(Iden "b", Just "b")]})
> ,makeSelect {qeSelectList = [(Iden [Name "a"], Just $ Name "a")
> ,(Iden [Name "b"], Just $ Name "b")]})
> ,("select a a, b b"
> ,makeSelect {qeSelectList = [(Iden "a", Just "a")
> ,(Iden "b", Just "b")]})
> ,makeSelect {qeSelectList = [(Iden [Name "a"], Just $ Name "a")
> ,(Iden [Name "b"], Just $ Name "b")]})
> ,("select a + b * c"
> ,makeSelect {qeSelectList =
> [(BinOp (Iden "a") "+"
> (BinOp (Iden "b") "*" (Iden "c"))
> [(BinOp (Iden [Name "a"]) [Name "+"]
> (BinOp (Iden [Name "b"]) [Name "*"] (Iden [Name "c"]))
> ,Nothing)]})
> ]
@ -76,47 +75,47 @@ These are a few misc tests which don't fit anywhere else.
> whereClause :: TestItem
> whereClause = Group "whereClause" $ map (uncurry TestQueryExpr)
> [("select a from t where a = 5"
> ,makeSelect {qeSelectList = [(Iden "a",Nothing)]
> ,qeFrom = [TRSimple "t"]
> ,qeWhere = Just $ BinOp (Iden "a") "=" (NumLit "5")})
> ,makeSelect {qeSelectList = [(Iden [Name "a"],Nothing)]
> ,qeFrom = [TRSimple [Name "t"]]
> ,qeWhere = Just $ BinOp (Iden [Name "a"]) [Name "="] (NumLit "5")})
> ]
> having :: TestItem
> having = Group "having" $ map (uncurry TestQueryExpr)
> [("select a,sum(b) from t group by a having sum(b) > 5"
> ,makeSelect {qeSelectList = [(Iden "a",Nothing)
> ,(App "sum" [Iden "b"],Nothing)]
> ,qeFrom = [TRSimple "t"]
> ,qeGroupBy = [SimpleGroup $ Iden "a"]
> ,qeHaving = Just $ BinOp (App "sum" [Iden "b"])
> ">" (NumLit "5")
> ,makeSelect {qeSelectList = [(Iden [Name "a"],Nothing)
> ,(App [Name "sum"] [Iden [Name "b"]],Nothing)]
> ,qeFrom = [TRSimple [Name "t"]]
> ,qeGroupBy = [SimpleGroup $ Iden [Name "a"]]
> ,qeHaving = Just $ BinOp (App [Name "sum"] [Iden [Name "b"]])
> [Name ">"] (NumLit "5")
> })
> ]
> orderBy :: TestItem
> orderBy = Group "orderBy" $ map (uncurry TestQueryExpr)
> [("select a from t order by a"
> ,ms [SortSpec (Iden "a") DirDefault NullsOrderDefault])
> ,ms [SortSpec (Iden [Name "a"]) DirDefault NullsOrderDefault])
> ,("select a from t order by a, b"
> ,ms [SortSpec (Iden "a") DirDefault NullsOrderDefault
> ,SortSpec (Iden "b") DirDefault NullsOrderDefault])
> ,ms [SortSpec (Iden [Name "a"]) DirDefault NullsOrderDefault
> ,SortSpec (Iden [Name "b"]) DirDefault NullsOrderDefault])
> ,("select a from t order by a asc"
> ,ms [SortSpec (Iden "a") Asc NullsOrderDefault])
> ,ms [SortSpec (Iden [Name "a"]) Asc NullsOrderDefault])
> ,("select a from t order by a desc, b desc"
> ,ms [SortSpec (Iden "a") Desc NullsOrderDefault
> ,SortSpec (Iden "b") Desc NullsOrderDefault])
> ,ms [SortSpec (Iden [Name "a"]) Desc NullsOrderDefault
> ,SortSpec (Iden [Name "b"]) Desc NullsOrderDefault])
> ,("select a from t order by a desc nulls first, b desc nulls last"
> ,ms [SortSpec (Iden "a") Desc NullsFirst
> ,SortSpec (Iden "b") Desc NullsLast])
> ,ms [SortSpec (Iden [Name "a"]) Desc NullsFirst
> ,SortSpec (Iden [Name "b"]) Desc NullsLast])
> ]
> where
> ms o = makeSelect {qeSelectList = [(Iden "a",Nothing)]
> ,qeFrom = [TRSimple "t"]
> ms o = makeSelect {qeSelectList = [(Iden [Name "a"],Nothing)]
> ,qeFrom = [TRSimple [Name "t"]]
> ,qeOrderBy = o}
> offsetFetch :: TestItem
@ -136,8 +135,8 @@ These are a few misc tests which don't fit anywhere else.
> ]
> where
> ms o l = makeSelect
> {qeSelectList = [(Iden "a",Nothing)]
> ,qeFrom = [TRSimple "t"]
> {qeSelectList = [(Iden [Name "a"],Nothing)]
> ,qeFrom = [TRSimple [Name "t"]]
> ,qeOffset = o
> ,qeFetchFirst = l}
@ -165,33 +164,33 @@ These are a few misc tests which don't fit anywhere else.
> ]
> where
> ms1 = makeSelect
> {qeSelectList = [(Iden "a",Nothing)]
> ,qeFrom = [TRSimple "t"]}
> {qeSelectList = [(Iden [Name "a"],Nothing)]
> ,qeFrom = [TRSimple [Name "t"]]}
> ms2 = makeSelect
> {qeSelectList = [(Iden "b",Nothing)]
> ,qeFrom = [TRSimple "u"]}
> {qeSelectList = [(Iden [Name "b"],Nothing)]
> ,qeFrom = [TRSimple [Name "u"]]}
> withQueries :: TestItem
> withQueries = Group "with queries" $ map (uncurry TestQueryExpr)
> [("with u as (select a from t) select a from u"
> ,With False [(Alias "u" Nothing, ms1)] ms2)
> ,With False [(Alias (Name "u") Nothing, ms1)] ms2)
> ,("with u(b) as (select a from t) select a from u"
> ,With False [(Alias "u" (Just ["b"]), ms1)] ms2)
> ,With False [(Alias (Name "u") (Just [Name "b"]), ms1)] ms2)
> ,("with x as (select a from t),\n\
> \ u as (select a from x)\n\
> \select a from u"
> ,With False [(Alias "x" Nothing, ms1), (Alias "u" Nothing,ms3)] ms2)
> ,With False [(Alias (Name "x") Nothing, ms1), (Alias (Name "u") Nothing,ms3)] ms2)
> ,("with recursive u as (select a from t) select a from u"
> ,With True [(Alias "u" Nothing, ms1)] ms2)
> ,With True [(Alias (Name "u") Nothing, ms1)] ms2)
> ]
> where
> ms c t = makeSelect
> {qeSelectList = [(Iden c,Nothing)]
> ,qeFrom = [TRSimple t]}
> {qeSelectList = [(Iden [Name c],Nothing)]
> ,qeFrom = [TRSimple [Name t]]}
> ms1 = ms "a" "t"
> ms2 = ms "a" "u"
> ms3 = ms "a" "x"
@ -205,5 +204,5 @@ These are a few misc tests which don't fit anywhere else.
> tables :: TestItem
> tables = Group "tables" $ map (uncurry TestQueryExpr)
> [("table tbl", Table "tbl")
> [("table tbl", Table [Name "tbl"])
> ]

View file

@ -8,7 +8,6 @@ We are only interested in the query syntax, goes through sections 5-10
The goal is to create some coverage tests to get close to supporting a
large amount of the SQL.
> {-# LANGUAGE OverloadedStrings #-}
> module Language.SQL.SimpleSQL.SQL2003 (sql2003Tests) where
> import Language.SQL.SimpleSQL.TestTypes
@ -486,7 +485,7 @@ The <quote symbol> rule consists of two immediately adjacent <quote> marks with
> ,("''"
> ,StringLit "")
> ,("_francais 'français'"
> ,TypedLit (TypeName "_francais") "français")
> ,TypedLit (TypeName [Name "_francais"]) "français")
> ]
TODO: all the stuff with character set representations. (?)
@ -576,19 +575,19 @@ TODO: separator stuff for all the string literals?
> ,("11.11E+23", NumLit "11.11E+23")
> ,("11.11E-23", NumLit "11.11E-23")
> ,("+11E23", PrefixOp "+" $ NumLit "11E23")
> ,("+11E+23", PrefixOp "+" $ NumLit "11E+23")
> ,("+11E-23", PrefixOp "+" $ NumLit "11E-23")
> ,("+11.11E23", PrefixOp "+" $ NumLit "11.11E23")
> ,("+11.11E+23", PrefixOp "+" $ NumLit "11.11E+23")
> ,("+11.11E-23", PrefixOp "+" $ NumLit "11.11E-23")
> ,("+11E23", PrefixOp [Name "+"] $ NumLit "11E23")
> ,("+11E+23", PrefixOp [Name "+"] $ NumLit "11E+23")
> ,("+11E-23", PrefixOp [Name "+"] $ NumLit "11E-23")
> ,("+11.11E23", PrefixOp [Name "+"] $ NumLit "11.11E23")
> ,("+11.11E+23", PrefixOp [Name "+"] $ NumLit "11.11E+23")
> ,("+11.11E-23", PrefixOp [Name "+"] $ NumLit "11.11E-23")
> ,("-11E23", PrefixOp "-" $ NumLit "11E23")
> ,("-11E+23", PrefixOp "-" $ NumLit "11E+23")
> ,("-11E-23", PrefixOp "-" $ NumLit "11E-23")
> ,("-11.11E23", PrefixOp "-" $ NumLit "11.11E23")
> ,("-11.11E+23", PrefixOp "-" $ NumLit "11.11E+23")
> ,("-11.11E-23", PrefixOp "-" $ NumLit "11.11E-23")
> ,("-11E23", PrefixOp [Name "-"] $ NumLit "11E23")
> ,("-11E+23", PrefixOp [Name "-"] $ NumLit "11E+23")
> ,("-11E-23", PrefixOp [Name "-"] $ NumLit "11E-23")
> ,("-11.11E23", PrefixOp [Name "-"] $ NumLit "11.11E23")
> ,("-11.11E+23", PrefixOp [Name "-"] $ NumLit "11.11E+23")
> ,("-11.11E-23", PrefixOp [Name "-"] $ NumLit "11.11E-23")
> ,("11.11e23", NumLit "11.11e23")
@ -665,7 +664,7 @@ normal typed literals
> intervalLiterals :: TestItem
> intervalLiterals = Group "intervalLiterals literals" $ map (uncurry TestValueExpr)
> [("interval '1'", TypedLit (TypeName "interval") "1")
> [("interval '1'", TypedLit (TypeName [Name "interval"]) "1")
> ,("interval '1' day"
> ,IntervalLit Nothing "1" (Itf "day" Nothing) Nothing)
> ,("interval '1' day(3)"
@ -689,9 +688,9 @@ normal typed literals
> booleanLiterals :: TestItem
> booleanLiterals = Group "boolean literals" $ map (uncurry TestValueExpr)
> [("true", Iden "true")
> ,("false", Iden "false")
> ,("unknown", Iden "unknown")
> [("true", Iden [Name "true"])
> ,("false", Iden [Name "false"])
> ,("unknown", Iden [Name "unknown"])
> ]
so is unknown effectively an alias for null with a cast or is it
@ -1016,37 +1015,37 @@ create a list of type name variations:
> -- 1111
> ,("char varying(5) character set something collate something_insensitive"
> ,CharTypeName [Name "char varying"] (Just 5)
> [Name "something"] (Just "something_insensitive"))
> [Name "something"] (Just (Name "something_insensitive")))
> -- 0111
> ,("char(5) character set something collate something_insensitive"
> ,CharTypeName [Name "char"] (Just 5)
> [Name "something"] (Just "something_insensitive"))
> [Name "something"] (Just (Name "something_insensitive")))
> -- 1011
> ,("char varying character set something collate something_insensitive"
> ,CharTypeName [Name "char varying"] Nothing
> [Name "something"] (Just "something_insensitive"))
> [Name "something"] (Just (Name "something_insensitive")))
> -- 0011
> ,("char character set something collate something_insensitive"
> ,CharTypeName [Name "char"] Nothing
> [Name "something"] (Just "something_insensitive"))
> [Name "something"] (Just (Name "something_insensitive")))
> -- 1101
> ,("char varying(5) collate something_insensitive"
> ,CharTypeName [Name "char varying"] (Just 5)
> [] (Just "something_insensitive"))
> [] (Just (Name "something_insensitive")))
> -- 0101
> ,("char(5) collate something_insensitive"
> ,CharTypeName [Name "char"] (Just 5)
> [] (Just "something_insensitive"))
> [] (Just (Name "something_insensitive")))
> -- 1001
> ,("char varying collate something_insensitive"
> ,CharTypeName [Name "char varying"] Nothing
> [] (Just "something_insensitive"))
> [] (Just (Name "something_insensitive")))
> -- 0001
> ,("char collate something_insensitive"
> ,CharTypeName [Name "char"] Nothing
> [] (Just "something_insensitive"))
> [] (Just (Name "something_insensitive")))
> -- 1110
> ,("char varying(5) character set something"
@ -1243,10 +1242,10 @@ for or how it works
> contextuallyTypeValueSpec :: TestItem
> contextuallyTypeValueSpec = Group "contextually typed value specification" $ map (uncurry TestValueExpr)
> [("null", Iden "null")
> ,("array[]", Array (Iden "array") [])
> [("null", Iden [Name "null"])
> ,("array[]", Array (Iden [Name "array"]) [])
> ,("multiset[]", MultisetCtor [])
> ,("default", Iden "default")
> ,("default", Iden [Name "default"])
> ]
todo: trigraphs?
@ -1494,15 +1493,15 @@ TODO: reference resolution
> arrayElementReference :: TestItem
> arrayElementReference = Group "array element reference" $ map (uncurry TestValueExpr)
> [("something[3]"
> ,Array (Iden "something") [NumLit "3"])
> ,Array (Iden [Name "something"]) [NumLit "3"])
> ,("(something(a))[x]"
> ,Array (Parens (App "something" [Iden "a"]))
> [Iden "x"])
> ,Array (Parens (App [Name "something"] [Iden [Name "a"]]))
> [Iden [Name "x"]])
> ,("(something(a))[x][y] "
> ,Array (
> Array (Parens (App "something" [Iden "a"]))
> [Iden "x"])
> [Iden "y"])
> Array (Parens (App [Name "something"] [Iden [Name "a"]]))
> [Iden [Name "x"]])
> [Iden [Name "y"]])
> ]
TODO: work out the precendence of the array element reference suffix
@ -1514,7 +1513,7 @@ TODO: work out the precendence of the array element reference suffix
> multisetElementReference :: TestItem
> multisetElementReference = Group "multiset element reference" $ map (uncurry TestValueExpr)
> [("element(something)", App "element" [Iden "something"])
> [("element(something)", App [Name "element"] [Iden [Name "something"]])
> ]
Not sure why this is called element reference, since it appears to be
@ -1916,20 +1915,20 @@ operator is ||, same as the string concatenation operator.
> arrayValueConstructor :: TestItem
> arrayValueConstructor = Group "array value constructor" $ map (uncurry TestValueExpr)
> [("array[1,2,3]"
> ,Array (Iden "array")
> ,Array (Iden [Name "array"])
> [NumLit "1", NumLit "2", NumLit "3"])
> ,("array[a,b,c]"
> ,Array (Iden "array")
> [Iden "a", Iden "b", Iden "c"])
> ,Array (Iden [Name "array"])
> [Iden [Name "a"], Iden [Name "b"], Iden [Name "c"]])
> ,("array(select * from t)"
> ,ArrayCtor (makeSelect
> {qeSelectList = [(Star,Nothing)]
> ,qeFrom = [TRSimple "t"]}))
> ,qeFrom = [TRSimple [Name "t"]]}))
> ,("array(select * from t order by a)"
> ,ArrayCtor (makeSelect
> {qeSelectList = [(Star,Nothing)]
> ,qeFrom = [TRSimple "t"]
> ,qeOrderBy = [SortSpec (Iden "a") DirDefault NullsOrderDefault] }))
> ,qeFrom = [TRSimple [Name "t"]]
> ,qeOrderBy = [SortSpec (Iden [Name "a"]) DirDefault NullsOrderDefault] }))
> ]
== 6.37 <multiset value expression> (p286)
@ -1948,15 +1947,15 @@ operator is ||, same as the string concatenation operator.
> multisetValueExpression :: TestItem
> multisetValueExpression = Group "multiset value expression" $ map (uncurry TestValueExpr)
> [("a multiset union b"
> ,MultisetBinOp (Iden "a") Union SQDefault (Iden "b"))
> ,MultisetBinOp (Iden [Name "a"]) Union SQDefault (Iden [Name "b"]))
> ,("a multiset union all b"
> ,MultisetBinOp (Iden "a") Union All (Iden "b"))
> ,MultisetBinOp (Iden [Name "a"]) Union All (Iden [Name "b"]))
> ,("a multiset union distinct b"
> ,MultisetBinOp (Iden "a") Union Distinct (Iden "b"))
> ,MultisetBinOp (Iden [Name "a"]) Union Distinct (Iden [Name "b"]))
> ,("a multiset except b"
> ,MultisetBinOp (Iden "a") Except SQDefault (Iden "b"))
> ,MultisetBinOp (Iden [Name "a"]) Except SQDefault (Iden [Name "b"]))
> ,("a multiset intersect b"
> ,MultisetBinOp (Iden "a") Intersect SQDefault (Iden "b"))
> ,MultisetBinOp (Iden [Name "a"]) Intersect SQDefault (Iden [Name "b"]))
> ]
== 6.38 <multiset value function> (p289)
@ -1967,7 +1966,7 @@ operator is ||, same as the string concatenation operator.
> multisetValueFunction :: TestItem
> multisetValueFunction = Group "multiset value function" $ map (uncurry TestValueExpr)
> [("set(a)", App "set" [Iden "a"])
> [("set(a)", App [Name "set"] [Iden [Name "a"]])
> ]
== 6.39 <multiset value constructor> (p290)
@ -1991,7 +1990,7 @@ table is just syntactic sugar for multiset (why does it exist?)
> multisetValueConstructor :: TestItem
> multisetValueConstructor = Group "multiset value constructor" $ map (uncurry TestValueExpr)
> [("multiset[a,b,c]", MultisetCtor[Iden "a", Iden "b", Iden "c"])
> [("multiset[a,b,c]", MultisetCtor[Iden [Name "a"], Iden [Name "b"], Iden [Name "c"]])
> ,("multiset(select * from t)", MultisetQueryCtor qe)
> ,("table(select * from t)", MultisetQueryCtor qe)
> ]
@ -2276,23 +2275,23 @@ groups, and not general value expressions.
> groupbyClause = Group "group by clause" $ map (uncurry TestQueryExpr)
> [("select a, sum(b) from t group by a",q)
> ,("select a, sum(b),c from t group by a,c"
> ,q1 {qeGroupBy = qeGroupBy q1 ++ [SimpleGroup $ Iden "c"]})
> ,q1 {qeGroupBy = qeGroupBy q1 ++ [SimpleGroup $ Iden [Name "c"]]})
> ,("select a, sum(b),c from t group by a,c collate x"
> ,q1 {qeGroupBy = qeGroupBy q1
> ++ [SimpleGroup $ Collate (Iden "c") "x"]})
> ++ [SimpleGroup $ Collate (Iden [Name "c"]) "x"]})
> ,("select a, sum(b),c from t group by a,c collate x having sum(b) > 100"
> ,q1 {qeGroupBy = qeGroupBy q1
> ++ [SimpleGroup $ Collate (Iden "c") "x"]
> ,qeHaving = Just (BinOp (App "sum" [Iden "b"])
> ">" (NumLit "100"))})
> ++ [SimpleGroup $ Collate (Iden [Name "c"]) "x"]
> ,qeHaving = Just (BinOp (App [Name "sum"] [Iden [Name "b"]])
> [Name ">"] (NumLit "100"))})
> ]
> where
> q = makeSelect
> {qeSelectList = [(Iden "a",Nothing), (App "sum" [Iden "b"],Nothing)]
> ,qeFrom = [TRSimple "t"]
> ,qeGroupBy = [SimpleGroup $ Iden "a"]
> {qeSelectList = [(Iden [Name "a"],Nothing), (App [Name "sum"] [Iden [Name "b"]],Nothing)]
> ,qeFrom = [TRSimple [Name "t"]]
> ,qeGroupBy = [SimpleGroup $ Iden [Name "a"]]
> }
> q1 = q {qeSelectList = qeSelectList q ++ [(Iden "c", Nothing)]}
> q1 = q {qeSelectList = qeSelectList q ++ [(Iden [Name "c"], Nothing)]}
7.10 <having clause> (p329)
@ -2700,19 +2699,19 @@ Specify a quantified comparison.
> quantifiedComparisonPredicate = Group "quantified comparison predicate" $ map (uncurry TestValueExpr)
> [("a = any (select * from t)"
> ,QuantifiedComparison (Iden "a") "=" CPAny qe)
> ,QuantifiedComparison (Iden [Name "a"]) [Name "="] CPAny qe)
> ,("a <= some (select * from t)"
> ,QuantifiedComparison (Iden "a") "<=" CPSome qe)
> ,QuantifiedComparison (Iden [Name "a"]) [Name "<="] CPSome qe)
> ,("a > all (select * from t)"
> ,QuantifiedComparison (Iden "a") ">" CPAll qe)
> ,QuantifiedComparison (Iden [Name "a"]) [Name ">"] CPAll qe)
> ,("(a,b) <> all (select * from t)"
> ,QuantifiedComparison
> (SpecialOp "rowctor" [Iden "a",Iden "b"]) "<>" CPAll qe)
> (SpecialOp [Name "rowctor"] [Iden [Name "a"],Iden [Name "b"]]) [Name "<>"] CPAll qe)
> ]
> where
> qe = makeSelect
> {qeSelectList = [(Star,Nothing)]
> ,qeFrom = [TRSimple "t"]}
> ,qeFrom = [TRSimple [Name "t"]]}
== 8.9 <exists predicate> (p399)
@ -2734,8 +2733,8 @@ Specify a test for the absence of duplicate rows
> ,SubQueryExpr SqUnique
> $ makeSelect
> {qeSelectList = [(Star,Nothing)]
> ,qeFrom = [TRSimple "t"]
> ,qeWhere = Just (BinOp (Iden "a") "=" (NumLit "4"))
> ,qeFrom = [TRSimple [Name "t"]]
> ,qeWhere = Just (BinOp (Iden [Name "a"]) [Name "="] (NumLit "4"))
> }
> )]
@ -2758,17 +2757,17 @@ Specify a test for matching rows.
> matchPredicate :: TestItem
> matchPredicate = Group "match predicate" $ map (uncurry TestValueExpr)
> [("a match (select a from t)"
> ,Match (Iden "a") False qe)
> ,Match (Iden [Name "a"]) False qe)
> ,("(a,b) match (select a,b from t)"
> ,Match (SpecialOp "rowctor" [Iden "a", Iden "b"]) False qea)
> ,Match (SpecialOp [Name "rowctor"] [Iden [Name "a"], Iden [Name "b"]]) False qea)
> ,("(a,b) match unique (select a,b from t)"
> ,Match (SpecialOp "rowctor" [Iden "a", Iden "b"]) True qea)
> ,Match (SpecialOp [Name "rowctor"] [Iden [Name "a"], Iden [Name "b"]]) True qea)
> ]
> where
> qe = makeSelect
> {qeSelectList = [(Iden "a",Nothing)]
> ,qeFrom = [TRSimple "t"]}
> qea = qe {qeSelectList = qeSelectList qe ++ [(Iden "b",Nothing)]}
> {qeSelectList = [(Iden [Name "a"],Nothing)]
> ,qeFrom = [TRSimple [Name "t"]]}
> qea = qe {qeSelectList = qeSelectList qe ++ [(Iden [Name "b"],Nothing)]}
== 8.13 <overlaps predicate> (p405)
@ -2988,7 +2987,7 @@ Specify a default collating sequence.
> collateClause :: TestItem
> collateClause = Group "collate clause" $ map (uncurry TestValueExpr)
> [("a collate my_collation"
> ,Collate (Iden "a") "my_collation")]
> ,Collate (Iden [Name "a"]) "my_collation")]
10.8 <constraint name definition> and <constraint characteristics> (p501)
@ -3073,19 +3072,19 @@ TODO: review sort specifications
> sortSpecificationList :: TestItem
> sortSpecificationList = Group "sort specification list" $ map (uncurry TestQueryExpr)
> [("select * from t order by a"
> ,qe {qeOrderBy = [SortSpec (Iden "a") DirDefault NullsOrderDefault]})
> ,qe {qeOrderBy = [SortSpec (Iden [Name "a"]) DirDefault NullsOrderDefault]})
> ,("select * from t order by a,b"
> ,qe {qeOrderBy = [SortSpec (Iden "a") DirDefault NullsOrderDefault
> ,SortSpec (Iden "b") DirDefault NullsOrderDefault]})
> ,qe {qeOrderBy = [SortSpec (Iden [Name "a"]) DirDefault NullsOrderDefault
> ,SortSpec (Iden [Name "b"]) DirDefault NullsOrderDefault]})
> ,("select * from t order by a asc,b"
> ,qe {qeOrderBy = [SortSpec (Iden "a") Asc NullsOrderDefault
> ,SortSpec (Iden "b") DirDefault NullsOrderDefault]})
> ,qe {qeOrderBy = [SortSpec (Iden [Name "a"]) Asc NullsOrderDefault
> ,SortSpec (Iden [Name "b"]) DirDefault NullsOrderDefault]})
> ,("select * from t order by a desc,b"
> ,qe {qeOrderBy = [SortSpec (Iden "a") Desc NullsOrderDefault
> ,SortSpec (Iden "b") DirDefault NullsOrderDefault]})
> ,qe {qeOrderBy = [SortSpec (Iden [Name "a"]) Desc NullsOrderDefault
> ,SortSpec (Iden [Name "b"]) DirDefault NullsOrderDefault]})
> ,("select * from t order by a collate x desc,b"
> ,qe {qeOrderBy = [SortSpec (Collate (Iden "a") "x") Desc NullsOrderDefault
> ,SortSpec (Iden "b") DirDefault NullsOrderDefault]})
> ,qe {qeOrderBy = [SortSpec (Collate (Iden [Name "a"]) "x") Desc NullsOrderDefault
> ,SortSpec (Iden [Name "b"]) DirDefault NullsOrderDefault]})
> ,("select * from t order by 1,2"
> ,qe {qeOrderBy = [SortSpec (NumLit "1") DirDefault NullsOrderDefault
> ,SortSpec (NumLit "2") DirDefault NullsOrderDefault]})
@ -3093,7 +3092,7 @@ TODO: review sort specifications
> where
> qe = makeSelect
> {qeSelectList = [(Star,Nothing)]
> ,qeFrom = [TRSimple "t"]}
> ,qeFrom = [TRSimple [Name "t"]]}
TODO: what happened to the collation in order by?
Answer: sort used to be a column reference with an optional

View file

@ -2,7 +2,6 @@
These are the tests for parsing focusing on the from part of query
expression
> {-# LANGUAGE OverloadedStrings #-}
> module Language.SQL.SimpleSQL.TableRefs (tableRefTests) where
> import Language.SQL.SimpleSQL.TestTypes
@ -12,96 +11,95 @@ expression
> tableRefTests :: TestItem
> tableRefTests = Group "tableRefTests" $ map (uncurry TestQueryExpr)
> [("select a from t"
> ,ms [TRSimple "t"])
> ,ms [TRSimple [Name "t"]])
> ,("select a from f(a)"
> ,ms [TRFunction "f" [Iden "a"]])
> ,ms [TRFunction [Name "f"] [Iden [Name "a"]]])
> ,("select a from t,u"
> ,ms [TRSimple "t", TRSimple "u"])
> ,ms [TRSimple [Name "t"], TRSimple [Name "u"]])
> ,("select a from s.t"
> ,ms [TRSimple ["s","t"]])
> ,ms [TRSimple [Name "s", Name "t"]])
these lateral queries make no sense but the syntax is valid
> ,("select a from lateral a"
> ,ms [TRLateral $ TRSimple "a"])
> ,ms [TRLateral $ TRSimple [Name "a"]])
> ,("select a from lateral a,b"
> ,ms [TRLateral $ TRSimple "a", TRSimple "b"])
> ,ms [TRLateral $ TRSimple [Name "a"], TRSimple [Name "b"]])
> ,("select a from a, lateral b"
> ,ms [TRSimple "a", TRLateral $ TRSimple "b"])
> ,ms [TRSimple [Name "a"], TRLateral $ TRSimple [Name "b"]])
> ,("select a from a natural join lateral b"
> ,ms [TRJoin (TRSimple "a") True JInner
> (TRLateral $ TRSimple "b")
> ,ms [TRJoin (TRSimple [Name "a"]) True JInner
> (TRLateral $ TRSimple [Name "b"])
> Nothing])
> -- the lateral binds on the outside of the join which is incorrect
> ,("select a from lateral a natural join lateral b"
> ,ms [TRJoin (TRLateral $ TRSimple "a") True JInner
> (TRLateral $ TRSimple "b")
> ,ms [TRJoin (TRLateral $ TRSimple [Name "a"]) True JInner
> (TRLateral $ TRSimple [Name "b"])
> Nothing])
> ,("select a from t inner join u on expr"
> ,ms [TRJoin (TRSimple "t") False JInner (TRSimple "u")
> (Just $ JoinOn $ Iden "expr")])
> ,ms [TRJoin (TRSimple [Name "t"]) False JInner (TRSimple [Name "u"])
> (Just $ JoinOn $ Iden [Name "expr"])])
> ,("select a from t join u on expr"
> ,ms [TRJoin (TRSimple "t") False JInner (TRSimple "u")
> (Just $ JoinOn $ Iden "expr")])
> ,ms [TRJoin (TRSimple [Name "t"]) False JInner (TRSimple [Name "u"])
> (Just $ JoinOn $ Iden [Name "expr"])])
> ,("select a from t left join u on expr"
> ,ms [TRJoin (TRSimple "t") False JLeft (TRSimple "u")
> (Just $ JoinOn $ Iden "expr")])
> ,ms [TRJoin (TRSimple [Name "t"]) False JLeft (TRSimple [Name "u"])
> (Just $ JoinOn $ Iden [Name "expr"])])
> ,("select a from t right join u on expr"
> ,ms [TRJoin (TRSimple "t") False JRight (TRSimple "u")
> (Just $ JoinOn $ Iden "expr")])
> ,ms [TRJoin (TRSimple [Name "t"]) False JRight (TRSimple [Name "u"])
> (Just $ JoinOn $ Iden [Name "expr"])])
> ,("select a from t full join u on expr"
> ,ms [TRJoin (TRSimple "t") False JFull (TRSimple "u")
> (Just $ JoinOn $ Iden "expr")])
> ,ms [TRJoin (TRSimple [Name "t"]) False JFull (TRSimple [Name "u"])
> (Just $ JoinOn $ Iden [Name "expr"])])
> ,("select a from t cross join u"
> ,ms [TRJoin (TRSimple "t") False
> JCross (TRSimple "u") Nothing])
> ,ms [TRJoin (TRSimple [Name "t"]) False
> JCross (TRSimple [Name "u"]) Nothing])
> ,("select a from t natural inner join u"
> ,ms [TRJoin (TRSimple "t") True JInner (TRSimple "u")
> ,ms [TRJoin (TRSimple [Name "t"]) True JInner (TRSimple [Name "u"])
> Nothing])
> ,("select a from t inner join u using(a,b)"
> ,ms [TRJoin (TRSimple "t") False JInner (TRSimple "u")
> (Just $ JoinUsing ["a", "b"])])
> ,ms [TRJoin (TRSimple [Name "t"]) False JInner (TRSimple [Name "u"])
> (Just $ JoinUsing [Name "a", Name "b"])])
> ,("select a from (select a from t)"
> ,ms [TRQueryExpr $ ms [TRSimple "t"]])
> ,ms [TRQueryExpr $ ms [TRSimple [Name "t"]]])
> ,("select a from t as u"
> ,ms [TRAlias (TRSimple "t") (Alias "u" Nothing)])
> ,ms [TRAlias (TRSimple [Name "t"]) (Alias (Name "u") Nothing)])
> ,("select a from t u"
> ,ms [TRAlias (TRSimple "t") (Alias "u" Nothing)])
> ,ms [TRAlias (TRSimple [Name "t"]) (Alias (Name "u") Nothing)])
> ,("select a from t u(b)"
> ,ms [TRAlias (TRSimple "t") (Alias "u" $ Just ["b"])])
> ,ms [TRAlias (TRSimple [Name "t"]) (Alias (Name "u") $ Just [Name "b"])])
> ,("select a from (t cross join u) as u"
> ,ms [TRAlias (TRParens $
> TRJoin (TRSimple "t") False JCross (TRSimple "u") Nothing)
> (Alias "u" Nothing)])
> TRJoin (TRSimple [Name "t"]) False JCross (TRSimple [Name "u"]) Nothing)
> (Alias (Name "u") Nothing)])
> -- todo: not sure if the associativity is correct
> ,("select a from t cross join u cross join v",
> ms [TRJoin
> (TRJoin (TRSimple "t") False
> JCross (TRSimple "u") Nothing)
> False JCross (TRSimple "v") Nothing])
> (TRJoin (TRSimple [Name "t"]) False
> JCross (TRSimple [Name "u"]) Nothing)
> False JCross (TRSimple [Name "v"]) Nothing])
> ]
> where
> ms f = makeSelect {qeSelectList = [(Iden "a",Nothing)]
> ms f = makeSelect {qeSelectList = [(Iden [Name "a"],Nothing)]
> ,qeFrom = f}

View file

@ -2,13 +2,10 @@
This is the types used to define the tests as pure data. See the
Tests.lhs module for the 'interpreter'.
> {-# LANGUAGE FlexibleInstances #-}
> module Language.SQL.SimpleSQL.TestTypes where
> import Language.SQL.SimpleSQL.Syntax
> import Data.String
> data TestItem = Group String [TestItem]
> | TestValueExpr String ValueExpr
> | TestQueryExpr String QueryExpr
@ -20,11 +17,3 @@ should all be TODO to convert to a testqueryexpr test.
> | ParseQueryExpr String
> deriving (Eq,Show)
hack to make the tests a bit simpler
> instance IsString Name where
> fromString = Name
> instance IsString [Name] where
> fromString = (:[]) . Name

View file

@ -1,7 +1,6 @@
Tests for parsing value expressions
> {-# LANGUAGE OverloadedStrings #-}
> module Language.SQL.SimpleSQL.ValueExprs (valueExprTests) where
> import Language.SQL.SimpleSQL.TestTypes
@ -42,12 +41,12 @@ Tests for parsing value expressions
> ,IntervalLit Nothing "3" (Itf "day" Nothing) Nothing)
> ,("interval '3' day (3)"
> ,IntervalLit Nothing "3" (Itf "day" $ Just (3,Nothing)) Nothing)
> ,("interval '3 weeks'", TypedLit (TypeName "interval") "3 weeks")
> ,("interval '3 weeks'", TypedLit (TypeName [Name "interval"]) "3 weeks")
> ]
> identifiers :: TestItem
> identifiers = Group "identifiers" $ map (uncurry TestValueExpr)
> [("iden1", Iden "iden1")
> [("iden1", Iden [Name "iden1"])
> --,("t.a", Iden2 "t" "a")
> ,("\"quoted identifier\"", Iden [QName "quoted identifier"])
> ]
@ -67,41 +66,41 @@ Tests for parsing value expressions
> dots :: TestItem
> dots = Group "dot" $ map (uncurry TestValueExpr)
> [("t.a", Iden ["t","a"])
> ,("t.*", BinOp (Iden "t") "." Star)
> ,("a.b.c", Iden ["a","b","c"])
> ,("ROW(t.*,42)", App "ROW" [BinOp (Iden "t") "." Star, NumLit "42"])
> [("t.a", Iden [Name "t",Name "a"])
> ,("t.*", BinOp (Iden [Name "t"]) [Name "."] Star)
> ,("a.b.c", Iden [Name "a",Name "b",Name "c"])
> ,("ROW(t.*,42)", App [Name "ROW"] [BinOp (Iden [Name "t"]) [Name "."] Star, NumLit "42"])
> ]
> app :: TestItem
> app = Group "app" $ map (uncurry TestValueExpr)
> [("f()", App "f" [])
> ,("f(a)", App "f" [Iden "a"])
> ,("f(a,b)", App "f" [Iden "a", Iden "b"])
> [("f()", App [Name "f"] [])
> ,("f(a)", App [Name "f"] [Iden [Name "a"]])
> ,("f(a,b)", App [Name "f"] [Iden [Name "a"], Iden [Name "b"]])
> ]
> caseexp :: TestItem
> caseexp = Group "caseexp" $ map (uncurry TestValueExpr)
> [("case a when 1 then 2 end"
> ,Case (Just $ Iden "a") [([NumLit "1"]
> ,Case (Just $ Iden [Name "a"]) [([NumLit "1"]
> ,NumLit "2")] Nothing)
> ,("case a when 1 then 2 when 3 then 4 end"
> ,Case (Just $ Iden "a") [([NumLit "1"], NumLit "2")
> ,Case (Just $ Iden [Name "a"]) [([NumLit "1"], NumLit "2")
> ,([NumLit "3"], NumLit "4")] Nothing)
> ,("case a when 1 then 2 when 3 then 4 else 5 end"
> ,Case (Just $ Iden "a") [([NumLit "1"], NumLit "2")
> ,Case (Just $ Iden [Name "a"]) [([NumLit "1"], NumLit "2")
> ,([NumLit "3"], NumLit "4")]
> (Just $ NumLit "5"))
> ,("case when a=1 then 2 when a=3 then 4 else 5 end"
> ,Case Nothing [([BinOp (Iden "a") "=" (NumLit "1")], NumLit "2")
> ,([BinOp (Iden "a") "=" (NumLit "3")], NumLit "4")]
> ,Case Nothing [([BinOp (Iden [Name "a"]) [Name "="] (NumLit "1")], NumLit "2")
> ,([BinOp (Iden [Name "a"]) [Name "="] (NumLit "3")], NumLit "4")]
> (Just $ NumLit "5"))
> ,("case a when 1,2 then 10 when 3,4 then 20 end"
> ,Case (Just $ Iden "a") [([NumLit "1",NumLit "2"]
> ,Case (Just $ Iden [Name "a"]) [([NumLit "1",NumLit "2"]
> ,NumLit "10")
> ,([NumLit "3",NumLit "4"]
> ,NumLit "20")]
@ -118,48 +117,48 @@ Tests for parsing value expressions
> binaryOperators :: TestItem
> binaryOperators = Group "binaryOperators" $ map (uncurry TestValueExpr)
> [("a + b", BinOp (Iden "a") "+" (Iden "b"))
> [("a + b", BinOp (Iden [Name "a"]) [Name "+"] (Iden [Name "b"]))
> -- sanity check fixities
> -- todo: add more fixity checking
> ,("a + b * c"
> ,BinOp (Iden "a") "+"
> (BinOp (Iden "b") "*" (Iden "c")))
> ,BinOp (Iden [Name "a"]) [Name "+"]
> (BinOp (Iden [Name "b"]) [Name "*"] (Iden [Name "c"])))
> ,("a * b + c"
> ,BinOp (BinOp (Iden "a") "*" (Iden "b"))
> "+" (Iden "c"))
> ,BinOp (BinOp (Iden [Name "a"]) [Name "*"] (Iden [Name "b"]))
> [Name "+"] (Iden [Name "c"]))
> ]
> unaryOperators :: TestItem
> unaryOperators = Group "unaryOperators" $ map (uncurry TestValueExpr)
> [("not a", PrefixOp "not" $ Iden "a")
> ,("not not a", PrefixOp "not" $ PrefixOp "not" $ Iden "a")
> ,("+a", PrefixOp "+" $ Iden "a")
> ,("-a", PrefixOp "-" $ Iden "a")
> [("not a", PrefixOp [Name "not"] $ Iden [Name "a"])
> ,("not not a", PrefixOp [Name "not"] $ PrefixOp [Name "not"] $ Iden [Name "a"])
> ,("+a", PrefixOp [Name "+"] $ Iden [Name "a"])
> ,("-a", PrefixOp [Name "-"] $ Iden [Name "a"])
> ]
> casts :: TestItem
> casts = Group "operators" $ map (uncurry TestValueExpr)
> [("cast('1' as int)"
> ,Cast (StringLit "1") $ TypeName "int")
> ,Cast (StringLit "1") $ TypeName [Name "int"])
> ,("int '3'"
> ,TypedLit (TypeName "int") "3")
> ,TypedLit (TypeName [Name "int"]) "3")
> ,("cast('1' as double precision)"
> ,Cast (StringLit "1") $ TypeName "double precision")
> ,Cast (StringLit "1") $ TypeName [Name "double precision"])
> ,("cast('1' as float(8))"
> ,Cast (StringLit "1") $ PrecTypeName "float" 8)
> ,Cast (StringLit "1") $ PrecTypeName [Name "float"] 8)
> ,("cast('1' as decimal(15,2))"
> ,Cast (StringLit "1") $ PrecScaleTypeName "decimal" 15 2)
> ,Cast (StringLit "1") $ PrecScaleTypeName [Name "decimal"] 15 2)
> ,("double precision '3'"
> ,TypedLit (TypeName "double precision") "3")
> ,TypedLit (TypeName [Name "double precision"]) "3")
> ]
> subqueries :: TestItem
@ -168,113 +167,113 @@ Tests for parsing value expressions
> ,("(select a from t)", SubQueryExpr SqSq ms)
> ,("a in (select a from t)"
> ,In True (Iden "a") (InQueryExpr ms))
> ,In True (Iden [Name "a"]) (InQueryExpr ms))
> ,("a not in (select a from t)"
> ,In False (Iden "a") (InQueryExpr ms))
> ,In False (Iden [Name "a"]) (InQueryExpr ms))
> ,("a > all (select a from t)"
> ,QuantifiedComparison (Iden "a") ">" CPAll ms)
> ,QuantifiedComparison (Iden [Name "a"]) [Name ">"] CPAll ms)
> ,("a = some (select a from t)"
> ,QuantifiedComparison (Iden "a") "=" CPSome ms)
> ,QuantifiedComparison (Iden [Name "a"]) [Name "="] CPSome ms)
> ,("a <= any (select a from t)"
> ,QuantifiedComparison (Iden "a") "<=" CPAny ms)
> ,QuantifiedComparison (Iden [Name "a"]) [Name "<="] CPAny ms)
> ]
> where
> ms = makeSelect
> {qeSelectList = [(Iden "a",Nothing)]
> ,qeFrom = [TRSimple "t"]
> {qeSelectList = [(Iden [Name "a"],Nothing)]
> ,qeFrom = [TRSimple [Name "t"]]
> }
> miscOps :: TestItem
> miscOps = Group "unaryOperators" $ map (uncurry TestValueExpr)
> [("a in (1,2,3)"
> ,In True (Iden "a") $ InList $ map NumLit ["1","2","3"])
> ,In True (Iden [Name "a"]) $ InList $ map NumLit ["1","2","3"])
> ,("a is null", PostfixOp "is null" (Iden "a"))
> ,("a is not null", PostfixOp "is not null" (Iden "a"))
> ,("a is true", PostfixOp "is true" (Iden "a"))
> ,("a is not true", PostfixOp "is not true" (Iden "a"))
> ,("a is false", PostfixOp "is false" (Iden "a"))
> ,("a is not false", PostfixOp "is not false" (Iden "a"))
> ,("a is unknown", PostfixOp "is unknown" (Iden "a"))
> ,("a is not unknown", PostfixOp "is not unknown" (Iden "a"))
> ,("a is distinct from b", BinOp (Iden "a") "is distinct from"(Iden "b"))
> ,("a is null", PostfixOp [Name "is null"] (Iden [Name "a"]))
> ,("a is not null", PostfixOp [Name "is not null"] (Iden [Name "a"]))
> ,("a is true", PostfixOp [Name "is true"] (Iden [Name "a"]))
> ,("a is not true", PostfixOp [Name "is not true"] (Iden [Name "a"]))
> ,("a is false", PostfixOp [Name "is false"] (Iden [Name "a"]))
> ,("a is not false", PostfixOp [Name "is not false"] (Iden [Name "a"]))
> ,("a is unknown", PostfixOp [Name "is unknown"] (Iden [Name "a"]))
> ,("a is not unknown", PostfixOp [Name "is not unknown"] (Iden [Name "a"]))
> ,("a is distinct from b", BinOp (Iden [Name "a"]) [Name "is distinct from"] (Iden [Name "b"]))
> ,("a is not distinct from b"
> ,BinOp (Iden "a") "is not distinct from" (Iden "b"))
> ,BinOp (Iden [Name "a"]) [Name "is not distinct from"] (Iden [Name "b"]))
> ,("a like b", BinOp (Iden "a") "like" (Iden "b"))
> ,("a not like b", BinOp (Iden "a") "not like" (Iden "b"))
> ,("a is similar to b", BinOp (Iden "a") "is similar to" (Iden "b"))
> ,("a like b", BinOp (Iden [Name "a"]) [Name "like"] (Iden [Name "b"]))
> ,("a not like b", BinOp (Iden [Name "a"]) [Name "not like"] (Iden [Name "b"]))
> ,("a is similar to b", BinOp (Iden [Name "a"]) [Name "is similar to"] (Iden [Name "b"]))
> ,("a is not similar to b"
> ,BinOp (Iden "a") "is not similar to" (Iden "b"))
> ,BinOp (Iden [Name "a"]) [Name "is not similar to"] (Iden [Name "b"]))
> ,("a overlaps b", BinOp (Iden "a") "overlaps" (Iden "b"))
> ,("a overlaps b", BinOp (Iden [Name "a"]) [Name "overlaps"] (Iden [Name "b"]))
special operators
> ,("a between b and c", SpecialOp "between" [Iden "a"
> ,Iden "b"
> ,Iden "c"])
> ,("a between b and c", SpecialOp [Name "between"] [Iden [Name "a"]
> ,Iden [Name "b"]
> ,Iden [Name "c"]])
> ,("a not between b and c", SpecialOp "not between" [Iden "a"
> ,Iden "b"
> ,Iden "c"])
> ,("a not between b and c", SpecialOp [Name "not between"] [Iden [Name "a"]
> ,Iden [Name "b"]
> ,Iden [Name "c"]])
> ,("(1,2)"
> ,SpecialOp "rowctor" [NumLit "1", NumLit "2"])
> ,SpecialOp [Name "rowctor"] [NumLit "1", NumLit "2"])
keyword special operators
> ,("extract(day from t)"
> , SpecialOpK "extract" (Just $ Iden "day") [("from", Iden "t")])
> , SpecialOpK [Name "extract"] (Just $ Iden [Name "day"]) [("from", Iden [Name "t"])])
> ,("substring(x from 1 for 2)"
> ,SpecialOpK "substring" (Just $ Iden "x") [("from", NumLit "1")
> ,SpecialOpK [Name "substring"] (Just $ Iden [Name "x"]) [("from", NumLit "1")
> ,("for", NumLit "2")])
> ,("substring(x from 1)"
> ,SpecialOpK "substring" (Just $ Iden "x") [("from", NumLit "1")])
> ,SpecialOpK [Name "substring"] (Just $ Iden [Name "x"]) [("from", NumLit "1")])
> ,("substring(x for 2)"
> ,SpecialOpK "substring" (Just $ Iden "x") [("for", NumLit "2")])
> ,SpecialOpK [Name "substring"] (Just $ Iden [Name "x"]) [("for", NumLit "2")])
> ,("substring(x from 1 for 2 collate C)"
> ,SpecialOpK "substring" (Just $ Iden "x")
> ,SpecialOpK [Name "substring"] (Just $ Iden [Name "x"])
> [("from", NumLit "1")
> ,("for", Collate (NumLit "2") "C")])
this doesn't work because of a overlap in the 'in' parser
> ,("POSITION( string1 IN string2 )"
> ,SpecialOpK "position" (Just $ Iden "string1") [("in", Iden "string2")])
> ,SpecialOpK [Name "position"] (Just $ Iden [Name "string1"]) [("in", Iden [Name "string2"])])
> ,("CONVERT(char_value USING conversion_char_name)"
> ,SpecialOpK "convert" (Just $ Iden "char_value")
> [("using", Iden "conversion_char_name")])
> ,SpecialOpK [Name "convert"] (Just $ Iden [Name "char_value"])
> [("using", Iden [Name "conversion_char_name"])])
> ,("TRANSLATE(char_value USING translation_name)"
> ,SpecialOpK "translate" (Just $ Iden "char_value")
> [("using", Iden "translation_name")])
> ,SpecialOpK [Name "translate"] (Just $ Iden [Name "char_value"])
> [("using", Iden [Name "translation_name"])])
OVERLAY(string PLACING embedded_string FROM start
[FOR length])
> ,("OVERLAY(string PLACING embedded_string FROM start)"
> ,SpecialOpK "overlay" (Just $ Iden "string")
> [("placing", Iden "embedded_string")
> ,("from", Iden "start")])
> ,SpecialOpK [Name "overlay"] (Just $ Iden [Name "string"])
> [("placing", Iden [Name "embedded_string"])
> ,("from", Iden [Name "start"])])
> ,("OVERLAY(string PLACING embedded_string FROM start FOR length)"
> ,SpecialOpK "overlay" (Just $ Iden "string")
> [("placing", Iden "embedded_string")
> ,("from", Iden "start")
> ,("for", Iden "length")])
> ,SpecialOpK [Name "overlay"] (Just $ Iden [Name "string"])
> [("placing", Iden [Name "embedded_string"])
> ,("from", Iden [Name "start"])
> ,("for", Iden [Name "length"])])
TRIM( [ [{LEADING | TRAILING | BOTH}] [removal_char] FROM ]
target_string
@ -283,117 +282,117 @@ target_string
> ,("trim(from target_string)"
> ,SpecialOpK "trim" Nothing
> ,SpecialOpK [Name "trim"] Nothing
> [("both", StringLit " ")
> ,("from", Iden "target_string")])
> ,("from", Iden [Name "target_string"])])
> ,("trim(leading from target_string)"
> ,SpecialOpK "trim" Nothing
> ,SpecialOpK [Name "trim"] Nothing
> [("leading", StringLit " ")
> ,("from", Iden "target_string")])
> ,("from", Iden [Name "target_string"])])
> ,("trim(trailing from target_string)"
> ,SpecialOpK "trim" Nothing
> ,SpecialOpK [Name "trim"] Nothing
> [("trailing", StringLit " ")
> ,("from", Iden "target_string")])
> ,("from", Iden [Name "target_string"])])
> ,("trim(both from target_string)"
> ,SpecialOpK "trim" Nothing
> ,SpecialOpK [Name "trim"] Nothing
> [("both", StringLit " ")
> ,("from", Iden "target_string")])
> ,("from", Iden [Name "target_string"])])
> ,("trim(leading 'x' from target_string)"
> ,SpecialOpK "trim" Nothing
> ,SpecialOpK [Name "trim"] Nothing
> [("leading", StringLit "x")
> ,("from", Iden "target_string")])
> ,("from", Iden [Name "target_string"])])
> ,("trim(trailing 'y' from target_string)"
> ,SpecialOpK "trim" Nothing
> ,SpecialOpK [Name "trim"] Nothing
> [("trailing", StringLit "y")
> ,("from", Iden "target_string")])
> ,("from", Iden [Name "target_string"])])
> ,("trim(both 'z' from target_string collate C)"
> ,SpecialOpK "trim" Nothing
> ,SpecialOpK [Name "trim"] Nothing
> [("both", StringLit "z")
> ,("from", Collate (Iden "target_string") "C")])
> ,("from", Collate (Iden [Name "target_string"]) "C")])
> ,("trim(leading from target_string)"
> ,SpecialOpK "trim" Nothing
> ,SpecialOpK [Name "trim"] Nothing
> [("leading", StringLit " ")
> ,("from", Iden "target_string")])
> ,("from", Iden [Name "target_string"])])
> ]
> aggregates :: TestItem
> aggregates = Group "aggregates" $ map (uncurry TestValueExpr)
> [("count(*)",App "count" [Star])
> [("count(*)",App [Name "count"] [Star])
> ,("sum(a order by a)"
> ,AggregateApp "sum" SQDefault [Iden "a"]
> [SortSpec (Iden "a") DirDefault NullsOrderDefault])
> ,AggregateApp [Name "sum"] SQDefault [Iden [Name "a"]]
> [SortSpec (Iden [Name "a"]) DirDefault NullsOrderDefault])
> ,("sum(all a)"
> ,AggregateApp "sum" All [Iden "a"] [])
> ,AggregateApp [Name "sum"] All [Iden [Name "a"]] [])
> ,("count(distinct a)"
> ,AggregateApp "count" Distinct [Iden "a"] [])
> ,AggregateApp [Name "count"] Distinct [Iden [Name "a"]] [])
> ]
> windowFunctions :: TestItem
> windowFunctions = Group "windowFunctions" $ map (uncurry TestValueExpr)
> [("max(a) over ()", WindowApp "max" [Iden "a"] [] [] Nothing)
> ,("count(*) over ()", WindowApp "count" [Star] [] [] Nothing)
> [("max(a) over ()", WindowApp [Name "max"] [Iden [Name "a"]] [] [] Nothing)
> ,("count(*) over ()", WindowApp [Name "count"] [Star] [] [] Nothing)
> ,("max(a) over (partition by b)"
> ,WindowApp "max" [Iden "a"] [Iden "b"] [] Nothing)
> ,WindowApp [Name "max"] [Iden [Name "a"]] [Iden [Name "b"]] [] Nothing)
> ,("max(a) over (partition by b,c)"
> ,WindowApp "max" [Iden "a"] [Iden "b",Iden "c"] [] Nothing)
> ,WindowApp [Name "max"] [Iden [Name "a"]] [Iden [Name "b"],Iden [Name "c"]] [] Nothing)
> ,("sum(a) over (order by b)"
> ,WindowApp "sum" [Iden "a"] []
> [SortSpec (Iden "b") DirDefault NullsOrderDefault] Nothing)
> ,WindowApp [Name "sum"] [Iden [Name "a"]] []
> [SortSpec (Iden [Name "b"]) DirDefault NullsOrderDefault] Nothing)
> ,("sum(a) over (order by b desc,c)"
> ,WindowApp "sum" [Iden "a"] []
> [SortSpec (Iden "b") Desc NullsOrderDefault
> ,SortSpec (Iden "c") DirDefault NullsOrderDefault] Nothing)
> ,WindowApp [Name "sum"] [Iden [Name "a"]] []
> [SortSpec (Iden [Name "b"]) Desc NullsOrderDefault
> ,SortSpec (Iden [Name "c"]) DirDefault NullsOrderDefault] Nothing)
> ,("sum(a) over (partition by b order by c)"
> ,WindowApp "sum" [Iden "a"] [Iden "b"]
> [SortSpec (Iden "c") DirDefault NullsOrderDefault] Nothing)
> ,WindowApp [Name "sum"] [Iden [Name "a"]] [Iden [Name "b"]]
> [SortSpec (Iden [Name "c"]) DirDefault NullsOrderDefault] Nothing)
> ,("sum(a) over (partition by b order by c range unbounded preceding)"
> ,WindowApp "sum" [Iden "a"] [Iden "b"]
> [SortSpec (Iden "c") DirDefault NullsOrderDefault]
> ,WindowApp [Name "sum"] [Iden [Name "a"]] [Iden [Name "b"]]
> [SortSpec (Iden [Name "c"]) DirDefault NullsOrderDefault]
> $ Just $ FrameFrom FrameRange UnboundedPreceding)
> ,("sum(a) over (partition by b order by c range 5 preceding)"
> ,WindowApp "sum" [Iden "a"] [Iden "b"]
> [SortSpec (Iden "c") DirDefault NullsOrderDefault]
> ,WindowApp [Name "sum"] [Iden [Name "a"]] [Iden [Name "b"]]
> [SortSpec (Iden [Name "c"]) DirDefault NullsOrderDefault]
> $ Just $ FrameFrom FrameRange $ Preceding (NumLit "5"))
> ,("sum(a) over (partition by b order by c range current row)"
> ,WindowApp "sum" [Iden "a"] [Iden "b"]
> [SortSpec (Iden "c") DirDefault NullsOrderDefault]
> ,WindowApp [Name "sum"] [Iden [Name "a"]] [Iden [Name "b"]]
> [SortSpec (Iden [Name "c"]) DirDefault NullsOrderDefault]
> $ Just $ FrameFrom FrameRange Current)
> ,("sum(a) over (partition by b order by c rows 5 following)"
> ,WindowApp "sum" [Iden "a"] [Iden "b"]
> [SortSpec (Iden "c") DirDefault NullsOrderDefault]
> ,WindowApp [Name "sum"] [Iden [Name "a"]] [Iden [Name "b"]]
> [SortSpec (Iden [Name "c"]) DirDefault NullsOrderDefault]
> $ Just $ FrameFrom FrameRows $ Following (NumLit "5"))
> ,("sum(a) over (partition by b order by c range unbounded following)"
> ,WindowApp "sum" [Iden "a"] [Iden "b"]
> [SortSpec (Iden "c") DirDefault NullsOrderDefault]
> ,WindowApp [Name "sum"] [Iden [Name "a"]] [Iden [Name "b"]]
> [SortSpec (Iden [Name "c"]) DirDefault NullsOrderDefault]
> $ Just $ FrameFrom FrameRange UnboundedFollowing)
> ,("sum(a) over (partition by b order by c \n\
> \range between 5 preceding and 5 following)"
> ,WindowApp "sum" [Iden "a"] [Iden "b"]
> [SortSpec (Iden "c") DirDefault NullsOrderDefault]
> ,WindowApp [Name "sum"] [Iden [Name "a"]] [Iden [Name "b"]]
> [SortSpec (Iden [Name "c"]) DirDefault NullsOrderDefault]
> $ Just $ FrameBetween FrameRange
> (Preceding (NumLit "5"))
> (Following (NumLit "5")))
@ -402,6 +401,6 @@ target_string
> parens :: TestItem
> parens = Group "parens" $ map (uncurry TestValueExpr)
> [("(a)", Parens (Iden "a"))
> ,("(a + b)", Parens (BinOp (Iden "a") "+" (Iden "b")))
> [("(a)", Parens (Iden [Name "a"]))
> ,("(a + b)", Parens (BinOp (Iden [Name "a"]) [Name "+"] (Iden [Name "b"])))
> ]