From 56e0d7afe77d53ebb213b2aba686143f94781096 Mon Sep 17 00:00:00 2001 From: parsonsmatt Date: Mon, 29 Mar 2021 09:46:20 -0600 Subject: [PATCH] it passed? --- test/PostgreSQL/Test.hs | 77 ++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/test/PostgreSQL/Test.hs b/test/PostgreSQL/Test.hs index 6815157..985ac7b 100644 --- a/test/PostgreSQL/Test.hs +++ b/test/PostgreSQL/Test.hs @@ -898,41 +898,48 @@ testConcatenationOperator = testMinusOperator :: Spec testMinusOperator = - describe "Minus Operator" $ do - it "creates sane SQL" $ - createSaneSQL @JSONValue - (jsonbVal (object ["a" .= False, "b" .= True]) JSON.-. "a") - "SELECT (? - ?)\nFROM \"Json\"\n" - [ PersistLiteralEscaped "{\"a\":false,\"b\":true}" - , PersistText "a" ] - it "creates sane SQL (chained)" $ do - let obj = object ["a" .= [object ["b" .= True]]] - createSaneSQL @JSONValue - (jsonbVal obj ->. "a" JSON.-. 0) - "SELECT ((? -> ?) - ?)\nFROM \"Json\"\n" - [ PersistLiteralEscaped "{\"a\":[{\"b\":true}]}" - , PersistText "a" - , PersistInt64 0 ] - it "works as expected" $ run $ do - x <- selectJSON $ \v -> do - where_ $ v @>. jsonbVal (toJSON ([] :: [Int])) - where_ $ v JSON.-. 0 @>. jsonbVal (toJSON [Bool True]) - y <- selectJSON $ \v -> do - where_ $ v @>. jsonbVal (toJSON ([] :: [Int])) - where_ $ v JSON.-. (-1) @>. jsonbVal (toJSON [Null]) - z <- selectJSON_ $ \v -> v JSON.-. "b" ?&. ["a", "b"] - w <- selectJSON_ $ \v -> do - v JSON.-. "test" @>. jsonbVal (toJSON [String "test"]) - liftIO $ length x `shouldBe` 2 - liftIO $ length y `shouldBe` 1 - liftIO $ length z `shouldBe` 0 - liftIO $ length w `shouldBe` 0 - sqlFailWith "22023" $ selectJSONwhere $ \v -> - v JSON.-. 0 @>. jsonbVal (toJSON ([] :: [Int])) - where selectJSON_ f = selectJSON $ \v -> do - where_ $ v @>. jsonbVal (object []) - ||. v @>. jsonbVal (toJSON ([] :: [Int])) - where_ $ f v + fdescribe "Minus Operator" $ do + it "creates sane SQL" $ do + let obj = object ["a" .= False, "b" .= True] + encoded = BSL.toStrict $ encode obj + createSaneSQL @JSONValue + (jsonbVal obj JSON.-. "a") + "SELECT (? - ?)\nFROM \"Json\"\n" + [ PersistLiteralEscaped encoded + , PersistText "a" + ] + it "creates sane SQL (chained)" $ do + let obj = object ["a" .= [object ["b" .= True]]] + encoded = BSL.toStrict $ encode obj + createSaneSQL @JSONValue + (jsonbVal obj ->. "a" JSON.-. 0) + "SELECT ((? -> ?) - ?)\nFROM \"Json\"\n" + [ PersistLiteralEscaped encoded + , PersistText "a" + , PersistInt64 0 + ] + it "works as expected" $ run $ do + x <- selectJSON $ \v -> do + where_ $ v @>. jsonbVal (toJSON ([] :: [Int])) + where_ $ v JSON.-. 0 @>. jsonbVal (toJSON [Bool True]) + y <- selectJSON $ \v -> do + where_ $ v @>. jsonbVal (toJSON ([] :: [Int])) + where_ $ v JSON.-. (-1) @>. jsonbVal (toJSON [Null]) + z <- selectJSON_ $ \v -> v JSON.-. "b" ?&. ["a", "b"] + w <- selectJSON_ $ \v -> do + v JSON.-. "test" @>. jsonbVal (toJSON [String "test"]) + liftIO $ length x `shouldBe` 2 + liftIO $ length y `shouldBe` 1 + liftIO $ length z `shouldBe` 0 + liftIO $ length w `shouldBe` 0 + sqlFailWith "22023" $ selectJSONwhere $ \v -> + v JSON.-. 0 @>. jsonbVal (toJSON ([] :: [Int])) + where + selectJSON_ f = selectJSON $ \v -> do + where_ + $ v @>. jsonbVal (object []) + ||. v @>. jsonbVal (toJSON ([] :: [Int])) + where_ $ f v testMinusOperatorV10 :: Spec testMinusOperatorV10 =