1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
package command
import (
"bytes"
"testing"
"github.com/ProtonMail/gluon/rfcparser"
"github.com/stretchr/testify/require"
)
func TestParser_UIDCommandCopy(t *testing.T) {
input := toIMAPLine(`tag UID COPY 1:* INBOX`)
s := rfcparser.NewScanner(bytes.NewReader(input))
p := NewParser(s)
expected := Command{
Tag: "tag",
Payload: &UID{
Command: &Copy{
Mailbox: "INBOX",
SeqSet: []SeqRange{{Begin: 1, End: SeqNumValueAsterisk}},
},
},
}
cmd, err := p.Parse()
require.NoError(t, err)
require.Equal(t, expected, cmd)
require.Equal(t, "uid", p.LastParsedCommand())
require.Equal(t, "tag", p.LastParsedTag())
}
func TestParser_UIDCommandMove(t *testing.T) {
expected := Command{
Tag: "tag",
Payload: &UID{
Command: &Move{
Mailbox: "INBOX",
SeqSet: []SeqRange{{Begin: 1, End: SeqNumValueAsterisk}},
},
},
}
cmd, err := testParseCommand(`tag UID MOVE 1:* INBOX`)
require.NoError(t, err)
require.Equal(t, expected, cmd)
}
func TestParser_UIDCommandStore(t *testing.T) {
expected := Command{
Tag: "tag",
Payload: &UID{
Command: &Store{
SeqSet: []SeqRange{{
Begin: 1,
End: 1,
}},
Action: StoreActionAddFlags,
Flags: []string{"Foo", "Bar"},
Silent: true,
},
},
}
cmd, err := testParseCommand(`tag UID STORE 1 +FLAGS.SILENT (Foo Bar)`)
require.NoError(t, err)
require.Equal(t, expected, cmd)
}
func TestParser_UIDCommandExpunge(t *testing.T) {
expected := Command{
Tag: "tag",
Payload: &UIDExpunge{
SeqSet: []SeqRange{{Begin: 1, End: SeqNumValueAsterisk}},
},
}
cmd, err := testParseCommand(`tag UID EXPUNGE 1:*`)
require.NoError(t, err)
require.Equal(t, expected, cmd)
}
func TestParser_UIDCommandFetch(t *testing.T) {
expected := Command{
Tag: "tag",
Payload: &UID{
Command: &Fetch{
SeqSet: []SeqRange{{Begin: 1, End: 1}},
Attributes: []FetchAttribute{
&FetchAttributeFast{},
},
},
},
}
cmd, err := testParseCommand(`tag UID FETCH 1 FAST`)
require.NoError(t, err)
require.Equal(t, expected, cmd)
}
func TestParser_UIDCommandSearch(t *testing.T) {
expected := Command{
Tag: "tag",
Payload: &UID{
Command: &Search{
Charset: "",
Keys: []SearchKey{
&SearchKeyAnswered{},
},
},
},
}
cmd, err := testParseCommand(`tag UID SEARCH ANSWERED`)
require.NoError(t, err)
require.Equal(t, expected, cmd)
}
func TestParser_UIDCommandInvalid(t *testing.T) {
_, err := testParseCommand(`tag UID LIST`)
require.Error(t, err)
}
|