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