File tree Expand file tree Collapse file tree
tests/src/Test/Compiler/Parse Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -404,6 +404,7 @@ whenBranchLoopParser : Array AST.WhenBranch -> Parser Context Error (Parser.Step
404404whenBranchLoopParser branches =
405405 Parser.oneOf
406406 [ Parser.succeed (\branch -> Parser.Loop (Array.pushLast branch branches))
407+ |> Parser.skip (Parser.mapError (\_ -> IndentError) Space.checkIndent)
407408 |> Parser.keep whenBranchParser
408409 , Parser.succeed (Parser.Done branches)
409410 ]
Original file line number Diff line number Diff line change @@ -309,7 +309,7 @@ tests =
309309 , exports = AST.Open
310310 , docs = Nothing
311311 , imports = []
312- , values =
312+ , values =
313313 [ SourcePosition.at
314314 { row = 3, col = 1 }
315315 { row = 4, col = 9 }
@@ -498,8 +498,214 @@ tests =
498498 }
499499 ]
500500 }
501- ]
501+ , test "Declaration after when expression" <| \_ ->
502+ Parser.run PM.parser Context.empty
503+ """
504+ module Test exposing (..)
505+
506+ foo : Int -> String
507+ foo n =
508+ when n is
509+ 0 -> "Zero"
510+ 1 -> "One"
511+ _ -> "Other"
502512
513+ bar : Int -> String
514+ bar n =
515+ String.fromInt n
516+ """
517+ |> expect
518+ { name =
519+ SourcePosition.at
520+ { row = 1, col = 8 }
521+ { row = 1, col = 12 }
522+ "Test"
523+ , exports = AST.Open
524+ , docs = Nothing
525+ , imports = []
526+ , aliases = []
527+ , binops = []
528+ , unions = []
529+ , effects = AST.NoEffects
530+ , values =
531+ [ SourcePosition.at
532+ { row = 3, col = 1 }
533+ { row = 8, col = 21 }
534+ { docs = Nothing
535+ , value =
536+ { name =
537+ SourcePosition.at
538+ { row = 3, col = 1 }
539+ { row = 3, col = 4 }
540+ "foo"
541+ , signature =
542+ Just
543+ (SourcePosition.at
544+ { row = 3, col = 7 }
545+ { row = 3, col = 20 }
546+ (AST.TLambda
547+ { from =
548+ SourcePosition.at
549+ { row = 3, col = 7 }
550+ { row = 3, col = 10 }
551+ (AST.TType
552+ { name =
553+ SourcePosition.at
554+ { row = 3, col = 7 }
555+ { row = 3, col = 10 }
556+ "Int"
557+ , args = []
558+ }
559+ )
560+ , to =
561+ SourcePosition.at
562+ { row = 3, col = 14 }
563+ { row = 3, col = 20 }
564+ (AST.TType
565+ { name =
566+ SourcePosition.at
567+ { row = 3, col = 14 }
568+ { row = 3, col = 20 }
569+ "String"
570+ , args = []
571+ }
572+ )
573+ }
574+ )
575+ )
576+ , args =
577+ [ SourcePosition.at
578+ { row = 4, col = 5 }
579+ { row = 4, col = 6 }
580+ (AST.PVar "n")
581+ ]
582+ , body =
583+ SourcePosition.at
584+ { row = 5, col = 5 }
585+ { row = 8, col = 21 }
586+ (AST.When
587+ { expression =
588+ SourcePosition.at
589+ { row = 5, col = 10 }
590+ { row = 5, col = 11 }
591+ (AST.Var { name = "n", varType = AST.LowVar })
592+ , branches =
593+ [ { pattern =
594+ SourcePosition.at
595+ { row = 6, col = 9 }
596+ { row = 6, col = 10 }
597+ (AST.PInt { value = 0, isHex = False })
598+ , body =
599+ SourcePosition.at
600+ { row = 6, col = 14 }
601+ { row = 6, col = 20 }
602+ (AST.StringLiteral "Zero")
603+ }
604+ , { pattern =
605+ SourcePosition.at
606+ { row = 7, col = 9 }
607+ { row = 7, col = 10 }
608+ (AST.PInt { value = 1, isHex = False })
609+ , body =
610+ SourcePosition.at
611+ { row = 7, col = 14 }
612+ { row = 7, col = 19 }
613+ (AST.StringLiteral "One")
614+ }
615+ , { pattern =
616+ SourcePosition.at
617+ { row = 8, col = 9 }
618+ { row = 8, col = 10 }
619+ (AST.PAnything "")
620+ , body =
621+ SourcePosition.at
622+ { row = 8, col = 14 }
623+ { row = 8, col = 21 }
624+ (AST.StringLiteral "Other")
625+ }
626+ ]
627+ }
628+ )
629+ }
630+ }
631+ , SourcePosition.at
632+ { row = 10, col = 1 }
633+ { row = 12, col = 21 }
634+ { docs = Nothing
635+ , value =
636+ { name =
637+ SourcePosition.at
638+ { row = 10, col = 1 }
639+ { row = 10, col = 4 }
640+ "bar"
641+ , signature =
642+ Just
643+ (SourcePosition.at
644+ { row = 10, col = 7 }
645+ { row = 10, col = 20 }
646+ (AST.TLambda
647+ { from =
648+ SourcePosition.at
649+ { row = 10, col = 7 }
650+ { row = 10, col = 10 }
651+ (AST.TType
652+ { name =
653+ SourcePosition.at
654+ { row = 10, col = 7 }
655+ { row = 10, col = 10 }
656+ "Int"
657+ , args = []
658+ }
659+ )
660+ , to =
661+ SourcePosition.at
662+ { row = 10, col = 14 }
663+ { row = 10, col = 20 }
664+ (AST.TType
665+ { name =
666+ SourcePosition.at
667+ { row = 10, col = 14 }
668+ { row = 10, col = 20 }
669+ "String"
670+ , args = []
671+ }
672+ )
673+ }
674+ )
675+ )
676+ , args =
677+ [ SourcePosition.at
678+ { row = 11, col = 5 }
679+ { row = 11, col = 6 }
680+ (AST.PVar "n")
681+ ]
682+ , body =
683+ SourcePosition.at
684+ { row = 12, col = 5 }
685+ { row = 12, col = 21 }
686+ (AST.Call
687+ { fn =
688+ SourcePosition.at
689+ { row = 12, col = 5 }
690+ { row = 12, col = 11 }
691+ (AST.Var { name = "String", varType = AST.CapVar })
692+ , args =
693+ [ SourcePosition.at
694+ { row = 12, col = 11 }
695+ { row = 12, col = 19 }
696+ (AST.Accessor "fromInt")
697+ , SourcePosition.at
698+ { row = 12, col = 20 }
699+ { row = 12, col = 21 }
700+ (AST.Var { name = "n", varType = AST.LowVar })
701+ ]
702+ }
703+ )
704+ }
705+ }
706+ ]
707+ }
708+ ]
503709
504710expect : AST.Module -> Result (Array (Parser.DeadEnd c e)) AST.Module -> Expectation
505711expect expected result =
You can’t perform that action at this time.
0 commit comments