Skip to content

Commit 2b10e36

Browse files
committed
greskell server-test: add spec_binder
1 parent 638a057 commit 2b10e36

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

greskell/test/ServerTest.hs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import Test.Hspec
2323
import Data.Greskell.AsIterator (AsIterator (IteratorItem))
2424
import Data.Greskell.AsLabel (AsLabel (..), lookupAsM)
2525
import qualified Data.Greskell.AsLabel as As
26-
import Data.Greskell.Binder (newBind, runBinder)
26+
import Data.Greskell.Binder (Binder, newBind, runBinder)
2727
import Data.Greskell.Extra (gWhenEmptyInput)
2828
import Data.Greskell.GMap (GMapEntry, unGMapEntry)
2929
import Data.Greskell.Graph (AEdge (..), AProperty (..), AVertex (..),
@@ -60,6 +60,7 @@ main = hspec spec
6060
spec :: Spec
6161
spec = withEnv $ do
6262
spec_basics
63+
spec_binder
6364
spec_comparator
6465
spec_predicate
6566
spec_T
@@ -155,6 +156,21 @@ checkOne :: (AsIterator a, b ~ IteratorItem a, FromGraphSON b, Eq b, Show b)
155156
=> Greskell a -> b -> SpecWith (String, Int)
156157
checkOne input expected = checkRaw input [expected]
157158

159+
checkBinder :: (AsIterator a, b ~ IteratorItem a, FromGraphSON b, Eq b, Show b)
160+
=> [b] -> Binder (Greskell a) -> SpecWith (String, Int)
161+
checkBinder expected binder = specify label $ withClient $ \client -> do
162+
got <- WS.slurpResults =<< WS.submit client script (Just binding)
163+
got `shouldBe` V.fromList expected
164+
where
165+
(script, binding) = runBinder binder
166+
label = (unpack $ toGremlin script) ++ " with " ++ show binding
167+
168+
spec_binder :: SpecWith (String, Int)
169+
spec_binder = describe "server and Binder" $ do
170+
checkBinder [100 :: Int] $ newBind (100 :: Int)
171+
checkBinder [110 :: Int] $ do
172+
b <- newBind (100 :: Int)
173+
return $ b + (10 :: Greskell Int)
158174

159175
spec_comparator :: SpecWith (String,Int)
160176
spec_comparator = do

0 commit comments

Comments
 (0)