package email

import (
	"reflect"
	"testing"
)

func TestInfo(t *testing.T) {
	datum := []struct {
		input string
		want  Info
		clean string // Expected result from .String(), empty defaults to input.
	}{
		{
			input: "mail:2,PRSTDF",
			want: Info{
				Base:    "mail",
				Passed:  true,
				Replied: true,
				Seen:    true,
				Trashed: true,
				Draft:   true,
				Flagged: true,
			},
		},
		{
			input: "mail:2,PRTDF",
			want: Info{
				Base:    "mail",
				Passed:  true,
				Replied: true,
				Seen:    false,
				Trashed: true,
				Draft:   true,
				Flagged: true,
			},
		},
		{
			input: "mail:2,PRSTD",
			want: Info{
				Base:    "mail",
				Passed:  true,
				Replied: true,
				Seen:    true,
				Trashed: true,
				Draft:   true,
				Flagged: false,
			},
		},
		{
			input: "mail:2,RSTDF",
			want: Info{
				Base:    "mail",
				Passed:  false,
				Replied: true,
				Seen:    true,
				Trashed: true,
				Draft:   true,
				Flagged: true,
			},
		},
		{
			input: "mail",
			want: Info{
				Base: "mail",
			},
		},
		{
			input: "mail:2,",
			want: Info{
				Base: "mail",
			},
			clean: "mail",
		},
	}

	for i, d := range datum {
		got := NewInfo(d.input)
		if !reflect.DeepEqual(d.want, got) {
			t.Errorf("%d. Got %#v want %#v", i, got, d.want)
		}

		expected := d.input
		if d.clean != "" {
			expected = d.clean
		}
		if gotStr := got.String(); gotStr != expected {
			t.Errorf("%d. Got %q want %q", i, gotStr, expected)
		}
	}
}
