module Hspec.Utils ( module Test.Hspec , module Test.Tasty , module Test.Tasty.Hspec , ($), (.) , Functor(..), (<$>) , Applicative(..) , Monad(..), (=<<) , Semigroup(..) , IO ) where import Data.Bool import Data.Eq (Eq(..)) import Data.Ord (Ord(..)) import Data.Semigroup (Semigroup(..)) import Control.Applicative (Applicative(..)) import Control.Monad (Monad(..), (=<<)) import Data.Either (Either(..)) import Data.Function (($), (.), id) import Data.Functor (Functor(..), (<$>)) import Data.Proxy (Proxy(..)) import Data.Semigroup (Semigroup(..)) import System.IO (IO) import Test.Hspec import Test.Tasty import Test.Tasty.Hspec import Text.Show (Show(..), showString, showParen, ShowS) import Data.String (String) import Symantic.HTTP import Symantic.HTTP.Server import qualified Data.Map.Strict as Map import qualified Data.Map.Merge.Strict as Map import Data.Function (const) import qualified Debug.Trace as Dbg import qualified Data.Text as Text instance (repr ~ Server) => Show (Router repr a b) where showsPrec p = \case Router_Any{} -> showString "X" Router_Map ms -> showParen (p>10) $ showString "map [" . go (Map.toList ms) . showString "]" where go :: forall a k. [(PathSegment, RouterUnion repr a k)] -> ShowS go ((n, RouterUnion _b2a r):xs) = (showParen True $ showString (show n<>", ") . showsPrec 0 r) . case xs of [] -> id _ -> showString ", " . go xs Router_Seg s -> showsPrec 10 s Router_Cat x y -> showParen (p>4) $ showsPrec 4 x . showString " <.> " . showsPrec 4 y Router_Alt x y -> showParen (p>3) $ showsPrec 3 x . showString " " . showsPrec 3 y Router_Cap n -> showString (":"<>n) Router_Caps cs -> showParen (p>10) $ showString "cap [" . go cs . showString "]" where go :: Captures (Router repr) cs k -> ShowS go (Captures0 a n r) = showParen True $ showString (":"<>n<>", ") . showsPrec 0 r go (Captures2 x y) = go x . showString ", " . go y