t8*: adjust the references to the default branch name "main"
[git] / t / helper / test-urlmatch-normalization.c
1 #include "test-tool.h"
2 #include "git-compat-util.h"
3 #include "urlmatch.h"
4
5 int cmd__urlmatch_normalization(int argc, const char **argv)
6 {
7         const char usage[] = "test-tool urlmatch-normalization [-p | -l] <url1> | <url1> <url2>";
8         char *url1, *url2;
9         int opt_p = 0, opt_l = 0;
10
11         /*
12          * For one url, succeed if url_normalize succeeds on it, fail otherwise.
13          * For two urls, succeed only if url_normalize succeeds on both and
14          * the results compare equal with strcmp.  If -p is given (one url only)
15          * and url_normalize succeeds, print the result followed by "\n".  If
16          * -l is given (one url only) and url_normalize succeeds, print the
17          * returned length in decimal followed by "\n".
18          */
19
20         if (argc > 1 && !strcmp(argv[1], "-p")) {
21                 opt_p = 1;
22                 argc--;
23                 argv++;
24         } else if (argc > 1 && !strcmp(argv[1], "-l")) {
25                 opt_l = 1;
26                 argc--;
27                 argv++;
28         }
29
30         if (argc < 2 || argc > 3)
31                 die("%s", usage);
32
33         if (argc == 2) {
34                 struct url_info info;
35                 url1 = url_normalize(argv[1], &info);
36                 if (!url1)
37                         return 1;
38                 if (opt_p)
39                         printf("%s\n", url1);
40                 if (opt_l)
41                         printf("%u\n", (unsigned)info.url_len);
42                 return 0;
43         }
44
45         if (opt_p || opt_l)
46                 die("%s", usage);
47
48         url1 = url_normalize(argv[1], NULL);
49         url2 = url_normalize(argv[2], NULL);
50         return (url1 && url2 && !strcmp(url1, url2)) ? 0 : 1;
51 }