test for dissalow multiline string without newline

This commit is contained in:
Gaute Berge 2023-10-25 15:41:53 +02:00
parent a8514bd7d7
commit dda71684bb
2 changed files with 16 additions and 3 deletions

View File

@ -196,7 +196,8 @@ data CustomType
-- EXPRESSIONS
data Expr
= Let Let Row Col
= ExpressionBadEnd Row Col
| Let Let Row Col
| Case Case Row Col
| If If Row Col
| Parenthesized Parenthesized Row Col
@ -2598,6 +2599,8 @@ isWithin desiredNode context =
toExprReport :: Code.Source -> Context -> Expr -> Row -> Col -> Report.Report
toExprReport source context expr startRow startCol =
case expr of
ExpressionBadEnd row col ->
toWeirdEndReport source row col
Let let_ row col ->
toLetReport source context let_ row col
Case case_ row col ->

View File

@ -7,9 +7,14 @@ import Data.ByteString qualified as BS
import Data.Utf8 qualified as Utf8
import Helpers.Instances ()
import Helpers.Parse qualified as Helpers
import Parse.Expression qualified as Expression
import Parse.Pattern qualified as Pattern
import Parse.Primitives qualified as P
import Repl (Input (Help))
import Reporting.Error.Syntax (Expr (ExpressionBadEnd))
import Reporting.Error.Syntax qualified as Error.Syntax
import Test.Hspec (Spec, describe, it)
import Test.Hspec qualified as Hspec
spec :: Spec
spec = do
@ -17,12 +22,12 @@ spec = do
it "regression test" $
parse
"normal string"
"\"\"\"normal string\"\"\""
"\"\"\"\nnormal string\"\"\""
it "mixing quotes work" $ do
parse
"string with \" in it"
"\"\"\"string with \" in it\"\"\""
"\"\"\"\nstring with \" in it\"\"\""
it "first newline, and leading whitespace, is dropped" $ do
parse
@ -39,6 +44,11 @@ spec = do
"this is\\na test"
"\"\"\"\n this is\n a test\n\"\"\""
it "does not allow non-newline characters on the first line" $ do
let isCorrectError ((Error.Syntax.String Error.Syntax.StringMultilineWithoutLeadingNewline _ _)) = True
isCorrectError _ = False
Helpers.checkParseError Expression.expression ExpressionBadEnd isCorrectError "\"\"\"this is not allowed\"\"\""
parse :: String -> BS.ByteString -> IO ()
parse expectedStr =
let isExpectedString :: Src.Pattern_ -> Bool