From: "Matheus Afonso Martins Moreira via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Matheus Moreira <matheus.a.m.moreira@gmail.com>,
Matheus Afonso Martins Moreira <matheus@matheusmoreira.com>
Subject: [PATCH 13/13] tests: add tests for the new url-parse builtin
Date: Sun, 28 Apr 2024 22:31:01 +0000 [thread overview]
Message-ID: <33e128496b3d250b45a27490fa45d40cb659c3b2.1714343461.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1715.git.git.1714343461.gitgitgadget@gmail.com>
From: Matheus Afonso Martins Moreira <matheus@matheusmoreira.com>
Test git URL parsing, validation and component extraction
on all documented git URL schemes and syntaxes.
Signed-off-by: Matheus Afonso Martins Moreira <matheus@matheusmoreira.com>
---
t/t9904-url-parse.sh | 194 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 194 insertions(+)
create mode 100755 t/t9904-url-parse.sh
diff --git a/t/t9904-url-parse.sh b/t/t9904-url-parse.sh
new file mode 100755
index 00000000000..f147f00591c
--- /dev/null
+++ b/t/t9904-url-parse.sh
@@ -0,0 +1,194 @@
+#!/bin/sh
+#
+# Copyright © 2024 Matheus Afonso Martins Moreira
+#
+
+test_description='git url-parse tests'
+
+. ./test-lib.sh
+
+test_expect_success 'git url-parse -- ssh syntax' '
+ git url-parse "ssh://user@example.com:1234/repository/path" &&
+ git url-parse "ssh://user@example.com/repository/path" &&
+ git url-parse "ssh://example.com:1234/repository/path" &&
+ git url-parse "ssh://example.com/repository/path"
+'
+
+test_expect_success 'git url-parse -- git syntax' '
+ git url-parse "git://example.com:1234/repository/path" &&
+ git url-parse "git://example.com/repository/path"
+'
+
+test_expect_success 'git url-parse -- http syntax' '
+ git url-parse "https://example.com:1234/repository/path" &&
+ git url-parse "https://example.com/repository/path" &&
+ git url-parse "http://example.com:1234/repository/path" &&
+ git url-parse "http://example.com/repository/path"
+'
+
+test_expect_success 'git url-parse -- scp syntax' '
+ git url-parse "user@example.com:/repository/path" &&
+ git url-parse "example.com:/repository/path"
+'
+
+test_expect_success 'git url-parse -- username expansion - ssh syntax' '
+ git url-parse "ssh://user@example.com:1234/~user/repository" &&
+ git url-parse "ssh://user@example.com/~user/repository" &&
+ git url-parse "ssh://example.com:1234/~user/repository" &&
+ git url-parse "ssh://example.com/~user/repository"
+'
+
+test_expect_success 'git url-parse -- username expansion - git syntax' '
+ git url-parse "git://example.com:1234/~user/repository" &&
+ git url-parse "git://example.com/~user/repository"
+'
+
+test_expect_success 'git url-parse -- username expansion - scp syntax' '
+ git url-parse "user@example.com:~user/repository" &&
+ git url-parse "example.com:~user/repository"
+'
+
+test_expect_success 'git url-parse -- file urls' '
+ git url-parse "file:///repository/path" &&
+ git url-parse "file:///" &&
+ git url-parse "file://"
+'
+
+test_expect_success 'git url-parse -c protocol -- ssh syntax' '
+ test ssh = "$(git url-parse -c protocol "ssh://user@example.com:1234/repository/path")" &&
+ test ssh = "$(git url-parse -c protocol "ssh://user@example.com/repository/path")" &&
+ test ssh = "$(git url-parse -c protocol "ssh://example.com:1234/repository/path")" &&
+ test ssh = "$(git url-parse -c protocol "ssh://example.com/repository/path")"
+'
+
+test_expect_success 'git url-parse -c protocol -- git syntax' '
+ test git = "$(git url-parse -c protocol "git://example.com:1234/repository/path")" &&
+ test git = "$(git url-parse -c protocol "git://example.com/repository/path")"
+'
+
+test_expect_success 'git url-parse -c protocol -- http syntax' '
+ test https = "$(git url-parse -c protocol "https://example.com:1234/repository/path")" &&
+ test https = "$(git url-parse -c protocol "https://example.com/repository/path")" &&
+ test http = "$(git url-parse -c protocol "http://example.com:1234/repository/path")" &&
+ test http = "$(git url-parse -c protocol "http://example.com/repository/path")"
+'
+
+test_expect_success 'git url-parse -c protocol -- scp syntax' '
+ test ssh = "$(git url-parse -c protocol "user@example.com:/repository/path")" &&
+ test ssh = "$(git url-parse -c protocol "example.com:/repository/path")"
+'
+
+test_expect_success 'git url-parse -c user -- ssh syntax' '
+ test user = "$(git url-parse -c user "ssh://user@example.com:1234/repository/path")" &&
+ test user = "$(git url-parse -c user "ssh://user@example.com/repository/path")" &&
+ test "" = "$(git url-parse -c user "ssh://example.com:1234/repository/path")" &&
+ test "" = "$(git url-parse -c user "ssh://example.com/repository/path")"
+'
+
+test_expect_success 'git url-parse -c user -- git syntax' '
+ test "" = "$(git url-parse -c user "git://example.com:1234/repository/path")" &&
+ test "" = "$(git url-parse -c user "git://example.com/repository/path")"
+'
+
+test_expect_success 'git url-parse -c user -- http syntax' '
+ test "" = "$(git url-parse -c user "https://example.com:1234/repository/path")" &&
+ test "" = "$(git url-parse -c user "https://example.com/repository/path")" &&
+ test "" = "$(git url-parse -c user "http://example.com:1234/repository/path")" &&
+ test "" = "$(git url-parse -c user "http://example.com/repository/path")"
+'
+
+test_expect_success 'git url-parse -c user -- scp syntax' '
+ test user = "$(git url-parse -c user "user@example.com:/repository/path")" &&
+ test "" = "$(git url-parse -c user "example.com:/repository/path")"
+'
+
+test_expect_success 'git url-parse -c host -- ssh syntax' '
+ test example.com = "$(git url-parse -c host "ssh://user@example.com:1234/repository/path")" &&
+ test example.com = "$(git url-parse -c host "ssh://user@example.com/repository/path")" &&
+ test example.com = "$(git url-parse -c host "ssh://example.com:1234/repository/path")" &&
+ test example.com = "$(git url-parse -c host "ssh://example.com/repository/path")"
+'
+
+test_expect_success 'git url-parse -c host -- git syntax' '
+ test example.com = "$(git url-parse -c host "git://example.com:1234/repository/path")" &&
+ test example.com = "$(git url-parse -c host "git://example.com/repository/path")"
+'
+
+test_expect_success 'git url-parse -c host -- http syntax' '
+ test example.com = "$(git url-parse -c host "https://example.com:1234/repository/path")" &&
+ test example.com = "$(git url-parse -c host "https://example.com/repository/path")" &&
+ test example.com = "$(git url-parse -c host "http://example.com:1234/repository/path")" &&
+ test example.com = "$(git url-parse -c host "http://example.com/repository/path")"
+'
+
+test_expect_success 'git url-parse -c host -- scp syntax' '
+ test example.com = "$(git url-parse -c host "user@example.com:/repository/path")" &&
+ test example.com = "$(git url-parse -c host "example.com:/repository/path")"
+'
+
+test_expect_success 'git url-parse -c port -- ssh syntax' '
+ test 1234 = "$(git url-parse -c port "ssh://user@example.com:1234/repository/path")" &&
+ test "" = "$(git url-parse -c port "ssh://user@example.com/repository/path")" &&
+ test 1234 = "$(git url-parse -c port "ssh://example.com:1234/repository/path")" &&
+ test "" = "$(git url-parse -c port "ssh://example.com/repository/path")"
+'
+
+test_expect_success 'git url-parse -c port -- git syntax' '
+ test 1234 = "$(git url-parse -c port "git://example.com:1234/repository/path")" &&
+ test "" = "$(git url-parse -c port "git://example.com/repository/path")"
+'
+
+test_expect_success 'git url-parse -c port -- http syntax' '
+ test 1234 = "$(git url-parse -c port "https://example.com:1234/repository/path")" &&
+ test "" = "$(git url-parse -c port "https://example.com/repository/path")" &&
+ test 1234 = "$(git url-parse -c port "http://example.com:1234/repository/path")" &&
+ test "" = "$(git url-parse -c port "http://example.com/repository/path")"
+'
+
+test_expect_success 'git url-parse -c port -- scp syntax' '
+ test "" = "$(git url-parse -c port "user@example.com:/repository/path")" &&
+ test "" = "$(git url-parse -c port "example.com:/repository/path")"
+'
+
+test_expect_success 'git url-parse -c path -- ssh syntax' '
+ test "/repository/path" = "$(git url-parse -c path "ssh://user@example.com:1234/repository/path")" &&
+ test "/repository/path" = "$(git url-parse -c path "ssh://user@example.com/repository/path")" &&
+ test "/repository/path" = "$(git url-parse -c path "ssh://example.com:1234/repository/path")" &&
+ test "/repository/path" = "$(git url-parse -c path "ssh://example.com/repository/path")"
+'
+
+test_expect_success 'git url-parse -c path -- git syntax' '
+ test "/repository/path" = "$(git url-parse -c path "git://example.com:1234/repository/path")" &&
+ test "/repository/path" = "$(git url-parse -c path "git://example.com/repository/path")"
+'
+
+test_expect_success 'git url-parse -c path -- http syntax' '
+ test "/repository/path" = "$(git url-parse -c path "https://example.com:1234/repository/path")" &&
+ test "/repository/path" = "$(git url-parse -c path "https://example.com/repository/path")" &&
+ test "/repository/path" = "$(git url-parse -c path "http://example.com:1234/repository/path")" &&
+ test "/repository/path" = "$(git url-parse -c path "http://example.com/repository/path")"
+'
+
+test_expect_success 'git url-parse -c path -- scp syntax' '
+ test "/repository/path" = "$(git url-parse -c path "user@example.com:/repository/path")" &&
+ test "/repository/path" = "$(git url-parse -c path "example.com:/repository/path")"
+'
+
+test_expect_success 'git url-parse -c path -- username expansion - ssh syntax' '
+ test "~user/repository" = "$(git url-parse -c path "ssh://user@example.com:1234/~user/repository")" &&
+ test "~user/repository" = "$(git url-parse -c path "ssh://user@example.com/~user/repository")" &&
+ test "~user/repository" = "$(git url-parse -c path "ssh://example.com:1234/~user/repository")" &&
+ test "~user/repository" = "$(git url-parse -c path "ssh://example.com/~user/repository")"
+'
+
+test_expect_success 'git url-parse -c path -- username expansion - git syntax' '
+ test "~user/repository" = "$(git url-parse -c path "git://example.com:1234/~user/repository")" &&
+ test "~user/repository" = "$(git url-parse -c path "git://example.com/~user/repository")"
+'
+
+test_expect_success 'git url-parse -c path -- username expansion - scp syntax' '
+ test "~user/repository" = "$(git url-parse -c path "user@example.com:~user/repository")" &&
+ test "~user/repository" = "$(git url-parse -c path "example.com:~user/repository")"
+'
+
+test_done
--
gitgitgadget
next prev parent reply other threads:[~2024-04-28 22:31 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-28 22:30 [PATCH 00/13] builtin: implement, document and test url-parse Matheus Moreira via GitGitGadget
2024-04-28 22:30 ` [PATCH 01/13] url: move helper function to URL header and source Matheus Afonso Martins Moreira via GitGitGadget
2024-04-28 22:30 ` [PATCH 02/13] urlmatch: define url_parse function Matheus Afonso Martins Moreira via GitGitGadget
2024-05-01 22:18 ` Ghanshyam Thakkar
2024-05-02 4:02 ` Torsten Bögershausen
2024-04-28 22:30 ` [PATCH 03/13] builtin: create url-parse command Matheus Afonso Martins Moreira via GitGitGadget
2024-04-28 22:30 ` [PATCH 04/13] url-parse: add URL parsing helper function Matheus Afonso Martins Moreira via GitGitGadget
2024-04-28 22:30 ` [PATCH 05/13] url-parse: enumerate possible URL components Matheus Afonso Martins Moreira via GitGitGadget
2024-04-28 22:30 ` [PATCH 06/13] url-parse: define component extraction helper fn Matheus Afonso Martins Moreira via GitGitGadget
2024-04-28 22:30 ` [PATCH 07/13] url-parse: define string to component converter fn Matheus Afonso Martins Moreira via GitGitGadget
2024-04-28 22:30 ` [PATCH 08/13] url-parse: define usage and options Matheus Afonso Martins Moreira via GitGitGadget
2024-04-28 22:30 ` [PATCH 09/13] url-parse: parse options given on the command line Matheus Afonso Martins Moreira via GitGitGadget
2024-04-28 22:30 ` [PATCH 10/13] url-parse: validate all given git URLs Matheus Afonso Martins Moreira via GitGitGadget
2024-04-28 22:30 ` [PATCH 11/13] url-parse: output URL components selected by user Matheus Afonso Martins Moreira via GitGitGadget
2024-04-28 22:31 ` [PATCH 12/13] Documentation: describe the url-parse builtin Matheus Afonso Martins Moreira via GitGitGadget
2024-04-30 7:37 ` Ghanshyam Thakkar
2024-04-28 22:31 ` Matheus Afonso Martins Moreira via GitGitGadget [this message]
2024-04-29 20:53 ` [PATCH 00/13] builtin: implement, document and test url-parse Torsten Bögershausen
2024-04-29 22:04 ` Reply to community feedback Matheus Afonso Martins Moreira
2024-04-30 6:51 ` Torsten Bögershausen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=33e128496b3d250b45a27490fa45d40cb659c3b2.1714343461.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=matheus.a.m.moreira@gmail.com \
--cc=matheus@matheusmoreira.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).