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.

helper_test.go 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package templates
  4. import (
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestSubjectBodySeparator(t *testing.T) {
  9. test := func(input, subject, body string) {
  10. loc := mailSubjectSplit.FindIndex([]byte(input))
  11. if loc == nil {
  12. assert.Empty(t, subject, "no subject found, but one expected")
  13. assert.Equal(t, body, input)
  14. } else {
  15. assert.Equal(t, subject, input[0:loc[0]])
  16. assert.Equal(t, body, input[loc[1]:])
  17. }
  18. }
  19. test("Simple\n---------------\nCase",
  20. "Simple\n",
  21. "\nCase")
  22. test("Only\nBody",
  23. "",
  24. "Only\nBody")
  25. test("Minimal\n---\nseparator",
  26. "Minimal\n",
  27. "\nseparator")
  28. test("False --- separator",
  29. "",
  30. "False --- separator")
  31. test("False\n--- separator",
  32. "",
  33. "False\n--- separator")
  34. test("False ---\nseparator",
  35. "",
  36. "False ---\nseparator")
  37. test("With extra spaces\n----- \t \nBody",
  38. "With extra spaces\n",
  39. "\nBody")
  40. test("With leading spaces\n -------\nOnly body",
  41. "",
  42. "With leading spaces\n -------\nOnly body")
  43. test("Multiple\n---\n-------\n---\nSeparators",
  44. "Multiple\n",
  45. "\n-------\n---\nSeparators")
  46. test("Insuficient\n--\nSeparators",
  47. "",
  48. "Insuficient\n--\nSeparators")
  49. }