parse only action from subject

This commit is contained in:
Erik Winter 2021-02-01 14:20:41 +01:00
parent 44ce94acd7
commit edc8c85fef
2 changed files with 5 additions and 65 deletions

View File

@ -305,22 +305,11 @@ func FieldFromBody(field, body string) (string, bool) {
func FieldFromSubject(field, subject string) string {
// TODO there are also subjects with date and without project
terms := strings.Split(subject, SUBJECT_SEPARATOR)
switch field {
case FIELD_ACTION:
return lowerAndTrim(terms[len(terms)-1])
case FIELD_PROJECT:
if len(terms) < 2 {
return ""
}
return lowerAndTrim(terms[len(terms)-2])
case FIELD_DUE:
if len(terms) < 3 {
return ""
}
return lowerAndTrim(terms[len(terms)-3])
if field != FIELD_ACTION {
return ""
}
return ""
terms := strings.Split(subject, SUBJECT_SEPARATOR)
return lowerAndTrim(terms[len(terms)-1])
}

View File

@ -184,22 +184,6 @@ project: %s
Project: project,
},
},
{
name: "project from subject if not present in body",
message: &mstore.Message{
Folder: task.FOLDER_PLANNED,
Subject: fmt.Sprintf("%s - %s", project, action),
Body: fmt.Sprintf(`id: %s`, id),
},
hasId: true,
exp: &task.Task{
Id: id,
Folder: task.FOLDER_PLANNED,
Action: action,
Project: project,
Dirty: true,
},
},
{
name: "quoted fields",
message: &mstore.Message{
@ -488,39 +472,6 @@ func TestFieldFromSubject(t *testing.T) {
subject: subjectThree,
exp: action,
},
{
name: "project with one",
field: task.FIELD_PROJECT,
subject: subjectOne,
},
{
name: "project with with two",
field: task.FIELD_PROJECT,
subject: subjectTwo,
exp: project,
},
{
name: "project with three",
field: task.FIELD_PROJECT,
subject: subjectThree,
exp: project,
},
{
name: "due with one",
field: task.FIELD_DUE,
subject: subjectOne,
},
{
name: "due with with two",
field: task.FIELD_DUE,
subject: subjectTwo,
},
{
name: "due with three",
field: task.FIELD_DUE,
subject: subjectThree,
exp: due,
},
} {
t.Run(tc.name, func(t *testing.T) {
test.Equals(t, tc.exp, task.FieldFromSubject(tc.field, tc.subject))