built-in add -i: accept open-ended ranges again
[git/debian.git] / t / helper / test-urlmatch-normalization.c
blob8f4d67e646953c5b094b55ec8112f6ba3b9b9024
1 #include "test-tool.h"
2 #include "git-compat-util.h"
3 #include "urlmatch.h"
5 int cmd__urlmatch_normalization(int argc, const char **argv)
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;
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".
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++;
30 if (argc < 2 || argc > 3)
31 die("%s", usage);
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;
45 if (opt_p || opt_l)
46 die("%s", usage);
48 url1 = url_normalize(argv[1], NULL);
49 url2 = url_normalize(argv[2], NULL);
50 return (url1 && url2 && !strcmp(url1, url2)) ? 0 : 1;