From ecb10ed62fdff179e34f82b0ff2569da8390f4ad Mon Sep 17 00:00:00 2001 From: Saturnino Abril Date: Sat, 22 Apr 2017 21:52:03 +0900 Subject: APIv4 DELETE /users/{user_id}/posts/{post_id}/reactions/name (#6117) * APIv4 DELETE /users/{user_id}/posts/{post_id}/reactions/name * updated v3 deleteReaction endpoint * update parameter of app.DeleteReactionForPost() * update utils.IsValidAlphaNum, add utils.IsValidAlphaNumHyphenUnderscore, and add related tests --- model/utils_test.go | 188 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 188 insertions(+) (limited to 'model/utils_test.go') diff --git a/model/utils_test.go b/model/utils_test.go index e77ce80fb..94ee55aa9 100644 --- a/model/utils_test.go +++ b/model/utils_test.go @@ -137,3 +137,191 @@ func TestParseHashtags(t *testing.T) { } } } + +func TestIsValidAlphaNum(t *testing.T) { + cases := []struct { + Input string + Result bool + }{ + { + Input: "test", + Result: true, + }, + { + Input: "test-name", + Result: true, + }, + { + Input: "test--name", + Result: true, + }, + { + Input: "test__name", + Result: true, + }, + { + Input: "-", + Result: false, + }, + { + Input: "__", + Result: false, + }, + { + Input: "test-", + Result: false, + }, + { + Input: "test--", + Result: false, + }, + { + Input: "test__", + Result: false, + }, + { + Input: "test:name", + Result: false, + }, + } + + for _, tc := range cases { + actual := IsValidAlphaNum(tc.Input) + if actual != tc.Result { + t.Fatalf("case: %v\tshould returned: %#v", tc, tc.Result) + } + } +} + +func TestIsValidAlphaNumHyphenUnderscore(t *testing.T) { + casesWithFormat := []struct { + Input string + Result bool + }{ + { + Input: "test", + Result: true, + }, + { + Input: "test-name", + Result: true, + }, + { + Input: "test--name", + Result: true, + }, + { + Input: "test__name", + Result: true, + }, + { + Input: "test_name", + Result: true, + }, + { + Input: "test_-name", + Result: true, + }, + { + Input: "-", + Result: false, + }, + { + Input: "__", + Result: false, + }, + { + Input: "test-", + Result: false, + }, + { + Input: "test--", + Result: false, + }, + { + Input: "test__", + Result: false, + }, + { + Input: "test:name", + Result: false, + }, + } + + for _, tc := range casesWithFormat { + actual := IsValidAlphaNumHyphenUnderscore(tc.Input, true) + if actual != tc.Result { + t.Fatalf("case: %v\tshould returned: %#v", tc, tc.Result) + } + } + + casesWithoutFormat := []struct { + Input string + Result bool + }{ + { + Input: "test", + Result: true, + }, + { + Input: "test-name", + Result: true, + }, + { + Input: "test--name", + Result: true, + }, + { + Input: "test__name", + Result: true, + }, + { + Input: "test_name", + Result: true, + }, + { + Input: "test_-name", + Result: true, + }, + { + Input: "-", + Result: true, + }, + { + Input: "_", + Result: true, + }, + { + Input: "test-", + Result: true, + }, + { + Input: "test--", + Result: true, + }, + { + Input: "test__", + Result: true, + }, + { + Input: ".", + Result: false, + }, + + { + Input: "test,", + Result: false, + }, + { + Input: "test:name", + Result: false, + }, + } + + for _, tc := range casesWithoutFormat { + actual := IsValidAlphaNumHyphenUnderscore(tc.Input, false) + if actual != tc.Result { + t.Fatalf("case: '%v'\tshould returned: %#v", tc.Input, tc.Result) + } + } +} -- cgit v1.2.3-1-g7c22