================================================================================
Case without branches followed by newline
================================================================================

-- Works in v4.5.0
update msg =
    case msg of

--------------------------------------------------------------------------------

(file
  (line_comment)
  (ERROR
    (function_declaration_left
      (lower_case_identifier)
      (lower_pattern
        (lower_case_identifier)))
    (eq)
    (case)
    (value_expr
      (value_qid
        (lower_case_identifier)))
    (of)))

================================================================================
Case without branches directly on file end without comment before update - Hangs in v4.5.0
================================================================================

update msg =
    case msg of
--------------------------------------------------------------------------------

(file
  (ERROR
    (function_declaration_left
      (lower_case_identifier)
      (lower_pattern
        (lower_case_identifier)))
    (eq)
    (case)
    (value_expr
      (value_qid
        (lower_case_identifier)))
    (of)))

================================================================================
Case without branches directly on file end with comment before update
================================================================================

-- Works in v4.5.0
update msg =
    case msg of
--------------------------------------------------------------------------------

(file
  (line_comment)
  (ERROR
    (function_declaration_left
      (lower_case_identifier)
      (lower_pattern
        (lower_case_identifier)))
    (eq)
    (case)
    (value_expr
      (value_qid
        (lower_case_identifier)))
    (of)))

================================================================================
Case without branches leading with one line comment at file end
================================================================================

-- Hangs in v4.5.0
update msg =
    -- one line comment
    case msg of
--------------------------------------------------------------------------------

(file
  (line_comment)
  (ERROR
    (function_declaration_left
      (lower_case_identifier)
      (lower_pattern
        (lower_case_identifier)))
    (eq)
    (line_comment)
    (case)
    (value_expr
      (value_qid
        (lower_case_identifier)))
    (of)))

================================================================================
Case without branches leading with one line comment + newline
================================================================================

-- Works in v4.5.0
update msg =
    -- one line comment
    case msg of

--------------------------------------------------------------------------------

(file
  (line_comment)
  (ERROR
    (function_declaration_left
      (lower_case_identifier)
      (lower_pattern
        (lower_case_identifier)))
    (eq)
    (line_comment)
    (case)
    (value_expr
      (value_qid
        (lower_case_identifier)))
    (of)))

================================================================================
Case without branches followed by new line + space + comment
================================================================================

-- Hangs in v4.5.0
update msg =
    case msg of
 -- Need to use a comment with leading space, because testsuite is removing trailing spaces
--------------------------------------------------------------------------------

(file
  (line_comment)
  (ERROR
    (function_declaration_left
      (lower_case_identifier)
      (lower_pattern
        (lower_case_identifier)))
    (eq)
    (case)
    (value_expr
      (value_qid
        (lower_case_identifier)))
    (of))
  (line_comment))

================================================================================
Case without branches followed by new line + without space + last line comment
================================================================================

-- Works in v4.5.0
update msg =
    case msg of
        -- With the comment in the last line, now you can have as much
        -- spaces as you want!
-- Workaround: Add an one line comment without leading space at the end of file
--------------------------------------------------------------------------------

(file
  (line_comment)
  (ERROR
    (function_declaration_left
      (lower_case_identifier)
      (lower_pattern
        (lower_case_identifier)))
    (eq)
    (case)
    (value_expr
      (value_qid
        (lower_case_identifier)))
    (of))
  (line_comment)
  (line_comment)
  (line_comment))

================================================================================
Case followed by comment: not fully indented
================================================================================

-- Wrong in v4.5.0
-- The comment is not indented, it should not be inside the case
update msg =
    case msg of
        Ok _ ->
            "Ok!"

        Err _ ->
            "Error!"

-- This comment should not be part of the case block
--------------------------------------------------------------------------------

(file
  (line_comment)
  (line_comment)
  (value_declaration
    (function_declaration_left
      (lower_case_identifier)
      (lower_pattern
        (lower_case_identifier)))
    (eq)
    (case_of_expr
      (case)
      (value_expr
        (value_qid
          (lower_case_identifier)))
      (of)
      (case_of_branch
        (pattern
          (union_pattern
            (upper_case_qid
              (upper_case_identifier))
            (anything_pattern
              (underscore))))
        (arrow)
        (string_constant_expr
          (open_quote)
          (regular_string_part)
          (close_quote)))
      (case_of_branch
        (pattern
          (union_pattern
            (upper_case_qid
              (upper_case_identifier))
            (anything_pattern
              (underscore))))
        (arrow)
        (string_constant_expr
          (open_quote)
          (regular_string_part)
          (close_quote)))))
  (line_comment))

