Skip to content

Commit

Permalink
fix failed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangjunphy committed Jun 12, 2024
1 parent 961c926 commit 0fa242c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/Util/Graph.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module Util.Graph
, build
, strictlyDominate
, strictlyPostDominate
, traverseM_
) where

import Control.Lens ((%=))
Expand Down
22 changes: 13 additions & 9 deletions test/LexerSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Data.Either (isLeft)
import Lexer
import qualified Util.SourceLoc as SL
import Test.Hspec
import Types

spec :: Spec
spec = do
Expand All @@ -26,23 +27,26 @@ spec = do
scanFunction
scannerLoc

getTokens :: [Either String (SL.Located Token)] -> [Token]
getTokens = fmap $ \(Right (SL.LocatedAt _ t)) -> t
getTokens :: Either [CompileError] [SL.Located Token] -> [Token]
getTokens (Left _) = []
getTokens (Right toks) = fmap SL.unLoc toks

scanTokens :: ByteString -> [Token]
scanTokens inp = getTokens $ scan inp

compareTokenStream :: ByteString -> [Token] -> Bool
compareTokenStream inp toks =
let res = scan inp
in getTokens res == toks
compareTokenStream inp toks = scanTokens inp == toks

shouldErrorOut :: ByteString -> Bool
shouldErrorOut inp =
let res = scan inp
in length res == 1 && isLeft (head res)
case scan inp of
Right _ -> False
Left errs -> not $ null errs

checkLoc :: ByteString -> Int -> SL.Range -> Bool
checkLoc inp idxEle range =
let res = scan inp
(Right (SL.LocatedAt pos _)) = res !! idxEle
let (Right res) = scan inp
(SL.LocatedAt pos _) = res !! idxEle
in pos == range

scanSingleElement :: SpecWith ()
Expand Down
2 changes: 1 addition & 1 deletion test/SemanticSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ typeCheckSpec = do
in view #tpe expr
pred program =
let (Right p) = Parser.parse program
(Right (AST.ASTRoot imports vars methods, _, st)) = Semantic.runSemanticAnalysis p
(Right (AST.ASTRoot imports vars methods, st)) = Semantic.analyze p
stmts = view #stmts $ view #block $ head methods
AST.Statement (AST.AssignStmt (AST.Assignment _ _ (Just expr) _)) _ = head stmts
tpe = view #tpe expr
Expand Down

0 comments on commit 0fa242c

Please sign in to comment.