(command.CommandList
  children: [
    (command.ShAssignment
      pairs: [
        (assign_pair
          lhs: (sh_lhs_expr.Name name:test_description)
          op: assign_op.Equal
          rhs: {(SQ <'git mailinfo and git mailsplit test'>)}
          spids: [13]
        )
      ]
    )
    (C {<.>} {<'./test-lib.sh'>})
    (command.ShAssignment
      pairs: [
        (assign_pair
          lhs: (sh_lhs_expr.Name name:DATA)
          op: assign_op.Equal
          rhs: {(DQ ($ Id.VSub_DollarName '$TEST_DIRECTORY') <'/t5100'>)}
          spids: [24]
        )
      ]
    )
    (C {<test_expect_success>} {(SQ <'split sample box'>)} 
      {
        (SQ <'git mailsplit -o. "$DATA/sample.mbox" >last &&\n'> <'\tlast=$(cat last) &&\n'> 
          <'\techo total is $last &&\n'> <'\ttest $(cat last) = 18'>
        )
      }
    )
    (command.ShFunction
      name: check_mailinfo
      body: 
        (BraceGroup
          children: [
            (command.ShAssignment
              pairs: [
                (assign_pair
                  lhs: (sh_lhs_expr.Name name:mail)
                  op: assign_op.Equal
                  rhs: {($ Id.VSub_Number '$1')}
                  spids: [55]
                )
                (assign_pair
                  lhs: (sh_lhs_expr.Name name:opt)
                  op: assign_op.Equal
                  rhs: {($ Id.VSub_Number '$2')}
                  spids: [58]
                )
              ]
            )
            (command.ShAssignment
              pairs: [
                (assign_pair
                  lhs: (sh_lhs_expr.Name name:mo)
                  op: assign_op.Equal
                  rhs: {(DQ ($ Id.VSub_DollarName '$mail') ($ Id.VSub_DollarName '$opt'))}
                  spids: [62]
                )
              ]
            )
            (command.AndOr
              ops: [Id.Op_DAmp Id.Op_DAmp Id.Op_DAmp]
              children: [
                (command.Simple
                  words: [
                    {<git>}
                    {<mailinfo>}
                    {<-u>}
                    {($ Id.VSub_DollarName '$opt')}
                    {(DQ <msg> ($ Id.VSub_DollarName '$mo'))}
                    {(DQ <patch> ($ Id.VSub_DollarName '$mo'))}
                  ]
                  redirects: [
                    (redir
                      op: <Id.Redir_Less '<'>
                      loc: (redir_loc.Fd fd:0)
                      arg: {(DQ ($ Id.VSub_DollarName '$mail'))}
                    )
                    (redir
                      op: <Id.Redir_Great '>'>
                      loc: (redir_loc.Fd fd:1)
                      arg: {(DQ <info> ($ Id.VSub_DollarName '$mo'))}
                    )
                  ]
                  do_fork: T
                )
                (C {<test_cmp>} 
                  {(DQ ($ Id.VSub_DollarName '$DATA') <'/msg'> ($ Id.VSub_DollarName '$mo'))} {(DQ <msg> ($ Id.VSub_DollarName '$mo'))}
                )
                (C {<test_cmp>} 
                  {(DQ ($ Id.VSub_DollarName '$DATA') <'/patch'> ($ Id.VSub_DollarName '$mo'))} {(DQ <patch> ($ Id.VSub_DollarName '$mo'))}
                )
                (C {<test_cmp>} 
                  {(DQ ($ Id.VSub_DollarName '$DATA') <'/info'> ($ Id.VSub_DollarName '$mo'))} {(DQ <info> ($ Id.VSub_DollarName '$mo'))}
                )
              ]
            )
          ]
        )
    )
    (command.ForEach
      iter_name: mail
      iter_words: [{<00> <Id.Lit_Star '*'>}]
      do_arg_iter: F
      body: 
        (command.DoGroup
          children: [
            (C {<test_expect_success>} {(DQ <'mailinfo '> ($ Id.VSub_DollarName '$mail'))} 
              {
                (SQ <'\n'> <'\t\tcheck_mailinfo "$mail" "" &&\n'> 
                  <'\t\tif test -f "$DATA/msg$mail--scissors"\n'> <'\t\tthen\n'> <'\t\t\tcheck_mailinfo "$mail" --scissors\n'> <'\t\tfi &&\n'> 
                  <'\t\tif test -f "$DATA/msg$mail--no-inbody-headers"\n'> <'\t\tthen\n'> <'\t\t\tcheck_mailinfo "$mail" --no-inbody-headers\n'> <'\t\tfi &&\n'> 
                  <'\t\tif test -f "$DATA/msg$mail--message-id"\n'> <'\t\tthen\n'> <'\t\t\tcheck_mailinfo "$mail" --message-id\n'> <'\t\tfi\n'> <'\t'>
                )
              }
            )
          ]
        )
    )
    (C {<test_expect_success>} {(SQ <'split box with rfc2047 samples'>)} 
      {
        (SQ <'mkdir rfc2047 &&\n'> <'\tgit mailsplit -orfc2047 "$DATA/rfc2047-samples.mbox" \\\n'> 
          <'\t  >rfc2047/last &&\n'> <'\tlast=$(cat rfc2047/last) &&\n'> <'\techo total is $last &&\n'> <'\ttest $(cat rfc2047/last) = 11'>
        )
      }
    )
    (command.ForEach
      iter_name: mail
      iter_words: [{<'rfc2047/00'> <Id.Lit_Star '*'>}]
      do_arg_iter: F
      body: 
        (command.DoGroup
          children: [
            (C {<test_expect_success>} {(DQ <'mailinfo '> ($ Id.VSub_DollarName '$mail'))} 
              {
                (SQ <'\n'> 
                  <'\t\tgit mailinfo -u "$mail-msg" "$mail-patch" <"$mail" >"$mail-info" &&\n'> <'\t\techo msg &&\n'> <'\t\ttest_cmp "$DATA/empty" "$mail-msg" &&\n'> <'\t\techo patch &&\n'> 
                  <'\t\ttest_cmp "$DATA/empty" "$mail-patch" &&\n'> <'\t\techo info &&\n'> <'\t\ttest_cmp "$DATA/rfc2047-info-$(basename $mail)" "$mail-info"\n'> <'\t'>
                )
              }
            )
          ]
        )
    )
    (C {<test_expect_success>} {(SQ <'respect NULs'>)} 
      {
        (SQ <'\n'> <'\n'> <'\tgit mailsplit -d3 -o. "$DATA/nul-plain" &&\n'> 
          <'\ttest_cmp "$DATA/nul-plain" 001 &&\n'> <'\t(cat 001 | git mailinfo msg patch) &&\n'> <'\ttest_line_count = 4 patch\n'> <'\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'Preserve NULs out of MIME encoded message'>)} 
      {
        (SQ <'\n'> <'\n'> <'\tgit mailsplit -d5 -o. "$DATA/nul-b64.in" &&\n'> 
          <'\ttest_cmp "$DATA/nul-b64.in" 00001 &&\n'> <'\tgit mailinfo msg patch <00001 &&\n'> <'\ttest_cmp "$DATA/nul-b64.expect" patch\n'> <'\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'mailinfo on from header without name works'>)} 
      {
        (SQ <'\n'> <'\n'> <'\tmkdir info-from &&\n'> 
          <'\tgit mailsplit -oinfo-from "$DATA/info-from.in" &&\n'> <'\ttest_cmp "$DATA/info-from.in" info-from/0001 &&\n'> 
          <'\tgit mailinfo info-from/msg info-from/patch \\\n'> <'\t  <info-from/0001 >info-from/out &&\n'> <'\ttest_cmp "$DATA/info-from.expect" info-from/out\n'> 
          <'\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'mailinfo finds headers after embedded From line'>)} 
      {
        (SQ <'\n'> <'\tmkdir embed-from &&\n'> 
          <'\tgit mailsplit -oembed-from "$DATA/embed-from.in" &&\n'> <'\ttest_cmp "$DATA/embed-from.in" embed-from/0001 &&\n'> 
          <'\tgit mailinfo embed-from/msg embed-from/patch \\\n'> <'\t  <embed-from/0001 >embed-from/out &&\n'> 
          <'\ttest_cmp "$DATA/embed-from.expect" embed-from/out\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'mailinfo on message with quoted >From'>)} 
      {
        (SQ <'\n'> <'\tmkdir quoted-from &&\n'> 
          <'\tgit mailsplit -oquoted-from "$DATA/quoted-from.in" &&\n'> <'\ttest_cmp "$DATA/quoted-from.in" quoted-from/0001 &&\n'> 
          <'\tgit mailinfo quoted-from/msg quoted-from/patch \\\n'> <'\t  <quoted-from/0001 >quoted-from/out &&\n'> 
          <'\ttest_cmp "$DATA/quoted-from.expect" quoted-from/msg\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'mailinfo unescapes with --mboxrd'>)} 
      {
        (SQ <'\n'> <'\tmkdir mboxrd &&\n'> <'\tgit mailsplit -omboxrd --mboxrd \\\n'> 
          <'\t\t"$DATA/sample.mboxrd" >last &&\n'> <'\ttest x"$(cat last)" = x2 &&\n'> <'\tfor i in 0001 0002\n'> <'\tdo\n'> 
          <'\t\tgit mailinfo mboxrd/msg mboxrd/patch \\\n'> <'\t\t  <mboxrd/$i >mboxrd/out &&\n'> <'\t\ttest_cmp "$DATA/${i}mboxrd" mboxrd/msg\n'> <'\tdone &&\n'> 
          <'\tsp=" " &&\n'> <'\techo "From " >expect &&\n'> <'\techo "From " >>expect &&\n'> <'\techo >> expect &&\n'> 
          <'\tcat >sp <<-INPUT_END &&\n'> <'\tFrom mboxrd Mon Sep 17 00:00:00 2001\n'> <'\tFrom: trailing spacer <sp@example.com>\n'> 
          <'\tSubject: [PATCH] a commit with trailing space\n'> <'\n'> <'\tFrom$sp\n'> <'\t>From$sp\n'> <'\n'> <'\tINPUT_END\n'> <'\n'> 
          <'\tgit mailsplit -f2 -omboxrd --mboxrd <sp >last &&\n'> <'\ttest x"$(cat last)" = x1 &&\n'> <'\tgit mailinfo mboxrd/msg mboxrd/patch <mboxrd/0003 &&\n'> 
          <'\ttest_cmp expect mboxrd/msg\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'mailinfo handles rfc2822 quoted-string'>)} 
      {
        (SQ <'\n'> <'\tmkdir quoted-string &&\n'> 
          <'\tgit mailinfo /dev/null /dev/null <"$DATA/quoted-string.in" \\\n'> <'\t\t>quoted-string/info &&\n'> <'\ttest_cmp "$DATA/quoted-string.expect" quoted-string/info\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'mailinfo handles rfc2822 comment'>)} 
      {
        (SQ <'\n'> <'\tmkdir comment &&\n'> 
          <'\tgit mailinfo /dev/null /dev/null <"$DATA/comment.in" \\\n'> <'\t\t>comment/info &&\n'> <'\ttest_cmp "$DATA/comment.expect" comment/info\n'>
        )
      }
    )
    (C {<test_done>})
  ]
)