mirror of
https://github.com/unisonweb/unison.git
synced 2024-11-10 01:16:12 +03:00
Add test harness for Parser.Error
This commit is contained in:
parent
6e98189fea
commit
f6f8b108f1
@ -3,9 +3,11 @@
|
||||
module Unison.Test.FileParser where
|
||||
|
||||
import EasyTest
|
||||
import Data.List (uncons)
|
||||
import Data.Set (elems)
|
||||
import qualified Text.Megaparsec.Error as MPE
|
||||
import Unison.FileParser (file)
|
||||
import Unison.Parser
|
||||
import qualified Unison.Parser as Parser
|
||||
import qualified Unison.Parser as P
|
||||
import Unison.Parsers (unsafeGetRightFrom, unsafeReadAndParseFile')
|
||||
import qualified Unison.Reference as R
|
||||
import qualified Unison.Referent as Referent
|
||||
@ -13,6 +15,7 @@ module Unison.Test.FileParser where
|
||||
import Unison.UnisonFile (UnisonFile)
|
||||
import qualified Unison.Names as Names
|
||||
import Unison.Names (Names)
|
||||
import Unison.Var (Var)
|
||||
|
||||
test1 :: Test ()
|
||||
test1 = scope "fileparser.test1" . tests . map parses $
|
||||
@ -53,6 +56,18 @@ module Unison.Test.FileParser where
|
||||
test :: Test ()
|
||||
test = test1
|
||||
|
||||
expectFileParseFailure :: Var e => String -> (P.Error e -> Test ()) -> Test ()
|
||||
expectFileParseFailure s expectation = scope s $ do
|
||||
let result = P.run (P.rootFile file) s builtins
|
||||
case result of
|
||||
Right _ -> crash "Parser succeeded"
|
||||
Left (MPE.FancyError _ sets) ->
|
||||
case (fmap (fst) . uncons . elems) sets of
|
||||
Just (MPE.ErrorCustom e) -> expectation e
|
||||
Just _ -> crash "Error encountered was not custom"
|
||||
Nothing -> crash "No error found"
|
||||
Left _ -> crash "Parser failed with an error which was not fancy"
|
||||
|
||||
builtins :: Names
|
||||
builtins = Names.fromTerms
|
||||
[ ("Pair" , Referent.Con (R.Builtin "Pair") 0)
|
||||
@ -62,7 +77,7 @@ module Unison.Test.FileParser where
|
||||
parses :: String -> Test ()
|
||||
parses s = scope s $ do
|
||||
let
|
||||
p :: UnisonFile Symbol Ann
|
||||
p :: UnisonFile Symbol P.Ann
|
||||
!p = snd . unsafeGetRightFrom s $
|
||||
Unison.Parser.run (Parser.rootFile file) s builtins
|
||||
P.run (P.rootFile file) s builtins
|
||||
pure p >> ok
|
||||
|
Loading…
Reference in New Issue
Block a user