mirror of
				https://gitea.com/gitea/tea.git
				synced 2025-10-31 01:05:26 +01:00 
			
		
		
		
	refactor: optimize PR title generation and expand test coverage (#549)
- Import "regexp" package in pull_create.go - Replace existing code for `GetDefaultPRTitle` with a more efficient regular expression approach - Add a new test file pull_create_test.go with a test function for `GetDefaultPRTitle` Signed-off-by: appleboy <appleboy.tw@gmail.com> Reviewed-on: https://gitea.com/gitea/tea/pulls/549 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: techknowlogick <techknowlogick@noreply.gitea.io> Co-authored-by: appleboy <appleboy.tw@gmail.com> Co-committed-by: appleboy <appleboy.tw@gmail.com>
This commit is contained in:
		
							
								
								
									
										28
									
								
								modules/task/pull_create_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								modules/task/pull_create_test.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,28 @@ | ||||
| // Copyright 2023 The Gitea Authors. All rights reserved. | ||||
| // Use of this source code is governed by a MIT-style | ||||
| // license that can be found in the LICENSE file. | ||||
|  | ||||
| package task | ||||
|  | ||||
| import "testing" | ||||
|  | ||||
| func TestGetDefaultPRTitle(t *testing.T) { | ||||
| 	tests := []struct { | ||||
| 		input string | ||||
| 		want  string | ||||
| 	}{ | ||||
| 		{input: "Add new feature", want: "Add New Feature"}, | ||||
| 		{input: "update-docs: Fix typo", want: "Fix Typo"}, | ||||
| 		{input: "remove_long-string", want: "Remove Long String"}, | ||||
| 		{input: "Replace_Underscores_With_Spaces", want: "Replace Underscores With Spaces"}, | ||||
| 		{input: "  leading-and-trailing-spaces ", want: "Leading And Trailing Spaces"}, | ||||
| 		{input: "-----No--Upper--Case-----", want: "No Upper Case"}, | ||||
| 		{input: "", want: ""}, | ||||
| 	} | ||||
| 	for _, test := range tests { | ||||
| 		got := GetDefaultPRTitle(test.input) | ||||
| 		if got != test.want { | ||||
| 			t.Errorf("GetDefaultPRTitle(%q) = %q, want %q", test.input, got, test.want) | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 appleboy
					appleboy