Skip to content

Commit 82b6846

Browse files
Added URL Origin tests
1 parent e66b580 commit 82b6846

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//
2+
// URLOriginTests.swift
3+
// swift-webpush
4+
//
5+
// Created by Dimitri Bouniol on 2024-12-22.
6+
// Copyright © 2024 Mochi Development, Inc. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import Testing
11+
@testable import WebPush
12+
13+
@Suite struct URLOriginTests {
14+
@Test func httpURLs() {
15+
#expect(URL(string: "http://example.com/subscriber")?.origin == "http://example.com")
16+
#expect(URL(string: "http://example.com/")?.origin == "http://example.com")
17+
#expect(URL(string: "http://example.com")?.origin == "http://example.com")
18+
#expect(URL(string: "HtTp://Example.com/")?.origin == "http://Example.com")
19+
#expect(URL(string: "http://example.com:80/")?.origin == "http://example.com")
20+
#expect(URL(string: "http://example.com:8081/")?.origin == "http://example.com:8081")
21+
#expect(URL(string: "http://example.com:443/")?.origin == "http://example.com:443")
22+
#expect(URL(string: "http://host/")?.origin == "http://host")
23+
#expect(URL(string: "http://user:pass@host/")?.origin == "http://host")
24+
#expect(URL(string: "http://")?.origin == "http://")
25+
#expect(URL(string: "http:///")?.origin == "http://")
26+
#expect(URL(string: "http://じぃ.app/")?.origin == "http://じぃ.app")
27+
#expect(URL(string: "http://xn--m8jyb.app/")?.origin == "http://じぃ.app")
28+
}
29+
30+
@Test func httpsURLs() {
31+
#expect(URL(string: "https://example.com/subscriber")?.origin == "https://example.com")
32+
#expect(URL(string: "https://example.com/")?.origin == "https://example.com")
33+
#expect(URL(string: "https://example.com")?.origin == "https://example.com")
34+
#expect(URL(string: "HtTps://Example.com/")?.origin == "https://Example.com")
35+
#expect(URL(string: "https://example.com:443/")?.origin == "https://example.com")
36+
#expect(URL(string: "https://example.com:4443/")?.origin == "https://example.com:4443")
37+
#expect(URL(string: "https://example.com:80/")?.origin == "https://example.com:80")
38+
#expect(URL(string: "https://host/")?.origin == "https://host")
39+
#expect(URL(string: "https://user:pass@host/")?.origin == "https://host")
40+
#expect(URL(string: "https://")?.origin == "https://")
41+
#expect(URL(string: "https:///")?.origin == "https://")
42+
#expect(URL(string: "https://じぃ.app/")?.origin == "https://じぃ.app")
43+
#expect(URL(string: "https://xn--m8jyb.app/")?.origin == "https://じぃ.app")
44+
}
45+
46+
@Test func otherURLs() {
47+
#expect(URL(string: "file://example.com/subscriber")?.origin == "null")
48+
#expect(URL(string: "ftp://example.com/")?.origin == "null")
49+
#expect(URL(string: "blob:example.com")?.origin == "null")
50+
#expect(URL(string: "mailto:[email protected]")?.origin == "null")
51+
#expect(URL(string: "example.com")?.origin == "null")
52+
#expect(URL(string: "otherFile.html")?.origin == "null")
53+
#expect(URL(string: "/subscriber")?.origin == "null")
54+
}
55+
}

0 commit comments

Comments
 (0)