forked from quoid/userscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserscriptsTests.swift
More file actions
99 lines (86 loc) · 3.78 KB
/
Copy pathUserscriptsTests.swift
File metadata and controls
99 lines (86 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//
// UserscriptsTests.swift
// UserscriptsTests
//
// Created by Justin Wasack on 1/23/22.
// Copyright © 2022 Justin Wasack. All rights reserved.
//
import XCTest
@testable import Userscripts_Extension
class UserscriptsTests: XCTestCase {
override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}
func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
// Any test you write for XCTest can be annotated as throws and async.
// Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
// Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
}
func testStringSanitization() throws {
// given
let strs = [
"String",
"https://something.com/?foo=12",
"I have backslashes \\\\",
".....ok",
":Akneh.,><>dkie:lm",
"..解锁B站大会员番剧、",
"解锁B站大会员番剧、B站视频解析下载;全网VIP视频免费破解去广告;全网音乐直接下载;油管、Facebook等国外视频解析下载;网盘搜索引擎破解无限下载等",
"5CLksm3AAbb2F2F2f----___--+87363&^#%o%3O3",
"Example Userscript Name"
]
// when
var result = [String]()
for str in strs {
let sanitizedString = sanitize(str)
let unsanitizedString = unsanitize(sanitizedString)
result.append(unsanitizedString)
}
// then
XCTAssert(result.elementsEqual(strs))
}
func testEncodedCheck() throws {
let urls = [
"https://greasyfork.org/scripts/416338-redirect-外链跳转/code/redirect%20外链跳转.user.js",
"https://raw.githubusercontent.com/Anarios/return-youtube-dislike/main/Extensions/UserScript/Return%20Youtube%20Dislike.user.js",
"https://cdn.frankerfacez.com/static/ffz_injector.user.js",
"http://www.k21p.com/example.user.js", // add http protocol
"https://greasyfork.org/scripts/416338-redirect-外链跳转/code/redirect 外链跳转.user.js"
]
var result = [String]()
for url in urls {
if isEncoded(url) {
result.append(url)
}
}
// 2 urls already percent encoded
XCTAssert(result.count == 2)
}
func testGetRemoteFileContents() throws {
let urls = [
"https://greasyfork.org/scripts/416338-redirect-外链跳转/code/redirect%20外链跳转.user.js",
"https://greasyfork.org/scripts/416338-redirect-外链跳转/code/redirect 外链跳转.user.js",
"https://raw.githubusercontent.com/Anarios/return-youtube-dislike/main/Extensions/UserScript/Return%20Youtube%20Dislike.user.js",
"https://cdn.frankerfacez.com/static/ffz_injector.user.js",
"http://www.k21p.com/example.user.js" // add http protocol
]
var result = [String]()
for url in urls {
if let contents = getRemoteFileContents(url) {
result.append(contents)
}
}
XCTAssert(result.count == urls.count)
}
func testPerformanceExample() throws {
// This is an example of a performance test case.
measure {
// Put the code you want to measure the time of here.
}
}
}