|
|
@ -58,29 +58,38 @@ func TestMircPost(t *testing.T) { |
|
|
|
func TestMircPostErrors(t *testing.T) { |
|
|
|
table := []struct { |
|
|
|
Input string |
|
|
|
Err error |
|
|
|
Err string |
|
|
|
}{ |
|
|
|
{"[12:34] <Stuff> Things said.", nil}, |
|
|
|
{"[12:34] >Stuff> Things said.", parsers.ErrNotPost}, |
|
|
|
{"12:34] <Stuff> Things said.", parsers.ErrNotPost}, |
|
|
|
{"* Stuff Things said.", parsers.ErrNotPost}, |
|
|
|
{"", parsers.ErrNotPost}, |
|
|
|
{"[12:34 <Stuff> Things said.", parsers.ErrNotPost}, |
|
|
|
{"[TE:XT] <Stuff> Things said.", parsers.ErrNotPost}, |
|
|
|
{"[10] <Stuff> Things said.", parsers.ErrNotPost}, |
|
|
|
{"[12:34:56:789] <Stuff> Things said.", nil}, |
|
|
|
{"[12:34:56.789] <Stuff> Things said.", parsers.ErrNotPost}, |
|
|
|
{"[12:34] <Stuff>", parsers.ErrNotPost}, |
|
|
|
{"[12:34] * Stuff", parsers.ErrNotPost}, |
|
|
|
{"[12:34] =Scene=", parsers.ErrNotPost}, |
|
|
|
{"[12:34] <=Scene=>", parsers.ErrNotPost}, |
|
|
|
{"[12:34] <Stuff> Things said.", ""}, |
|
|
|
{"[12:34] >Stuff> Things said.", "line is neither action nor text post"}, |
|
|
|
{"12:34] <Stuff> Things said.", "no timestamp"}, |
|
|
|
{"* Stuff Things said.", "no timestamp"}, |
|
|
|
{"", "no timestamp"}, |
|
|
|
{"[12:34 <Stuff> Things said.", "incomplete timestamp"}, |
|
|
|
{"[TE:XT] <Stuff> Things said.", "invalid number in timestamp"}, |
|
|
|
{"[10] <Stuff> Things said.", "invalid timestamp"}, |
|
|
|
{"[12:34:56:789] <Stuff> Things said.", ""}, |
|
|
|
{"[12:34:56.789] <Stuff> Things said.", "invalid number in timestamp"}, |
|
|
|
{"[12:34] <Stuff>", "post is empty"}, |
|
|
|
{"[12:34] * Stuff", "post is empty"}, |
|
|
|
{"[12:34] =Scene=", "line is neither action nor text post"}, |
|
|
|
{"[12:34] <=Scene=>", "post is empty"}, |
|
|
|
} |
|
|
|
|
|
|
|
for i, row := range table { |
|
|
|
t.Run(fmt.Sprintf("Row_%d", i), func(t *testing.T) { |
|
|
|
_, err := parsers.MircPost(row.Input, time.Now(), models.Post{}) |
|
|
|
|
|
|
|
assert.Equal(t, row.Err, err, "Error should match") |
|
|
|
errProblem := "" |
|
|
|
if err != nil { |
|
|
|
if e2, ok := err.(*parsers.ParseError); ok { |
|
|
|
errProblem = e2.Problem |
|
|
|
} else { |
|
|
|
errProblem = err.Error() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
assert.Equal(t, row.Err, errProblem, "Error should match") |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
@ -160,7 +169,7 @@ func TestMircLogErrors(t *testing.T) { |
|
|
|
_, err2 := parsers.MircLog("\n\n\n\n\n[14:57]* Stuff \n\t\r\n", time.Time{}, true) |
|
|
|
|
|
|
|
assert.Equal(t, parsers.ErrEmptyLog, err1) |
|
|
|
assert.Equal(t, parsers.ErrNotPost, err2) |
|
|
|
assert.True(t, parsers.IsParseError(err2)) |
|
|
|
} |
|
|
|
|
|
|
|
func parseDate(t *testing.T, date string) time.Time { |
|
|
|