Hspec error for lexer

This commit is contained in:
Igor Ranieri 2025-09-21 09:54:45 +02:00
parent 68f9b88c83
commit c299af1c06

View file

@ -3,16 +3,15 @@
import Test.Hspec import Test.Hspec
import Data.String (IsString (..))
import Data.Text (Text)
import Text.Parsec.Pos
import Control.Monad (zipWithM_)
import Identifier (Identifier) import Identifier (Identifier)
import Lexer import Lexer
import Parser import Parser
import Types import Types
import Data.String (IsString (..))
import Data.Text (Text)
import Text.Parsec.Pos
shouldParseTo :: Text -> DocMarkup mod Identifier -> Expectation shouldParseTo :: Text -> DocMarkup mod Identifier -> Expectation
shouldParseTo input ast = parseText input `shouldBe` ast shouldParseTo input ast = parseText input `shouldBe` ast
@ -38,11 +37,6 @@ shouldLexTo :: String -> [(Int, Int, Token)] -> Expectation
shouldLexTo input expected = shouldLexTo input expected =
case lexer input of case lexer input of
Right tokens -> do Right tokens -> do
length tokens `shouldBe` length expected let actual = map (\(pos, tok) -> (sourceLine pos, sourceColumn pos, tok)) tokens
zipWithM_ checkToken tokens expected actual `shouldBe` expected
Left err -> expectationFailure $ "Parse error: " <> show err Left err -> expectationFailure $ "Parse error: " <> show err
where
checkToken (pos, tok) (line, col, expectedTok) = do
tok `shouldBe` expectedTok
sourceLine pos `shouldBe` line
sourceColumn pos `shouldBe` col