Skip to content

Commit

Permalink
Fix patterns in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPenner committed Aug 9, 2022
1 parent 6f73ca8 commit b0345a3
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
9 changes: 5 additions & 4 deletions parser-typechecker/tests/Unison/Test/DataDeclaration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

module Unison.Test.DataDeclaration where

import Data.Map (Map, (!))
import Data.Map ((!))
import qualified Data.Map as Map
import Data.Text.Encoding (encodeUtf8)
import EasyTest
import Text.RawString.QQ
import qualified U.Util.Hash as Hash
Expand All @@ -21,11 +20,13 @@ import qualified Unison.Type as Type
import Unison.UnisonFile (UnisonFile (..))
import qualified Unison.Var as Var
import qualified Unison.Var.RefNamed as Var
import Unison.Prelude
import Data.Bifunctor (second)

test :: Test ()
test =
scope "datadeclaration" $
let Right hashes = Hashing.hashDataDecls . (snd <$>) . dataDeclarationsId $ file
let hashes = fromRight (error "Expected Right") $ Hashing.hashDataDecls . (snd <$>) . dataDeclarationsId $ file
hashMap = Map.fromList $ fmap (\(a, b, _) -> (a, b)) hashes
hashOf k = Map.lookup (Var.named k) hashMap
in tests
Expand Down Expand Up @@ -113,7 +114,7 @@ unhashComponentTest =
component = Map.singleton listRef (Right listDecl)
component' :: Map R.Id (Symbol, Decl Symbol ())
component' = DD.unhashComponent component
(listVar, Right listDecl') = component' ! listRef
(listVar, listDecl') = second (fromRight (error "Expected Right")) $ component' ! listRef
listType' = var listVar
constructors = Map.fromList $ DD.constructors listDecl'
nilType' = constructors ! nil
Expand Down
2 changes: 1 addition & 1 deletion parser-typechecker/tests/Unison/Test/TermParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ parses = parseWith TP.term

parseWith :: P Symbol a -> String -> Test ()
parseWith p s = scope (join . take 1 $ lines s) $
case Ps.parse @ Symbol p s Common.parsingEnv of
case Ps.parse @Symbol p s Common.parsingEnv of
Left e -> do
note $ renderParseErrorAsANSI 60 s e
crash $ renderParseErrorAsANSI 60 s e
Expand Down
10 changes: 6 additions & 4 deletions parser-typechecker/tests/Unison/Test/Typechecker/TypeError.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ noYieldsError s ex = not $ yieldsError s ex

yieldsError :: forall a. String -> ErrorExtractor Symbol Ann a -> Bool
yieldsError s ex =
let Result notes (Just _) = Common.parseAndSynthesizeAsFile [] "> test" s
notes' :: [C.ErrorNote Symbol Ann]
notes' = [n | Result.TypeError n <- toList notes]
in any (isJust . Ex.extract ex) notes'
case Common.parseAndSynthesizeAsFile [] "> test" s of
Result notes (Just _) ->
let notes' :: [C.ErrorNote Symbol Ann]
notes' = [n | Result.TypeError n <- toList notes]
in any (isJust . Ex.extract ex) notes'
_ -> error "yieldsError: Failed to parse file"
2 changes: 1 addition & 1 deletion parser-typechecker/tests/Unison/Test/UnisonSources.hs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ resultTest rt uf filepath = do
case term of
Right tm -> do
-- compare the the watch expression from the .u with the expr in .ur
let [watchResult] = view _5 <$> Map.elems watches
let watchResult = head (view _5 <$> Map.elems watches)
tm' = Term.letRec' False bindings watchResult
-- note . show $ tm'
-- note . show $ Term.amap (const ()) tm
Expand Down
2 changes: 1 addition & 1 deletion parser-typechecker/tests/Unison/Test/Util/Bytes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test =
b1 <- BS.pack <$> replicateM n word8
b2 <- BS.pack <$> replicateM m word8
b3 <- BS.pack <$> replicateM o word8
let [b1s, b2s, b3s] = Bytes.fromArray <$> [b1, b2, b3]
let (b1s, b2s, b3s) = (Bytes.fromArray b1, Bytes.fromArray b2, Bytes.fromArray b3)
scope "associtivity" . expect' $
b1s <> (b2s <> b3s) == (b1s <> b2s) <> b3s
scope "<>" . expect' $
Expand Down
2 changes: 1 addition & 1 deletion parser-typechecker/tests/Unison/Test/Util/Text.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ test =
t1 <- T.pack <$> replicateM n ch
t2 <- T.pack <$> replicateM m ch
t3 <- T.pack <$> replicateM o ch
let [t1s, t2s, t3s] = Text.fromText <$> [t1, t2, t3]
let (t1s, t2s, t3s) = (Text.fromText t1, Text.fromText t2, Text.fromText t3)
scope "associativity" $ do
-- note $ show (t1s, t2s, t3s)
expect' $ t1s <> (t2s <> t3s) == (t1s <> t2s) <> t3s
Expand Down

0 comments on commit b0345a3

Please sign in to comment.