================================================================================
Case followed by comment: indented as sibling
================================================================================

-- Wrong in v4.5.0
update msg =
    case msg of
        Ok _ ->
            "Ok!"

        Err _ ->
            "Error!"

    -- This comment is a sibling to the case and part of the update function.
    -- I know, that elm-format will format it to a toplevel comment again.
--------------------------------------------------------------------------------

(file
  (line_comment)
  (value_declaration
    (function_declaration_left
      (lower_case_identifier)
      (lower_pattern
        (lower_case_identifier)))
    (eq)
    (case_of_expr
      (case)
      (value_expr
        (value_qid
          (lower_case_identifier)))
      (of)
      (case_of_branch
        (pattern
          (union_pattern
            (upper_case_qid
              (upper_case_identifier))
            (anything_pattern
              (underscore))))
        (arrow)
        (string_constant_expr
          (open_quote)
          (regular_string_part)
          (close_quote)))
      (case_of_branch
        (pattern
          (union_pattern
            (upper_case_qid
              (upper_case_identifier))
            (anything_pattern
              (underscore))))
        (arrow)
        (string_constant_expr
          (open_quote)
          (regular_string_part)
          (close_quote)))))
  (line_comment)
  (line_comment))

================================================================================
Case followed by comment: indented inside case
================================================================================

-- Correct in v4.5.0
update msg =
    case msg of
        Ok _ ->
            "Ok!"

        Err _ ->
            "Error!"

        -- This comment is a sibling to the branches and part of the case block.
        -- I know, that elm-format will format it to a toplevel comment again.
--------------------------------------------------------------------------------

(file
  (line_comment)
  (value_declaration
    (function_declaration_left
      (lower_case_identifier)
      (lower_pattern
        (lower_case_identifier)))
    (eq)
    (case_of_expr
      (case)
      (value_expr
        (value_qid
          (lower_case_identifier)))
      (of)
      (case_of_branch
        (pattern
          (union_pattern
            (upper_case_qid
              (upper_case_identifier))
            (anything_pattern
              (underscore))))
        (arrow)
        (string_constant_expr
          (open_quote)
          (regular_string_part)
          (close_quote)))
      (case_of_branch
        (pattern
          (union_pattern
            (upper_case_qid
              (upper_case_identifier))
            (anything_pattern
              (underscore))))
        (arrow)
        (string_constant_expr
          (open_quote)
          (regular_string_part)
          (close_quote)))
      (line_comment)
      (line_comment))))

================================================================================
Case followed by comment: indented inside case branch
================================================================================

-- Maybe wrong in v4.5.0
-- Currently it is inside the string_constant_expr, but i think it should be
-- a sibling to it. Maybe i am wrong in this case.
update msg =
    case msg of
        Ok _ ->
            "Ok!"

        Err _ ->
            "Error!"

            -- This comment is a sibling to the branch result and part of the Err branch.
            -- I know, that elm-format will format it to a toplevel comment again.
--------------------------------------------------------------------------------

(file
  (line_comment)
  (line_comment)
  (line_comment)
  (value_declaration
    (function_declaration_left
      (lower_case_identifier)
      (lower_pattern
        (lower_case_identifier)))
    (eq)
    (case_of_expr
      (case)
      (value_expr
        (value_qid
          (lower_case_identifier)))
      (of)
      (case_of_branch
        (pattern
          (union_pattern
            (upper_case_qid
              (upper_case_identifier))
            (anything_pattern
              (underscore))))
        (arrow)
        (string_constant_expr
          (open_quote)
          (regular_string_part)
          (close_quote)))
      (case_of_branch
        (pattern
          (union_pattern
            (upper_case_qid
              (upper_case_identifier))
            (anything_pattern
              (underscore))))
        (arrow)
        (string_constant_expr
          (open_quote)
          (regular_string_part)
          (close_quote)))
      (line_comment)
      (line_comment))))
