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

View file

@ -1,7 +1,6 @@
Some tests for parsing full queries. Some tests for parsing full queries.
> {-# LANGUAGE OverloadedStrings #-}
> module Language.SQL.SimpleSQL.FullQueries (fullQueriesTests) where > module Language.SQL.SimpleSQL.FullQueries (fullQueriesTests) where
> import Language.SQL.SimpleSQL.TestTypes > import Language.SQL.SimpleSQL.TestTypes
@ -12,8 +11,8 @@ Some tests for parsing full queries.
> fullQueriesTests = Group "queries" $ map (uncurry TestQueryExpr) > fullQueriesTests = Group "queries" $ map (uncurry TestQueryExpr)
> [("select count(*) from t" > [("select count(*) from t"
> ,makeSelect > ,makeSelect
> {qeSelectList = [(App "count" [Star], Nothing)] > {qeSelectList = [(App [Name "count"] [Star], Nothing)]
> ,qeFrom = [TRSimple "t"] > ,qeFrom = [TRSimple [Name "t"]]
> } > }
> ) > )
@ -24,16 +23,17 @@ Some tests for parsing full queries.
> \ having count(1) > 5\n\ > \ having count(1) > 5\n\
> \ order by s" > \ order by s"
> ,makeSelect > ,makeSelect
> {qeSelectList = [(Iden "a", Nothing) > {qeSelectList = [(Iden [Name "a"], Nothing)
> ,(App "sum" [BinOp (Iden "c") > ,(App [Name "sum"]
> "+" (Iden "d")] > [BinOp (Iden [Name "c"])
> ,Just "s")] > [Name "+"] (Iden [Name "d"])]
> ,qeFrom = [TRSimple "t", TRSimple "u"] > ,Just $ Name "s")]
> ,qeWhere = Just $ BinOp (Iden "a") ">" (NumLit "5") > ,qeFrom = [TRSimple [Name "t"], TRSimple [Name "u"]]
> ,qeGroupBy = [SimpleGroup $ Iden "a"] > ,qeWhere = Just $ BinOp (Iden [Name "a"]) [Name ">"] (NumLit "5")
> ,qeHaving = Just $ BinOp (App "count" [NumLit "1"]) > ,qeGroupBy = [SimpleGroup $ Iden [Name "a"]]
> ">" (NumLit "5") > ,qeHaving = Just $ BinOp (App [Name "count"] [NumLit "1"])
> ,qeOrderBy = [SortSpec (Iden "s") DirDefault NullsOrderDefault] > [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 Here are the tests for the group by component of query exprs
> {-# LANGUAGE OverloadedStrings #-}
> module Language.SQL.SimpleSQL.GroupBy (groupByTests) where > module Language.SQL.SimpleSQL.GroupBy (groupByTests) where
> import Language.SQL.SimpleSQL.TestTypes > import Language.SQL.SimpleSQL.TestTypes
@ -18,19 +17,19 @@ Here are the tests for the group by component of query exprs
> simpleGroupBy :: TestItem > simpleGroupBy :: TestItem
> simpleGroupBy = Group "simpleGroupBy" $ map (uncurry TestQueryExpr) > simpleGroupBy = Group "simpleGroupBy" $ map (uncurry TestQueryExpr)
> [("select a,sum(b) from t group by a" > [("select a,sum(b) from t group by a"
> ,makeSelect {qeSelectList = [(Iden "a",Nothing) > ,makeSelect {qeSelectList = [(Iden [Name "a"],Nothing)
> ,(App "sum" [Iden "b"],Nothing)] > ,(App [Name "sum"] [Iden [Name "b"]],Nothing)]
> ,qeFrom = [TRSimple "t"] > ,qeFrom = [TRSimple [Name "t"]]
> ,qeGroupBy = [SimpleGroup $ Iden "a"] > ,qeGroupBy = [SimpleGroup $ Iden [Name "a"]]
> }) > })
> ,("select a,b,sum(c) from t group by a,b" > ,("select a,b,sum(c) from t group by a,b"
> ,makeSelect {qeSelectList = [(Iden "a",Nothing) > ,makeSelect {qeSelectList = [(Iden [Name "a"],Nothing)
> ,(Iden "b",Nothing) > ,(Iden [Name "b"],Nothing)
> ,(App "sum" [Iden "c"],Nothing)] > ,(App [Name "sum"] [Iden [Name "c"]],Nothing)]
> ,qeFrom = [TRSimple "t"] > ,qeFrom = [TRSimple [Name "t"]]
> ,qeGroupBy = [SimpleGroup $ Iden "a" > ,qeGroupBy = [SimpleGroup $ Iden [Name "a"]
> ,SimpleGroup $ Iden "b"] > ,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 ()", ms [GroupingParens []])
> ,("select * from t group by grouping sets ((), (a))" > ,("select * from t group by grouping sets ((), (a))"
> ,ms [GroupingSets [GroupingParens [] > ,ms [GroupingSets [GroupingParens []
> ,GroupingParens [SimpleGroup $ Iden "a"]]]) > ,GroupingParens [SimpleGroup $ Iden [Name "a"]]]])
> ,("select * from t group by cube(a,b)" > ,("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)" > ,("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 > where
> ms g = makeSelect {qeSelectList = [(Star,Nothing)] > ms g = makeSelect {qeSelectList = [(Star,Nothing)]
> ,qeFrom = [TRSimple "t"] > ,qeFrom = [TRSimple [Name "t"]]
> ,qeGroupBy = g} > ,qeGroupBy = g}
> randomGroupBy :: TestItem > 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. These are a few misc tests which don't fit anywhere else.
> {-# LANGUAGE OverloadedStrings #-}
> module Language.SQL.SimpleSQL.QueryExprComponents (queryExprComponentTests) where > module Language.SQL.SimpleSQL.QueryExprComponents (queryExprComponentTests) where
> import Language.SQL.SimpleSQL.TestTypes > import Language.SQL.SimpleSQL.TestTypes
@ -37,8 +36,8 @@ These are a few misc tests which don't fit anywhere else.
> where > where
> ms d = makeSelect > ms d = makeSelect
> {qeSetQuantifier = d > {qeSetQuantifier = d
> ,qeSelectList = [(Iden "a",Nothing)] > ,qeSelectList = [(Iden [Name "a"],Nothing)]
> ,qeFrom = [TRSimple "t"]} > ,qeFrom = [TRSimple [Name "t"]]}
> selectLists :: TestItem > selectLists :: TestItem
> selectLists = Group "selectLists" $ map (uncurry TestQueryExpr) > 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)]}) > makeSelect {qeSelectList = [(NumLit "1",Nothing)]})
> ,("select a" > ,("select a"
> ,makeSelect {qeSelectList = [(Iden "a",Nothing)]}) > ,makeSelect {qeSelectList = [(Iden [Name "a"],Nothing)]})
> ,("select a,b" > ,("select a,b"
> ,makeSelect {qeSelectList = [(Iden "a",Nothing) > ,makeSelect {qeSelectList = [(Iden [Name "a"],Nothing)
> ,(Iden "b",Nothing)]}) > ,(Iden [Name "b"],Nothing)]})
> ,("select 1+2,3+4" > ,("select 1+2,3+4"
> ,makeSelect {qeSelectList = > ,makeSelect {qeSelectList =
> [(BinOp (NumLit "1") "+" (NumLit "2"),Nothing) > [(BinOp (NumLit "1") [Name "+"] (NumLit "2"),Nothing)
> ,(BinOp (NumLit "3") "+" (NumLit "4"),Nothing)]}) > ,(BinOp (NumLit "3") [Name "+"] (NumLit "4"),Nothing)]})
> ,("select a as a, /*comment*/ b as b" > ,("select a as a, /*comment*/ b as b"
> ,makeSelect {qeSelectList = [(Iden "a", Just "a") > ,makeSelect {qeSelectList = [(Iden [Name "a"], Just $ Name "a")
> ,(Iden "b", Just "b")]}) > ,(Iden [Name "b"], Just $ Name "b")]})
> ,("select a a, b b" > ,("select a a, b b"
> ,makeSelect {qeSelectList = [(Iden "a", Just "a") > ,makeSelect {qeSelectList = [(Iden [Name "a"], Just $ Name "a")
> ,(Iden "b", Just "b")]}) > ,(Iden [Name "b"], Just $ Name "b")]})
> ,("select a + b * c" > ,("select a + b * c"
> ,makeSelect {qeSelectList = > ,makeSelect {qeSelectList =
> [(BinOp (Iden "a") "+" > [(BinOp (Iden [Name "a"]) [Name "+"]
> (BinOp (Iden "b") "*" (Iden "c")) > (BinOp (Iden [Name "b"]) [Name "*"] (Iden [Name "c"]))
> ,Nothing)]}) > ,Nothing)]})
> ] > ]
@ -76,47 +75,47 @@ These are a few misc tests which don't fit anywhere else.
> whereClause :: TestItem > whereClause :: TestItem
> whereClause = Group "whereClause" $ map (uncurry TestQueryExpr) > whereClause = Group "whereClause" $ map (uncurry TestQueryExpr)
> [("select a from t where a = 5" > [("select a from t where a = 5"
> ,makeSelect {qeSelectList = [(Iden "a",Nothing)] > ,makeSelect {qeSelectList = [(Iden [Name "a"],Nothing)]
> ,qeFrom = [TRSimple "t"] > ,qeFrom = [TRSimple [Name "t"]]
> ,qeWhere = Just $ BinOp (Iden "a") "=" (NumLit "5")}) > ,qeWhere = Just $ BinOp (Iden [Name "a"]) [Name "="] (NumLit "5")})
> ] > ]
> having :: TestItem > having :: TestItem
> having = Group "having" $ map (uncurry TestQueryExpr) > having = Group "having" $ map (uncurry TestQueryExpr)
> [("select a,sum(b) from t group by a having sum(b) > 5" > [("select a,sum(b) from t group by a having sum(b) > 5"
> ,makeSelect {qeSelectList = [(Iden "a",Nothing) > ,makeSelect {qeSelectList = [(Iden [Name "a"],Nothing)
> ,(App "sum" [Iden "b"],Nothing)] > ,(App [Name "sum"] [Iden [Name "b"]],Nothing)]
> ,qeFrom = [TRSimple "t"] > ,qeFrom = [TRSimple [Name "t"]]
> ,qeGroupBy = [SimpleGroup $ Iden "a"] > ,qeGroupBy = [SimpleGroup $ Iden [Name "a"]]
> ,qeHaving = Just $ BinOp (App "sum" [Iden "b"]) > ,qeHaving = Just $ BinOp (App [Name "sum"] [Iden [Name "b"]])
> ">" (NumLit "5") > [Name ">"] (NumLit "5")
> }) > })
> ] > ]
> orderBy :: TestItem > orderBy :: TestItem
> orderBy = Group "orderBy" $ map (uncurry TestQueryExpr) > orderBy = Group "orderBy" $ map (uncurry TestQueryExpr)
> [("select a from t order by a" > [("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" > ,("select a from t order by a, b"
> ,ms [SortSpec (Iden "a") DirDefault NullsOrderDefault > ,ms [SortSpec (Iden [Name "a"]) DirDefault NullsOrderDefault
> ,SortSpec (Iden "b") DirDefault NullsOrderDefault]) > ,SortSpec (Iden [Name "b"]) DirDefault NullsOrderDefault])
> ,("select a from t order by a asc" > ,("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" > ,("select a from t order by a desc, b desc"
> ,ms [SortSpec (Iden "a") Desc NullsOrderDefault > ,ms [SortSpec (Iden [Name "a"]) Desc NullsOrderDefault
> ,SortSpec (Iden "b") Desc NullsOrderDefault]) > ,SortSpec (Iden [Name "b"]) Desc NullsOrderDefault])
> ,("select a from t order by a desc nulls first, b desc nulls last" > ,("select a from t order by a desc nulls first, b desc nulls last"
> ,ms [SortSpec (Iden "a") Desc NullsFirst > ,ms [SortSpec (Iden [Name "a"]) Desc NullsFirst
> ,SortSpec (Iden "b") Desc NullsLast]) > ,SortSpec (Iden [Name "b"]) Desc NullsLast])
> ] > ]
> where > where
> ms o = makeSelect {qeSelectList = [(Iden "a",Nothing)] > ms o = makeSelect {qeSelectList = [(Iden [Name "a"],Nothing)]
> ,qeFrom = [TRSimple "t"] > ,qeFrom = [TRSimple [Name "t"]]
> ,qeOrderBy = o} > ,qeOrderBy = o}
> offsetFetch :: TestItem > offsetFetch :: TestItem
@ -136,8 +135,8 @@ These are a few misc tests which don't fit anywhere else.
> ] > ]
> where > where
> ms o l = makeSelect > ms o l = makeSelect
> {qeSelectList = [(Iden "a",Nothing)] > {qeSelectList = [(Iden [Name "a"],Nothing)]
> ,qeFrom = [TRSimple "t"] > ,qeFrom = [TRSimple [Name "t"]]
> ,qeOffset = o > ,qeOffset = o
> ,qeFetchFirst = l} > ,qeFetchFirst = l}
@ -165,33 +164,33 @@ These are a few misc tests which don't fit anywhere else.
> ] > ]
> where > where
> ms1 = makeSelect > ms1 = makeSelect
> {qeSelectList = [(Iden "a",Nothing)] > {qeSelectList = [(Iden [Name "a"],Nothing)]
> ,qeFrom = [TRSimple "t"]} > ,qeFrom = [TRSimple [Name "t"]]}
> ms2 = makeSelect > ms2 = makeSelect
> {qeSelectList = [(Iden "b",Nothing)] > {qeSelectList = [(Iden [Name "b"],Nothing)]
> ,qeFrom = [TRSimple "u"]} > ,qeFrom = [TRSimple [Name "u"]]}
> withQueries :: TestItem > withQueries :: TestItem
> withQueries = Group "with queries" $ map (uncurry TestQueryExpr) > withQueries = Group "with queries" $ map (uncurry TestQueryExpr)
> [("with u as (select a from t) select a from u" > [("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 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\ > ,("with x as (select a from t),\n\
> \ u as (select a from x)\n\ > \ u as (select a from x)\n\
> \select a from u" > \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 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 > where
> ms c t = makeSelect > ms c t = makeSelect
> {qeSelectList = [(Iden c,Nothing)] > {qeSelectList = [(Iden [Name c],Nothing)]
> ,qeFrom = [TRSimple t]} > ,qeFrom = [TRSimple [Name t]]}
> ms1 = ms "a" "t" > ms1 = ms "a" "t"
> ms2 = ms "a" "u" > ms2 = ms "a" "u"
> ms3 = ms "a" "x" > ms3 = ms "a" "x"
@ -205,5 +204,5 @@ These are a few misc tests which don't fit anywhere else.
> tables :: TestItem > tables :: TestItem
> tables = Group "tables" $ map (uncurry TestQueryExpr) > 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 The goal is to create some coverage tests to get close to supporting a
large amount of the SQL. large amount of the SQL.
> {-# LANGUAGE OverloadedStrings #-}
> module Language.SQL.SimpleSQL.SQL2003 (sql2003Tests) where > module Language.SQL.SimpleSQL.SQL2003 (sql2003Tests) where
> import Language.SQL.SimpleSQL.TestTypes > import Language.SQL.SimpleSQL.TestTypes
@ -486,7 +485,7 @@ The <quote symbol> rule consists of two immediately adjacent <quote> marks with
> ,("''" > ,("''"
> ,StringLit "") > ,StringLit "")
> ,("_francais 'français'" > ,("_francais 'français'"
> ,TypedLit (TypeName "_francais") "français") > ,TypedLit (TypeName [Name "_francais"]) "français")
> ] > ]
TODO: all the stuff with character set representations. (?) 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")
> ,("11.11E-23", NumLit "11.11E-23") > ,("11.11E-23", NumLit "11.11E-23")
> ,("+11E23", PrefixOp "+" $ NumLit "11E23") > ,("+11E23", PrefixOp [Name "+"] $ NumLit "11E23")
> ,("+11E+23", PrefixOp "+" $ NumLit "11E+23") > ,("+11E+23", PrefixOp [Name "+"] $ NumLit "11E+23")
> ,("+11E-23", PrefixOp "+" $ NumLit "11E-23") > ,("+11E-23", PrefixOp [Name "+"] $ NumLit "11E-23")
> ,("+11.11E23", PrefixOp "+" $ NumLit "11.11E23") > ,("+11.11E23", PrefixOp [Name "+"] $ NumLit "11.11E23")
> ,("+11.11E+23", PrefixOp "+" $ NumLit "11.11E+23") > ,("+11.11E+23", PrefixOp [Name "+"] $ NumLit "11.11E+23")
> ,("+11.11E-23", PrefixOp "+" $ NumLit "11.11E-23") > ,("+11.11E-23", PrefixOp [Name "+"] $ NumLit "11.11E-23")
> ,("-11E23", PrefixOp "-" $ NumLit "11E23") > ,("-11E23", PrefixOp [Name "-"] $ NumLit "11E23")
> ,("-11E+23", PrefixOp "-" $ NumLit "11E+23") > ,("-11E+23", PrefixOp [Name "-"] $ NumLit "11E+23")
> ,("-11E-23", PrefixOp "-" $ NumLit "11E-23") > ,("-11E-23", PrefixOp [Name "-"] $ NumLit "11E-23")
> ,("-11.11E23", PrefixOp "-" $ NumLit "11.11E23") > ,("-11.11E23", PrefixOp [Name "-"] $ NumLit "11.11E23")
> ,("-11.11E+23", PrefixOp "-" $ NumLit "11.11E+23") > ,("-11.11E+23", PrefixOp [Name "-"] $ NumLit "11.11E+23")
> ,("-11.11E-23", PrefixOp "-" $ NumLit "11.11E-23") > ,("-11.11E-23", PrefixOp [Name "-"] $ NumLit "11.11E-23")
> ,("11.11e23", NumLit "11.11e23") > ,("11.11e23", NumLit "11.11e23")
@ -665,7 +664,7 @@ normal typed literals
> intervalLiterals :: TestItem > intervalLiterals :: TestItem
> intervalLiterals = Group "intervalLiterals literals" $ map (uncurry TestValueExpr) > intervalLiterals = Group "intervalLiterals literals" $ map (uncurry TestValueExpr)
> [("interval '1'", TypedLit (TypeName "interval") "1") > [("interval '1'", TypedLit (TypeName [Name "interval"]) "1")
> ,("interval '1' day" > ,("interval '1' day"
> ,IntervalLit Nothing "1" (Itf "day" Nothing) Nothing) > ,IntervalLit Nothing "1" (Itf "day" Nothing) Nothing)
> ,("interval '1' day(3)" > ,("interval '1' day(3)"
@ -689,9 +688,9 @@ normal typed literals
> booleanLiterals :: TestItem > booleanLiterals :: TestItem
> booleanLiterals = Group "boolean literals" $ map (uncurry TestValueExpr) > booleanLiterals = Group "boolean literals" $ map (uncurry TestValueExpr)
> [("true", Iden "true") > [("true", Iden [Name "true"])
> ,("false", Iden "false") > ,("false", Iden [Name "false"])
> ,("unknown", Iden "unknown") > ,("unknown", Iden [Name "unknown"])
> ] > ]
so is unknown effectively an alias for null with a cast or is it 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 > -- 1111
> ,("char varying(5) character set something collate something_insensitive" > ,("char varying(5) character set something collate something_insensitive"
> ,CharTypeName [Name "char varying"] (Just 5) > ,CharTypeName [Name "char varying"] (Just 5)
> [Name "something"] (Just "something_insensitive")) > [Name "something"] (Just (Name "something_insensitive")))
> -- 0111 > -- 0111
> ,("char(5) character set something collate something_insensitive" > ,("char(5) character set something collate something_insensitive"
> ,CharTypeName [Name "char"] (Just 5) > ,CharTypeName [Name "char"] (Just 5)
> [Name "something"] (Just "something_insensitive")) > [Name "something"] (Just (Name "something_insensitive")))
> -- 1011 > -- 1011
> ,("char varying character set something collate something_insensitive" > ,("char varying character set something collate something_insensitive"
> ,CharTypeName [Name "char varying"] Nothing > ,CharTypeName [Name "char varying"] Nothing
> [Name "something"] (Just "something_insensitive")) > [Name "something"] (Just (Name "something_insensitive")))
> -- 0011 > -- 0011
> ,("char character set something collate something_insensitive" > ,("char character set something collate something_insensitive"
> ,CharTypeName [Name "char"] Nothing > ,CharTypeName [Name "char"] Nothing
> [Name "something"] (Just "something_insensitive")) > [Name "something"] (Just (Name "something_insensitive")))
> -- 1101 > -- 1101
> ,("char varying(5) collate something_insensitive" > ,("char varying(5) collate something_insensitive"
> ,CharTypeName [Name "char varying"] (Just 5) > ,CharTypeName [Name "char varying"] (Just 5)
> [] (Just "something_insensitive")) > [] (Just (Name "something_insensitive")))
> -- 0101 > -- 0101
> ,("char(5) collate something_insensitive" > ,("char(5) collate something_insensitive"
> ,CharTypeName [Name "char"] (Just 5) > ,CharTypeName [Name "char"] (Just 5)
> [] (Just "something_insensitive")) > [] (Just (Name "something_insensitive")))
> -- 1001 > -- 1001
> ,("char varying collate something_insensitive" > ,("char varying collate something_insensitive"
> ,CharTypeName [Name "char varying"] Nothing > ,CharTypeName [Name "char varying"] Nothing
> [] (Just "something_insensitive")) > [] (Just (Name "something_insensitive")))
> -- 0001 > -- 0001
> ,("char collate something_insensitive" > ,("char collate something_insensitive"
> ,CharTypeName [Name "char"] Nothing > ,CharTypeName [Name "char"] Nothing
> [] (Just "something_insensitive")) > [] (Just (Name "something_insensitive")))
> -- 1110 > -- 1110
> ,("char varying(5) character set something" > ,("char varying(5) character set something"
@ -1243,10 +1242,10 @@ for or how it works
> contextuallyTypeValueSpec :: TestItem > contextuallyTypeValueSpec :: TestItem
> contextuallyTypeValueSpec = Group "contextually typed value specification" $ map (uncurry TestValueExpr) > contextuallyTypeValueSpec = Group "contextually typed value specification" $ map (uncurry TestValueExpr)
> [("null", Iden "null") > [("null", Iden [Name "null"])
> ,("array[]", Array (Iden "array") []) > ,("array[]", Array (Iden [Name "array"]) [])
> ,("multiset[]", MultisetCtor []) > ,("multiset[]", MultisetCtor [])
> ,("default", Iden "default") > ,("default", Iden [Name "default"])
> ] > ]
todo: trigraphs? todo: trigraphs?
@ -1494,15 +1493,15 @@ TODO: reference resolution
> arrayElementReference :: TestItem > arrayElementReference :: TestItem
> arrayElementReference = Group "array element reference" $ map (uncurry TestValueExpr) > arrayElementReference = Group "array element reference" $ map (uncurry TestValueExpr)
> [("something[3]" > [("something[3]"
> ,Array (Iden "something") [NumLit "3"]) > ,Array (Iden [Name "something"]) [NumLit "3"])
> ,("(something(a))[x]" > ,("(something(a))[x]"
> ,Array (Parens (App "something" [Iden "a"])) > ,Array (Parens (App [Name "something"] [Iden [Name "a"]]))
> [Iden "x"]) > [Iden [Name "x"]])
> ,("(something(a))[x][y] " > ,("(something(a))[x][y] "
> ,Array ( > ,Array (
> Array (Parens (App "something" [Iden "a"])) > Array (Parens (App [Name "something"] [Iden [Name "a"]]))
> [Iden "x"]) > [Iden [Name "x"]])
> [Iden "y"]) > [Iden [Name "y"]])
> ] > ]
TODO: work out the precendence of the array element reference suffix 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 :: TestItem
> multisetElementReference = Group "multiset element reference" $ map (uncurry TestValueExpr) > 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 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 :: TestItem
> arrayValueConstructor = Group "array value constructor" $ map (uncurry TestValueExpr) > arrayValueConstructor = Group "array value constructor" $ map (uncurry TestValueExpr)
> [("array[1,2,3]" > [("array[1,2,3]"
> ,Array (Iden "array") > ,Array (Iden [Name "array"])
> [NumLit "1", NumLit "2", NumLit "3"]) > [NumLit "1", NumLit "2", NumLit "3"])
> ,("array[a,b,c]" > ,("array[a,b,c]"
> ,Array (Iden "array") > ,Array (Iden [Name "array"])
> [Iden "a", Iden "b", Iden "c"]) > [Iden [Name "a"], Iden [Name "b"], Iden [Name "c"]])
> ,("array(select * from t)" > ,("array(select * from t)"
> ,ArrayCtor (makeSelect > ,ArrayCtor (makeSelect
> {qeSelectList = [(Star,Nothing)] > {qeSelectList = [(Star,Nothing)]
> ,qeFrom = [TRSimple "t"]})) > ,qeFrom = [TRSimple [Name "t"]]}))
> ,("array(select * from t order by a)" > ,("array(select * from t order by a)"
> ,ArrayCtor (makeSelect > ,ArrayCtor (makeSelect
> {qeSelectList = [(Star,Nothing)] > {qeSelectList = [(Star,Nothing)]
> ,qeFrom = [TRSimple "t"] > ,qeFrom = [TRSimple [Name "t"]]
> ,qeOrderBy = [SortSpec (Iden "a") DirDefault NullsOrderDefault] })) > ,qeOrderBy = [SortSpec (Iden [Name "a"]) DirDefault NullsOrderDefault] }))
> ] > ]
== 6.37 <multiset value expression> (p286) == 6.37 <multiset value expression> (p286)
@ -1948,15 +1947,15 @@ operator is ||, same as the string concatenation operator.
> multisetValueExpression :: TestItem > multisetValueExpression :: TestItem
> multisetValueExpression = Group "multiset value expression" $ map (uncurry TestValueExpr) > multisetValueExpression = Group "multiset value expression" $ map (uncurry TestValueExpr)
> [("a multiset union b" > [("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" > ,("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" > ,("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" > ,("a multiset except b"
> ,MultisetBinOp (Iden "a") Except SQDefault (Iden "b")) > ,MultisetBinOp (Iden [Name "a"]) Except SQDefault (Iden [Name "b"]))
> ,("a multiset intersect 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) == 6.38 <multiset value function> (p289)
@ -1967,7 +1966,7 @@ operator is ||, same as the string concatenation operator.
> multisetValueFunction :: TestItem > multisetValueFunction :: TestItem
> multisetValueFunction = Group "multiset value function" $ map (uncurry TestValueExpr) > 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) == 6.39 <multiset value constructor> (p290)
@ -1991,7 +1990,7 @@ table is just syntactic sugar for multiset (why does it exist?)
> multisetValueConstructor :: TestItem > multisetValueConstructor :: TestItem
> multisetValueConstructor = Group "multiset value constructor" $ map (uncurry TestValueExpr) > 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) > ,("multiset(select * from t)", MultisetQueryCtor qe)
> ,("table(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) > groupbyClause = Group "group by clause" $ map (uncurry TestQueryExpr)
> [("select a, sum(b) from t group by a",q) > [("select a, sum(b) from t group by a",q)
> ,("select a, sum(b),c from t group by a,c" > ,("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" > ,("select a, sum(b),c from t group by a,c collate x"
> ,q1 {qeGroupBy = qeGroupBy q1 > ,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" > ,("select a, sum(b),c from t group by a,c collate x having sum(b) > 100"
> ,q1 {qeGroupBy = qeGroupBy q1 > ,q1 {qeGroupBy = qeGroupBy q1
> ++ [SimpleGroup $ Collate (Iden "c") "x"] > ++ [SimpleGroup $ Collate (Iden [Name "c"]) "x"]
> ,qeHaving = Just (BinOp (App "sum" [Iden "b"]) > ,qeHaving = Just (BinOp (App [Name "sum"] [Iden [Name "b"]])
> ">" (NumLit "100"))}) > [Name ">"] (NumLit "100"))})
> ] > ]
> where > where
> q = makeSelect > q = makeSelect
> {qeSelectList = [(Iden "a",Nothing), (App "sum" [Iden "b"],Nothing)] > {qeSelectList = [(Iden [Name "a"],Nothing), (App [Name "sum"] [Iden [Name "b"]],Nothing)]
> ,qeFrom = [TRSimple "t"] > ,qeFrom = [TRSimple [Name "t"]]
> ,qeGroupBy = [SimpleGroup $ Iden "a"] > ,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) 7.10 <having clause> (p329)
@ -2700,19 +2699,19 @@ Specify a quantified comparison.
> quantifiedComparisonPredicate = Group "quantified comparison predicate" $ map (uncurry TestValueExpr) > quantifiedComparisonPredicate = Group "quantified comparison predicate" $ map (uncurry TestValueExpr)
> [("a = any (select * from t)" > [("a = any (select * from t)"
> ,QuantifiedComparison (Iden "a") "=" CPAny qe) > ,QuantifiedComparison (Iden [Name "a"]) [Name "="] CPAny qe)
> ,("a <= some (select * from t)" > ,("a <= some (select * from t)"
> ,QuantifiedComparison (Iden "a") "<=" CPSome qe) > ,QuantifiedComparison (Iden [Name "a"]) [Name "<="] CPSome qe)
> ,("a > all (select * from t)" > ,("a > all (select * from t)"
> ,QuantifiedComparison (Iden "a") ">" CPAll qe) > ,QuantifiedComparison (Iden [Name "a"]) [Name ">"] CPAll qe)
> ,("(a,b) <> all (select * from t)" > ,("(a,b) <> all (select * from t)"
> ,QuantifiedComparison > ,QuantifiedComparison
> (SpecialOp "rowctor" [Iden "a",Iden "b"]) "<>" CPAll qe) > (SpecialOp [Name "rowctor"] [Iden [Name "a"],Iden [Name "b"]]) [Name "<>"] CPAll qe)
> ] > ]
> where > where
> qe = makeSelect > qe = makeSelect
> {qeSelectList = [(Star,Nothing)] > {qeSelectList = [(Star,Nothing)]
> ,qeFrom = [TRSimple "t"]} > ,qeFrom = [TRSimple [Name "t"]]}
== 8.9 <exists predicate> (p399) == 8.9 <exists predicate> (p399)
@ -2734,8 +2733,8 @@ Specify a test for the absence of duplicate rows
> ,SubQueryExpr SqUnique > ,SubQueryExpr SqUnique
> $ makeSelect > $ makeSelect
> {qeSelectList = [(Star,Nothing)] > {qeSelectList = [(Star,Nothing)]
> ,qeFrom = [TRSimple "t"] > ,qeFrom = [TRSimple [Name "t"]]
> ,qeWhere = Just (BinOp (Iden "a") "=" (NumLit "4")) > ,qeWhere = Just (BinOp (Iden [Name "a"]) [Name "="] (NumLit "4"))
> } > }
> )] > )]
@ -2758,17 +2757,17 @@ Specify a test for matching rows.
> matchPredicate :: TestItem > matchPredicate :: TestItem
> matchPredicate = Group "match predicate" $ map (uncurry TestValueExpr) > matchPredicate = Group "match predicate" $ map (uncurry TestValueExpr)
> [("a match (select a from t)" > [("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)" > ,("(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)" > ,("(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 > where
> qe = makeSelect > qe = makeSelect
> {qeSelectList = [(Iden "a",Nothing)] > {qeSelectList = [(Iden [Name "a"],Nothing)]
> ,qeFrom = [TRSimple "t"]} > ,qeFrom = [TRSimple [Name "t"]]}
> qea = qe {qeSelectList = qeSelectList qe ++ [(Iden "b",Nothing)]} > qea = qe {qeSelectList = qeSelectList qe ++ [(Iden [Name "b"],Nothing)]}
== 8.13 <overlaps predicate> (p405) == 8.13 <overlaps predicate> (p405)
@ -2988,7 +2987,7 @@ Specify a default collating sequence.
> collateClause :: TestItem > collateClause :: TestItem
> collateClause = Group "collate clause" $ map (uncurry TestValueExpr) > collateClause = Group "collate clause" $ map (uncurry TestValueExpr)
> [("a collate my_collation" > [("a collate my_collation"
> ,Collate (Iden "a") "my_collation")] > ,Collate (Iden [Name "a"]) "my_collation")]
10.8 <constraint name definition> and <constraint characteristics> (p501) 10.8 <constraint name definition> and <constraint characteristics> (p501)
@ -3073,19 +3072,19 @@ TODO: review sort specifications
> sortSpecificationList :: TestItem > sortSpecificationList :: TestItem
> sortSpecificationList = Group "sort specification list" $ map (uncurry TestQueryExpr) > sortSpecificationList = Group "sort specification list" $ map (uncurry TestQueryExpr)
> [("select * from t order by a" > [("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" > ,("select * from t order by a,b"
> ,qe {qeOrderBy = [SortSpec (Iden "a") DirDefault NullsOrderDefault > ,qe {qeOrderBy = [SortSpec (Iden [Name "a"]) DirDefault NullsOrderDefault
> ,SortSpec (Iden "b") DirDefault NullsOrderDefault]}) > ,SortSpec (Iden [Name "b"]) DirDefault NullsOrderDefault]})
> ,("select * from t order by a asc,b" > ,("select * from t order by a asc,b"
> ,qe {qeOrderBy = [SortSpec (Iden "a") Asc NullsOrderDefault > ,qe {qeOrderBy = [SortSpec (Iden [Name "a"]) Asc NullsOrderDefault
> ,SortSpec (Iden "b") DirDefault NullsOrderDefault]}) > ,SortSpec (Iden [Name "b"]) DirDefault NullsOrderDefault]})
> ,("select * from t order by a desc,b" > ,("select * from t order by a desc,b"
> ,qe {qeOrderBy = [SortSpec (Iden "a") Desc NullsOrderDefault > ,qe {qeOrderBy = [SortSpec (Iden [Name "a"]) Desc NullsOrderDefault
> ,SortSpec (Iden "b") DirDefault NullsOrderDefault]}) > ,SortSpec (Iden [Name "b"]) DirDefault NullsOrderDefault]})
> ,("select * from t order by a collate x desc,b" > ,("select * from t order by a collate x desc,b"
> ,qe {qeOrderBy = [SortSpec (Collate (Iden "a") "x") Desc NullsOrderDefault > ,qe {qeOrderBy = [SortSpec (Collate (Iden [Name "a"]) "x") Desc NullsOrderDefault
> ,SortSpec (Iden "b") DirDefault NullsOrderDefault]}) > ,SortSpec (Iden [Name "b"]) DirDefault NullsOrderDefault]})
> ,("select * from t order by 1,2" > ,("select * from t order by 1,2"
> ,qe {qeOrderBy = [SortSpec (NumLit "1") DirDefault NullsOrderDefault > ,qe {qeOrderBy = [SortSpec (NumLit "1") DirDefault NullsOrderDefault
> ,SortSpec (NumLit "2") DirDefault NullsOrderDefault]}) > ,SortSpec (NumLit "2") DirDefault NullsOrderDefault]})
@ -3093,7 +3092,7 @@ TODO: review sort specifications
> where > where
> qe = makeSelect > qe = makeSelect
> {qeSelectList = [(Star,Nothing)] > {qeSelectList = [(Star,Nothing)]
> ,qeFrom = [TRSimple "t"]} > ,qeFrom = [TRSimple [Name "t"]]}
TODO: what happened to the collation in order by? TODO: what happened to the collation in order by?
Answer: sort used to be a column reference with an optional 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 These are the tests for parsing focusing on the from part of query
expression expression
> {-# LANGUAGE OverloadedStrings #-}
> module Language.SQL.SimpleSQL.TableRefs (tableRefTests) where > module Language.SQL.SimpleSQL.TableRefs (tableRefTests) where
> import Language.SQL.SimpleSQL.TestTypes > import Language.SQL.SimpleSQL.TestTypes
@ -12,96 +11,95 @@ expression
> tableRefTests :: TestItem > tableRefTests :: TestItem
> tableRefTests = Group "tableRefTests" $ map (uncurry TestQueryExpr) > tableRefTests = Group "tableRefTests" $ map (uncurry TestQueryExpr)
> [("select a from t" > [("select a from t"
> ,ms [TRSimple "t"]) > ,ms [TRSimple [Name "t"]])
> ,("select a from f(a)" > ,("select a from f(a)"
> ,ms [TRFunction "f" [Iden "a"]]) > ,ms [TRFunction [Name "f"] [Iden [Name "a"]]])
> ,("select a from t,u" > ,("select a from t,u"
> ,ms [TRSimple "t", TRSimple "u"]) > ,ms [TRSimple [Name "t"], TRSimple [Name "u"]])
> ,("select a from s.t" > ,("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 these lateral queries make no sense but the syntax is valid
> ,("select a from lateral a" > ,("select a from lateral a"
> ,ms [TRLateral $ TRSimple "a"]) > ,ms [TRLateral $ TRSimple [Name "a"]])
> ,("select a from lateral a,b" > ,("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" > ,("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" > ,("select a from a natural join lateral b"
> ,ms [TRJoin (TRSimple "a") True JInner > ,ms [TRJoin (TRSimple [Name "a"]) True JInner
> (TRLateral $ TRSimple "b") > (TRLateral $ TRSimple [Name "b"])
> Nothing]) > Nothing])
> -- the lateral binds on the outside of the join which is incorrect
> ,("select a from lateral a natural join lateral b" > ,("select a from lateral a natural join lateral b"
> ,ms [TRJoin (TRLateral $ TRSimple "a") True JInner > ,ms [TRJoin (TRLateral $ TRSimple [Name "a"]) True JInner
> (TRLateral $ TRSimple "b") > (TRLateral $ TRSimple [Name "b"])
> Nothing]) > Nothing])
> ,("select a from t inner join u on expr" > ,("select a from t inner join u on expr"
> ,ms [TRJoin (TRSimple "t") False JInner (TRSimple "u") > ,ms [TRJoin (TRSimple [Name "t"]) False JInner (TRSimple [Name "u"])
> (Just $ JoinOn $ Iden "expr")]) > (Just $ JoinOn $ Iden [Name "expr"])])
> ,("select a from t join u on expr" > ,("select a from t join u on expr"
> ,ms [TRJoin (TRSimple "t") False JInner (TRSimple "u") > ,ms [TRJoin (TRSimple [Name "t"]) False JInner (TRSimple [Name "u"])
> (Just $ JoinOn $ Iden "expr")]) > (Just $ JoinOn $ Iden [Name "expr"])])
> ,("select a from t left join u on expr" > ,("select a from t left join u on expr"
> ,ms [TRJoin (TRSimple "t") False JLeft (TRSimple "u") > ,ms [TRJoin (TRSimple [Name "t"]) False JLeft (TRSimple [Name "u"])
> (Just $ JoinOn $ Iden "expr")]) > (Just $ JoinOn $ Iden [Name "expr"])])
> ,("select a from t right join u on expr" > ,("select a from t right join u on expr"
> ,ms [TRJoin (TRSimple "t") False JRight (TRSimple "u") > ,ms [TRJoin (TRSimple [Name "t"]) False JRight (TRSimple [Name "u"])
> (Just $ JoinOn $ Iden "expr")]) > (Just $ JoinOn $ Iden [Name "expr"])])
> ,("select a from t full join u on expr" > ,("select a from t full join u on expr"
> ,ms [TRJoin (TRSimple "t") False JFull (TRSimple "u") > ,ms [TRJoin (TRSimple [Name "t"]) False JFull (TRSimple [Name "u"])
> (Just $ JoinOn $ Iden "expr")]) > (Just $ JoinOn $ Iden [Name "expr"])])
> ,("select a from t cross join u" > ,("select a from t cross join u"
> ,ms [TRJoin (TRSimple "t") False > ,ms [TRJoin (TRSimple [Name "t"]) False
> JCross (TRSimple "u") Nothing]) > JCross (TRSimple [Name "u"]) Nothing])
> ,("select a from t natural inner join u" > ,("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]) > Nothing])
> ,("select a from t inner join u using(a,b)" > ,("select a from t inner join u using(a,b)"
> ,ms [TRJoin (TRSimple "t") False JInner (TRSimple "u") > ,ms [TRJoin (TRSimple [Name "t"]) False JInner (TRSimple [Name "u"])
> (Just $ JoinUsing ["a", "b"])]) > (Just $ JoinUsing [Name "a", Name "b"])])
> ,("select a from (select a from t)" > ,("select a from (select a from t)"
> ,ms [TRQueryExpr $ ms [TRSimple "t"]]) > ,ms [TRQueryExpr $ ms [TRSimple [Name "t"]]])
> ,("select a from t as u" > ,("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" > ,("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)" > ,("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" > ,("select a from (t cross join u) as u"
> ,ms [TRAlias (TRParens $ > ,ms [TRAlias (TRParens $
> TRJoin (TRSimple "t") False JCross (TRSimple "u") Nothing) > TRJoin (TRSimple [Name "t"]) False JCross (TRSimple [Name "u"]) Nothing)
> (Alias "u" Nothing)]) > (Alias (Name "u") Nothing)])
> -- todo: not sure if the associativity is correct > -- todo: not sure if the associativity is correct
> ,("select a from t cross join u cross join v", > ,("select a from t cross join u cross join v",
> ms [TRJoin > ms [TRJoin
> (TRJoin (TRSimple "t") False > (TRJoin (TRSimple [Name "t"]) False
> JCross (TRSimple "u") Nothing) > JCross (TRSimple [Name "u"]) Nothing)
> False JCross (TRSimple "v") Nothing]) > False JCross (TRSimple [Name "v"]) Nothing])
> ] > ]
> where > where
> ms f = makeSelect {qeSelectList = [(Iden "a",Nothing)] > ms f = makeSelect {qeSelectList = [(Iden [Name "a"],Nothing)]
> ,qeFrom = f} > ,qeFrom = f}

View file

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