GraphQL API and utilities for the rpdata project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.4 KiB

  1. package mirclike_test
  2. import (
  3. "strings"
  4. "testing"
  5. "time"
  6. "github.com/stretchr/testify/assert"
  7. "git.aiterp.net/rpdata/api/internal/importers/mirclike"
  8. "git.aiterp.net/rpdata/api/models"
  9. )
  10. var testLog = strings.Join([]string{
  11. "[11:21] * Va`ynna_Atana returns to the apartment at the end of another long day. She hangs up her jacket and a green scarf next to the door before going straight to the bathroom; she leaves the door open, though. She walked home with Uvena this time, but the two parted ways downstairs.",
  12. "",
  13. "[11:21] <=Scene=> The weather outside is not pleasant in the slightest. The storm is still going on, visibility is reduced and the worst gusts of wind can be felt inside the apartment as a faint shudder. ",
  14. "",
  15. "[11:",
  16. " [11:27] <Test> Stuff and things.",
  17. }, "\r\n")
  18. var testLogPosts = []models.Post{
  19. {
  20. ID: "UNASSIGNED",
  21. LogID: "UNASSIGNED",
  22. Time: parseDate(nil, "2018-05-11 11:21:00"),
  23. Kind: "action",
  24. Nick: "Va`ynna_Atana",
  25. Position: 1,
  26. Text: "returns to the apartment at the end of another long day. She hangs up her jacket and a green scarf next to the door before going straight to the bathroom; she leaves the door open, though. She walked home with Uvena this time, but the two parted ways downstairs.",
  27. },
  28. {
  29. ID: "UNASSIGNED",
  30. LogID: "UNASSIGNED",
  31. Time: parseDate(nil, "2018-05-11 11:21:00"),
  32. Kind: "scene",
  33. Nick: "=Scene=",
  34. Position: 2,
  35. Text: "The weather outside is not pleasant in the slightest. The storm is still going on, visibility is reduced and the worst gusts of wind can be felt inside the apartment as a faint shudder.",
  36. },
  37. {
  38. ID: "UNASSIGNED",
  39. LogID: "UNASSIGNED",
  40. Time: parseDate(nil, "2018-05-11 11:27:00"),
  41. Kind: "text",
  42. Nick: "Test",
  43. Position: 3,
  44. Text: "Stuff and things.",
  45. },
  46. }
  47. func TestParseLog(t *testing.T) {
  48. log, posts, err := mirclike.ParseLog(testLog, parseDate(t, "2018-05-11 00:00:00"), false)
  49. if err != nil {
  50. t.Fatal("ParseLog", err)
  51. }
  52. assert.Equal(t, testLogPosts, posts)
  53. assert.Equal(t, posts[0].Time, log.Date, "Log's date should be the first post's.")
  54. }
  55. func TestParseLogErrors(t *testing.T) {
  56. _, _, err1 := mirclike.ParseLog("\n\n\n\n\n \n\t\r\n", time.Time{}, false)
  57. _, _, err2 := mirclike.ParseLog("\n\n\n\n\n[14:57]* Stuff \n\t\r\n", time.Time{}, true)
  58. assert.Equal(t, mirclike.ErrEmptyLog, err1)
  59. assert.Equal(t, mirclike.ErrNotPost, err2)
  60. }