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.

util_render_test.go 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package templates
  4. import (
  5. "context"
  6. "html/template"
  7. "testing"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. func TestRenderCommitBody(t *testing.T) {
  11. type args struct {
  12. ctx context.Context
  13. msg string
  14. urlPrefix string
  15. metas map[string]string
  16. }
  17. tests := []struct {
  18. name string
  19. args args
  20. want template.HTML
  21. }{
  22. {
  23. name: "multiple lines",
  24. args: args{
  25. ctx: context.Background(),
  26. msg: "first line\nsecond line",
  27. },
  28. want: "second line",
  29. },
  30. {
  31. name: "multiple lines with leading newlines",
  32. args: args{
  33. ctx: context.Background(),
  34. msg: "\n\n\n\nfirst line\nsecond line",
  35. },
  36. want: "second line",
  37. },
  38. {
  39. name: "multiple lines with trailing newlines",
  40. args: args{
  41. ctx: context.Background(),
  42. msg: "first line\nsecond line\n\n\n",
  43. },
  44. want: "second line",
  45. },
  46. }
  47. for _, tt := range tests {
  48. t.Run(tt.name, func(t *testing.T) {
  49. assert.Equalf(t, tt.want, RenderCommitBody(tt.args.ctx, tt.args.msg, tt.args.urlPrefix, tt.args.metas), "RenderCommitBody(%v, %v, %v, %v)", tt.args.ctx, tt.args.msg, tt.args.urlPrefix, tt.args.metas)
  50. })
  51. }
  52. }