packages feed

parser-combinators-tests 1.0.3 → 1.1.0

raw patch · 2 files changed

+19/−4 lines, 2 filesdep ~parser-combinators

Dependency ranges changed: parser-combinators

Files

parser-combinators-tests.cabal view
@@ -1,5 +1,5 @@ name:                 parser-combinators-tests-version:              1.0.3+version:              1.1.0 cabal-version:        1.18 tested-with:          GHC==8.0.2, GHC==8.2.2, GHC==8.4.4, GHC==8.6.5 license:              BSD3@@ -34,7 +34,7 @@                     , hspec-megaparsec >= 2.0 && < 3.0                     , megaparsec       >= 7.0 && < 8.0                     , megaparsec-tests >= 7.0 && < 8.0-                    , parser-combinators == 1.0.2+                    , parser-combinators == 1.1.0   other-modules:      Control.Applicative.CombinatorsSpec                     , Control.Applicative.PermutationsSpec                     , Control.Monad.Combinators.ExprSpec
tests/Control/Monad/Combinators/ExprSpec.hs view
@@ -3,6 +3,7 @@  module Control.Monad.Combinators.ExprSpec (spec) where +import Control.Monad import Control.Monad.Combinators.Expr import Data.Monoid ((<>)) import Test.Hspec@@ -51,6 +52,7 @@                    , etok '+'                    , etok '-'                    , etok '/'+                   , etok '?'                    , etok '^'                    ]) @@ -64,6 +66,7 @@   | Pro Node Node -- ^ product   | Div Node Node -- ^ division   | Exp Node Node -- ^ exponentiation+  | If Node Node Node -- ^ ternary conditional operator     deriving (Eq, Show)  instance Enum Node where@@ -76,6 +79,7 @@   fromEnum (Div _ _) = 2   fromEnum (Sum _ _) = 3   fromEnum (Sub _ _) = 3+  fromEnum (If _ _ _ ) = 4   toEnum   _         = error "Oops!"  instance Ord Node where@@ -91,6 +95,7 @@ showNode n@(Pro x y) = showGT n x ++ " * " ++ showGE n y showNode n@(Div x y) = showGT n x ++ " / " ++ showGE n y showNode n@(Exp x y) = showGE n x ++ " ^ " ++ showGT n y+showNode n@(If c x y) = showGE n c ++ " ? " ++ showGT n x ++ " : " ++ showGT n y  showGT :: Node -> Node -> String showGT parent node = (if node > parent then showCmp else showNode) node@@ -121,7 +126,15 @@  arbitraryN2 :: Int -> Gen Node arbitraryN2 0 = Val . getNonNegative <$> arbitrary-arbitraryN2 n = elements [Sum,Sub,Pro,Div,Exp] <*> leaf <*> leaf+arbitraryN2 n =+  (join . elements)+    [ pure Sum+    , pure Sub+    , pure Pro+    , pure Div+    , pure Exp+    , If <$> leaf+    ] <*> leaf <*> leaf   where     leaf = arbitraryN0 (n `div` 2) @@ -157,4 +170,6 @@   , [ InfixL  (Pro <$ symbol "*")     , InfixL  (Div <$ symbol "/") ]   , [ InfixL  (Sum <$ symbol "+")-    , InfixL  (Sub <$ symbol "-")] ]+    , InfixL  (Sub <$ symbol "-") ]+  , [ TernR   ((If <$ symbol ":") <$ symbol "?") ]+  ]