-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Slightly better error messages.
Instead of internal names, we now have descriptions of each token type.
- Loading branch information
Showing
11 changed files
with
370 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# OPTIONS_GHC -Wno-orphans #-} | ||
module Language.Cimple.DescribeAstSpec where | ||
|
||
import Test.Hspec (Spec, describe, it, shouldBe, | ||
shouldNotContain) | ||
|
||
import qualified Data.List.Extra as List | ||
import Data.Text (Text) | ||
import qualified Data.Text as Text | ||
import Language.Cimple.IO (parseExpr, parseStmt, parseText) | ||
import Language.CimpleSpec (sampleToken) | ||
import Test.QuickCheck (Testable (property)) | ||
|
||
|
||
expected :: (Text -> Either String a) -> Text -> String | ||
expected parse code = | ||
case parse code of | ||
Left err -> snd $ List.breakOn "expected " err | ||
Right _ -> "" | ||
|
||
|
||
spec :: Spec | ||
spec = do | ||
describe "error messages" $ do | ||
it "has useful suggestions" $ do | ||
parseText "int a() {}" `shouldBe` Left | ||
":1:10: Parse error near right brace: \"}\"; expected statement or declaration" | ||
|
||
expected parseText "Beep Boop" `shouldBe` | ||
"expected variable name" | ||
|
||
expected parseText "const *a() {}" `shouldBe` | ||
"expected type specifier" | ||
|
||
expected parseText "int a() { int }" `shouldBe` | ||
"expected variable name" | ||
|
||
it "has suggestions for any sequence of tokens in top level" $ do | ||
property $ \tokens -> | ||
expected parseText (Text.intercalate " " (map sampleToken tokens)) `shouldNotContain` | ||
"expected one of" | ||
|
||
it "has suggestions for any sequence of tokens in expressions" $ do | ||
property $ \tokens -> | ||
expected parseExpr (Text.intercalate " " (map sampleToken tokens)) `shouldNotContain` | ||
"expected one of" | ||
|
||
it "has suggestions for any sequence of tokens in statements" $ do | ||
property $ \tokens -> | ||
expected parseStmt (Text.intercalate " " (map sampleToken tokens)) `shouldNotContain` | ||
"expected one of" | ||
|
||
it "does not support multiple declarators per declaration" $ do | ||
let ast = parseText "int main() { int a, b; }" | ||
ast `shouldBe` Left | ||
":1:19: Parse error near comma: \",\"; expected '=' or ';'" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.