|
| 1 | +/* |
| 2 | + * Copyright 2017, OpenRemote Inc. |
| 3 | + * |
| 4 | + * See the CONTRIBUTORS.txt file in the distribution for a |
| 5 | + * full listing of individual contributors. |
| 6 | + * |
| 7 | + * This program is free software: you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU Affero General Public License as |
| 9 | + * published by the Free Software Foundation, either version 3 of the |
| 10 | + * License, or (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU Affero General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU Affero General Public License |
| 18 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | + */ |
| 20 | + |
| 21 | +import Testing |
| 22 | +@testable import ORLib |
| 23 | + |
| 24 | +struct StringUtilsTest { |
| 25 | + |
| 26 | + @Test func fqdnWithScheme() async throws { |
| 27 | + #expect("http://www.example.com".buildBaseUrlFromDomain() == "http://www.example.com") |
| 28 | + #expect("https://www.example.com".buildBaseUrlFromDomain() == "https://www.example.com") |
| 29 | + } |
| 30 | + |
| 31 | + @Test func fqdnWithNonWebScheme() async throws { |
| 32 | + #expect("ftp://www.example.com".buildBaseUrlFromDomain() == "ftp://www.example.com") |
| 33 | + } |
| 34 | + |
| 35 | + @Test func fqdnNoScheme() async throws { |
| 36 | + #expect("www.example.com".buildBaseUrlFromDomain() == "https://www.example.com") |
| 37 | + } |
| 38 | + |
| 39 | + @Test func fqdnAndPortWithScheme() async throws { |
| 40 | + #expect("http://www.example.com:8080".buildBaseUrlFromDomain() == "http://www.example.com:8080") |
| 41 | + #expect("https://www.example.com:443".buildBaseUrlFromDomain() == "https://www.example.com:443") |
| 42 | + } |
| 43 | + |
| 44 | + @Test func fqdnAndPortWithNonWebScheme() async throws { |
| 45 | + #expect("ftp://www.example.com:21".buildBaseUrlFromDomain() == "ftp://www.example.com:21") |
| 46 | + } |
| 47 | + |
| 48 | + @Test func fqdnAndPortNoScheme() async throws { |
| 49 | + #expect("www.example.com:8080".buildBaseUrlFromDomain() == "https://www.example.com:8080") |
| 50 | + } |
| 51 | + |
| 52 | + @Test func hostnameNoScheme() async throws { |
| 53 | + #expect("example".buildBaseUrlFromDomain() == "https://example.openremote.app") |
| 54 | + } |
| 55 | + |
| 56 | + @Test func ipAddressWithScheme () async throws { |
| 57 | + #expect("http://192.168.1.1".buildBaseUrlFromDomain() == "http://192.168.1.1") |
| 58 | + } |
| 59 | + |
| 60 | + @Test func ipAddressWithNonWebScheme () async throws { |
| 61 | + #expect("ftp://192.168.1.1".buildBaseUrlFromDomain() == "ftp://192.168.1.1") |
| 62 | + } |
| 63 | + |
| 64 | + @Test func ipAddressAndPortWithScheme () async throws { |
| 65 | + #expect("http://192.168.1.1:8080".buildBaseUrlFromDomain() == "http://192.168.1.1:8080") |
| 66 | + } |
| 67 | + |
| 68 | + @Test func ipAddressAndPortWithNonWebScheme () async throws { |
| 69 | + #expect("ftp://192.168.1.1:25".buildBaseUrlFromDomain() == "ftp://192.168.1.1:25") |
| 70 | + } |
| 71 | + |
| 72 | + @Test func ipAddressAndInvalidPortWithScheme () async throws { |
| 73 | + #expect("http://192.168.1.1:InvalidPort".buildBaseUrlFromDomain() == "http://192.168.1.1:InvalidPort") |
| 74 | + } |
| 75 | + |
| 76 | + @Test func ipAddressNoScheme () async throws { |
| 77 | + #expect("192.168.1.1".buildBaseUrlFromDomain() == "https://192.168.1.1") |
| 78 | + } |
| 79 | + |
| 80 | + @Test func ipAddressAndPortNoScheme () async throws { |
| 81 | + #expect("192.168.1.1:8080".buildBaseUrlFromDomain() == "https://192.168.1.1:8080") |
| 82 | + } |
| 83 | + |
| 84 | + @Test func ipv6AddressWithScheme () async throws { |
| 85 | + #expect("http://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]".buildBaseUrlFromDomain() == "http://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]") |
| 86 | + } |
| 87 | + |
| 88 | + @Test func ipv6AddressAndPortWithScheme () async throws { |
| 89 | + #expect("http://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:8080".buildBaseUrlFromDomain() == "http://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:8080") |
| 90 | + } |
| 91 | + |
| 92 | + @Test func ipv6AddressNoScheme () async throws { |
| 93 | + #expect("2001:0db8:85a3:0000:0000:8a2e:0370:7334".buildBaseUrlFromDomain() == "https://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]") |
| 94 | + #expect("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]".buildBaseUrlFromDomain() == "https://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]") |
| 95 | + } |
| 96 | + |
| 97 | + @Test func ipv6AddressAndPortNoScheme () async throws { |
| 98 | + #expect("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:8080".buildBaseUrlFromDomain() == "https://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:8080") |
| 99 | + } |
| 100 | + |
| 101 | + @Test func ipv6CompressedAddressWithScheme () async throws { |
| 102 | + #expect("http://[2001:db8:85a3::8a2e:370:7334]".buildBaseUrlFromDomain() == "http://[2001:db8:85a3::8a2e:370:7334]") |
| 103 | + } |
| 104 | + |
| 105 | + @Test func ipv6CompressedAddressAndPortWithScheme () async throws { |
| 106 | + #expect("http://[2001:db8:85a3::8a2e:370:7334]:8080".buildBaseUrlFromDomain() == "http://[2001:db8:85a3::8a2e:370:7334]:8080") |
| 107 | + } |
| 108 | + |
| 109 | + @Test func ipv6CompressedAddressNoScheme () async throws { |
| 110 | + #expect("2001:db8:85a3::8a2e:370:7334".buildBaseUrlFromDomain() == "https://[2001:db8:85a3::8a2e:370:7334]") |
| 111 | + #expect("[2001:db8:85a3::8a2e:370:7334]".buildBaseUrlFromDomain() == "https://[2001:db8:85a3::8a2e:370:7334]") |
| 112 | + } |
| 113 | + |
| 114 | + @Test func ipv6CompressedAddressAndPortNoScheme () async throws { |
| 115 | + #expect("[2001:db8:85a3::8a2e:370:7334]:8080".buildBaseUrlFromDomain() == "https://[2001:db8:85a3::8a2e:370:7334]:8080") |
| 116 | + } |
| 117 | + |
| 118 | +} |
0 commit comments