|
| 1 | +// Copyright 2022 The Gitea Authors. All rights reserved. |
| 2 | +// SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +package pull |
| 5 | + |
| 6 | +import ( |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/stretchr/testify/assert" |
| 10 | +) |
| 11 | + |
| 12 | +func Test_expandDefaultMergeMessage(t *testing.T) { |
| 13 | + type args struct { |
| 14 | + template string |
| 15 | + vars map[string]string |
| 16 | + } |
| 17 | + tests := []struct { |
| 18 | + name string |
| 19 | + args args |
| 20 | + want string |
| 21 | + want1 string |
| 22 | + }{ |
| 23 | + { |
| 24 | + name: "single line", |
| 25 | + args: args{ |
| 26 | + template: "Merge ${PullRequestTitle}", |
| 27 | + vars: map[string]string{ |
| 28 | + "PullRequestTitle": "PullRequestTitle", |
| 29 | + "PullRequestDescription": "Pull\nRequest\nDescription\n", |
| 30 | + }, |
| 31 | + }, |
| 32 | + want: "Merge PullRequestTitle", |
| 33 | + want1: "", |
| 34 | + }, |
| 35 | + { |
| 36 | + name: "multiple lines", |
| 37 | + args: args{ |
| 38 | + template: "Merge ${PullRequestTitle}\nDescription:\n\n${PullRequestDescription}\n", |
| 39 | + vars: map[string]string{ |
| 40 | + "PullRequestTitle": "PullRequestTitle", |
| 41 | + "PullRequestDescription": "Pull\nRequest\nDescription\n", |
| 42 | + }, |
| 43 | + }, |
| 44 | + want: "Merge PullRequestTitle", |
| 45 | + want1: "Description:\n\nPull\nRequest\nDescription\n", |
| 46 | + }, |
| 47 | + { |
| 48 | + name: "leading newlines", |
| 49 | + args: args{ |
| 50 | + template: "\n\n\nMerge ${PullRequestTitle}\n\n\nDescription:\n\n${PullRequestDescription}\n", |
| 51 | + vars: map[string]string{ |
| 52 | + "PullRequestTitle": "PullRequestTitle", |
| 53 | + "PullRequestDescription": "Pull\nRequest\nDescription\n", |
| 54 | + }, |
| 55 | + }, |
| 56 | + want: "Merge PullRequestTitle", |
| 57 | + want1: "Description:\n\nPull\nRequest\nDescription\n", |
| 58 | + }, |
| 59 | + } |
| 60 | + for _, tt := range tests { |
| 61 | + t.Run(tt.name, func(t *testing.T) { |
| 62 | + got, got1 := expandDefaultMergeMessage(tt.args.template, tt.args.vars) |
| 63 | + assert.Equalf(t, tt.want, got, "expandDefaultMergeMessage(%v, %v)", tt.args.template, tt.args.vars) |
| 64 | + assert.Equalf(t, tt.want1, got1, "expandDefaultMergeMessage(%v, %v)", tt.args.template, tt.args.vars) |
| 65 | + }) |
| 66 | + } |
| 67 | +} |
0 commit comments