feat: Rename parse_uri.sh to uri.sh

This commit is contained in:
ge 2022-05-14 01:07:01 +03:00
parent efd493bc3f
commit 68b4def813
3 changed files with 24 additions and 23 deletions

View File

@ -15,7 +15,7 @@ help:
@echo 'tests run tests from $(tests_dir)' @echo 'tests run tests from $(tests_dir)'
@echo 'docs build documentation from $(docs_dir)' @echo 'docs build documentation from $(docs_dir)'
@echo @echo
@echo See README.rst for more info @echo See README.rst for more info.
tests: tests:
# See bats(1), https://bats-core.readthedocs.io/en/latest/index.html # See bats(1), https://bats-core.readthedocs.io/en/latest/index.html

View File

@ -1,6 +1,6 @@
#! /usr/bin/env bash #! /usr/bin/env bash
# parse_uri.sh - URI parser function (mostly compatible with RFC3986). # uri.sh - URI processing functions.
# Copyright (c) 2022 ge <https://nixhacks.net/> # Copyright (c) 2022 ge <https://nixhacks.net/>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
@ -18,7 +18,8 @@
parse_uri() { parse_uri() {
# Universal URI parser. There is fantastic shitcode, but it works. # Universal URI parser. There is fantastic shitcode, but it works.
# Refer RFC3986: https://datatracker.ietf.org/doc/html/rfc3986 # This parser is mostly compatible with RFC3986:
# https://datatracker.ietf.org/doc/html/rfc3986
# URL-encoded passwords supported. # URL-encoded passwords supported.
# #
# Usage: parse_uri URI # Usage: parse_uri URI

View File

@ -1,6 +1,6 @@
#! /usr/bin/env bats #! /usr/bin/env bats
# lib/parse_uri.sh tests. # parse_uri() from lib/uri.sh tests.
# See: https://bats-core.readthedocs.io/en/latest/index.html # See: https://bats-core.readthedocs.io/en/latest/index.html
setup() { setup() {
@ -16,7 +16,7 @@ setup() {
# ------------------------------ # # ------------------------------ #
@test "Test file:/" { @test "Test file:/" {
. parse_uri.sh . uri.sh
parse_uri 'file:/' parse_uri 'file:/'
[ "$scheme" == 'file' ] [ "$scheme" == 'file' ]
[ "$hostname" == '' ] [ "$hostname" == '' ]
@ -29,7 +29,7 @@ setup() {
} }
@test "Test file:/path" { @test "Test file:/path" {
. parse_uri.sh . uri.sh
parse_uri 'file:/path' parse_uri 'file:/path'
[ "$scheme" == 'file' ] [ "$scheme" == 'file' ]
[ "$hostname" == '' ] [ "$hostname" == '' ]
@ -42,7 +42,7 @@ setup() {
} }
@test "Test file:///" { @test "Test file:///" {
. parse_uri.sh . uri.sh
parse_uri 'file:///' parse_uri 'file:///'
[ "$scheme" == 'file' ] [ "$scheme" == 'file' ]
[ "$hostname" == '' ] [ "$hostname" == '' ]
@ -55,7 +55,7 @@ setup() {
} }
@test "Test sqlite:///path" { @test "Test sqlite:///path" {
. parse_uri.sh . uri.sh
parse_uri 'sqlite:///path' parse_uri 'sqlite:///path'
[ "$scheme" == 'sqlite' ] [ "$scheme" == 'sqlite' ]
[ "$hostname" == '' ] [ "$hostname" == '' ]
@ -68,7 +68,7 @@ setup() {
} }
@test "Test file://host" { @test "Test file://host" {
. parse_uri.sh . uri.sh
parse_uri 'file://host' parse_uri 'file://host'
[ "$scheme" == 'file' ] [ "$scheme" == 'file' ]
[ "$hostname" == 'host' ] [ "$hostname" == 'host' ]
@ -81,7 +81,7 @@ setup() {
} }
@test "Test s3://host/path" { @test "Test s3://host/path" {
. parse_uri.sh . uri.sh
parse_uri 's3://host/path' parse_uri 's3://host/path'
[ "$scheme" == 's3' ] [ "$scheme" == 's3' ]
[ "$hostname" == 'host' ] [ "$hostname" == 'host' ]
@ -94,7 +94,7 @@ setup() {
} }
@test "Test dav://user@host/" { @test "Test dav://user@host/" {
. parse_uri.sh . uri.sh
parse_uri 'dav://user@host/' parse_uri 'dav://user@host/'
[ "$scheme" == 'dav' ] [ "$scheme" == 'dav' ]
[ "$hostname" == 'host' ] [ "$hostname" == 'host' ]
@ -107,7 +107,7 @@ setup() {
} }
@test "Test dav://user:p%40%24%24w0rD@host/path/" { @test "Test dav://user:p%40%24%24w0rD@host/path/" {
. parse_uri.sh . uri.sh
parse_uri 'dav://user:p%40%24%24w0rD@host/path/' parse_uri 'dav://user:p%40%24%24w0rD@host/path/'
[ "$scheme" == 'dav' ] [ "$scheme" == 'dav' ]
[ "$hostname" == 'host' ] [ "$hostname" == 'host' ]
@ -120,7 +120,7 @@ setup() {
} }
@test "Test rsync://user:password@host:~/backups" { @test "Test rsync://user:password@host:~/backups" {
. parse_uri.sh . uri.sh
parse_uri 'rsync://user:password@host:~/backups' parse_uri 'rsync://user:password@host:~/backups'
[ "$scheme" == 'rsync' ] [ "$scheme" == 'rsync' ]
[ "$hostname" == 'host' ] [ "$hostname" == 'host' ]
@ -133,7 +133,7 @@ setup() {
} }
@test "Test postgres://user:password@host:5432" { @test "Test postgres://user:password@host:5432" {
. parse_uri.sh . uri.sh
parse_uri 'postgres://user:password@host:5432' parse_uri 'postgres://user:password@host:5432'
[ "$scheme" == 'postgres' ] [ "$scheme" == 'postgres' ]
[ "$hostname" == 'host' ] [ "$hostname" == 'host' ]
@ -146,7 +146,7 @@ setup() {
} }
@test "Test http://user:password@host:port/path?q=val" { @test "Test http://user:password@host:port/path?q=val" {
. parse_uri.sh . uri.sh
parse_uri 'scheme://user:password@host:123/path?q=val' parse_uri 'scheme://user:password@host:123/path?q=val'
[ "$scheme" == 'scheme' ] [ "$scheme" == 'scheme' ]
[ "$hostname" == 'host' ] [ "$hostname" == 'host' ]
@ -159,7 +159,7 @@ setup() {
} }
@test "Test ftp://user:%24t%D0%AFo%7C%5C%7C6@[fe80::5054:ff:fe24:382]:2021/srv/" { @test "Test ftp://user:%24t%D0%AFo%7C%5C%7C6@[fe80::5054:ff:fe24:382]:2021/srv/" {
. parse_uri.sh . uri.sh
parse_uri 'ftp://user:%24t%D0%AFo%7C%5C%7C6@[fe80::5054:ff:fe24:382]:2021/srv/' parse_uri 'ftp://user:%24t%D0%AFo%7C%5C%7C6@[fe80::5054:ff:fe24:382]:2021/srv/'
[ "$scheme" == 'ftp' ] [ "$scheme" == 'ftp' ]
[ "$hostname" == '[fe80::5054:ff:fe24:382]' ] [ "$hostname" == '[fe80::5054:ff:fe24:382]' ]
@ -176,7 +176,7 @@ setup() {
# ------------------------------ # # ------------------------------ #
@test "Test https://john.doe@www.example.com:123/forum/questions/?tag=networking&order=newest#top" { @test "Test https://john.doe@www.example.com:123/forum/questions/?tag=networking&order=newest#top" {
. parse_uri.sh . uri.sh
parse_uri 'https://john.doe@www.example.com:123/forum/questions/?tag=networking&order=newest#top' parse_uri 'https://john.doe@www.example.com:123/forum/questions/?tag=networking&order=newest#top'
[ "$scheme" == 'https' ] [ "$scheme" == 'https' ]
[ "$hostname" == 'www.example.com' ] [ "$hostname" == 'www.example.com' ]
@ -189,7 +189,7 @@ setup() {
} }
@test "Test ldap://[2001:db8::7]/c=GB?objectClass?one" { @test "Test ldap://[2001:db8::7]/c=GB?objectClass?one" {
. parse_uri.sh . uri.sh
parse_uri 'ldap://[2001:db8::7]/c=GB?objectClass?one' parse_uri 'ldap://[2001:db8::7]/c=GB?objectClass?one'
[ "$scheme" == 'ldap' ] [ "$scheme" == 'ldap' ]
[ "$hostname" == '[2001:db8::7]' ] [ "$hostname" == '[2001:db8::7]' ]
@ -202,7 +202,7 @@ setup() {
} }
@test "Test mailto:John.Doe@example.com" { @test "Test mailto:John.Doe@example.com" {
. parse_uri.sh . uri.sh
parse_uri 'mailto:John.Doe@example.com' parse_uri 'mailto:John.Doe@example.com'
[ "$scheme" == 'mailto' ] [ "$scheme" == 'mailto' ]
[ "$hostname" == '' ] [ "$hostname" == '' ]
@ -215,7 +215,7 @@ setup() {
} }
@test "Test news:comp.infosystems.www.servers.unix" { @test "Test news:comp.infosystems.www.servers.unix" {
. parse_uri.sh . uri.sh
parse_uri 'news:comp.infosystems.www.servers.unix' parse_uri 'news:comp.infosystems.www.servers.unix'
[ "$scheme" == 'news' ] [ "$scheme" == 'news' ]
[ "$hostname" == '' ] [ "$hostname" == '' ]
@ -228,7 +228,7 @@ setup() {
} }
@test "Test tel:+1-816-555-1212" { @test "Test tel:+1-816-555-1212" {
. parse_uri.sh . uri.sh
parse_uri 'tel:+1-816-555-1212' parse_uri 'tel:+1-816-555-1212'
[ "$scheme" == 'tel' ] [ "$scheme" == 'tel' ]
[ "$hostname" == '' ] [ "$hostname" == '' ]
@ -242,7 +242,7 @@ setup() {
} }
@test "Test telnet://192.0.2.16:80/" { @test "Test telnet://192.0.2.16:80/" {
. parse_uri.sh . uri.sh
parse_uri 'telnet://192.0.2.16:80/' parse_uri 'telnet://192.0.2.16:80/'
[ "$scheme" == 'telnet' ] [ "$scheme" == 'telnet' ]
[ "$hostname" == '192.0.2.16' ] [ "$hostname" == '192.0.2.16' ]
@ -255,7 +255,7 @@ setup() {
} }
@test "Test urn:oasis:names:specification:docbook:dtd:xml:4.1.2" { @test "Test urn:oasis:names:specification:docbook:dtd:xml:4.1.2" {
. parse_uri.sh . uri.sh
parse_uri 'urn:oasis:names:specification:docbook:dtd:xml:4.1.2' parse_uri 'urn:oasis:names:specification:docbook:dtd:xml:4.1.2'
[ "$scheme" == 'urn' ] [ "$scheme" == 'urn' ]
[ "$hostname" == '' ] [ "$hostname" == '' ]