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.3KB

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